gemfire::DataInput Class Reference


Detailed Description

Provide operations for reading primitive data values, byte arrays, strings, Serializable objects from a byte stream.

This class is intentionally not thread safe.

Remarks:
None of the output parameters in the methods below can be NULL unless otherwise noted.

Public Member Functions

void advanceCursor (int32_t offset)
 advance the cursor by given offset
const uint8_t * currentBufferPosition () const
 Get the pointer to current buffer position.
 DataInput (const uint8_t *m_buffer, int32_t len)
 constructor given a pre-allocated byte array with size
int32_t getBytesRead () const
 get the number of bytes read in the buffer
int32_t getBytesRemaining () const
 get the number of bytes remaining to be read in the buffer
void read (int8_t *value)
 Read a signed byte from the DataInput.
void read (uint8_t *value)
 Read an unsigned byte from the DataInput.
void readArrayLen (int32_t *len)
 Read a 32-bit signed integer array length value from the DataInput in a manner compatible with java server's DataSerializer.readArrayLength.
void readASCII (char **value, uint16_t *len=NULL)
 Allocates a c string buffer, and reads an ASCII string having maximum length of 64K from DataInput into it.
void readASCIIHuge (char **value, uint32_t *len=NULL)
 Allocates a c string buffer, and reads an ASCII string from DataInput into it.
void readBoolean (bool *value)
 Read a boolean value from the DataInput.
void readBytes (int8_t **bytes, int32_t *len)
 Read an array of signed bytes from the DataInput expecting to find the length of array in the stream at the start.
void readBytes (uint8_t **bytes, int32_t *len)
 Read an array of unsigned bytes from the DataInput expecting to find the length of array in the stream at the start.
void readBytesOnly (int8_t *buffer, uint32_t len)
 Read the given number of signed bytes from the DataInput.
void readBytesOnly (uint8_t *buffer, uint32_t len)
 Read the given number of unsigned bytes from the DataInput.
void readDouble (double *value)
 Read a double precision number from the DataInput.
void readFloat (float *value)
 Read a float from the DataInput.
void readInt (int64_t *value)
 Read a 64-bit signed integer from the DataInput.
void readInt (int32_t *value)
 Read a 32-bit signed integer from the DataInput.
void readInt (int16_t *value)
 Read a 16-bit signed integer from the DataInput.
void readInt (uint64_t *value)
 Read a 64-bit unsigned integer from the DataInput.
void readInt (uint32_t *value)
 Read a 32-bit unsigned integer from the DataInput.
void readInt (uint16_t *value)
 Read a 16-bit unsigned integer from the DataInput.
void readObject (SerializablePtr &ptr)
 Read a Serializable object from the DataInput.
template<class PTR>
void readObject (SharedPtr< PTR > &ptr, bool throwOnError=false)
 Read a Serializable object from the DataInput.
void readUnsignedVL (int64_t *value)
 Decode a 64 bit integer as a variable length array.
void readUTF (wchar_t **value, uint16_t *len=NULL)
 Allocates a wide-character string buffer, and reads a java modified UTF-8 encoded string having maximum encoded length of 64K from DataInput into it.
void readUTF (char **value, uint16_t *len=NULL)
 Allocates a c string buffer, and reads a java modified UTF-8 encoded string having maximum encoded length of 64K from DataInput into it.
void readUTFHuge (wchar_t **value, uint32_t *len=NULL)
 Allocates a wide-character string buffer, and reads a java modified UTF-8 encoded string from DataInput into it.
void readUTFHuge (char **value, uint32_t *len=NULL)
 Allocates a c string buffer, and reads a java modified UTF-8 encoded string from DataInput into it.
void readUTFNoLen (wchar_t **value, uint16_t decodedLen)
 Reads a java modified UTF-8 encoded string having maximum encoded length of 64K without reading the length which must be passed as a parameter.
void reset ()
 reset the cursor to the start of buffer
