VMware GemFire Native C++ Reference  9.1
apache::geode::client::DataInput Class Reference

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

Public Member Functions

void advanceCursor (int32_t offset)
 advance the cursor by given offset More...
 
const uint8_t * currentBufferPosition () const
 Get the pointer to current buffer position. More...
 
 DataInput (const uint8_t *m_buffer, int32_t len)
 constructor given a pre-allocated byte array with size More...
 
int32_t getBytesRead () const
 get the number of bytes read in the buffer More...
 
int32_t getBytesRemaining () const
 get the number of bytes remaining to be read in the buffer More...
 
void read (uint8_t *value)
 Read an unsigned byte from the DataInput. More...
 
void read (int8_t *value)
 Read a signed byte from the DataInput. More...
 
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. More...
 
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. More...
 
void readASCIIHuge (char **value, uint32_t *len=NULL)
 Allocates a c string buffer, and reads an ASCII string from DataInput into it. More...
 
void readBoolean (bool *value)
 Read a boolean value from the DataInput. More...
 
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. More...
 
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. More...
 
void readBytesOnly (uint8_t *buffer, uint32_t len)
 Read the given number of unsigned bytes from the DataInput. More...
 
void readBytesOnly (int8_t *buffer, uint32_t len)
 Read the given number of signed bytes from the DataInput. More...
 
void readDouble (double *value)
 Read a double precision number from the DataInput. More...
 
void readFloat (float *value)
 Read a float from the DataInput. More...
 
void readInt (uint16_t *value)
 Read a 16-bit unsigned integer from the DataInput. More...
 
void readInt (uint32_t *value)
 Read a 32-bit unsigned integer from the DataInput. More...
 
void readInt (uint64_t *value)
 Read a 64-bit unsigned integer from the DataInput. More...
 
void readInt (int16_t *value)
 Read a 16-bit signed integer from the DataInput. More...
 
void readInt (int32_t *value)
 Read a 32-bit signed integer from the DataInput. More...
 
void readInt (int64_t *value)
 Read a 64-bit signed integer from the DataInput. More...
 
template<class PTR >
void readObject (SharedPtr< PTR > &ptr, bool throwOnError=false)
 Read a Serializable object from the DataInput. More...
 
void readObject (SerializablePtr &ptr)
 Read a Serializable object from the DataInput. More...
 
void readUnsignedVL (int64_t *value)
 Decode a 64 bit integer as a variable length array. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
void reset ()
 reset the cursor to the start of buffer More...
 
void rewindCursor (int32_t offset)
 rewind the cursor by given offset More...
 
 ~DataInput ()
 destructor More...
 

Static Public Member Functions

static void freeUTFMemory (char *value)
 free the C string allocated by readASCII, readASCIIHuge, readUTF, readUTFHuge methods More...
 
static void freeUTFMemory (wchar_t *value)
 free the wide-characted string allocated by readASCII, readASCIIHuge, readUTF, readUTFHuge methods More...
 
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. More...
 

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.

Constructor & Destructor Documentation

apache::geode::client::DataInput::DataInput ( const uint8_t *  m_buffer,
int32_t  len 
)
inline

constructor given a pre-allocated byte array with size

apache::geode::client::DataInput::~DataInput ( )
inline

destructor

Member Function Documentation

void apache::geode::client::DataInput::advanceCursor ( int32_t  offset)
inline

advance the cursor by given offset

const uint8_t* apache::geode::client::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 apache::geode::client::DataInput::freeUTFMemory ( char *  value)
inlinestatic

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

static void apache::geode::client::DataInput::freeUTFMemory ( wchar_t *  value)
inlinestatic

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

int32_t apache::geode::client::DataInput::getBytesRead ( ) const
inline

get the number of bytes read in the buffer

int32_t apache::geode::client::DataInput::getBytesRemaining ( ) const
inline

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

static int32_t apache::geode::client::DataInput::getDecodedLength ( const uint8_t *  value,
int32_t  length 
)
inlinestatic

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
valueThe UTF-8 encoded stream.
lengthThe length of the stream to be read.
Returns
The length of the decoded string.
See also
DataOutput::getEncodedLength
void apache::geode::client::DataInput::read ( uint8_t *  value)
inline

Read an unsigned byte from the DataInput.

