CommHeader.h

Go to the documentation of this file.
00001 
00022 #ifndef HYPERTABLE_COMMHEADER_H
00023 #define HYPERTABLE_COMMHEADER_H
00024 
00025 namespace Hypertable {
00026 
00027   class CommHeader {
00028 
00029   public:
00030 
00031     static const uint8_t PROTOCOL_VERSION = 1;
00032 
00033     static const size_t FIXED_LENGTH = 38;
00034 
00035     static const uint16_t FLAGS_BIT_REQUEST          = 0x0001;
00036     static const uint16_t FLAGS_BIT_IGNORE_RESPONSE  = 0x0002;
00037     static const uint16_t FLAGS_BIT_URGENT           = 0x0004;
00038     static const uint16_t FLAGS_BIT_PROXY_MAP_UPDATE = 0x4000;
00039     static const uint16_t FLAGS_BIT_PAYLOAD_CHECKSUM = 0x8000;
00040 
00041     static const uint16_t FLAGS_MASK_REQUEST          = 0xFFFE;
00042     static const uint16_t FLAGS_MASK_IGNORE_RESPONSE  = 0xFFFD;
00043     static const uint16_t FLAGS_MASK_URGENT           = 0xFFFB;
00044     static const uint16_t FLAGS_MASK_PROXY_MAP_UPDATE = 0xBFFF;
00045     static const uint16_t FLAGS_MASK_PAYLOAD_CHECKSUM = 0x7FFF;
00046 
00047     CommHeader()
00048       : version(1), header_len(FIXED_LENGTH), alignment(0), flags(0),
00049         header_checksum(0), id(0), gid(0), total_len(0),
00050         timeout_ms(0), payload_checksum(0), command(0) {  }
00051 
00052     CommHeader(uint64_t cmd, uint32_t timeout=0)
00053       : version(1), header_len(FIXED_LENGTH), alignment(0), flags(0),
00054         header_checksum(0), id(0), gid(0), total_len(0),
00055         timeout_ms(timeout), payload_checksum(0),
00056         command(cmd) {  }
00057 
00058     size_t fixed_length() const { return FIXED_LENGTH; }
00059     size_t encoded_length() const { return FIXED_LENGTH; }
00060     void encode(uint8_t **bufp);
00061     void decode(const uint8_t **bufp, size_t *remainp);
00062 
00063     void set_total_length(uint32_t len) { total_len = len; }
00064 
00065     void initialize_from_request_header(CommHeader &req_header) {
00066       flags = req_header.flags;
00067       id = req_header.id;
00068       gid = req_header.gid;
00069       command = req_header.command;
00070       total_len = 0;
00071     }
00072 
00073     uint8_t version;
00074     uint8_t header_len;
00075     uint16_t alignment;
00076     uint16_t flags;
00077     uint32_t header_checksum;
00078     uint32_t id;
00079     uint32_t gid;
00080     uint32_t total_len;
00081     uint32_t timeout_ms;
00082     uint32_t payload_checksum;
00083     uint64_t command;
00084   };
00085 
00086 }
00087 
00088 #endif // HYPERTABLE_COMMHEADER_H