GridGain C++
binary_raw_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_RAW_READER
23 #define _IGNITE_BINARY_BINARY_RAW_READER
24 
25 #include <stdint.h>
26 #include <string>
27 
28 #include <ignite/common/common.h>
29 
30 #include "ignite/impl/binary/binary_reader_impl.h"
34 #include "ignite/guid.h"
35 #include "ignite/date.h"
36 #include "ignite/timestamp.h"
37 
38 namespace ignite
39 {
40  namespace binary
41  {
56  class IGNITE_IMPORT_EXPORT BinaryRawReader
57  {
58  public:
66  BinaryRawReader(ignite::impl::binary::BinaryReaderImpl* impl);
67 
73  bool SkipIfNull();
74 
80  int8_t ReadInt8();
81 
92  int32_t ReadInt8Array(int8_t* res, int32_t len);
93 
99  bool ReadBool();
100 
111  int32_t ReadBoolArray(bool* res, int32_t len);
112 
118  int16_t ReadInt16();
119 
130  int32_t ReadInt16Array(int16_t* res, int32_t len);
131 
137  uint16_t ReadUInt16();
138 
149  int32_t ReadUInt16Array(uint16_t* res, int32_t len);
150 
156  int32_t ReadInt32();
157 
168  int32_t ReadInt32Array(int32_t* res, int32_t len);
169 
175  int64_t ReadInt64();
176 
187  int32_t ReadInt64Array(int64_t* res, int32_t len);
188 
194  float ReadFloat();
195 
206  int32_t ReadFloatArray(float* res, int32_t len);
207 
213  double ReadDouble();
214 
225  int32_t ReadDoubleArray(double* res, int32_t len);
226 
232  Guid ReadGuid();
233 
244  int32_t ReadGuidArray(Guid* res, int32_t len);
245 
251  Date ReadDate();
252 
263  int32_t ReadDateArray(Date* res, int32_t len);
264 
270  Timestamp ReadTimestamp();
271 
282  int32_t ReadTimestampArray(Timestamp* res, int32_t len);
283 
289  Time ReadTime();
290 
301  int32_t ReadTimeArray(Time* res, int32_t len);
302 
314  int32_t ReadString(char* res, int32_t len);
315 
321  std::string ReadString()
322  {
323  std::string res;
324 
325  ReadString(res);
326 
327  return res;
328  }
329 
335  void ReadString(std::string& dst)
336  {
337  int32_t len = ReadString(NULL, 0);
338 
339  if (len != -1)
340  {
341  dst.resize(static_cast<size_t>(len));
342 
343  ReadString(&dst[0], len);
344  }
345  else
346  dst.clear();
347  }
348 
359  BinaryStringArrayReader ReadStringArray();
360 
366  BinaryEnumEntry ReadBinaryEnum();
367 
378  template<typename T>
380  {
381  int32_t size;
382 
383  int32_t id = impl->ReadArray(&size);
384 
385  return BinaryArrayReader<T>(impl, id, size);
386  }
387 
398  template<typename T>
400  {
402  int32_t size;
403 
404  int32_t id = impl->ReadCollection(&typ, &size);
405 
406  return BinaryCollectionReader<T>(impl, id, typ, size);
407  }
408 
415  template<typename T, typename OutputIterator>
416  int32_t ReadCollection(OutputIterator out)
417  {
418  return impl->ReadCollection<T>(out);
419  }
420 
431  template<typename K, typename V>
433  {
434  MapType::Type typ;
435  int32_t size;
436 
437  int32_t id = impl->ReadMap(&typ, &size);
438 
439  return BinaryMapReader<K, V>(impl, id, typ, size);
440  }
441 
447  CollectionType::Type ReadCollectionType();
448 
454  int32_t ReadCollectionSize();
455 
463  template<typename T>
465  {
466  return impl->ReadObject<T>();
467  }
468 
476  template<typename T>
478  {
479  return impl->ReadEnum<T>();
480  }
481 
491  template<typename T>
492  bool TryReadObject(T& res)
493  {
494  if (impl->SkipIfNull())
495  return false;
496 
497  res = impl->ReadObject<T>();
498 
499  return true;
500  }
501 
502  private:
504  ignite::impl::binary::BinaryReaderImpl* impl;
505  };
506  }
507 }
508 
509 #endif //_IGNITE_BINARY_BINARY_RAW_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::BinaryRawReader::ReadMap
BinaryMapReader< K, V > ReadMap()
Start map read.
Definition: binary_raw_reader.h:432
ignite::Guid
Global universally unique identifier (GUID).
Definition: guid.h:35
ignite::binary::BinaryCollectionReader
Binary collection reader.
Definition: binary_containers.h:467
binary_consts.h
ignite::binary::BinaryMapReader
Binary map reader.
Definition: binary_containers.h:560
ignite::binary::BinaryRawReader::ReadCollection
int32_t ReadCollection(OutputIterator out)
Read values and insert them to specified position.
Definition: binary_raw_reader.h:416
binary_enum_entry.h
ignite::binary::BinaryRawReader::ReadCollection
BinaryCollectionReader< T > ReadCollection()
Start collection read.
Definition: binary_raw_reader.h:399
ignite::binary::BinaryRawReader::TryReadObject
bool TryReadObject(T &res)
Try read object.
Definition: binary_raw_reader.h:492
ignite::binary::BinaryRawReader::ReadObject
T ReadObject()
Read object.
Definition: binary_raw_reader.h:464
ignite::binary::BinaryRawReader::ReadArray
BinaryArrayReader< T > ReadArray()
Start array read.
Definition: binary_raw_reader.h:379
ignite::binary::BinaryArrayReader
Binary array reader.
Definition: binary_containers.h:388
date.h
ignite::binary::BinaryEnumEntry
Binary enum entry.
Definition: binary_enum_entry.h:38
ignite::Timestamp
Timestamp type.
Definition: timestamp.h:36
ignite::Date
Date type.
Definition: date.h:34
ignite::binary::BinaryStringArrayReader
Binary string array reader.
Definition: binary_containers.h:296
ignite::binary::BinaryRawReader::ReadString
std::string ReadString()
Read string from the stream.
Definition: binary_raw_reader.h:321
ignite::binary::CollectionType::Type
Type
Definition: binary_consts.h:34
ignite::binary::BinaryRawReader::ReadEnum
T ReadEnum()
Read enum value.
Definition: binary_raw_reader.h:477
guid.h
ignite::binary::BinaryRawReader::ReadString
void ReadString(std::string &dst)
Read string from the stream.
Definition: binary_raw_reader.h:335
binary_containers.h
timestamp.h