GridGain C++
binary_reader.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 GridGain Systems, Inc. and Contributors.
3  *
4  * Licensed under the GridGain Community Edition License (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * https://www.gridgain.com/products/software/community-edition/gridgain-community-edition-license
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
22 #ifndef _IGNITE_BINARY_BINARY_READER
23 #define _IGNITE_BINARY_BINARY_READER
24 
25 #include <stdint.h>
26 #include <string>
27 
28 #include <ignite/common/common.h>
29 
31 #include "ignite/guid.h"
32 #include "ignite/date.h"
33 #include "ignite/timestamp.h"
34 
35 namespace ignite
36 {
37  namespace binary
38  {
53  class IGNITE_IMPORT_EXPORT BinaryReader
54  {
55  public:
63  BinaryReader(ignite::impl::binary::BinaryReaderImpl* impl);
64 
71  bool IsNull(const char* fieldName);
72 
79  int8_t ReadInt8(const char* fieldName);
80 
92  int32_t ReadInt8Array(const char* fieldName, int8_t* res, int32_t len);
93 
100  bool ReadBool(const char* fieldName);
101 
113  int32_t ReadBoolArray(const char* fieldName, bool* res, int32_t len);
114 
121  int16_t ReadInt16(const char* fieldName);
122 
134  int32_t ReadInt16Array(const char* fieldName, int16_t* res, int32_t len);
135 
142  uint16_t ReadUInt16(const char* fieldName);
143 
155  int32_t ReadUInt16Array(const char* fieldName, uint16_t* res, int32_t len);
156 
163  int32_t ReadInt32(const char* fieldName);
164 
176  int32_t ReadInt32Array(const char* fieldName, int32_t* res, int32_t len);
177 
184  int64_t ReadInt64(const char* fieldName);
185 
197  int32_t ReadInt64Array(const char* fieldName, int64_t* res, int32_t len);
198 
205  float ReadFloat(const char* fieldName);
206 
218  int32_t ReadFloatArray(const char* fieldName, float* res, int32_t len);
219 
226  double ReadDouble(const char* fieldName);
227 
239  int32_t ReadDoubleArray(const char* fieldName, double* res, int32_t len);
240 
247  Guid ReadGuid(const char* fieldName);
248 
260  int32_t ReadGuidArray(const char* fieldName, Guid* res, int32_t len);
261 
268  Date ReadDate(const char* fieldName);
269 
281  int32_t ReadDateArray(const char* fieldName, Date* res, int32_t len);
282 
289  Timestamp ReadTimestamp(const char* fieldName);
290 
302  int32_t ReadTimestampArray(const char* fieldName, Timestamp* res, int32_t len);
303 
310  Time ReadTime(const char* fieldName);
311 
323  int32_t ReadTimeArray(const char* fieldName, Time* res, int32_t len);
324 
337  int32_t ReadString(const char* fieldName, char* res, int32_t len);
338 
345  std::string ReadString(const char* fieldName)
346  {
347  int32_t len = ReadString(fieldName, NULL, 0);
348 
349  if (len != -1)
350  {
351  ignite::common::FixedSizeArray<char> arr(len + 1);
352 
353  ReadString(fieldName, arr.GetData(), static_cast<int32_t>(arr.GetSize()));
354 
355  return std::string(arr.GetData());
356  }
357  else
358  return std::string();
359  }
360 
372  BinaryStringArrayReader ReadStringArray(const char* fieldName);
373 
380  BinaryEnumEntry ReadBinaryEnum(const char* fieldName);
381 
393  template<typename T>
394  BinaryArrayReader<T> ReadArray(const char* fieldName)
395  {
396  int32_t size;
397 
398  int32_t id = impl->ReadArray(fieldName, &size);
399 
400  return BinaryArrayReader<T>(impl, id, size);
401  }
402 
414  template<typename T>
416  {
418  int32_t size;
419 
420  int32_t id = impl->ReadCollection(fieldName, &typ, &size);
421 
422  return BinaryCollectionReader<T>(impl, id, typ, size);
423  }
424 
432  template<typename T, typename OutputIterator>
433  int32_t ReadCollection(const char* fieldName, OutputIterator out)
434  {
435  return impl->ReadCollection<T>(fieldName, out);
436  }
437 
449  template<typename K, typename V>
450  BinaryMapReader<K, V> ReadMap(const char* fieldName)
451  {
452  MapType::Type typ;
453  int32_t size;
454 
455  int32_t id = impl->ReadMap(fieldName, &typ, &size);
456 
457  return BinaryMapReader<K, V>(impl, id, typ, size);
458  }
459 
466  CollectionType::Type ReadCollectionType(const char* fieldName);
467 
474  int32_t ReadCollectionSize(const char* fieldName);
475 
484  template<typename T>
485  T ReadObject(const char* fieldName)
486  {
487  return impl->ReadObject<T>(fieldName);
488  }
489 
497  template<typename T>
498  T ReadEnum(const char* fieldName)
499  {
500  return impl->ReadEnum<T>(fieldName);
501  }
502 
508  BinaryRawReader RawReader();
509  private:
511  ignite::impl::binary::BinaryReaderImpl* impl;
512  };
513  }
514 }
515 
516 #endif //_IGNITE_BINARY_BINARY_READER
ignite::binary::BinaryRawReader
Binary raw reader.
Definition: binary_raw_reader.h:56
ignite
Ignite API.
Definition: cache.h:47
ignite::binary::MapType::Type
Type
Definition: binary_consts.h:68
ignite::Time
Time type.
Definition: time.h:34
ignite::binary::BinaryReader::ReadCollection
BinaryCollectionReader< T > ReadCollection(const char *fieldName)
Start collection read.
Definition: binary_reader.h:415
ignite::Guid
Global universally unique identifier (GUID).
Definition: guid.h:35
ignite::binary::BinaryCollectionReader
Binary collection reader.
Definition: binary_containers.h:467
ignite::binary::BinaryReader::ReadCollection
int32_t ReadCollection(const char *fieldName, OutputIterator out)
Read values and insert them to specified position.
Definition: binary_reader.h:433
ignite::binary::BinaryMapReader
Binary map reader.
Definition: binary_containers.h:560
ignite::binary::BinaryReader::ReadString
std::string ReadString(const char *fieldName)
Read string from the stream.
Definition: binary_reader.h:345
binary_raw_reader.h
ignite::binary::BinaryArrayReader
Binary array reader.
Definition: binary_containers.h:388
ignite::binary::BinaryReader::ReadObject
T ReadObject(const char *fieldName)
Read object.
Definition: binary_reader.h:485
date.h
ignite::binary::BinaryReader::ReadMap
BinaryMapReader< K, V > ReadMap(const char *fieldName)
Start map read.
Definition: binary_reader.h:450
ignite::binary::BinaryReader
Binary reader.
Definition: binary_reader.h:53
ignite::binary::BinaryEnumEntry
Binary enum entry.
Definition: binary_enum_entry.h:38
ignite::binary::BinaryReader::ReadArray
BinaryArrayReader< T > ReadArray(const char *fieldName)
Start array read.
Definition: binary_reader.h:394
ignite::Timestamp
Timestamp type.
Definition: timestamp.h:36
ignite::Date
Date type.
Definition: date.h:34
ignite::binary::BinaryReader::ReadEnum
T ReadEnum(const char *fieldName)
Read enum value.
Definition: binary_reader.h:498
ignite::binary::BinaryStringArrayReader
Binary string array reader.
Definition: binary_containers.h:296
ignite::binary::CollectionType::Type
Type
Definition: binary_consts.h:34
guid.h
timestamp.h