Parameters
valueoutput parameter to hold the unsigned byte read from stream
void apache::geode::client::DataInput::read ( int8_t *  value)
inline

Read a signed byte from the DataInput.

Parameters
valueoutput parameter to hold the signed byte read from stream
void apache::geode::client::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
lenoutput parameter to hold the 32-bit signed length read from stream
void apache::geode::client::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
valueoutput C string to hold the read characters; it is allocated by this method
lenoutput parameter to hold the number of characters read from stream; not set if NULL
void apache::geode::client::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
valueoutput C string to hold the read characters; it is allocated by this method
lenoutput parameter to hold the number of characters read from stream; not set if NULL
void apache::geode::client::DataInput::readBoolean ( bool *  value)
inline

Read a boolean value from the DataInput.

Parameters
valueoutput parameter to hold the boolean read from stream
void apache::geode::client::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
bytesoutput array to hold the bytes read from stream; the array is allocated by this method
lenoutput parameter to hold the length of array read from stream
void apache::geode::client::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
bytesoutput array to hold the bytes read from stream; the array is allocated by this method
lenoutput parameter to hold the length of array read from stream
void apache::geode::client::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
bufferarray to hold the bytes read from stream
lennumber of unsigned bytes to be read
void apache::geode::client::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
bufferarray to hold the bytes read from stream
lennumber of signed bytes to be read
void apache::geode::client::DataInput::readDouble ( double *  value)
inline

Read a double precision number from the DataInput.

Parameters
valueoutput parameter to hold the double precision number read from stream
void apache::geode::client::DataInput::readFloat ( float *  value)
inline

Read a float from the DataInput.

Parameters
valueoutput parameter to hold the float read from stream
void apache::geode::client::DataInput::readInt ( uint16_t *  value)
inline

Read a 16-bit unsigned integer from the DataInput.

Parameters
valueoutput parameter to hold the 16-bit unsigned integer read from stream
void apache::geode::client::DataInput::readInt ( uint32_t *  value)
inline

Read a 32-bit unsigned integer from the DataInput.

Parameters
valueoutput parameter to hold the 32-bit unsigned integer read from stream
void apache::geode::client::DataInput::readInt ( uint64_t *  value)
inline

Read a 64-bit unsigned integer from the DataInput.

Parameters
valueoutput parameter to hold the 64-bit unsigned integer read from stream
void apache::geode::client::DataInput::readInt ( int16_t *  value)
inline

Read a 16-bit signed integer from the DataInput.

Parameters
valueoutput parameter to hold the 16-bit signed integer read from stream
void apache::geode::client::DataInput::readInt ( int32_t *  value)
inline

Read a 32-bit signed integer from the DataInput.

Parameters
valueoutput parameter to hold the 32-bit signed integer read from stream
void apache::geode::client::DataInput::readInt ( int64_t *  value)
inline

Read a 64-bit signed integer from the DataInput.

Parameters
valueoutput parameter to hold the 64-bit signed integer read from stream
template<class PTR >
void apache::geode::client::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
ptrThe object to be read which is output by reference. The type of this must match the type of object that the application expects.
throwOnErrorThrow 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
ClassCastExceptionWhen dynCast fails for the given ptr.
See also
dynCast
staticCast
void apache::geode::client::DataInput::readObject ( SerializablePtr ptr)
inline

Read a Serializable object from the DataInput.

Null objects are handled.

void apache::geode::client::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 apache::geode::client::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
valueoutput C string to hold the read characters; it is allocated by this method
lenoutput parameter to hold the number of characters read from stream; not set if NULL
void apache::geode::client::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
valueoutput wide-character string to hold the read characters; it is allocated by this method
lenoutput parameter to hold the number of characters read from stream; not set if NULL
void apache::geode::client::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
valueoutput C string to hold the read characters; it is allocated by this method
lenoutput parameter to hold the number of characters read from stream; not set if NULL
void apache::geode::client::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
valueoutput wide-character string to hold the read characters; it is allocated by this method
lenoutput parameter to hold the number of characters read from stream; not set if NULL
void apache::geode::client::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 apache::geode::client::DataInput::reset ( )
inline

reset the cursor to the start of buffer

void apache::geode::client::DataInput::rewindCursor ( int32_t  offset)
inline

rewind the cursor by given offset


Pivotal GemFire C++ Cache API Documentation