void rewindCursor (int32_t offset)
 rewind the cursor by given offset
 ~DataInput ()
 destructor

Static Public Member Functions

static void freeUTFMemory (wchar_t *value)
 free the wide-characted string allocated by readASCII, readASCIIHuge, readUTF, readUTFHuge methods
static void freeUTFMemory (char *value)
 free the C string allocated by readASCII, readASCIIHuge, readUTF, readUTFHuge methods
static int32_t getDecodedLength (const uint8_t *value, int32_t length)
 Get the length required to represent a given UTF-8 encoded string (created using DataOutput::writeUTF or java.io.DataOutput.writeUTF) in wide-character format.

Constructor & Destructor Documentation

gemfire::DataInput::DataInput ( const uint8_t *  m_buffer,
int32_t  len 
) [inline]

constructor given a pre-allocated byte array with size

gemfire::DataInput::~DataInput (  )  [inline]

destructor


Member Function Documentation

void gemfire::DataInput::advanceCursor ( int32_t  offset  )  [inline]

advance the cursor by given offset

const uint8_t* gemfire::DataInput::currentBufferPosition (  )  const [inline]

Get the pointer to current buffer position.

This should be treated as readonly and modification of contents using this internal pointer has undefined behavior.

static void gemfire::DataInput::freeUTFMemory ( wchar_t *  value  )  [inline, static]

free the wide-characted string allocated by readASCII, readASCIIHuge, readUTF, readUTFHuge methods

static void gemfire::DataInput::freeUTFMemory ( char *  value  )  [inline, static]

free the C string allocated by readASCII, readASCIIHuge, readUTF, readUTFHuge methods

int32_t gemfire::DataInput::getBytesRead (  )  const [inline]

get the number of bytes read in the buffer

int32_t gemfire::DataInput::getBytesRemaining (  )  const [inline]

get the number of bytes remaining to be read in the buffer

static int32_t gemfire::DataInput::getDecodedLength ( const uint8_t *  value,
int32_t  length 
) [inline, static]

Get the length required to represent a given UTF-8 encoded string (created using DataOutput::writeUTF or java.io.DataOutput.writeUTF) in wide-character format.

Parameters:
value The UTF-8 encoded stream.
length The length of the stream to be read.
Returns:
The length of the decoded string.
See also:
DataOutput::getEncodedLength

void gemfire::DataInput::read ( int8_t *  value  )  [inline]

Read a signed byte from the DataInput.

Parameters:
value output parameter to hold the signed byte read from stream

void gemfire::DataInput::read ( uint8_t *  value  )  [inline]

Read an unsigned byte from the DataInput.

Parameters:
value output parameter to hold the unsigned byte read from stream

void gemfire::DataInput::readArrayLen ( int32_t *  len  )  [inline]

Read a 32-bit signed integer array length value from the DataInput in a manner compatible with java server's DataSerializer.readArrayLength.

Parameters:
len output parameter to hold the 32-bit signed length read from stream

void gemfire::DataInput::readASCII ( char **  value,
uint16_t *  len = NULL 
) [inline]

Allocates a c string buffer, and reads an ASCII string having maximum length of 64K from DataInput into it.

Remarks:
Sets integer at length to hold the strlen of the string. Value is modified to point to the new allocation. The chars are allocated as an array, so the caller must use freeUTFMemory when done. Like DataOutput::writeASCII the maximum length supported by this method is 64K; use readASCIIHuge or readBytes to read strings of length larger than this.
Parameters:
value output C string to hold the read characters; it is allocated by this method
len output parameter to hold the number of characters read from stream; not set if NULL

void gemfire::DataInput::readASCIIHuge ( char **  value,
uint32_t *  len = NULL 
) [inline]

Allocates a c string buffer, and reads an ASCII string from DataInput into it.

Remarks:
Sets integer at length to hold the strlen of the string. Value is modified to point to the new allocation. The chars are allocated as an array, so the caller must use freeUTFMemory when done. Use this instead of readUTF when reading a string of length greater than 64K.
Parameters:
value output C string to hold the read characters; it is allocated by this method
len output parameter to hold the number of characters read from stream; not set if NULL

void gemfire::DataInput::readBoolean ( bool *  value  )  [inline]

Read a boolean value from the DataInput.

Parameters:
value output parameter to hold the boolean read from stream

void gemfire::DataInput::readBytes ( int8_t **  bytes,
int32_t *  len 
) [inline]

Read an array of signed bytes from the DataInput expecting to find the length of array in the stream at the start.

Remarks:
This method is complimentary to DataOutput::writeBytes.
Parameters:
bytes output array to hold the bytes read from stream; the array is allocated by this method
len output parameter to hold the length of array read from stream

void gemfire::DataInput::readBytes ( uint8_t **  bytes,
int32_t *  len 
) [inline]

Read an array of unsigned bytes from the DataInput expecting to find the length of array in the stream at the start.

Remarks:
This method is complimentary to DataOutput::writeBytes.
Parameters:
bytes output array to hold the bytes read from stream; the array is allocated by this method
len output parameter to hold the length of array read from stream

void gemfire::DataInput::readBytesOnly ( int8_t *  buffer,
uint32_t  len 
) [inline]

Read the given number of signed bytes from the DataInput.

Remarks:
This method is complimentary to DataOutput::writeBytesOnly and, unlike readBytes, does not expect the length of array in the stream.
Parameters:
buffer array to hold the bytes read from stream
len number of signed bytes to be read

void gemfire::DataInput::readBytesOnly ( uint8_t *  buffer,
uint32_t  len 
) [inline]

Read the given number of unsigned bytes from the DataInput.

Remarks:
This method is complimentary to DataOutput::writeBytesOnly and, unlike readBytes, does not expect the length of array in the stream.
Parameters:
buffer array to hold the bytes read from stream
len number of unsigned bytes to be read

void gemfire::DataInput::readDouble ( double *  value  )  [inline]

Read a double precision number from the DataInput.

Parameters:
value output parameter to hold the double precision number read from stream

void gemfire::DataInput::readFloat ( float *  value  )  [inline]

Read a float from the DataInput.

Parameters:
value output parameter to hold the float read from stream

void gemfire::DataInput::readInt ( int64_t *  value  )  [inline]

Read a 64-bit signed integer from the DataInput.

Parameters:
value output parameter to hold the 64-bit signed integer read from stream

void gemfire::DataInput::readInt ( int32_t *  value  )  [inline]

Read a 32-bit signed integer from the DataInput.

Parameters:
value output parameter to hold the 32-bit signed integer read from stream

void gemfire::DataInput::readInt ( int16_t *  value  )  [inline]

Read a 16-bit signed integer from the DataInput.

Parameters:
value output parameter to hold the 16-bit signed integer read from stream

void gemfire::DataInput::readInt ( uint64_t *  value  )  [inline]

Read a 64-bit unsigned integer from the DataInput.

Parameters:
value output parameter to hold the 64-bit unsigned integer read from stream

void gemfire::DataInput::readInt ( uint32_t *  value  )  [inline]

Read a 32-bit unsigned integer from the DataInput.

Parameters:
value output parameter to hold the 32-bit unsigned integer read from stream

void gemfire::DataInput::readInt ( uint16_t *  value  )  [inline]

Read a 16-bit unsigned integer from the DataInput.

Parameters:
value output parameter to hold the 16-bit unsigned integer read from stream

void gemfire::DataInput::readObject ( SerializablePtr ptr  )  [inline]

Read a Serializable object from the DataInput.

Null objects are handled.

template<class PTR>
void gemfire::DataInput::readObject ( SharedPtr< PTR > &  ptr,
bool  throwOnError = false 
) [inline]

Read a Serializable object from the DataInput.

