Apache Ignite C++
binary_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_READER
24 #define _IGNITE_BINARY_BINARY_READER
25 
26 #include <stdint.h>
27 #include <string>
28 
29 #include <ignite/common/common.h>
30 
32 #include "ignite/guid.h"
33 #include "ignite/date.h"
34 #include "ignite/timestamp.h"
35 
36 namespace ignite
37 {
38  namespace binary
39  {
54  class IGNITE_IMPORT_EXPORT BinaryReader
55  {
56  public:
64  BinaryReader(ignite::impl::binary::BinaryReaderImpl* impl);
65 
73  int8_t ReadInt8(const char* fieldName);
74 
86  int32_t ReadInt8Array(const char* fieldName, int8_t* res, int32_t len);
87 
94  bool ReadBool(const char* fieldName);
95 
107  int32_t ReadBoolArray(const char* fieldName, bool* res, int32_t len);
108 
115  int16_t ReadInt16(const char* fieldName);
116 
128  int32_t ReadInt16Array(const char* fieldName, int16_t* res, int32_t len);
129 
136  uint16_t ReadUInt16(const char* fieldName);
137 
149  int32_t ReadUInt16Array(const char* fieldName, uint16_t* res, int32_t len);
150 
157  int32_t ReadInt32(const char* fieldName);
158 
170  int32_t ReadInt32Array(const char* fieldName, int32_t* res, int32_t len);
171 
178  int64_t ReadInt64(const char* fieldName);
179 
191  int32_t ReadInt64Array(const char* fieldName, int64_t* res, int32_t len);
192 
199  float ReadFloat(const char* fieldName);
200 
212  int32_t ReadFloatArray(const char* fieldName, float* res, int32_t len);
213 
220  double ReadDouble(const char* fieldName);
221 
233  int32_t ReadDoubleArray(const char* fieldName, double* res, int32_t len);
234 
241  Guid ReadGuid(const char* fieldName);
242 
254  int32_t ReadGuidArray(const char* fieldName, Guid* res, int32_t len);
255 
262  Date ReadDate(const char* fieldName);
263 
275  int32_t ReadDateArray(const char* fieldName, Date* res, const int32_t len);
276 
283  Timestamp ReadTimestamp(const char* fieldName);
284 
296  int32_t ReadTimestampArray(const char* fieldName, Timestamp* res, const int32_t len);
297 
304  Time ReadTime(const char* fieldName);
305 
317  int32_t ReadTimeArray(const char* fieldName, Time* res, const int32_t len);
318 
331  int32_t ReadString(const char* fieldName, char* res, int32_t len);
332 
339  std::string ReadString(const char* fieldName)
340  {
341  int32_t len = ReadString(fieldName, NULL, 0);
342 
343  if (len != -1)
344  {
345  ignite::common::FixedSizeArray<char> arr(len + 1);
346 
347  ReadString(fieldName, arr.GetData(), static_cast<int32_t>(arr.GetSize()));
348 
349  return std::string(arr.GetData());
350  }
351  else
352  return std::string();
353  }
354 
361  BinaryStringArrayReader ReadStringArray(const char* fieldName);
362 
369  template<typename T>
370  BinaryArrayReader<T> ReadArray(const char* fieldName)
371  {
372  int32_t size;
373 
374  int32_t id = impl->ReadArray(fieldName, &size);
375 
376  return BinaryArrayReader<T>(impl, id, size);
377  }
378 
385  template<typename T>
387  {
389  int32_t size;
390 
391  int32_t id = impl->ReadCollection(fieldName, &typ, &size);
392 
393  return BinaryCollectionReader<T>(impl, id, typ, size);
394  }
395 
403  template<typename T, typename OutputIterator>
404  int32_t ReadCollection(const char* fieldName, OutputIterator out)
405  {
406  return impl->ReadCollection<T>(fieldName, out);
407  }
408 
415  template<typename K, typename V>
416  BinaryMapReader<K, V> ReadMap(const char* fieldName)
417  {
418  MapType::Type typ;
419  int32_t size;
420 
421  int32_t id = impl->ReadMap(fieldName, &typ, &size);
422 
423  return BinaryMapReader<K, V>(impl, id, typ, size);
424  }
425 
432  CollectionType::Type ReadCollectionType(const char* fieldName);
433 
440  int32_t ReadCollectionSize(const char* fieldName);
441 
448  template<typename T>
449  T ReadObject(const char* fieldName)
450  {
451  return impl->ReadObject<T>(fieldName);
452  }
453 
459  BinaryRawReader RawReader();
460  private:
462  ignite::impl::binary::BinaryReaderImpl* impl;
463  };
464  }
465 }
466 
467 #endif //_IGNITE_BINARY_BINARY_READER
Timestamp type.
Definition: timestamp.h:37
Date type.
Definition: date.h:35
Binary string array reader.
Definition: binary_containers.h:297
Binary map reader.
Definition: binary_containers.h:561
Binary collection reader.
Definition: binary_containers.h:468
Declares ignite::Guid class.
Declares ignite::Timestamp class.
BinaryCollectionReader< T > ReadCollection(const char *fieldName)
Start collection read.
Definition: binary_reader.h:386
int32_t ReadCollection(const char *fieldName, OutputIterator out)
Read values and insert them to specified position.
Definition: binary_reader.h:404
BinaryMapReader< K, V > ReadMap(const char *fieldName)
Start map read.
Definition: binary_reader.h:416
Binary array reader.
Definition: binary_containers.h:389
Type
Definition: binary_consts.h:35
Type
Definition: binary_consts.h:69
Time type.
Definition: time.h:35
T ReadObject(const char *fieldName)
Read object.
Definition: binary_reader.h:449
std::string ReadString(const char *fieldName)
Read string from the stream.
Definition: binary_reader.h:339
BinaryArrayReader< T > ReadArray(const char *fieldName)
Start array read.
Definition: binary_reader.h:370
Global universally unique identifier (GUID).
Definition: guid.h:36
Declares ignite::binary::BinaryRawReader class.
Apache Ignite API.
Definition: cache.h:48
Declares ignite::Date class.
Binary raw reader.
Definition: binary_raw_reader.h:56
Binary reader.
Definition: binary_reader.h:54