0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Public Attributes | Protected Attributes | Friends | List of all members
Hypertable::CommBuf Class Reference

Message buffer for holding data to be transmitted over a network. More...

#include <CommBuf.h>

Collaboration diagram for Hypertable::CommBuf:
Collaboration graph
[legend]

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
 

Detailed Description

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);

Definition at line 79 of file CommBuf.h.

Constructor & Destructor Documentation

Hypertable::CommBuf::CommBuf ( CommHeader hdr,
uint32_t  len = 0 
)
inline

Constructor.

This constructor initializes the CommBuf object by allocating a primary buffer of length len and writing the header into it. The internal pointer into the primary buffer is positioned to just after the header.

Parameters
hdrComm header
lenLength of the primary buffer to allocate

Definition at line 89 of file CommBuf.h.

Hypertable::CommBuf::CommBuf ( CommHeader hdr,
uint32_t  len,
StaticBuffer 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 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.

Parameters
hdrComm header
lenLength of the primary buffer to allocate
bufferExtended buffer

Definition at line 106 of file CommBuf.h.

Hypertable::CommBuf::CommBuf ( CommHeader hdr,
uint32_t  len,
boost::shared_array< uint8_t > &  ext_buffer,
uint32_t  ext_len 
)
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.

Parameters
hdrComm header
lenLength of the primary buffer to allocate
ext_bufferShared array pointer to extended buffer
ext_lenLength of valid data in ext_buffer

Definition at line 127 of file CommBuf.h.

Member Function Documentation

void* Hypertable::CommBuf::advance_data_ptr ( size_t  len)
inline

Advance the primary buffer internal data pointer by len bytes.

Parameters
lenthe number of bytes to advance the pointer by
Returns
returns the advanced internal data pointer

Definition at line 167 of file CommBuf.h.

void Hypertable::CommBuf::append_bool ( bool  bval)
inline

Appends a boolean value to the primary buffer.

After appending, this method advances the primary buffer internal data pointer by 1

Parameters
bvalBoolean value to append to primary buffer

Definition at line 173 of file CommBuf.h.

void Hypertable::CommBuf::append_byte ( uint8_t  bval)
inline

Appends a byte of data to the primary buffer.

After appending, this method advances the primary buffer internal data pointer by 1

Parameters
bvalbyte value to append into buffer

Definition at line 179 of file CommBuf.h.

void Hypertable::CommBuf::append_bytes ( const uint8_t *  bytes,
uint32_t  len 
)
inline

Appends a sequence of bytes to the primary buffer.

After appending, this method advances the primary buffer internal data pointer by the number of bytes appended

Parameters
bytesStarting address of byte sequence
lenNumber of bytes in sequence

Definition at line 187 of file CommBuf.h.

void Hypertable::CommBuf::append_i16 ( uint16_t  sval)
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.

Parameters
svalTwo-byte short integer to append into buffer

Definition at line 221 of file CommBuf.h.

void Hypertable::CommBuf::append_i32 ( uint32_t  ival)
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.

Parameters
ivalFour-byte integer value to append into buffer

Definition at line 230 of file CommBuf.h.

void Hypertable::CommBuf::append_i64 ( uint64_t  lval)
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.

Parameters
lvalEight-byte long integer value to append into buffer

Definition at line 239 of file CommBuf.h.

void Hypertable::CommBuf::append_inet_addr ( const InetAddr addr)
inline

Appends an InetAddr structure to the primary buffer.

Parameters
addraddress structure
See also
Serialization::encode_inet_addr

Definition at line 281 of file CommBuf.h.

void Hypertable::CommBuf::append_str16 ( const char *  str)
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'.

Parameters
strc-style string to append
See also
Serialization::encode_str16

Definition at line 199 of file CommBuf.h.

void Hypertable::CommBuf::append_str16 ( const String str)
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'.

Parameters
strstd string to append
See also
Serialization::encode_str16

Definition at line 211 of file CommBuf.h.

void Hypertable::CommBuf::append_vstr ( const char *  str)
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'.

Parameters
strC-style string to append
See also
Serialization::encode_vstr

Definition at line 250 of file CommBuf.h.

void Hypertable::CommBuf::append_vstr ( const String str)
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'.

Parameters
strC++ string to append
See also
Serialization::encode_vstr

Definition at line 260 of file CommBuf.h.

void Hypertable::CommBuf::append_vstr ( const void *  str,
uint32_t  len 
)
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').

Parameters
strC-style string to encode
lenLength of string
See also
Serialization::encode_vstr

Definition at line 272 of file CommBuf.h.

void* Hypertable::CommBuf::get_data_ptr ( )
inline

Returns the primary buffer internal data pointer.

Definition at line 156 of file CommBuf.h.

uint8_t** Hypertable::CommBuf::get_data_ptr_address ( )
inline

Returns address of the primary buffer internal data pointer.

Definition at line 160 of file CommBuf.h.

void Hypertable::CommBuf::write_header_and_reset ( )
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.

Definition at line 146 of file CommBuf.h.

Friends And Related Function Documentation

friend class IOHandlerData
friend

Definition at line 285 of file CommBuf.h.

friend class IOHandlerDatagram
friend

Definition at line 286 of file CommBuf.h.

Member Data Documentation

StaticBuffer Hypertable::CommBuf::data

Primary data buffer.

Definition at line 288 of file CommBuf.h.

uint8_t* Hypertable::CommBuf::data_ptr
protected

Write pointer into data buffer.

Definition at line 295 of file CommBuf.h.

StaticBuffer Hypertable::CommBuf::ext

Extended buffer.

Definition at line 289 of file CommBuf.h.

const uint8_t* Hypertable::CommBuf::ext_ptr
protected

Write pointer into ext buffer.

Definition at line 298 of file CommBuf.h.

boost::shared_array<uint8_t> Hypertable::CommBuf::ext_shared_array
protected

Smart pointer to extended buffer memory.

Definition at line 301 of file CommBuf.h.

CommHeader Hypertable::CommBuf::header

Comm header.

Definition at line 290 of file CommBuf.h.


The documentation for this class was generated from the following file: