VMware GemFire Native C++ Reference  9.1
DataInput.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #ifndef GEODE_DATAINPUT_H_
4 #define GEODE_DATAINPUT_H_
5 
6 /*
7  * Licensed to the Apache Software Foundation (ASF) under one or more
8  * contributor license agreements. See the NOTICE file distributed with
9  * this work for additional information regarding copyright ownership.
10  * The ASF licenses this file to You under the Apache License, Version 2.0
11  * (the "License"); you may not use this file except in compliance with
12  * the License. You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 
23 #include "geode_globals.hpp"
24 #include "ExceptionTypes.hpp"
25 #include <cstring>
26 #include <string>
27 #include "geode_types.hpp"
28 #include "Serializable.hpp"
29 #include "CacheableString.hpp"
30 
35 #if GF_DEBUG_ASSERTS == 1
36 #define DINP_THROWONERROR_DEFAULT true
37 #else
38 #define DINP_THROWONERROR_DEFAULT false
39 #endif
40 
41 #define checkBufferSize(x) _checkBufferSize(x, __LINE__)
42 
43 namespace apache {
44 namespace geode {
45 namespace client {
46 
47 extern int gf_sprintf(char* buffer, const char* fmt, ...);
48 
57  public:
63  inline void read(uint8_t* value) {
64  checkBufferSize(1);
65  *value = *(m_buf++);
66  }
67 
73  inline void read(int8_t* value) {
74  checkBufferSize(1);
75  *value = *(m_buf++);
76  }
77 
83  inline void readBoolean(bool* value) {
84  checkBufferSize(1);
85  *value = (*m_buf == 1 ? true : false);
86  m_buf++;
87  }
88 
99  inline void readBytesOnly(uint8_t* buffer, uint32_t len) {
100  if (len > 0) {
101  checkBufferSize(len);
102  std::memcpy(buffer, m_buf, len);
103  m_buf += len;
104  }
105  }
106 
117  inline void readBytesOnly(int8_t* buffer, uint32_t len) {
118  if (len > 0) {
119  checkBufferSize(len);
120  std::memcpy(buffer, m_buf, len);
121  m_buf += len;
122  }
123  }
124 
135  inline void readBytes(uint8_t** bytes, int32_t* len) {
136  int32_t length;
137  readArrayLen(&length);
138  *len = length;
139  uint8_t* buffer = NULL;
140  if (length > 0) {
141  checkBufferSize(length);
142  GF_NEW(buffer, uint8_t[length]);
143  std::memcpy(buffer, m_buf, length);
144  m_buf += length;
145  }
146  *bytes = buffer;
147  }
148 
159  inline void readBytes(int8_t** bytes, int32_t* len) {
160  int32_t length;
161  readArrayLen(&length);
162  *len = length;
163  int8_t* buffer = NULL;
164  if (length > 0) {
165  checkBufferSize(length);
166  GF_NEW(buffer, int8_t[length]);
167  std::memcpy(buffer, m_buf, length);
168  m_buf += length;
169  }
170  *bytes = buffer;
171  }
172 
179  inline void readInt(uint16_t* value) {
180  checkBufferSize(2);
181  uint16_t tmp = *(m_buf++);
182  tmp = static_cast<uint16_t>((tmp << 8) | *(m_buf++));
183  *value = tmp;
184  }
185 
192  inline void readInt(uint32_t* value) {
193  checkBufferSize(4);
194  uint32_t tmp = *(m_buf++);
195  tmp = (tmp << 8) | *(m_buf++);
196  tmp = (tmp << 8) | *(m_buf++);
197  tmp = (tmp << 8) | *(m_buf++);
198  *value = tmp;
199  }
200 
207  inline void readInt(uint64_t* value) {
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  checkBufferSize(2);
243  readInt(reinterpret_cast<uint16_t*>(value));
244  }
245 
252  inline void readInt(int32_t* value) {
253  checkBufferSize(4);
254  readInt(reinterpret_cast<uint32_t*>(value));
255  }
256 
263  inline void readInt(int64_t* value) {
264  checkBufferSize(8);
265  readInt(reinterpret_cast<uint64_t*>(value));
266  }
267 
276  inline void readArrayLen(int32_t* len) {
277  uint8_t code;
278  read(&code);
279  if (code == 0xFF) {
280  *len = -1;
281  } else {
282  int32_t result = code;
283  if (result > 252) { // 252 is java's ((byte)-4 && 0xFF)
284  if (code == 0xFE) {
285  uint16_t val;
286  readInt(&val);
287  result = val;
288  } else if (code == 0xFD) {
289  uint32_t val;
290  readInt(&val);
291  result = val;
292  } else {
293  throw IllegalStateException("unexpected array length code");
294  }
295  }
296  *len = result;
297  }
298  }
299 
306  inline void readUnsignedVL(int64_t* value) {
307  int32_t shift = 0;
308  int64_t result = 0;
309  while (shift < 64) {
310  int8_t b;
311  read(&b);
312  result |= static_cast<int64_t>(b & 0x7F) << shift;
313  if ((b & 0x80) == 0) {
314  *value = result;
315  return;
316  }
317  shift += 7;
318  }
319  throw IllegalStateException("Malformed variable length integer");
320  }
321 
327  inline void readFloat(float* value) {
328  checkBufferSize(4);
329  union float_uint32_t {
330  float f;
331  uint32_t u;
332  } v;
333  readInt(&v.u);
334  *value = v.f;
335  }
336 
343  inline void readDouble(double* value) {
344  checkBufferSize(8);
345  union double_uint64_t {
346  double d;
347  uint64_t ll;
348  } v;
349  readInt(&v.ll);
350  *value = v.d;
351  }
352 
358  static inline void freeUTFMemory(char* value) { delete[] value; }
359 
365  static inline void freeUTFMemory(wchar_t* value) { delete[] value; }
366 
382  inline void readASCII(char** value, uint16_t* len = NULL) {
383  uint16_t length;
384  readInt(&length);
385  checkBufferSize(length);
386  if (len != NULL) {
387  *len = length;
388  }
389  char* str;
390  GF_NEW(str, char[length + 1]);
391  *value = str;
392  readBytesOnly(reinterpret_cast<int8_t*>(str), length);
393  str[length] = '\0';
394  }
395 
410  inline void readASCIIHuge(char** value, uint32_t* len = NULL) {
411  uint32_t length;
412  readInt(&length);
413  if (len != NULL) {
414  *len = length;
415  }
416  char* str;
417  GF_NEW(str, char[length + 1]);
418  *value = str;
419  readBytesOnly(reinterpret_cast<int8_t*>(str), length);
420  str[length] = '\0';
421  }
422 
439  inline void readUTF(char** value, uint16_t* len = NULL) {
440  uint16_t length;
441  readInt(&length);
442  checkBufferSize(length);
443  uint16_t decodedLen =
444  static_cast<uint16_t>(getDecodedLength(m_buf, length));
445  if (len != NULL) {
446  *len = decodedLen;
447  }
448  char* str;
449  GF_NEW(str, char[decodedLen + 1]);
450  *value = str;
451  for (uint16_t i = 0; i < decodedLen; i++) {
452  decodeChar(str++);
453  }
454  *str = '\0'; // null terminate for c-string.
455  }
456 
466  inline void readUTFNoLen(wchar_t** value, uint16_t decodedLen) {
467  wchar_t* str;
468  GF_NEW(str, wchar_t[decodedLen + 1]);
469  *value = str;
470  for (uint16_t i = 0; i < decodedLen; i++) {
471  decodeChar(str++);
472  }
473  *str = L'\0'; // null terminate for c-string.
474  }
475 
490  inline void readUTFHuge(char** value, uint32_t* len = NULL) {
491  uint32_t length;
492  readInt(&length);
493  if (len != NULL) {
494  *len = length;
495  }
496  char* str;
497  GF_NEW(str, char[length + 1]);
498  *value = str;
499  for (uint32_t i = 0; i < length; i++) {
500  int8_t item;
501  read(&item); // ignore this - should be higher order zero byte
502  read(&item);
503  *str = item;
504  str++;
505  }
506  *str = '\0'; // null terminate for c-string.
507  }
508 
525  inline void readUTF(wchar_t** value, uint16_t* len = NULL) {
526  uint16_t length;
527  readInt(&length);
528  checkBufferSize(length);
529  uint16_t decodedLen =
530  static_cast<uint16_t>(getDecodedLength(m_buf, length));
531  if (len != NULL) {
532  *len = decodedLen;
533  }
534  wchar_t* str;
535  GF_NEW(str, wchar_t[decodedLen + 1]);
536  *value = str;
537  for (uint16_t i = 0; i < decodedLen; i++) {
538  decodeChar(str++);
539  }
540  *str = L'\0'; // null terminate for c-string.
541  }
542 
557  inline void readUTFHuge(wchar_t** value, uint32_t* len = NULL) {
558  uint32_t length;
559  readInt(&length);
560  if (len != NULL) {
561  *len = length;
562  }
563  wchar_t* str;
564  GF_NEW(str, wchar_t[length + 1]);
565  *value = str;
566  for (uint32_t i = 0; i < length; i++) {
567  uint8_t hibyte;
568  read(&hibyte);
569  uint8_t lobyte;
570  read(&lobyte);
571  *str = ((static_cast<uint16_t>(hibyte)) << 8) |
572  static_cast<uint16_t>(lobyte);
573  str++;
574  }
575  *str = L'\0'; // null terminate for c-string.
576  }
577 
597  template <class PTR>
598  inline void readObject(SharedPtr<PTR>& ptr,
599  bool throwOnError = DINP_THROWONERROR_DEFAULT) {
600  SerializablePtr sPtr;
601  readObjectInternal(sPtr);
602  if (throwOnError) {
603  ptr = dynCast<SharedPtr<PTR> >(sPtr);
604  } else {
605  ptr = staticCast<SharedPtr<PTR> >(sPtr);
606  }
607  }
608 
609  inline bool readNativeBool() {
610  int8_t typeId = 0;
611  read(&typeId);
612 
613  bool val;
614  readBoolean(&val);
615  return val;
616  }
617 
618  inline int32_t readNativeInt32() {
619  int8_t typeId = 0;
620  read(&typeId);
621 
622  int32_t val;
623  readInt(&val);
624  return val;
625  }
626 
627  inline bool readNativeString(CacheableStringPtr& csPtr) {
628  int8_t typeId = 0;
629  read(&typeId);
630  int64_t compId = typeId;
631  if (compId == GeodeTypeIds::NullObj) {
632  csPtr = NULLPTR;
633  } else if (compId == GeodeTypeIds::CacheableNullString) {
634  csPtr = CacheableStringPtr(dynamic_cast<CacheableString*>(
636  } else if (compId ==
637  apache::geode::client::GeodeTypeIds::CacheableASCIIString) {
638  csPtr = CacheableStringPtr(dynamic_cast<CacheableString*>(
640  csPtr.ptr()->fromData(*this);
641  } else if (compId ==
642  apache::geode::client::GeodeTypeIds::CacheableASCIIStringHuge) {
643  csPtr = CacheableStringPtr(dynamic_cast<CacheableString*>(
645  csPtr.ptr()->fromData(*this);
646  } else if (compId == apache::geode::client::GeodeTypeIds::CacheableString) {
647  csPtr = CacheableStringPtr(dynamic_cast<CacheableString*>(
649  csPtr.ptr()->fromData(*this);
650  } else if (compId ==
651  apache::geode::client::GeodeTypeIds::CacheableStringHuge) {
652  csPtr = CacheableStringPtr(dynamic_cast<CacheableString*>(
654  csPtr.ptr()->fromData(*this);
655  } else {
656  LOGDEBUG("In readNativeString something is wrong while expecting string");
657  rewindCursor(1);
658  csPtr = NULLPTR;
659  return false;
660  }
661  return true;
662  }
663 
664  inline void readDirectObject(SerializablePtr& ptr, int8_t typeId = -1) {
665  readObjectInternal(ptr, typeId);
666  }
667 
672  inline void readObject(SerializablePtr& ptr) { readObjectInternal(ptr); }
673 
674  inline void readObject(wchar_t* value) {
675  uint16_t temp = 0;
676  readInt(&temp);
677  *value = static_cast<wchar_t>(temp);
678  }
679 
680  inline void readObject(bool* value) { readBoolean(value); }
681 
682  inline void readObject(int8_t* value) { read(value); }
683 
684  inline void readObject(int16_t* value) { readInt(value); }
685 
686  inline void readObject(int32_t* value) { readInt(value); }
687 
688  inline void readObject(int64_t* value) { readInt(value); }
689 
690  inline void readObject(float* value) { readFloat(value); }
691 
692  inline void readObject(double* value) { readDouble(value); }
693 
694  inline void readCharArray(char** value, int32_t& length) {
695  int arrayLen = 0;
696  readArrayLen(&arrayLen);
697  length = arrayLen;
698  char* objArray = NULL;
699  if (arrayLen > 0) {
700  objArray = new char[arrayLen];
701  int i = 0;
702  for (i = 0; i < arrayLen; i++) {
703  char tmp = 0;
704  readPdxChar(&tmp);
705  objArray[i] = tmp;
706  }
707  *value = objArray;
708  }
709  }
710 
711  inline void readWideCharArray(wchar_t** value, int32_t& length) {
712  readObject(value, length);
713  }
714 
715  inline void readBooleanArray(bool** value, int32_t& length) {
716  readObject(value, length);
717  }
718 
719  inline void readByteArray(int8_t** value, int32_t& length) {
720  readObject(value, length);
721  }
722 
723  inline void readShortArray(int16_t** value, int32_t& length) {
724  readObject(value, length);
725  }
726 
727  inline void readIntArray(int32_t** value, int32_t& length) {
728  readObject(value, length);
729  }
730 
731  inline void readLongArray(int64_t** value, int32_t& length) {
732  readObject(value, length);
733  }
734 
735  inline void readFloatArray(float** value, int32_t& length) {
736  readObject(value, length);
737  }
738 
739  inline void readDoubleArray(double** value, int32_t& length) {
740  readObject(value, length);
741  }
742 
743  inline void readString(char** value) {
744  int8_t typeId;
745  read(&typeId);
746 
747  // Check for NULL String
748  if (typeId == GeodeTypeIds::CacheableNullString) {
749  *value = NULL;
750  return;
751  }
752  /*
753  if (typeId == GeodeTypeIds::CacheableString) {
754  readUTF(value);
755  } else {
756  readUTFHuge(value);
757  }
758  */
759  if (typeId == static_cast<int8_t>(GeodeTypeIds::CacheableASCIIString) ||
760  typeId == static_cast<int8_t>(GeodeTypeIds::CacheableString)) {
761  // readUTF( value);
762  readASCII(value);
763  // m_len = shortLen;
764  } else if (typeId == static_cast<int8_t>(
765  GeodeTypeIds::CacheableASCIIStringHuge) ||
766  typeId ==
767  static_cast<int8_t>(GeodeTypeIds::CacheableStringHuge)) {
768  // readUTFHuge( value);
769  readASCIIHuge(value);
770  } else {
771  throw IllegalArgumentException(
772  "DI readString error:: String type not supported ");
773  }
774  }
775 
776  inline void readWideString(wchar_t** value) {
777  int8_t typeId;
778  read(&typeId);
779 
780  // Check for NULL String
781  if (typeId == GeodeTypeIds::CacheableNullString) {
782  *value = NULL;
783  return;
784  }
785 
786  if (typeId == static_cast<int8_t>(GeodeTypeIds::CacheableASCIIString) ||
787  typeId == static_cast<int8_t>(GeodeTypeIds::CacheableString)) {
788  readUTF(value);
789  } else if (typeId == static_cast<int8_t>(
790  GeodeTypeIds::CacheableASCIIStringHuge) ||
791  typeId ==
792  static_cast<int8_t>(GeodeTypeIds::CacheableStringHuge)) {
793  readUTFHuge(value);
794  } else {
795  throw IllegalArgumentException(
796  "DI readWideString error:: WideString type provided is not "
797  "supported ");
798  }
799  }
800 
801  inline void readStringArray(char*** strArray, int32_t& length) {
802  int32_t arrLen;
803  readArrayLen(&arrLen);
804  length = arrLen;
805  if (arrLen == -1) {
806  *strArray = NULL;
807  return;
808  } else {
809  char** tmpArray;
810  GF_NEW(tmpArray, char * [arrLen]);
811  for (int i = 0; i < arrLen; i++) {
812  readString(&tmpArray[i]);
813  }
814  *strArray = tmpArray;
815  }
816  }
817 
818  inline void readWideStringArray(wchar_t*** strArray, int32_t& length) {
819  int32_t arrLen;
820  readArrayLen(&arrLen);
821  length = arrLen;
822  if (arrLen == -1) {
823  *strArray = NULL;
824  return;
825  } else {
826  wchar_t** tmpArray;
827  GF_NEW(tmpArray, wchar_t * [arrLen]);
828  for (int i = 0; i < arrLen; i++) {
829  readWideString(&tmpArray[i]);
830  }
831  *strArray = tmpArray;
832  }
833  }
834 
835  inline void readArrayOfByteArrays(int8_t*** arrayofBytearr,
836  int32_t& arrayLength,
837  int32_t** elementLength) {
838  int32_t arrLen;
839  readArrayLen(&arrLen);
840  arrayLength = arrLen;
841 
842  if (arrLen == -1) {
843  *arrayofBytearr = NULL;
844  return;
845  } else {
846  int8_t** tmpArray;
847  int32_t* tmpLengtharr;
848  GF_NEW(tmpArray, int8_t * [arrLen]);
849  GF_NEW(tmpLengtharr, int32_t[arrLen]);
850  for (int i = 0; i < arrLen; i++) {
851  readBytes(&tmpArray[i], &tmpLengtharr[i]);
852  }
853  *arrayofBytearr = tmpArray;
854  *elementLength = tmpLengtharr;
855  }
856  }
857 
868  static int32_t getDecodedLength(const uint8_t* value, int32_t length) {
869  const uint8_t* end = value + length;
870  int32_t decodedLen = 0;
871  while (value < end) {
872  // get next byte unsigned
873  int32_t b = *value++ & 0xff;
874  int32_t k = b >> 5;
875  // classify based on the high order 3 bits
876  switch (k) {
877  case 6: {
878  value++;
879  break;
880  }
881  case 7: {
882  value += 2;
883  break;
884  }
885  default:
886  break;
887  }
888  decodedLen += 1;
889  }
890  if (value > end) decodedLen--;
891  return decodedLen;
892  }
893 
895  DataInput(const uint8_t* m_buffer, int32_t len)
896  : m_buf(m_buffer),
897  m_bufHead(m_buffer),
898  m_bufLength(len),
899  m_poolName(NULL) {}
900 
903 
909  inline const uint8_t* currentBufferPosition() const { return m_buf; }
910 
912  inline int32_t getBytesRead() const {
913  return static_cast<int32_t>(m_buf - m_bufHead);
914  }
915 
917  inline int32_t getBytesRemaining() const {
918  return (m_bufLength - getBytesRead());
919  }
920 
922  inline void advanceCursor(int32_t offset) { m_buf += offset; }
923 
925  inline void rewindCursor(int32_t offset) { m_buf -= offset; }
926 
928  inline void reset() { m_buf = m_bufHead; }
929 
930  inline void setBuffer() {
931  m_buf = currentBufferPosition();
932  m_bufLength = getBytesRemaining();
933  }
934 
935  inline void resetPdx(int32_t offset) { m_buf = m_bufHead + offset; }
936 
937  inline int32_t getPdxBytes() const { return m_bufLength; }
938 
939  static uint8_t* getBufferCopy(const uint8_t* from, uint32_t length) {
940  uint8_t* result;
941  GF_NEW(result, uint8_t[length]);
942  std::memcpy(result, from, length);
943 
944  return result;
945  }
946 
947  inline void reset(int32_t offset) { m_buf = m_bufHead + offset; }
948 
949  uint8_t* getBufferCopyFrom(const uint8_t* from, uint32_t length) {
950  uint8_t* result;
951  GF_NEW(result, uint8_t[length]);
952  std::memcpy(result, from, length);
953 
954  return result;
955  }
956 
957  /*
958  * This is for internal use
959  */
960  const char* getPoolName() { return m_poolName; }
961 
962  /*
963  * This is for internal use
964  */
965  void setPoolName(const char* poolName) { m_poolName = poolName; }
966 
967  private:
968  const uint8_t* m_buf;
969  const uint8_t* m_bufHead;
970  int32_t m_bufLength;
971  const char* m_poolName;
972 
973  void readObjectInternal(SerializablePtr& ptr, int8_t typeId = -1);
974 
975  template <typename mType>
976  void readObject(mType** value, int32_t& length) {
977  int arrayLen;
978  readArrayLen(&arrayLen);
979  length = arrayLen;
980  mType* objArray;
981  if (arrayLen > 0) {
982  objArray = new mType[arrayLen];
983  int i = 0;
984  for (i = 0; i < arrayLen; i++) {
985  mType tmp = 0;
986  readObject(&tmp);
987  objArray[i] = tmp; //*value[i] = tmp;
988  }
989  *value = objArray;
990  }
991  }
992 
993  inline void readPdxChar(char* value) {
994  int16_t val = 0;
995  readInt(&val);
996  *value = static_cast<char>(val);
997  }
998 
999  inline void _checkBufferSize(int32_t size, int32_t line) {
1000  if ((m_bufLength - (m_buf - m_bufHead)) < size) {
1001  char exMsg[128];
1002  gf_sprintf(exMsg,
1003  "DataInput: attempt to read beyond buffer at line %d: "
1004  "available buffer size %d, attempted read of size %d ",
1005  line, m_bufLength - (m_buf - m_bufHead), size);
1006  throw OutOfRangeException(exMsg);
1007  }
1008  }
1009 
1010  inline void decodeChar(char* str) {
1011  uint8_t bt = *(m_buf++);
1012  if (bt & 0x80) {
1013  if (bt & 0x20) {
1014  // three bytes.
1015  *str =
1016  static_cast<char>(((bt & 0x0f) << 12) | (((*m_buf++) & 0x3f) << 6));
1017  *str |= static_cast<char>((*m_buf++) & 0x3f);
1018  } else {
1019  // two bytes.
1020  *str = static_cast<char>(((bt & 0x1f) << 6) | ((*m_buf++) & 0x3f));
1021  }
1022  } else {
1023  // single byte...
1024  *str = bt;
1025  }
1026  }
1027 
1028  inline void decodeChar(wchar_t* str) {
1029  // get next byte unsigned
1030  int32_t b = *m_buf++ & 0xff;
1031  int32_t k = b >> 5;
1032  // classify based on the high order 3 bits
1033  switch (k) {
1034  case 6: {
1035  // two byte encoding
1036  // 110yyyyy 10xxxxxx
1037  // use low order 6 bits
1038  int32_t y = b & 0x1f;
1039  // use low order 6 bits of the next byte
1040  // It should have high order bits 10, which we don't check.
1041  int32_t x = *m_buf++ & 0x3f;
1042  // 00000yyy yyxxxxxx
1043  *str = (y << 6 | x);
1044  break;
1045  }
1046  case 7: {
1047  // three byte encoding
1048  // 1110zzzz 10yyyyyy 10xxxxxx
1049  // assert ( b & 0x10 )
1050  // == 0 : "UTF8Decoder does not handle 32-bit characters";
1051  // use low order 4 bits
1052  int32_t z = b & 0x0f;
1053  // use low order 6 bits of the next byte
1054  // It should have high order bits 10, which we don't check.
1055  int32_t y = *m_buf++ & 0x3f;
1056  // use low order 6 bits of the next byte
1057  // It should have high order bits 10, which we don't check.
1058  int32_t x = *m_buf++ & 0x3f;
1059  // zzzzyyyy yyxxxxxx
1060  int32_t asint = (z << 12 | y << 6 | x);
1061  *str = asint;
1062  break;
1063  }
1064  default:
1065  // one byte encoding
1066  // 0xxxxxxx
1067  // use just low order 7 bits
1068  // 00000000 0xxxxxxx
1069  *str = (b & 0x7f);
1070  break;
1071  }
1072  }
1073 
1074  // disable other constructors and assignment
1075  DataInput();
1076  DataInput(const DataInput&);
1077  DataInput& operator=(const DataInput&);
1078 };
1079 } // namespace client
1080 } // namespace geode
1081 } // namespace apache
1082 
1083 #endif // GEODE_DATAINPUT_H_
void readInt(uint64_t *value)
Read a 64-bit unsigned integer from the DataInput.
Definition: DataInput.hpp:207
~DataInput()
destructor
Definition: DataInput.hpp:902
static Serializable * createDeserializable()
creation function for strings
Each enum represents a predefined RegionAttributes in a Cache.
Definition: Assert.hpp:31
virtual Serializable * fromData(DataInput &input)
deserialize this object Throw IllegalArgumentException if the packed CacheableString is not less than...
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:276
void readObject(SerializablePtr &ptr)
Read a Serializable object from the DataInput.
Definition: DataInput.hpp:672
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:525
static Serializable * createDeserializableHuge()
creation function for strings > 64K length
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:439
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:466
#define CPPCACHE_EXPORT
Defines a Geode CPPCACHE export.
Definition: geode_base.hpp:58
int32_t getBytesRemaining() const
get the number of bytes remaining to be read in the buffer
Definition: DataInput.hpp:917
DataInput(const uint8_t *m_buffer, int32_t len)
constructor given a pre-allocated byte array with size
Definition: DataInput.hpp:895
static void freeUTFMemory(char *value)
free the C string allocated by readASCII, readASCIIHuge, readUTF, readUTFHuge methods ...
Definition: DataInput.hpp:358
void readInt(int16_t *value)
Read a 16-bit signed integer from the DataInput.
Definition: DataInput.hpp:241
void read(int8_t *value)
Read a signed byte from the DataInput.
Definition: DataInput.hpp:73
void readFloat(float *value)
Read a float from the DataInput.
Definition: DataInput.hpp:327
void readInt(uint16_t *value)
Read a 16-bit unsigned integer from the DataInput.
Definition: DataInput.hpp:179
void readInt(uint32_t *value)
Read a 32-bit unsigned integer from the DataInput.
Definition: DataInput.hpp:192
void readInt(int32_t *value)
Read a 32-bit signed integer from the DataInput.
Definition: DataInput.hpp:252
void readBytesOnly(int8_t *buffer, uint32_t len)
Read the given number of signed bytes from the DataInput.
Definition: DataInput.hpp:117
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:382
Defines a reference counted shared pointer.
Definition: SharedPtr.hpp:52
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:868
int gf_sprintf(char *buffer, const char *fmt,...)
sprintf implementation.
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:410
void readInt(int64_t *value)
Read a 64-bit signed integer from the DataInput.
Definition: DataInput.hpp:263
void readBoolean(bool *value)
Read a boolean value from the DataInput.
Definition: DataInput.hpp:83
static void freeUTFMemory(wchar_t *value)
free the wide-characted string allocated by readASCII, readASCIIHuge, readUTF, readUTFHuge methods ...
Definition: DataInput.hpp:365
static Serializable * createUTFDeserializable()
creation function for wide strings
void readObject(SharedPtr< PTR > &ptr, bool throwOnError=false)
Read a Serializable object from the DataInput.
Definition: DataInput.hpp:598
void readUnsignedVL(int64_t *value)
Decode a 64 bit integer as a variable length array.
Definition: DataInput.hpp:306
static Serializable * createUTFDeserializableHuge()
creation function for wide strings > 64K length in UTF8 encoding
Provide operations for reading primitive data values, byte arrays, strings, Serializable objects from...
Definition: DataInput.hpp:56
void rewindCursor(int32_t offset)
rewind the cursor by given offset
Definition: DataInput.hpp:925
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:490
int32_t getBytesRead() const
get the number of bytes read in the buffer
Definition: DataInput.hpp:912
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:159
#define GF_NEW(v, stmt)
Allocates x and throws OutOfMemoryException if it fails.
Definition: geode_base.hpp:293
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:557
void read(uint8_t *value)
Read an unsigned byte from the DataInput.
Definition: DataInput.hpp:63
const uint8_t * currentBufferPosition() const
Get the pointer to current buffer position.
Definition: DataInput.hpp:909
void reset()
reset the cursor to the start of buffer
Definition: DataInput.hpp:928
void advanceCursor(int32_t offset)
advance the cursor by given offset
Definition: DataInput.hpp:922
void readDouble(double *value)
Read a double precision number from the DataInput.
Definition: DataInput.hpp:343
This namespace contains all the Geode C++ API classes, enumerations and globals.
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:135
void readBytesOnly(uint8_t *buffer, uint32_t len)
Read the given number of unsigned bytes from the DataInput.
Definition: DataInput.hpp:99

Pivotal GemFire C++ Cache API Documentation