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  std::string res;
317 
318  ReadString(res);
319 
320  return res;
321  }
322 
328  void ReadString(std::string& dst)
329  {
330  int32_t len = ReadString(NULL, 0);
331 
332  if (len != -1)
333  {
334  dst.resize(static_cast<size_t>(len));
335 
336  ReadString(&dst[0], len);
337  }
338  else
339  dst.clear();
340  }
341 
347  BinaryStringArrayReader ReadStringArray();
348 
354  template<typename T>
356  {
357  int32_t size;
358 
359  int32_t id = impl->ReadArray(&size);
360 
361  return BinaryArrayReader<T>(impl, id, size);
362  }
363 
369  template<typename T>
371  {
373  int32_t size;
374 
375  int32_t id = impl->ReadCollection(&typ, &size);
376 
377  return BinaryCollectionReader<T>(impl, id, typ, size);
378  }
379 
386  template<typename T, typename OutputIterator>
387  int32_t ReadCollection(OutputIterator out)
388  {
389  return impl->ReadCollection<T>(out);
390  }
391 
397  template<typename K, typename V>
399  {
400  MapType::Type typ;
401  int32_t size;
402 
403  int32_t id = impl->ReadMap(&typ, &size);
404 
405  return BinaryMapReader<K, V>(impl, id, typ, size);
406  }
407 
413  CollectionType::Type ReadCollectionType();
414 
420  int32_t ReadCollectionSize();
421 
427  template<typename T>
429  {
430  return impl->ReadObject<T>();
431  }
432 
442  template<typename T>
443  bool TryReadObject(T& res)
444  {
445  if (impl->SkipIfNull())
446  return false;
447 
448  res = impl->ReadObject<T>();
449 
450  return true;
451  }
452 
453  private:
455  ignite::impl::binary::BinaryReaderImpl* impl;
456  };
457  }
458 }
459 
460 #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:370
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:398
int32_t ReadCollection(OutputIterator out)
Read values and insert them to specified position.
Definition: binary_raw_reader.h:387
BinaryArrayReader< T > ReadArray()
Start array read.
Definition: binary_raw_reader.h:355
Binary array reader.
Definition: binary_containers.h:389
bool TryReadObject(T &res)
Try read object.
Definition: binary_raw_reader.h:443
Type
Definition: binary_consts.h:35
T ReadObject()
Read object.
Definition: binary_raw_reader.h:428
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
void ReadString(std::string &dst)
Read string from the stream.
Definition: binary_raw_reader.h:328
Apache Ignite API.
Definition: cache.h:48
Declares ignite::Date class.
Binary raw reader.
Definition: binary_raw_reader.h:56