1 #ifndef __GEMFIRE_DATAINPUT_H__ 2 #define __GEMFIRE_DATAINPUT_H__ 12 #include "gfcpp_globals.hpp" 24 #if GF_DEBUG_ASSERTS == 1 25 #define DINP_THROWONERROR_DEFAULT true 27 #define DINP_THROWONERROR_DEFAULT false 30 #define checkBufferSize(x) _checkBufferSize(x,__LINE__) 35 extern int gf_sprintf(
char* buffer,
const char* fmt, ...);
53 inline void read( uint8_t* value )
64 inline void read( int8_t* value )
78 *value = (*m_buf == 1 ?
true :
false);
96 memcpy( buffer, m_buf, len );
114 checkBufferSize(len);
115 memcpy( buffer, m_buf, len );
133 readArrayLen( &length );
135 uint8_t* buffer = NULL;
137 checkBufferSize(length);
138 GF_NEW( buffer, uint8_t[ length ] );
139 memcpy( buffer, m_buf, length );
158 readArrayLen( &length );
160 int8_t* buffer = NULL;
162 checkBufferSize(length);
163 GF_NEW( buffer, int8_t[ length ] );
164 memcpy( buffer, m_buf, length );
179 uint16_t tmp = *(m_buf++);
180 tmp = (uint16_t)((tmp << 8) | *(m_buf++));
193 uint32_t tmp = *(m_buf++);
194 tmp = (tmp << 8) | *(m_buf++);
195 tmp = (tmp << 8) | *(m_buf++);
196 tmp = (tmp << 8) | *(m_buf++);
210 if (
sizeof(
long ) == 8 ) {
212 tmp = (tmp << 8) | *(m_buf++);
213 tmp = (tmp << 8) | *(m_buf++);
214 tmp = (tmp << 8) | *(m_buf++);
215 tmp = (tmp << 8) | *(m_buf++);
216 tmp = (tmp << 8) | *(m_buf++);
217 tmp = (tmp << 8) | *(m_buf++);
218 tmp = (tmp << 8) | *(m_buf++);
220 uint32_t hword = *(m_buf++);
221 hword = (hword << 8) | *(m_buf++);
222 hword = (hword << 8) | *(m_buf++);
223 hword = (hword << 8) | *(m_buf++);
227 hword = (hword << 8) | *(m_buf++);
228 hword = (hword << 8) | *(m_buf++);
229 hword = (hword << 8) | *(m_buf++);
230 tmp = (tmp << 32) | hword;
244 readInt( (uint16_t*)value );
256 readInt( (uint32_t*)value );
268 readInt( (uint64_t*)value );
286 int32_t result = code;
292 }
else if (code == 0xFD) {
297 throw IllegalStateException(
"unexpected array length code");
317 result |= (int64_t)(b & 0x7F) << shift;
318 if ((b & 0x80) == 0) {
324 throw IllegalStateException(
"Malformed variable length integer");
340 readInt( (uint32_t*)&v.u);
353 union double_uint64_t
358 readInt( (uint64_t*)&v.ll);
397 inline void readASCII(
char** value, uint16_t* len = NULL )
401 checkBufferSize(length);
406 GF_NEW( str,
char[ length + 1 ] );
408 readBytesOnly((int8_t*)str, length);
409 str[ length ] =
'\0';
434 GF_NEW( str,
char[ length + 1 ] );
436 readBytesOnly( (int8_t*)str, length );
437 str[ length ] =
'\0';
456 inline void readUTF(
char** value, uint16_t* len = NULL )
460 checkBufferSize(length);
461 uint16_t decodedLen = (uint16_t)getDecodedLength( m_buf, length );
466 GF_NEW( str,
char[ decodedLen + 1 ] );
468 for( uint16_t i = 0; i < decodedLen; i++ ) {
486 GF_NEW(str,
wchar_t[decodedLen + 1]);
488 for (uint16_t i = 0; i < decodedLen; i++) {
516 GF_NEW( str,
char[ length + 1 ] );
518 for( uint32_t i = 0; i < length; i++ ) {
544 inline void readUTF(
wchar_t** value, uint16_t* len = NULL )
548 checkBufferSize(length);
549 uint16_t decodedLen = (uint16_t)getDecodedLength( m_buf, length );
554 GF_NEW( str,
wchar_t[ decodedLen + 1 ] );
556 for( uint16_t i = 0; i < decodedLen; i++ ) {
584 GF_NEW( str,
wchar_t[ length + 1 ] );
586 for( uint32_t i = 0; i < length; i++ ) {
591 *str = (((uint16_t)hibyte) << 8) | (uint16_t)lobyte;
616 template<
class PTR >
618 bool throwOnError = DINP_THROWONERROR_DEFAULT )
621 readObjectInternal( sPtr );
622 if ( throwOnError ) {
623 ptr = dynCast< SharedPtr<PTR> >( sPtr );
625 ptr = staticCast< SharedPtr<PTR> >( sPtr );
629 inline bool readNativeBool( )
639 inline int32_t readNativeInt32( )
653 int64_t compId = typeId;
654 if (compId == GemfireTypeIds::NullObj) {
657 else if (compId == GemfireTypeIds::CacheableNullString) {
660 else if ( compId == gemfire::GemfireTypeIds::CacheableASCIIString) {
664 else if ( compId == gemfire::GemfireTypeIds::CacheableASCIIStringHuge) {
668 else if ( compId == gemfire::GemfireTypeIds::CacheableString) {
672 else if ( compId == gemfire::GemfireTypeIds::CacheableStringHuge) {
677 LOGDEBUG(
"In readNativeString something is wrong while expecting string");
685 inline void readDirectObject(
SerializablePtr& ptr, int8_t typeId = -1 )
687 readObjectInternal( ptr, typeId );
696 readObjectInternal( ptr );
699 inline void readObject(
wchar_t* value){
702 *value = (wchar_t)temp;
705 inline void readObject(
bool* value){
709 inline void readObject(int8_t* value){
713 inline void readObject(int16_t* value){
717 inline void readObject(int32_t* value){
721 inline void readObject(int64_t* value){
725 inline void readObject(
float* value){
729 inline void readObject(
double* value){
733 inline void readCharArray(
char** value, int32_t& length){
735 readArrayLen(&arrayLen);
737 char* objArray = NULL;
739 objArray =
new char[arrayLen];
741 for( i = 0; i < arrayLen; i++ ){
750 inline void readWideCharArray(
wchar_t** value, int32_t& length){
751 readObject(value, length);
754 inline void readBooleanArray(
bool** value, int32_t& length){
755 readObject(value, length);
758 inline void readByteArray(int8_t** value, int32_t& length){
759 readObject(value, length);
762 inline void readShortArray(int16_t** value, int32_t& length){
763 readObject(value, length);
766 inline void readIntArray(int32_t** value, int32_t& length){
767 readObject(value, length);
770 inline void readLongArray(int64_t** value, int32_t& length){
771 readObject(value, length);
774 inline void readFloatArray(
float** value, int32_t& length){
775 readObject(value, length);
778 inline void readDoubleArray(
double** value, int32_t& length){
779 readObject(value, length);
782 inline void readString(
char** value) {
787 if (typeId == GemfireTypeIds::CacheableNullString){
798 if (typeId == (int8_t)GemfireTypeIds::CacheableASCIIString || typeId == (int8_t)GemfireTypeIds::CacheableString) {
802 }
else if (typeId == (int8_t)GemfireTypeIds::CacheableASCIIStringHuge || typeId == (int8_t)GemfireTypeIds::CacheableStringHuge) {
804 readASCIIHuge(value);
807 throw IllegalArgumentException(
"DI readString error:: String type not supported ");
812 inline void readWideString(
wchar_t** value) {
817 if (typeId == GemfireTypeIds::CacheableNullString){
822 if (typeId == (int8_t)GemfireTypeIds::CacheableASCIIString || typeId == (int8_t)GemfireTypeIds::CacheableString) {
824 }
else if (typeId == (int8_t)GemfireTypeIds::CacheableASCIIStringHuge || typeId == (int8_t)GemfireTypeIds::CacheableStringHuge) {
828 throw IllegalArgumentException(
"DI readWideString error:: WideString type provided is not supported ");
832 inline void readStringArray(
char*** strArray, int32_t& length) {
834 readArrayLen(&arrLen);
841 GF_NEW( tmpArray,
char*[arrLen]);
842 for (
int i = 0; i < arrLen; i++) {
843 readString(&tmpArray[i]);
845 *strArray = tmpArray;
849 inline void readWideStringArray(
wchar_t*** strArray, int32_t& length) {
851 readArrayLen(&arrLen);
858 GF_NEW( tmpArray,
wchar_t*[arrLen]);
859 for (
int i = 0; i < arrLen; i++) {
860 readWideString(&tmpArray[i]);
862 *strArray = tmpArray;
866 inline void readArrayOfByteArrays(int8_t*** arrayofBytearr,
867 int32_t& arrayLength, int32_t** elementLength) {
869 readArrayLen(&arrLen);
870 arrayLength = arrLen;
873 *arrayofBytearr = NULL;
877 int32_t* tmpLengtharr;
878 GF_NEW( tmpArray, int8_t*[arrLen]);
879 GF_NEW( tmpLengtharr, int32_t[arrLen]);
880 for (
int i = 0; i < arrLen; i++) {
881 readBytes(&tmpArray[i], &tmpLengtharr[i]);
883 *arrayofBytearr = tmpArray;
884 *elementLength = tmpLengtharr;
900 const uint8_t* end = value + length;
901 int32_t decodedLen = 0;
902 while ( value < end ) {
904 int32_t b = *value++ & 0xff;
924 if ( value > end ) decodedLen--;
930 : m_buf(m_buffer), m_bufHead(m_buffer), m_bufLength(len), m_poolName(NULL)
950 return static_cast<int32_t
>(m_buf - m_bufHead);
956 return (m_bufLength - getBytesRead());
977 inline void setBuffer()
979 m_buf = currentBufferPosition();
980 m_bufLength = getBytesRemaining();
983 inline void resetPdx(int32_t offset )
985 m_buf = m_bufHead + offset;
989 inline int32_t getPdxBytes()
const 994 static uint8_t * getBufferCopy(
const uint8_t *from, uint32_t length)
997 GF_NEW( result, uint8_t[ length ] );
998 memcpy( result, from, length);
1003 inline void reset(int32_t offset )
1005 m_buf = m_bufHead + offset;
1008 uint8_t * getBufferCopyFrom(
const uint8_t *from, uint32_t length)
1011 GF_NEW( result, uint8_t[ length ] );
1012 memcpy( result, from, length);
1020 const char* getPoolName()
1028 void setPoolName(
const char* poolName)
1030 m_poolName = poolName;
1035 const uint8_t* m_buf;
1036 const uint8_t* m_bufHead;
1037 int32_t m_bufLength;
1038 const char* m_poolName;
1042 template <
typename mType>
1043 void readObject(mType** value, int32_t& length)
1046 readArrayLen(&arrayLen);
1050 objArray =
new mType[arrayLen];
1052 for( i = 0; i < arrayLen; i++ ){
1061 inline void readPdxChar(
char* value){
1067 inline void _checkBufferSize(int32_t size, int32_t line)
1069 if ((m_bufLength - (m_buf - m_bufHead)) < size) {
1071 gf_sprintf(exMsg,
"DataInput: attempt to read beyond buffer at line %d: " 1072 "available buffer size %d, attempted read of size %d ", line,
1073 m_bufLength - (m_buf - m_bufHead), size);
1074 throw OutOfRangeException(exMsg);
1078 inline void decodeChar(
char* str )
1080 uint8_t bt = *(m_buf++);
1084 *str = (char)(((bt & 0x0f) << 12) | (((*m_buf++) & 0x3f) << 6));
1085 *str |= (char)((*m_buf++) & 0x3f);
1088 *str = (char)(((bt & 0x1f) << 6) | ((*m_buf++) & 0x3f));
1096 inline void decodeChar(
wchar_t* str )
1099 int32_t b = *m_buf++ & 0xff;
1109 int32_t y = b & 0x1f;
1112 int32_t x = *m_buf++ & 0x3f;
1114 *str = ( y << 6 | x );
1124 int32_t z = b & 0x0f;
1127 int32_t y = *m_buf++ & 0x3f;
1130 int32_t x = *m_buf++ & 0x3f;
1132 int32_t asint = ( z << 12 | y << 6 | x );
1141 *str = ( b & 0x7f );
1154 #endif // __GEMFIRE_DATAINPUT_H__
virtual Serializable * fromData(DataInput &input)
deserialize this object Throw IllegalArgumentException if the packed CacheableString is not less than...
static Serializable * createUTFDeserializable()
creation function for wide strings
This namespace contains all the GemFire C++ API classes, enumerations and globals.
Definition: Assert.hpp:19
static Serializable * createDeserializable()
creation function for strings
#define CPPCACHE_EXPORT
Defines a GemFire CPPCACHE export.
Definition: gf_base.hpp:51
#define GF_NEW(v, stmt)
Allocates x and throws OutOfMemoryException if it fails.
Definition: gf_base.hpp:315
int gf_sprintf(char *buffer, const char *fmt,...)
sprintf implementation.
static Serializable * createDeserializableHuge()
creation function for strings > 64K length
static Serializable * createUTFDeserializableHuge()
creation function for wide strings > 64K length in UTF8 encoding
Defines a reference counted shared pointer.
Definition: SharedPtr.hpp:35