Open Lighting Architecture  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RpcHeader.h
1 /*
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation; either
5  * version 2.1 of the License, or (at your option) any later version.
6  *
7  * This library is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10  * Lesser General Public License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with this library; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  *
16  * RpcHeader.h
17  * The header for the RPC messages.
18  * Copyright (C) 2005-2008 Simon Newton
19  */
20 
21 #ifndef COMMON_RPC_RPCHEADER_H_
22 #define COMMON_RPC_RPCHEADER_H_
23 
24 #include <stdint.h>
25 
26 namespace ola {
27 namespace rpc {
28 
29 class RpcHeader {
30  /*
31  * The first 4 bytes are the header which contains the RPC protocol version
32  * (this is separate from the protobuf version) and the size of the protobuf.
33  */
34  public:
38  static void EncodeHeader(uint32_t *header, unsigned int version,
39  unsigned int size) {
40  *header = (version << 28) & VERSION_MASK;
41  *header |= size & SIZE_MASK;
42  }
43 
47  static void DecodeHeader(uint32_t header, unsigned int *version,
48  unsigned int *size) {
49  *version = (header & VERSION_MASK) >> 28;
50  *size = header & SIZE_MASK;
51  }
52 
53  private:
54  static const unsigned int VERSION_MASK = 0xf0000000;
55  static const unsigned int SIZE_MASK = 0x0fffffff;
56 };
57 } // namespace rpc
58 } // namespace ola
59 #endif // COMMON_RPC_RPCHEADER_H_