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 
310  int32_t ReadString(const char* fieldName, char* res, int32_t len);
311 
318  std::string ReadString(const char* fieldName)
319  {
320  int32_t len = ReadString(fieldName, NULL, 0);
321 
322  if (len != -1)
323  {
324  ignite::common::FixedSizeArray<char> arr(len + 1);
325 
326  ReadString(fieldName, arr.GetData(), static_cast<int32_t>(arr.GetSize()));
327 
328  return std::string(arr.GetData());
329  }
330  else
331  return std::string();
332  }
333 
340  BinaryStringArrayReader ReadStringArray(const char* fieldName);
341 
348  template<typename T>
349  BinaryArrayReader<T> ReadArray(const char* fieldName)
350  {
351  int32_t size;
352 
353  int32_t id = impl->ReadArray(fieldName, &size);
354 
355  return BinaryArrayReader<T>(impl, id, size);
356  }
357 
364  template<typename T>
366  {
367  CollectionType typ;
368  int32_t size;
369 
370  int32_t id = impl->ReadCollection(fieldName, &typ, &size);
371 
372  return BinaryCollectionReader<T>(impl, id, typ, size);
373  }
374 
382  template<typename T, typename OutputIterator>
383  int32_t ReadCollection(const char* fieldName, OutputIterator out)
384  {
385  return impl->ReadCollection<T>(fieldName, out);
386  }
387 
394  template<typename K, typename V>
395  BinaryMapReader<K, V> ReadMap(const char* fieldName)
396  {
397  MapType typ;
398  int32_t size;
399 
400  int32_t id = impl->ReadMap(fieldName, &typ, &size);
401 
402  return BinaryMapReader<K, V>(impl, id, typ, size);
403  }
404 
411  CollectionType ReadCollectionType(const char* fieldName);
412 
419  int32_t ReadCollectionSize(const char* fieldName);
420 
427  template<typename T>
428  T ReadObject(const char* fieldName)
429  {
430  return impl->ReadObject<T>(fieldName);
431  }
432 
438  BinaryRawReader RawReader();
439  private:
441  ignite::impl::binary::BinaryReaderImpl* impl;
442  };
443  }
444 }
445 
446 #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.
CollectionType
Binary collection types.
Definition: binary_consts.h:35
BinaryCollectionReader< T > ReadCollection(const char *fieldName)
Start collection read.
Definition: binary_reader.h:365
int32_t ReadCollection(const char *fieldName, OutputIterator out)
Read values and insert them to specified position.
Definition: binary_reader.h:383
BinaryMapReader< K, V > ReadMap(const char *fieldName)
Start map read.
Definition: binary_reader.h:395
Binary array reader.
Definition: binary_containers.h:389
T ReadObject(const char *fieldName)
Read object.
Definition: binary_reader.h:428
std::string ReadString(const char *fieldName)
Read string from the stream.
Definition: binary_reader.h:318
BinaryArrayReader< T > ReadArray(const char *fieldName)
Start array read.
Definition: binary_reader.h:349
Global universally unique identifier (GUID).
Definition: guid.h:36
Declares ignite::binary::BinaryRawReader class.
Apache Ignite API.
Definition: cache.h:43
Declares ignite::Date class.
MapType
Binary map types.
Definition: binary_consts.h:66
Binary raw reader.
Definition: binary_raw_reader.h:56
Binary reader.
Definition: binary_reader.h:54