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_READER
24 #define _IGNITE_BINARY_READER
25 
26 #include <stdint.h>
27 #include <string>
28 
29 #include <ignite/common/common.h>
30 
32 #include "ignite/guid.h"
33 
34 namespace ignite
35 {
36  namespace binary
37  {
41  class IGNITE_IMPORT_EXPORT BinaryReader
42  {
43  public:
49  BinaryReader(ignite::impl::binary::BinaryReaderImpl* impl);
50 
58  int8_t ReadInt8(const char* fieldName);
59 
71  int32_t ReadInt8Array(const char* fieldName, int8_t* res, int32_t len);
72 
79  bool ReadBool(const char* fieldName);
80 
92  int32_t ReadBoolArray(const char* fieldName, bool* res, int32_t len);
93 
100  int16_t ReadInt16(const char* fieldName);
101 
113  int32_t ReadInt16Array(const char* fieldName, int16_t* res, int32_t len);
114 
121  uint16_t ReadUInt16(const char* fieldName);
122 
134  int32_t ReadUInt16Array(const char* fieldName, uint16_t* res, int32_t len);
135 
142  int32_t ReadInt32(const char* fieldName);
143 
155  int32_t ReadInt32Array(const char* fieldName, int32_t* res, int32_t len);
156 
163  int64_t ReadInt64(const char* fieldName);
164 
176  int32_t ReadInt64Array(const char* fieldName, int64_t* res, int32_t len);
177 
184  float ReadFloat(const char* fieldName);
185 
197  int32_t ReadFloatArray(const char* fieldName, float* res, int32_t len);
198 
205  double ReadDouble(const char* fieldName);
206 
218  int32_t ReadDoubleArray(const char* fieldName, double* res, int32_t len);
219 
226  Guid ReadGuid(const char* fieldName);
227 
239  int32_t ReadGuidArray(const char* fieldName, Guid* res, int32_t len);
240 
253  int32_t ReadString(const char* fieldName, char* res, int32_t len);
254 
261  std::string ReadString(const char* fieldName)
262  {
263  int32_t len = ReadString(fieldName, NULL, 0);
264 
265  if (len != -1)
266  {
267  ignite::impl::utils::SafeArray<char> arr(len + 1);
268 
269  ReadString(fieldName, arr.target, len + 1);
270 
271  return std::string(arr.target);
272  }
273  else
274  return std::string();
275  }
276 
283  BinaryStringArrayReader ReadStringArray(const char* fieldName);
284 
291  template<typename T>
292  BinaryArrayReader<T> ReadArray(const char* fieldName)
293  {
294  int32_t size;
295 
296  int32_t id = impl->ReadArray(fieldName, &size);
297 
298  return BinaryArrayReader<T>(impl, id, size);
299  }
300 
307  template<typename T>
309  {
310  CollectionType typ;
311  int32_t size;
312 
313  int32_t id = impl->ReadCollection(fieldName, &typ, &size);
314 
315  return BinaryCollectionReader<T>(impl, id, typ, size);
316  }
317 
325  template<typename T, typename OutputIterator>
326  int32_t ReadCollection(const char* fieldName, OutputIterator out)
327  {
328  return impl->ReadCollection<T>(fieldName, out);
329  }
330 
337  template<typename K, typename V>
338  BinaryMapReader<K, V> ReadMap(const char* fieldName)
339  {
340  MapType typ;
341  int32_t size;
342 
343  int32_t id = impl->ReadMap(fieldName, &typ, &size);
344 
345  return BinaryMapReader<K, V>(impl, id, typ, size);
346  }
347 
354  CollectionType ReadCollectionType(const char* fieldName);
355 
362  int32_t ReadCollectionSize(const char* fieldName);
363 
370  template<typename T>
371  T ReadObject(const char* fieldName)
372  {
373  return impl->ReadObject<T>(fieldName);
374  }
375 
381  BinaryRawReader RawReader();
382  private:
384  ignite::impl::binary::BinaryReaderImpl* impl;
385  };
386  }
387 }
388 
389 #endif
Binary string array reader.
Definition: binary_containers.h:220
Binary map reader.
Definition: binary_containers.h:449
Binary collection reader.
Definition: binary_containers.h:367
Declares ignite::Guid class.
CollectionType
Binary collection types.
Definition: binary_consts.h:35
BinaryCollectionReader< T > ReadCollection(const char *fieldName)
Start collection read.
Definition: binary_reader.h:308
int32_t ReadCollection(const char *fieldName, OutputIterator out)
Read values and insert them to specified position.
Definition: binary_reader.h:326
BinaryMapReader< K, V > ReadMap(const char *fieldName)
Start map read.
Definition: binary_reader.h:338
Binary array reader.
Definition: binary_containers.h:299
T ReadObject(const char *fieldName)
Read object.
Definition: binary_reader.h:371
std::string ReadString(const char *fieldName)
Read string from the stream.
Definition: binary_reader.h:261
BinaryArrayReader< T > ReadArray(const char *fieldName)
Start array read.
Definition: binary_reader.h:292
Global universally unique identifier (GUID).
Definition: guid.h:35
Declares ignite::binary::BinaryRawReader class.
Apache Ignite API.
Definition: binary_consts.h:28
MapType
Binary map types.
Definition: binary_consts.h:66
Binary raw reader.
Definition: binary_raw_reader.h:43
Binary reader.
Definition: binary_reader.h:41