Pivotal GemFire Native Client Cache Reference  9.0.6
DataInput.hpp
Go to the documentation of this file.
1 #ifndef __GEMFIRE_DATAINPUT_H__
2 #define __GEMFIRE_DATAINPUT_H__
3 
4 /*=========================================================================
5  * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved.
6  * This product is protected by U.S. and international copyright
7  * and intellectual property laws. Pivotal products are covered by
8  * more patents listed at http://www.pivotal.io/patents.
9  *=========================================================================
10  */
11 
12 #include "gfcpp_globals.hpp"
13 #include "ExceptionTypes.hpp"
14 #include <string.h>
15 #include "gf_types.hpp"
16 #include "Serializable.hpp"
17 #include "CacheableString.hpp"
18 
24 #if GF_DEBUG_ASSERTS == 1
25 #define DINP_THROWONERROR_DEFAULT true
26 #else
27 #define DINP_THROWONERROR_DEFAULT false
28 #endif
29 
30 #define checkBufferSize(x) _checkBufferSize(x,__LINE__)
31 
32 namespace gemfire
33 {
34 
35 extern int gf_sprintf(char* buffer, const char* fmt, ...);
36 
45 {
46 public:
47 
53  inline void read( uint8_t* value )
54  {
55  checkBufferSize(1);
56  *value = *(m_buf++);
57  }
58 
64  inline void read( int8_t* value )
65  {
66  checkBufferSize(1);
67  *value = *(m_buf++);
68  }
69 
75  inline void readBoolean( bool* value )
76  {
77  checkBufferSize(1);
78  *value = (*m_buf == 1 ? true : false);
79  m_buf++;
80  }
81 
92  inline void readBytesOnly(uint8_t* buffer, uint32_t len)
93  {
94  if (len > 0) {
95  checkBufferSize(len);
96  memcpy( buffer, m_buf, len );
97  m_buf += len;
98  }
99  }
100 
111  inline void readBytesOnly(int8_t* buffer, uint32_t len)
112  {
113  if (len > 0) {
114  checkBufferSize(len);
115  memcpy( buffer, m_buf, len );
116  m_buf += len;
117  }
118  }
119 
130  inline void readBytes( uint8_t** bytes, int32_t* len )
131  {
132  int32_t length;
133  readArrayLen( &length );
134  *len = length;
135  uint8_t* buffer = NULL;
136  if ( length > 0 ) {
137  checkBufferSize(length);
138  GF_NEW( buffer, uint8_t[ length ] );
139  memcpy( buffer, m_buf, length );
140  m_buf += length;
141  }
142  *bytes = buffer;
143  }
144 
155  inline void readBytes( int8_t** bytes, int32_t* len )
156  {
157  int32_t length;
158  readArrayLen( &length );
159  *len = length;
160  int8_t* buffer = NULL;
161  if ( length > 0 ) {
162  checkBufferSize(length);
163  GF_NEW( buffer, int8_t[ length ] );
164  memcpy( buffer, m_buf, length );
165  m_buf += length;
166  }
167  *bytes = buffer;
168  }
169 
176  inline void readInt( uint16_t* value )
177  {
178  checkBufferSize(2);
179  uint16_t tmp = *(m_buf++);
180  tmp = (uint16_t)((tmp << 8) | *(m_buf++));
181  *value = tmp;
182  }
183 
190  inline void readInt( uint32_t* value )
191  {
192  checkBufferSize(4);
193  uint32_t tmp = *(m_buf++);
194  tmp = (tmp << 8) | *(m_buf++);
195  tmp = (tmp << 8) | *(m_buf++);
196  tmp = (tmp << 8) | *(m_buf++);
197  *value = tmp;
198  }
199 
206  inline void readInt( uint64_t* value )
207  {
208  checkBufferSize(8);
209  uint64_t tmp;
210  if ( sizeof( long ) == 8 ) {
211  tmp = *(m_buf++);
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++);
219  } else {
220  uint32_t hword = *(m_buf++);
221  hword = (hword << 8) | *(m_buf++);
222  hword = (hword << 8) | *(m_buf++);
223  hword = (hword << 8) | *(m_buf++);
224 
225  tmp = hword;
226  hword = *(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;
231  }
232  *value = tmp;
233  }
234 
241  inline void readInt( int16_t* value )
242  {
243  checkBufferSize(2);
244  readInt( (uint16_t*)value );
245  }
246 
253  inline void readInt( int32_t* value )
254  {
255  checkBufferSize(4);
256  readInt( (uint32_t*)value );
257  }
258 
265  inline void readInt( int64_t* value )
266  {
267  checkBufferSize(8);
268  readInt( (uint64_t*)value );
269  }
270 
279  inline void readArrayLen( int32_t* len )
280  {
281  uint8_t code;
282  read(&code);
283  if (code == 0xFF) {
284  *len = -1;
285  } else {
286  int32_t result = code;
287  if (result > 252) { // 252 is java's ((byte)-4 && 0xFF)
288  if (code == 0xFE) {
289  uint16_t val;
290  readInt(&val);
291  result = val;
292  } else if (code == 0xFD) {
293  uint32_t val;
294  readInt(&val);
295  result = val;
296  } else {
297  throw IllegalStateException("unexpected array length code");
298  }
299  }
300  *len = result;
301  }
302  }
303 
310  inline void readUnsignedVL(int64_t * value)
311  {
312  int32_t shift = 0;
313  int64_t result = 0;
314  while (shift < 64) {
315  int8_t b;
316  read(&b);
317  result |= (int64_t)(b & 0x7F) << shift;
318  if ((b & 0x80) == 0) {
319  *value = result;
320  return;
321  }
322  shift += 7;
323  }
324  throw IllegalStateException("Malformed variable length integer");
325  }
326 
332  inline void readFloat( float* value )
333  {
334  checkBufferSize(4);
335  union float_uint32_t
336  {
337  float f;
338  uint32_t u;
339  }v;
340  readInt( (uint32_t*)&v.u);
341  *value = v.f;
342  }
343 
350  inline void readDouble( double* value )
351  {
352  checkBufferSize(8);
353  union double_uint64_t
354  {
355  double d;
356  uint64_t ll;
357  }v;
358  readInt( (uint64_t*)&v.ll);
359  *value = v.d;
360  }
361 
367  static inline void freeUTFMemory( char* value )
368  {
369  delete [] value;
370  }
371 
377  static inline void freeUTFMemory( wchar_t* value )
378  {
379  delete [] value;
380  }
381 
397  inline void readASCII( char** value, uint16_t* len = NULL )
398  {
399  uint16_t length;
400  readInt( &length );
401  checkBufferSize(length);
402  if ( len != NULL ) {
403  *len = length;
404  }
405  char* str;
406  GF_NEW( str, char[ length + 1 ] );
407  *value = str;
408  readBytesOnly((int8_t*)str, length);
409  str[ length ] = '\0';
410  }
411 
426  inline void readASCIIHuge( char** value, uint32_t* len = NULL )
427  {
428  uint32_t length;
429  readInt( &length );
430  if ( len != NULL ) {
431  *len = length;
432  }
433  char* str;
434  GF_NEW( str, char[ length + 1 ] );
435  *value = str;
436  readBytesOnly( (int8_t*)str, length );
437  str[ length ] = '\0';
438  }
439 
456  inline void readUTF( char** value, uint16_t* len = NULL )
457  {
458  uint16_t length;
459  readInt( &length );
460  checkBufferSize(length);
461  uint16_t decodedLen = (uint16_t)getDecodedLength( m_buf, length );
462  if ( len != NULL ) {
463  *len = decodedLen;
464  }
465  char* str;
466  GF_NEW( str, char[ decodedLen + 1 ] );
467  *value = str;
468  for( uint16_t i = 0; i < decodedLen; i++ ) {
469  decodeChar( str++ );
470  }
471  *str = '\0'; // null terminate for c-string.
472  }
473 
483  inline void readUTFNoLen(wchar_t** value, uint16_t decodedLen)
484  {
485  wchar_t* str;
486  GF_NEW(str, wchar_t[decodedLen + 1]);
487  *value = str;
488  for (uint16_t i = 0; i < decodedLen; i++) {
489  decodeChar(str++);
490  }
491  *str = L'\0'; // null terminate for c-string.
492  }
493 
508  inline void readUTFHuge( char** value, uint32_t* len = NULL )
509  {
510  uint32_t length;
511  readInt( &length );
512  if ( len != NULL ) {
513  *len = length;
514  }
515  char* str;
516  GF_NEW( str, char[ length + 1 ] );
517  *value = str;
518  for( uint32_t i = 0; i < length; i++ ) {
519  int8_t item;
520  read(&item); // ignore this - should be higher order zero byte
521  read(&item);
522  *str = item;
523  str++;
524  }
525  *str = '\0'; // null terminate for c-string.
526  }
527 
544  inline void readUTF( wchar_t** value, uint16_t* len = NULL )
545  {
546  uint16_t length;
547  readInt( &length );
548  checkBufferSize(length);
549  uint16_t decodedLen = (uint16_t)getDecodedLength( m_buf, length );
550  if ( len != NULL ) {
551  *len = decodedLen;
552  }
553  wchar_t* str;
554  GF_NEW( str, wchar_t[ decodedLen + 1 ] );
555  *value = str;
556  for( uint16_t i = 0; i < decodedLen; i++ ) {
557  decodeChar( str++ );
558  }
559  *str = L'\0'; // null terminate for c-string.
560  }
561 
576  inline void readUTFHuge( wchar_t** value, uint32_t* len = NULL )
577  {
578  uint32_t length;
579  readInt( &length );
580  if ( len != NULL ) {
581  *len = length;
582  }
583  wchar_t* str;
584  GF_NEW( str, wchar_t[ length + 1 ] );
585  *value = str;
586  for( uint32_t i = 0; i < length; i++ ) {
587  uint8_t hibyte;
588  read(&hibyte);
589  uint8_t lobyte;
590  read(&lobyte);
591  *str = (((uint16_t)hibyte) << 8) | (uint16_t)lobyte;
592  str++;
593  }
594  *str = L'\0'; // null terminate for c-string.
595  }
596 
616  template< class PTR >
617  inline void readObject( SharedPtr<PTR>& ptr,
618  bool throwOnError = DINP_THROWONERROR_DEFAULT )
619  {
620  SerializablePtr sPtr;
621  readObjectInternal( sPtr );
622  if ( throwOnError ) {
623  ptr = dynCast< SharedPtr<PTR> >( sPtr );
624  } else {
625  ptr = staticCast< SharedPtr<PTR> >( sPtr );
626  }
627  }
628 
629  inline bool readNativeBool( )
630  {
631  int8_t typeId = 0;
632  read( &typeId );
633 
634  bool val;
635  readBoolean(&val);
636  return val;
637  }
638 
639  inline int32_t readNativeInt32( )
640  {
641  int8_t typeId = 0;
642  read( &typeId );
643 
644  int32_t val;
645  readInt(&val);
646  return val;
647  }
648 
649  inline bool readNativeString(CacheableStringPtr& csPtr)
650  {
651  int8_t typeId = 0;
652  read( &typeId );
653  int64_t compId = typeId;
654  if (compId == GemfireTypeIds::NullObj) {
655  csPtr = NULLPTR;
656  }
657  else if (compId == GemfireTypeIds::CacheableNullString) {
658  csPtr = CacheableStringPtr(dynamic_cast<CacheableString *>(CacheableString::createDeserializable()));
659  }
660  else if ( compId == gemfire::GemfireTypeIds::CacheableASCIIString) {
661  csPtr = CacheableStringPtr(dynamic_cast<CacheableString *>(CacheableString::createDeserializable()));
662  csPtr.ptr()->fromData(*this);
663  }
664  else if ( compId == gemfire::GemfireTypeIds::CacheableASCIIStringHuge) {
665  csPtr = CacheableStringPtr(dynamic_cast<CacheableString *>(CacheableString::createDeserializableHuge()));
666  csPtr.ptr()->fromData(*this);
667  }
668  else if ( compId == gemfire::GemfireTypeIds::CacheableString) {
669  csPtr = CacheableStringPtr(dynamic_cast<CacheableString *>(CacheableString::createUTFDeserializable()));
670  csPtr.ptr()->fromData(*this);
671  }
672  else if ( compId == gemfire::GemfireTypeIds::CacheableStringHuge) {
673  csPtr = CacheableStringPtr(dynamic_cast<CacheableString *>(CacheableString::createUTFDeserializableHuge()));
674  csPtr.ptr()->fromData(*this);
675  }
676  else {
677  LOGDEBUG("In readNativeString something is wrong while expecting string");
678  rewindCursor(1);
679  csPtr = NULLPTR;
680  return false;
681  }
682  return true;
683  }
684 
685  inline void readDirectObject( SerializablePtr& ptr, int8_t typeId = -1 )
686  {
687  readObjectInternal( ptr, typeId );
688  }
689 
694  inline void readObject( SerializablePtr& ptr )
695  {
696  readObjectInternal( ptr );
697  }
698 
699  inline void readObject(wchar_t* value){
700  uint16_t temp = 0;
701  readInt(&temp);
702  *value = (wchar_t)temp;
703  }
704 
705  inline void readObject(bool* value){
706  readBoolean(value);
707  }
708 
709  inline void readObject(int8_t* value){
710  read(value);
711  }
712 
713  inline void readObject(int16_t* value){
714  readInt(value);
715  }
716 
717  inline void readObject(int32_t* value){
718  readInt(value);
719  }
720 
721  inline void readObject(int64_t* value){
722  readInt(value);
723  }
724 
725  inline void readObject(float* value){
726  readFloat(value);
727  }
728 
729  inline void readObject(double* value){
730  readDouble(value);
731  }
732 
733  inline void readCharArray(char** value, int32_t& length){
734  int arrayLen = 0;
735  readArrayLen(&arrayLen);
736  length = arrayLen;
737  char* objArray = NULL;
738  if(arrayLen > 0) {
739  objArray = new char[arrayLen];
740  int i = 0;
741  for( i = 0; i < arrayLen; i++ ){
742  char tmp = 0;
743  readPdxChar(&tmp);
744  objArray[i] = tmp;
745  }
746  *value = objArray;
747  }
748  }
749 
750  inline void readWideCharArray(wchar_t** value, int32_t& length){
751  readObject(value, length);
752  }
753 
754  inline void readBooleanArray(bool** value, int32_t& length){
755  readObject(value, length);
756  }
757 
758  inline void readByteArray(int8_t** value, int32_t& length){
759  readObject(value, length);
760  }
761 
762  inline void readShortArray(int16_t** value, int32_t& length){
763  readObject(value, length);
764  }
765 
766  inline void readIntArray(int32_t** value, int32_t& length){
767  readObject(value, length);
768  }
769 
770  inline void readLongArray(int64_t** value, int32_t& length){
771  readObject(value, length);
772  }
773 
774  inline void readFloatArray(float** value, int32_t& length){
775  readObject(value, length);
776  }
777 
778  inline void readDoubleArray(double** value, int32_t& length){
779  readObject(value, length);
780  }
781 
782  inline void readString(char** value) {
783  int8_t typeId;
784  read(&typeId);
785 
786  //Check for NULL String
787  if (typeId == GemfireTypeIds::CacheableNullString){
788  *value = NULL;
789  return;
790  }
791  /*
792  if (typeId == GemfireTypeIds::CacheableString) {
793  readUTF(value);
794  } else {
795  readUTFHuge(value);
796  }
797  */
798  if (typeId == (int8_t)GemfireTypeIds::CacheableASCIIString || typeId == (int8_t)GemfireTypeIds::CacheableString) {
799  //readUTF( value);
800  readASCII(value);
801  //m_len = shortLen;
802  }else if (typeId == (int8_t)GemfireTypeIds::CacheableASCIIStringHuge || typeId == (int8_t)GemfireTypeIds::CacheableStringHuge) {
803  //readUTFHuge( value);
804  readASCIIHuge(value);
805  }
806  else {
807  throw IllegalArgumentException("DI readString error:: String type not supported ");
808  }
809 
810  }
811 
812  inline void readWideString(wchar_t** value) {
813  int8_t typeId;
814  read(&typeId);
815 
816  //Check for NULL String
817  if (typeId == GemfireTypeIds::CacheableNullString){
818  *value = NULL;
819  return;
820  }
821 
822  if (typeId == (int8_t)GemfireTypeIds::CacheableASCIIString || typeId == (int8_t)GemfireTypeIds::CacheableString) {
823  readUTF( value);
824  }else if (typeId == (int8_t)GemfireTypeIds::CacheableASCIIStringHuge || typeId == (int8_t)GemfireTypeIds::CacheableStringHuge) {
825  readUTFHuge( value);
826  }
827  else {
828  throw IllegalArgumentException("DI readWideString error:: WideString type provided is not supported ");
829  }
830  }
831 
832  inline void readStringArray(char*** strArray, int32_t& length) {
833  int32_t arrLen;
834  readArrayLen(&arrLen);
835  length = arrLen;
836  if (arrLen == -1) {
837  *strArray = NULL;
838  return;
839  } else {
840  char** tmpArray;
841  GF_NEW( tmpArray, char*[arrLen]);
842  for (int i = 0; i < arrLen; i++) {
843  readString(&tmpArray[i]);
844  }
845  *strArray = tmpArray;
846  }
847  }
848 
849  inline void readWideStringArray(wchar_t*** strArray, int32_t& length) {
850  int32_t arrLen;
851  readArrayLen(&arrLen);
852  length = arrLen;
853  if (arrLen == -1) {
854  *strArray = NULL;
855  return;
856  } else {
857  wchar_t** tmpArray;
858  GF_NEW( tmpArray, wchar_t*[arrLen]);
859  for (int i = 0; i < arrLen; i++) {
860  readWideString(&tmpArray[i]);
861  }
862  *strArray = tmpArray;
863  }
864  }
865 
866  inline void readArrayOfByteArrays(int8_t*** arrayofBytearr,
867  int32_t& arrayLength, int32_t** elementLength) {
868  int32_t arrLen;
869  readArrayLen(&arrLen);
870  arrayLength = arrLen;
871 
872  if (arrLen == -1) {
873  *arrayofBytearr = NULL;
874  return;
875  } else {
876  int8_t** tmpArray;
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]);
882  }
883  *arrayofBytearr = tmpArray;
884  *elementLength = tmpLengtharr;
885  }
886  }
887 
898  static int32_t getDecodedLength( const uint8_t* value, int32_t length )
899  {
900  const uint8_t* end = value + length;
901  int32_t decodedLen = 0;
902  while ( value < end ) {
903  // get next byte unsigned
904  int32_t b = *value++ & 0xff;
905  int32_t k = b >> 5;
906  // classify based on the high order 3 bits
907  switch ( k )
908  {
909  case 6:
910  {
911  value++;
912  break;
913  }
914  case 7:
915  {
916  value += 2;
917  break;
918  }
919  default:
920  break;
921  }
922  decodedLen += 1;
923  }
924  if ( value > end ) decodedLen--;
925  return decodedLen;
926  }
927 
929  DataInput(const uint8_t* m_buffer, int32_t len)
930  : m_buf(m_buffer), m_bufHead(m_buffer), m_bufLength(len), m_poolName(NULL)
931  {
932  }
933 
935  ~DataInput( ) { }
936 
942  inline const uint8_t* currentBufferPosition() const
943  {
944  return m_buf;
945  }
946 
948  inline int32_t getBytesRead() const
949  {
950  return static_cast<int32_t>(m_buf - m_bufHead);
951  }
952 
954  inline int32_t getBytesRemaining() const
955  {
956  return (m_bufLength - getBytesRead());
957  }
958 
960  inline void advanceCursor(int32_t offset)
961  {
962  m_buf += offset;
963  }
964 
966  inline void rewindCursor(int32_t offset)
967  {
968  m_buf -= offset;
969  }
970 
972  inline void reset()
973  {
974  m_buf = m_bufHead;
975  }
976 
977  inline void setBuffer()
978  {
979  m_buf = currentBufferPosition();
980  m_bufLength = getBytesRemaining();
981  }
982 
983  inline void resetPdx(int32_t offset )
984  {
985  m_buf = m_bufHead + offset;
986  //setBuffer();
987  }
988 
989  inline int32_t getPdxBytes() const
990  {
991  return m_bufLength;
992  }
993 
994  static uint8_t * getBufferCopy(const uint8_t *from, uint32_t length)
995  {
996  uint8_t * result;
997  GF_NEW( result, uint8_t[ length ] );
998  memcpy( result, from, length);
999 
1000  return result;
1001  }
1002 
1003  inline void reset(int32_t offset )
1004  {
1005  m_buf = m_bufHead + offset;
1006  }
1007 
1008  uint8_t * getBufferCopyFrom(const uint8_t *from, uint32_t length)
1009  {
1010  uint8_t * result;
1011  GF_NEW( result, uint8_t[ length ] );
1012  memcpy( result, from, length);
1013 
1014  return result;
1015  }
1016 
1017  /*
1018  * This is for internal use
1019  */
1020  const char* getPoolName()
1021  {
1022  return m_poolName;
1023  }
1024 
1025  /*
1026  * This is for internal use
1027  */
1028  void setPoolName(const char* poolName)
1029  {
1030  m_poolName = poolName;
1031  }
1032 
1033 private:
1034 
1035  const uint8_t* m_buf;
1036  const uint8_t* m_bufHead;
1037  int32_t m_bufLength;
1038  const char* m_poolName;
1039 
1040  void readObjectInternal( SerializablePtr& ptr, int8_t typeId = -1 );
1041 
1042  template <typename mType>
1043  void readObject(mType** value, int32_t& length)
1044  {
1045  int arrayLen;
1046  readArrayLen(&arrayLen);
1047  length = arrayLen;
1048  mType* objArray;
1049  if(arrayLen > 0) {
1050  objArray = new mType[arrayLen];
1051  int i = 0;
1052  for( i = 0; i < arrayLen; i++ ){
1053  mType tmp = 0;
1054  readObject(&tmp);
1055  objArray[i] = tmp; //*value[i] = tmp;
1056  }
1057  *value = objArray;
1058  }
1059  }
1060 
1061  inline void readPdxChar(char* value){
1062  int16_t val = 0;
1063  readInt(&val);
1064  *value = (char)val;
1065  }
1066 
1067  inline void _checkBufferSize(int32_t size, int32_t line)
1068  {
1069  if ((m_bufLength - (m_buf - m_bufHead)) < size) {
1070  char exMsg[128];
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);
1075  }
1076  }
1077 
1078  inline void decodeChar( char* str )
1079  {
1080  uint8_t bt = *(m_buf++);
1081  if ( bt & 0x80 ) {
1082  if ( bt & 0x20 ) {
1083  // three bytes.
1084  *str = (char)(((bt & 0x0f) << 12) | (((*m_buf++) & 0x3f) << 6));
1085  *str |= (char)((*m_buf++) & 0x3f);
1086  } else {
1087  // two bytes.
1088  *str = (char)(((bt & 0x1f) << 6) | ((*m_buf++) & 0x3f));
1089  }
1090  } else {
1091  // single byte...
1092  *str = bt;
1093  }
1094  }
1095 
1096  inline void decodeChar( wchar_t* str )
1097  {
1098  // get next byte unsigned
1099  int32_t b = *m_buf++ & 0xff;
1100  int32_t k = b >> 5;
1101  // classify based on the high order 3 bits
1102  switch ( k )
1103  {
1104  case 6:
1105  {
1106  // two byte encoding
1107  // 110yyyyy 10xxxxxx
1108  // use low order 6 bits
1109  int32_t y = b & 0x1f;
1110  // use low order 6 bits of the next byte
1111  // It should have high order bits 10, which we don't check.
1112  int32_t x = *m_buf++ & 0x3f;
1113  // 00000yyy yyxxxxxx
1114  *str = ( y << 6 | x );
1115  break;
1116  }
1117  case 7:
1118  {
1119  // three byte encoding
1120  // 1110zzzz 10yyyyyy 10xxxxxx
1121  //assert ( b & 0x10 )
1122  // == 0 : "UTF8Decoder does not handle 32-bit characters";
1123  // use low order 4 bits
1124  int32_t z = b & 0x0f;
1125  // use low order 6 bits of the next byte
1126  // It should have high order bits 10, which we don't check.
1127  int32_t y = *m_buf++ & 0x3f;
1128  // use low order 6 bits of the next byte
1129  // It should have high order bits 10, which we don't check.
1130  int32_t x = *m_buf++ & 0x3f;
1131  // zzzzyyyy yyxxxxxx
1132  int32_t asint = ( z << 12 | y << 6 | x );
1133  *str = asint;
1134  break;
1135  }
1136  default:
1137  // one byte encoding
1138  // 0xxxxxxx
1139  // use just low order 7 bits
1140  // 00000000 0xxxxxxx
1141  *str = ( b & 0x7f );
1142  break;
1143  }
1144  }
1145 
1146  // disable other constructors and assignment
1147  DataInput();
1148  DataInput(const DataInput&);
1149  DataInput& operator =(const DataInput&);
1150 };
1151 
1152 }
1153 
1154 #endif // __GEMFIRE_DATAINPUT_H__
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 le...
Definition: DataInput.hpp:456
virtual Serializable * fromData(DataInput &input)
deserialize this object Throw IllegalArgumentException if the packed CacheableString is not less than...
static void freeUTFMemory(char *value)
free the C string allocated by readASCII, readASCIIHuge, readUTF, readUTFHuge methods ...
Definition: DataInput.hpp:367
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 strea...
Definition: DataInput.hpp:130
static void freeUTFMemory(wchar_t *value)
free the wide-characted string allocated by readASCII, readASCIIHuge, readUTF, readUTFHuge methods ...
Definition: DataInput.hpp:377
void readDouble(double *value)
Read a double precision number from the DataInput.
Definition: DataInput.hpp:350
void readObject(SerializablePtr &ptr)
Read a Serializable object from the DataInput.
Definition: DataInput.hpp:694
static Serializable * createUTFDeserializable()
creation function for wide strings
void readInt(uint64_t *value)
Read a 64-bit unsigned integer from the DataInput.
Definition: DataInput.hpp:206
void readFloat(float *value)
Read a float from the DataInput.
Definition: DataInput.hpp:332
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 in...
Definition: DataInput.hpp:397
void read(uint8_t *value)
Read an unsigned byte from the DataInput.
Definition: DataInput.hpp:53
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 ...
Definition: DataInput.hpp:155
const uint8_t * currentBufferPosition() const
Get the pointer to current buffer position.
Definition: DataInput.hpp:942
This namespace contains all the GemFire C++ API classes, enumerations and globals.
Definition: Assert.hpp:19
void readInt(int32_t *value)
Read a 32-bit signed integer from the DataInput.
Definition: DataInput.hpp:253
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 maxim...
Definition: DataInput.hpp:544
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 DataInp...
Definition: DataInput.hpp:576
void readUnsignedVL(int64_t *value)
Decode a 64 bit integer as a variable length array.
Definition: DataInput.hpp:310
void readArrayLen(int32_t *len)
Read a 32-bit signed integer array length value from the DataInput in a manner compatible with java s...
Definition: DataInput.hpp:279
void readInt(int16_t *value)
Read a 16-bit signed integer from the DataInput.
Definition: DataInput.hpp:241
static Serializable * createDeserializable()
creation function for strings
void readBytesOnly(int8_t *buffer, uint32_t len)
Read the given number of signed bytes from the DataInput.
Definition: DataInput.hpp:111
void readBytesOnly(uint8_t *buffer, uint32_t len)
Read the given number of unsigned bytes from the DataInput.
Definition: DataInput.hpp:92
void readBoolean(bool *value)
Read a boolean value from the DataInput.
Definition: DataInput.hpp:75
DataInput(const uint8_t *m_buffer, int32_t len)
constructor given a pre-allocated byte array with size
Definition: DataInput.hpp:929
void rewindCursor(int32_t offset)
rewind the cursor by given offset
Definition: DataInput.hpp:966
Provide operations for reading primitive data values, byte arrays, strings, Serializable objects from...
Definition: DataInput.hpp:44
void readObject(SharedPtr< PTR > &ptr, bool throwOnError=false)
Read a Serializable object from the DataInput.
Definition: DataInput.hpp:617
void readASCIIHuge(char **value, uint32_t *len=NULL)
Allocates a c string buffer, and reads an ASCII string from DataInput into it.
Definition: DataInput.hpp:426
#define CPPCACHE_EXPORT
Defines a GemFire CPPCACHE export.
Definition: gf_base.hpp:51
~DataInput()
destructor
Definition: DataInput.hpp:935
int32_t getBytesRead() const
get the number of bytes read in the buffer
Definition: DataInput.hpp:948
int32_t getBytesRemaining() const
get the number of bytes remaining to be read in the buffer
Definition: DataInput.hpp:954
void readInt(uint32_t *value)
Read a 32-bit unsigned integer from the DataInput.
Definition: DataInput.hpp:190
void reset()
reset the cursor to the start of buffer
Definition: DataInput.hpp:972
#define GF_NEW(v, stmt)
Allocates x and throws OutOfMemoryException if it fails.
Definition: gf_base.hpp:315
void read(int8_t *value)
Read a signed byte from the DataInput.
Definition: DataInput.hpp:64
void readInt(int64_t *value)
Read a 64-bit signed integer from the DataInput.
Definition: DataInput.hpp:265
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 l...
Definition: DataInput.hpp:483
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...
Definition: DataInput.hpp:898
int gf_sprintf(char *buffer, const char *fmt,...)
sprintf implementation.
void readInt(uint16_t *value)
Read a 16-bit unsigned integer from the DataInput.
Definition: DataInput.hpp:176
static Serializable * createDeserializableHuge()
creation function for strings > 64K length
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...
Definition: DataInput.hpp:508
static Serializable * createUTFDeserializableHuge()
creation function for wide strings > 64K length in UTF8 encoding
Defines a reference counted shared pointer.
Definition: SharedPtr.hpp:35
void advanceCursor(int32_t offset)
advance the cursor by given offset
Definition: DataInput.hpp:960

GemFire C++ Cache API Documentation