Apache Ignite C++
binary_raw_reader.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
23 #ifndef _IGNITE_BINARY_BINARY_RAW_READER
24 #define _IGNITE_BINARY_BINARY_RAW_READER
25 
26 #include <stdint.h>
27 #include <string>
28 
29 #include <ignite/common/common.h>
30 
31 #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  int8_t ReadInt8();
74 
85  int32_t ReadInt8Array(int8_t* res, int32_t len);
86 
92  bool ReadBool();
93 
104  int32_t ReadBoolArray(bool* res, int32_t len);
105 
111  int16_t ReadInt16();
112 
123  int32_t ReadInt16Array(int16_t* res, int32_t len);
124 
130  uint16_t ReadUInt16();
131 
142  int32_t ReadUInt16Array(uint16_t* res, int32_t len);
143 
149  int32_t ReadInt32();
150 
161  int32_t ReadInt32Array(int32_t* res, int32_t len);
162 
168  int64_t ReadInt64();
169 
180  int32_t ReadInt64Array(int64_t* res, int32_t len);
181 
187  float ReadFloat();
188 
199  int32_t ReadFloatArray(float* res, int32_t len);
200 
206  double ReadDouble();
207 
218  int32_t ReadDoubleArray(double* res, int32_t len);
219 
225  Guid ReadGuid();
226 
237  int32_t ReadGuidArray(Guid* res, int32_t len);
238 
244  Date ReadDate();
245 
256  int32_t ReadDateArray(Date* res, int32_t len);
257 
263  Timestamp ReadTimestamp();
264 
275  int32_t ReadTimestampArray(Timestamp* res, int32_t len);
276 
282  Time ReadTime();
283 
294  int32_t ReadTimeArray(Time* res, int32_t len);
295 
307  int32_t ReadString(char* res, int32_t len);
308 
314  std::string ReadString()
315  {
316  int32_t len = ReadString(NULL, 0);
317 
318  if (len != -1)
319  {
320  ignite::common::FixedSizeArray<char> arr(len + 1);
321 
322  ReadString(arr.GetData(), static_cast<int32_t>(arr.GetSize()));
323 
324  return std::string(arr.GetData());
325  }
326  else
327  return std::string();
328  }
329 
335  BinaryStringArrayReader ReadStringArray();
336 
342  template<typename T>
344  {
345  int32_t size;
346 
347  int32_t id = impl->ReadArray(&size);
348 
349  return BinaryArrayReader<T>(impl, id, size);
350  }
351 
357  template<typename T>
359  {
361  int32_t size;
362 
363  int32_t id = impl->ReadCollection(&typ, &size);
364 
365  return BinaryCollectionReader<T>(impl, id, typ, size);
366  }
367 
374  template<typename T, typename OutputIterator>
375  int32_t ReadCollection(OutputIterator out)
376  {
377  return impl->ReadCollection<T>(out);
378  }
379 
385  template<typename K, typename V>
387  {
388  MapType::Type typ;
389  int32_t size;
390 
391  int32_t id = impl->ReadMap(&typ, &size);
392 
393  return BinaryMapReader<K, V>(impl, id, typ, size);
394  }
395 
401  CollectionType::Type ReadCollectionType();
402 
408  int32_t ReadCollectionSize();
409 
415  template<typename T>
417  {
418  return impl->ReadObject<T>();
419  }
420 
430  template<typename T>
431  bool TryReadObject(T& res)
432  {
433  if (impl->SkipIfNull())
434  return false;
435 
436  res = impl->ReadObject<T>();
437 
438  return true;
439  }
440 
441  private:
443  ignite::impl::binary::BinaryReaderImpl* impl;
444  };
445  }
446 }
447 
448 #endif //_IGNITE_BINARY_BINARY_RAW_READER
Timestamp type.
Definition: timestamp.h:37
Declares specific binary constatants.
Date type.
Definition: date.h:35
Declares binary reader and writer types for the collections.
Binary string array reader.
Definition: binary_containers.h:297
Binary map reader.
Definition: binary_containers.h:561
BinaryCollectionReader< T > ReadCollection()
Start collection read.
Definition: binary_raw_reader.h:358
Binary collection reader.
Definition: binary_containers.h:468
Declares ignite::Guid class.
Declares ignite::Timestamp class.
BinaryMapReader< K, V > ReadMap()
Start map read.
Definition: binary_raw_reader.h:386
int32_t ReadCollection(OutputIterator out)
Read values and insert them to specified position.
Definition: binary_raw_reader.h:375
BinaryArrayReader< T > ReadArray()
Start array read.
Definition: binary_raw_reader.h:343
Binary array reader.
Definition: binary_containers.h:389
bool TryReadObject(T &res)
Try read object.
Definition: binary_raw_reader.h:431
Type
Definition: binary_consts.h:35
T ReadObject()
Read object.
Definition: binary_raw_reader.h:416
Type
Definition: binary_consts.h:69
Time type.
Definition: time.h:35
std::string ReadString()
Read string from the stream.
Definition: binary_raw_reader.h:314
Global universally unique identifier (GUID).
Definition: guid.h:36
Apache Ignite API.
Definition: cache.h:48
Declares ignite::Date class.
Binary raw reader.
Definition: binary_raw_reader.h:56