0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CommHeader.h
Go to the documentation of this file.
1 /* -*- c++ -*-
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
29 #ifndef AsyncComm_COMMHEADER_H
30 #define AsyncComm_COMMHEADER_H
31 
32 namespace Hypertable {
33 
40  class CommHeader {
41 
42  public:
43 
44  static const uint8_t PROTOCOL_VERSION = 1;
45 
46  static const size_t FIXED_LENGTH = 38;
47 
50  enum Flags {
51  FLAGS_BIT_REQUEST = 0x0001,
53  FLAGS_BIT_URGENT = 0x0004,
54  FLAGS_BIT_PROFILE = 0x0008,
57  };
58 
61  enum FlagMask {
62  FLAGS_MASK_REQUEST = 0xFFFE,
64  FLAGS_MASK_URGENT = 0xFFFB,
65  FLAGS_MASK_PROFILE = 0xFFF7,
68  };
69 
73  : version(1), header_len(FIXED_LENGTH), alignment(0), flags(0),
74  header_checksum(0), id(0), gid(0), total_len(0),
75  timeout_ms(0), payload_checksum(0), command(0) { }
76 
81  CommHeader(uint64_t cmd, uint32_t timeout=0)
82  : version(1), header_len(FIXED_LENGTH), alignment(0), flags(0),
83  header_checksum(0), id(0), gid(0), total_len(0),
84  timeout_ms(timeout), payload_checksum(0),
85  command(cmd) { }
86 
90  size_t fixed_length() const { return FIXED_LENGTH; }
91 
95  size_t encoded_length() const { return FIXED_LENGTH; }
96 
102  void encode(uint8_t **bufp);
103 
116  void decode(const uint8_t **bufp, size_t *remainp);
117 
121  void set_total_length(uint32_t len) { total_len = len; }
122 
129  flags = req_header.flags;
130  id = req_header.id;
131  gid = req_header.gid;
132  command = req_header.command;
133  total_len = 0;
134  }
135 
136  uint8_t version;
137  uint8_t header_len;
138  uint16_t alignment;
139  uint16_t flags;
140  uint32_t header_checksum;
141  uint32_t id;
142  uint32_t gid;
143  uint32_t total_len;
144  uint32_t timeout_ms;
145  uint32_t payload_checksum;
146  uint64_t command;
147  };
149 }
150 
151 #endif // AsyncComm_COMMHEADER_H
uint32_t header_checksum
Header checksum (computed with this member 0)
Definition: CommHeader.h:140
void initialize_from_request_header(CommHeader &req_header)
Initializes header from req_header.
Definition: CommHeader.h:128
Request should be profiled.
Definition: CommHeader.h:65
uint16_t flags
Flags.
Definition: CommHeader.h:139
void set_total_length(uint32_t len)
Set total length of message (header + payload).
Definition: CommHeader.h:121
Payload checksumming is enabled bit.
Definition: CommHeader.h:67
uint32_t id
Request ID.
Definition: CommHeader.h:141
uint32_t timeout_ms
Request timeout.
Definition: CommHeader.h:144
Request should be profiled.
Definition: CommHeader.h:54
uint16_t alignment
Align payload to this byte offset.
Definition: CommHeader.h:138
static const size_t FIXED_LENGTH
Definition: CommHeader.h:46
uint32_t gid
Group ID (see ApplicationQueue)
Definition: CommHeader.h:142
CommHeader(uint64_t cmd, uint32_t timeout=0)
Constructor taking command number and optional timeout.
Definition: CommHeader.h:81
void decode(const uint8_t **bufp, size_t *remainp)
Decode serialized header at *bufp The bufp pointer is advanced to the address immediately following t...
Definition: CommHeader.cc:58
void encode(uint8_t **bufp)
Encode header to memory pointed to by *bufp.
Definition: CommHeader.cc:39
uint32_t payload_checksum
Payload checksum (currently unused)
Definition: CommHeader.h:145
Flags
Enumeration constants for bits in flags field.
Definition: CommHeader.h:50
uint32_t total_len
Total length of message including header.
Definition: CommHeader.h:143
Payload checksumming is enabled.
Definition: CommHeader.h:56
Hypertable definitions
Header for messages transmitted via AsyncComm.
Definition: CommHeader.h:40
size_t encoded_length() const
Returns encoded length of header.
Definition: CommHeader.h:95
size_t fixed_length() const
Returns fixed length of header.
Definition: CommHeader.h:90
Response should be ignored bit.
Definition: CommHeader.h:63
uint8_t header_len
Length of header.
Definition: CommHeader.h:137
CommHeader()
Default constructor.
Definition: CommHeader.h:72
uint8_t version
Protocol version.
Definition: CommHeader.h:136
static const uint8_t PROTOCOL_VERSION
Definition: CommHeader.h:44
uint64_t command
Request command number.
Definition: CommHeader.h:146
FlagMask
Enumeration constants for flags field bitmaks.
Definition: CommHeader.h:61