3 #ifndef GEODE_SERIALIZER_H_ 4 #define GEODE_SERIALIZER_H_ 23 #include "geode_globals.hpp" 29 #include "GeodeTypeIds.hpp" 30 #include "TypeHelper.hpp" 35 namespace serializer {
59 const uint8_t* bytes, int32_t len) {
69 const int8_t* bytes, int32_t len) {
166 output.
writeInt(static_cast<int16_t>(value));
177 const char* value, uint32_t length) {
181 template <
typename TLen>
199 const wchar_t* value, uint32_t length) {
203 template <
typename TLen>
212 const wchar_t* value) {
223 template <
typename TObj>
224 inline void writeObject(
227 apache::geode::client::TypeHelper::yes_type isSerializable) {
231 template <
typename TObj>
234 writeObject(output, value, GF_TYPE_IS_SERIALIZABLE_TYPE(TObj));
237 template <
typename TObj>
238 inline void readObject(
241 apache::geode::client::TypeHelper::yes_type isSerializable) {
245 template <
typename TObj>
248 readObject(input, value, GF_TYPE_IS_SERIALIZABLE_TYPE(TObj));
253 template <
typename TObj,
typename TLen>
255 const TObj* array, TLen len) {
257 output.
write(static_cast<int8_t>(-1));
260 const TObj* endArray = array + len;
261 while (array < endArray) {
262 writeObject(output, *array++);
267 template <
typename TObj,
typename TLen>
273 TObj* startArray = array;
274 TObj* endArray = array + len;
275 while (startArray < endArray) {
276 readObject(input, *startArray++);
283 template <
typename TObj,
typename TLen>
284 inline uint32_t objectSize(
285 const TObj* array, TLen len,
286 apache::geode::client::TypeHelper::yes_type isSerializable) {
288 const TObj* endArray = array + len;
289 while (array < endArray) {
290 if (*array != NULL) {
291 size += (*array)->objectSize();
295 size += (uint32_t)(
sizeof(TObj) * len);
299 template <
typename TObj,
typename TLen>
300 inline uint32_t objectSize(
301 const TObj* array, TLen len,
302 apache::geode::client::TypeHelper::no_type isNotSerializable) {
303 return (uint32_t)(
sizeof(TObj) * len);
306 template <
typename TObj,
typename TLen>
307 inline uint32_t objectSize(
const TObj* array, TLen len) {
308 return objectSize(array, len, GF_TYPE_IS_SERIALIZABLE_TYPE(TObj));
313 template <
typename TObj>
315 const VectorT<TObj>& value) {
316 int32_t len = (int32_t)value.size();
318 for (
typename VectorT<TObj>::Iterator iter = value.begin();
319 iter != value.end(); ++iter) {
320 writeObject(output, *iter);
324 inline uint32_t objectSize(
const _VectorOfCacheable& value) {
325 uint32_t objectSize = 0;
326 for (_VectorOfCacheable::Iterator iter = value.begin(); iter != value.end();
328 if (*iter != NULLPTR) {
329 objectSize += (*iter)->objectSize();
332 objectSize +=
static_cast<uint32_t
>(
sizeof(CacheablePtr) * value.size());
336 template <
typename TObj>
338 VectorT<TObj>& value) {
343 for (int32_t index = 0; index < len; index++) {
344 readObject(input, obj);
345 value.push_back(obj);
350 template <
typename TKey,
typename TValue>
352 const HashMapT<TKey, TValue>& value) {
353 int32_t len = (int32_t)value.size();
356 for (
typename HashMapT<TKey, TValue>::Iterator iter = value.begin();
357 iter != value.end(); ++iter) {
358 writeObject(output, iter.first());
359 writeObject(output, iter.second());
364 inline uint32_t objectSize(
const _HashMapOfCacheable& value) {
365 uint32_t objectSize = 0;
366 for (_HashMapOfCacheable::Iterator iter = value.begin(); iter != value.end();
368 objectSize += iter.first()->objectSize();
369 if (iter.second() != NULLPTR) {
370 objectSize += iter.second()->objectSize();
373 objectSize +=
static_cast<uint32_t
>(
374 (
sizeof(CacheableKeyPtr) +
sizeof(CacheablePtr)) * value.size());
378 template <
typename TKey,
typename TValue>
380 HashMapT<TKey, TValue>& value) {
386 for (int32_t index = 0; index < len; index++) {
387 readObject(input, key);
388 readObject(input, val);
389 value.insert(key, val);
394 template <
typename TKey>
396 const HashSetT<TKey>& value) {
397 int32_t len = (int32_t)value.size();
399 for (
typename HashSetT<TKey>::Iterator iter = value.begin();
400 iter != value.end(); ++iter) {
401 writeObject(output, *iter);
405 inline uint32_t objectSize(
const _HashSetOfCacheableKey& value) {
406 uint32_t objectSize = 0;
407 for (_HashSetOfCacheableKey::Iterator iter = value.begin();
408 iter != value.end(); ++iter) {
409 if (*iter != NULLPTR) {
410 objectSize += (*iter)->objectSize();
413 objectSize +=
static_cast<uint32_t
>(
sizeof(CacheableKeyPtr) * value.size());
417 template <
typename TKey>
419 HashSetT<TKey>& value) {
424 for (int32_t index = 0; index < len; index++) {
425 readObject(input, key);
433 template <
typename TObj>
434 inline TObj zeroObject() {
439 inline bool zeroObject<bool>() {
444 inline double zeroObject<double>() {
449 inline float zeroObject<float>() {
457 #endif // GEODE_SERIALIZER_H_ void writeArrayLen(int32_t len)
Write a 32-bit signed integer array length value to the DataOutput in a manner compatible with java s...
Definition: DataOutput.hpp:270
void writeFloat(float value)
Write a float value to the DataOutput.
Definition: DataOutput.hpp:289
Each enum represents a predefined RegionAttributes in a Cache.
Definition: Assert.hpp:31
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 writeASCII(const char *value, uint32_t length=0)
Writes the given ASCII string supporting maximum length of 64K (i.e.
Definition: DataOutput.hpp:324
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 writeBoolean(bool value)
Write a boolean value to the DataOutput.
Definition: DataOutput.hpp:103
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
Provide operations for writing primitive data values, byte arrays, strings, Serializable objects to a...
Definition: DataOutput.hpp:74
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
void writeObject(const SharedPtr< PTR > &objptr, bool isDelta=false)
Write a Serializable object to the DataOutput.
Definition: DataOutput.hpp:582
void readBoolean(bool *value)
Read a boolean value from the DataInput.
Definition: DataInput.hpp:83
void readObject(SharedPtr< PTR > &ptr, bool throwOnError=false)
Read a Serializable object from the DataInput.
Definition: DataInput.hpp:598
void writeBytes(const uint8_t *bytes, int32_t len)
Write an array of unsigned bytes to the DataOutput.
Definition: DataOutput.hpp:111
Provide operations for reading primitive data values, byte arrays, strings, Serializable objects from...
Definition: DataInput.hpp:56
void writeUTF(const char *value, uint32_t length=0)
Writes the given given string using java modified UTF-8 encoding supporting maximum encoded length of...
Definition: DataOutput.hpp:406
void writeInt(uint16_t value)
Write a 16-bit unsigned integer value to the DataOutput.
Definition: DataOutput.hpp:171
void writeDouble(double value)
Write a double precision real number to the DataOutput.
Definition: DataOutput.hpp:303
#define GF_NEW(v, stmt)
Allocates x and throws OutOfMemoryException if it fails.
Definition: geode_base.hpp:293
void read(uint8_t *value)
Read an unsigned byte from the DataInput.
Definition: DataInput.hpp:63
void write(uint8_t value)
Write an unsigned byte to the DataOutput.
Definition: DataOutput.hpp:86
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