Message buffer for holding data to be transmitted over a network. More...
#include <CommBuf.h>
Public Member Functions | |
CommBuf (CommHeader &hdr, uint32_t len=0) | |
Constructor. More... | |
CommBuf (CommHeader &hdr, uint32_t len, StaticBuffer &buffer) | |
Constructor. More... | |
CommBuf (CommHeader &hdr, uint32_t len, boost::shared_array< uint8_t > &ext_buffer, uint32_t ext_len) | |
Constructor. More... | |
void | write_header_and_reset () |
Encodes the header at the beginning of the primary buffer. More... | |
void * | get_data_ptr () |
Returns the primary buffer internal data pointer. More... | |
uint8_t ** | get_data_ptr_address () |
Returns address of the primary buffer internal data pointer. More... | |
void * | advance_data_ptr (size_t len) |
Advance the primary buffer internal data pointer by len bytes. More... | |
void | append_bool (bool bval) |
Appends a boolean value to the primary buffer. More... | |
void | append_byte (uint8_t bval) |
Appends a byte of data to the primary buffer. More... | |
void | append_bytes (const uint8_t *bytes, uint32_t len) |
Appends a sequence of bytes to the primary buffer. More... | |
void | append_str16 (const char *str) |
Appends a c-style string to the primary buffer. More... | |
void | append_str16 (const String &str) |
Appends a String to the primary buffer. More... | |
void | append_i16 (uint16_t sval) |
Appends a 16-bit integer to the primary buffer. More... | |
void | append_i32 (uint32_t ival) |
Appends a 32-bit integer to the primary buffer. More... | |
void | append_i64 (uint64_t lval) |
Appends a 64-bit integer to the primary buffer. More... | |
void | append_vstr (const char *str) |
Appends a c-style string to the primary buffer. More... | |
void | append_vstr (const String &str) |
Appends a String to the primary buffer. More... | |
void | append_vstr (const void *str, uint32_t len) |
Appends a variable sized string to the primary buffer. More... | |
void | append_inet_addr (const InetAddr &addr) |
Appends an InetAddr structure to the primary buffer. More... | |
Public Attributes | |
StaticBuffer | data |
Primary data buffer. More... | |
StaticBuffer | ext |
Extended buffer. More... | |
CommHeader | header |
Comm header. More... | |
Protected Attributes | |
uint8_t * | data_ptr |
Write pointer into data buffer. More... | |
const uint8_t * | ext_ptr |
Write pointer into ext buffer. More... | |
boost::shared_array< uint8_t > | ext_shared_array |
Smart pointer to extended buffer memory. More... | |
Friends | |
class | IOHandlerData |
class | IOHandlerDatagram |
Message buffer for holding data to be transmitted over a network.
The CommBuf class contains a primary buffer and an extended buffer along with buffer pointers to keep track of how much data has been written into the buffers. These pointers are managed by the IOHandler while the buffer is being transmitted. The following example illustrates how to build a request message using the CommBuf.
CommHeader header(COMMAND_FETCH_SCANBLOCK); header.gid = scanner_id; CommBuf *cbuf = new CommBuf(header, 4); cbuf->append_i32(scanner_id);
The following is a real world example of a CommBuf being used to send back a response from a read request.
CommHeader header; header.initialize_from_request_header(m_event->header); CommBufPtr cbp(new CommBuf( header, 10, ext)); cbp->append_i32(Error::OK); cbp->append_i16(moreflag); cbp->append_i32(id); error = m_comm->send_response(m_event->addr, cbp);
|
inline |
|
inline |
Constructor.
This constructor initializes the CommBuf object by allocating a primary buffer of length len and writing the header into it. It also sets the extended buffer to ext and takes ownership of it. The total length written into the header is len plus ext.size. The internal pointer into the primary buffer is positioned to just after the header.
hdr | Comm header |
len | Length of the primary buffer to allocate |
buffer | Extended buffer |
|
inline |
Constructor.
This constructor initializes the CommBuf object by allocating a primary buffer of length len and writing the header into it. It also sets the extended buffer to the buffer pointed to by ext_buffer. The total length written into the header is len plus ext_len. The internal pointer into the primary buffer is positioned to just after the header.
hdr | Comm header |
len | Length of the primary buffer to allocate |
ext_buffer | Shared array pointer to extended buffer |
ext_len | Length of valid data in ext_buffer |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Appends a 16-bit integer to the primary buffer.
The integer is encoded in little endian order and the primary buffer internal data pointer is advanced to the position immediately following the encoded integer.
sval | Two-byte short integer to append into buffer |
|
inline |
Appends a 32-bit integer to the primary buffer.
The integer is encoded in little endian order and the primary buffer internal data pointer is advanced to the position immediately following the encoded integer.
ival | Four-byte integer value to append into buffer |
|
inline |
Appends a 64-bit integer to the primary buffer.
The integer is encoded in little endian order and the primary buffer pointer is advanced to the position immediately following the encoded integer.
lval | Eight-byte long integer value to append into buffer |
|
inline |
Appends an InetAddr structure to the primary buffer.
addr | address structure |
|
inline |
Appends a c-style string to the primary buffer.
A string is encoded as a 16-bit length, followed by the characters, followed by a terminating '\0'.
str | c-style string to append |
|
inline |
Appends a String to the primary buffer.
A string is encoded as a 16-bit length, followed by the characters, followed by a terminating '\0'.
str | std string to append |
|
inline |
Appends a c-style string to the primary buffer.
A string is encoded as a vint64 length, followed by the characters, followed by a terminating '\0'.
str | C-style string to append |
|
inline |
Appends a String to the primary buffer.
A string is encoded as a vint64 length, followed by the characters, followed by a terminating '\0'.
str | C++ string to append |
|
inline |
Appends a variable sized string to the primary buffer.
The string is encoded as a vint length, followed by the bytes (followed by a terminating '\0').
str | C-style string to encode |
len | Length of string |
|
inline |
|
inline |
|
inline |
Encodes the header at the beginning of the primary buffer.
This method resets the primary and extended data pointers to point to the beginning of their respective buffers. The AsyncComm layer uses these pointers to track how much data has been sent and what is remaining to be sent.
|
friend |
|
friend |
StaticBuffer Hypertable::CommBuf::data |
|
protected |
StaticBuffer Hypertable::CommBuf::ext |
|
protected |
|
protected |
CommHeader Hypertable::CommBuf::header |