Null objects are handled. This accepts an argument throwOnError that specifies whether to check the type dynamically and throw a ClassCastException when the cast fails.

Parameters:
ptr The object to be read which is output by reference. The type of this must match the type of object that the application expects.
throwOnError Throw a ClassCastException when the type of object does not match ptr. Default is true when GF_DEBUG_ASSERTS macro is set and false in normal case.
Exceptions:
ClassCastException When dynCast fails for the given ptr.
See also:
dynCast

staticCast

void gemfire::DataInput::readUnsignedVL ( int64_t *  value  )  [inline]

Decode a 64 bit integer as a variable length array.

This is taken from the varint encoding in protobufs (BSD licensed). See https://developers.google.com/protocol-buffers/docs/encoding

void gemfire::DataInput::readUTF ( wchar_t **  value,
uint16_t *  len = NULL 
) [inline]

Allocates a wide-character string buffer, and reads a java modified UTF-8 encoded string having maximum encoded length of 64K from DataInput into it.

Remarks:
Sets integer at length to hold the strlen of the string. Value is modified to point to the new allocation. The chars are allocated as an array, so the caller must use freeUTFMemory when done. Like DataOutput::writeUTF the maximum length supported by this method is 64K; use readAUTFHuge to read strings of length larger than this.
Parameters:
value output wide-character string to hold the read characters; it is allocated by this method
len output parameter to hold the number of characters read from stream; not set if NULL

void gemfire::DataInput::readUTF ( char **  value,
uint16_t *  len = NULL 
) [inline]

Allocates a c string buffer, and reads a java modified UTF-8 encoded string having maximum encoded length of 64K from DataInput into it.

Remarks:
Sets integer at length to hold the strlen of the string. Value is modified to point to the new allocation. The chars are allocated as an array, so the caller must use freeUTFMemory when done. Like DataOutput::writeUTF the maximum length supported by this method is 64K; use readAUTFHuge to read strings of length larger than this.
Parameters:
value output C string to hold the read characters; it is allocated by this method
len output parameter to hold the number of characters read from stream; not set if NULL

void gemfire::DataInput::readUTFHuge ( wchar_t **  value,
uint32_t *  len = NULL 
) [inline]

Allocates a wide-character string buffer, and reads a java modified UTF-8 encoded string from DataInput into it.

Remarks:
Sets integer at length to hold the strlen of the string. Value is modified to point to the new allocation. The chars are allocated as an array, so the caller must use freeUTFMemory when done. Use this instead of readUTF when reading a string of length greater than 64K.
Parameters:
value output wide-character string to hold the read characters; it is allocated by this method
len output parameter to hold the number of characters read from stream; not set if NULL

void gemfire::DataInput::readUTFHuge ( char **  value,
uint32_t *  len = NULL 
) [inline]

Allocates a c string buffer, and reads a java modified UTF-8 encoded string from DataInput into it.

Remarks:
Sets integer at length to hold the strlen of the string. Value is modified to point to the new allocation. The chars are allocated as an array, so the caller must use freeUTFMemory when done. Use this instead of readUTF when reading a string of length greater than 64K.
Parameters:
value output C string to hold the read characters; it is allocated by this method
len output parameter to hold the number of characters read from stream; not set if NULL

void gemfire::DataInput::readUTFNoLen ( wchar_t **  value,
uint16_t  decodedLen 
) [inline]

Reads a java modified UTF-8 encoded string having maximum encoded length of 64K without reading the length which must be passed as a parameter.

Allocates a c string buffer, and deserializes into it. Sets integer at length to hold the length of the string. Value is modified to point to the new allocation. The chars are allocated as an array, so the caller must use freeUTFMemory when done. If len == NULL, then the decoded string length is not set.

void gemfire::DataInput::reset (  )  [inline]

reset the cursor to the start of buffer

void gemfire::DataInput::rewindCursor ( int32_t  offset  )  [inline]

rewind the cursor by given offset


GemFire C++ Cache API Documentation