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_RAW_READER
24 #define _IGNITE_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 
36 namespace ignite
37 {
38  namespace binary
39  {
43  class IGNITE_IMPORT_EXPORT BinaryRawReader
44  {
45  public:
51  BinaryRawReader(ignite::impl::binary::BinaryReaderImpl* impl);
52 
58  int8_t ReadInt8();
59 
70  int32_t ReadInt8Array(int8_t* res, int32_t len);
71 
77  bool ReadBool();
78 
89  int32_t ReadBoolArray(bool* res, int32_t len);
90 
96  int16_t ReadInt16();
97 
108  int32_t ReadInt16Array(int16_t* res, int32_t len);
109 
115  uint16_t ReadUInt16();
116 
127  int32_t ReadUInt16Array(uint16_t* res, int32_t len);
128 
134  int32_t ReadInt32();
135 
146  int32_t ReadInt32Array(int32_t* res, int32_t len);
147 
153  int64_t ReadInt64();
154 
165  int32_t ReadInt64Array(int64_t* res, int32_t len);
166 
172  float ReadFloat();
173 
184  int32_t ReadFloatArray(float* res, int32_t len);
185 
191  double ReadDouble();
192 
203  int32_t ReadDoubleArray(double* res, int32_t len);
204 
210  Guid ReadGuid();
211 
222  int32_t ReadGuidArray(Guid* res, int32_t len);
223 
235  int32_t ReadString(char* res, int32_t len);
236 
242  std::string ReadString()
243  {
244  int32_t len = ReadString(NULL, 0);
245 
246  if (len != -1)
247  {
248  ignite::impl::utils::SafeArray<char> arr(len + 1);
249 
250  ReadString(arr.target, len + 1);
251 
252  return std::string(arr.target);
253  }
254  else
255  return std::string();
256  }
257 
263  BinaryStringArrayReader ReadStringArray();
264 
270  template<typename T>
272  {
273  int32_t size;
274 
275  int32_t id = impl->ReadArray(&size);
276 
277  return BinaryArrayReader<T>(impl, id, size);
278  }
279 
285  template<typename T>
287  {
288  CollectionType typ;
289  int32_t size;
290 
291  int32_t id = impl->ReadCollection(&typ, &size);
292 
293  return BinaryCollectionReader<T>(impl, id, typ, size);
294  }
295 
302  template<typename T, typename OutputIterator>
303  int32_t ReadCollection(OutputIterator out)
304  {
305  return impl->ReadCollection<T>(out);
306  }
307 
313  template<typename K, typename V>
315  {
316  MapType typ;
317  int32_t size;
318 
319  int32_t id = impl->ReadMap(&typ, &size);
320 
321  return BinaryMapReader<K, V>(impl, id, typ, size);
322  }
323 
329  CollectionType ReadCollectionType();
330 
336  int32_t ReadCollectionSize();
337 
343  template<typename T>
345  {
346  return impl->ReadObject<T>();
347  }
348  private:
350  ignite::impl::binary::BinaryReaderImpl* impl;
351  };
352  }
353 }
354 
355 #endif
Declares specific binary constatants.
Declares binary reader and writer types for the collections.
Binary string array reader.
Definition: binary_containers.h:220
Binary map reader.
Definition: binary_containers.h:449
BinaryCollectionReader< T > ReadCollection()
Start collection read.
Definition: binary_raw_reader.h:286
Binary collection reader.
Definition: binary_containers.h:367
Declares ignite::Guid class.
BinaryMapReader< K, V > ReadMap()
Start map read.
Definition: binary_raw_reader.h:314
int32_t ReadCollection(OutputIterator out)
Read values and insert them to specified position.
Definition: binary_raw_reader.h:303
CollectionType
Binary collection types.
Definition: binary_consts.h:35
BinaryArrayReader< T > ReadArray()
Start array read.
Definition: binary_raw_reader.h:271
Binary array reader.
Definition: binary_containers.h:299
T ReadObject()
Read object.
Definition: binary_raw_reader.h:344
std::string ReadString()
Read string from the stream.
Definition: binary_raw_reader.h:242
Global universally unique identifier (GUID).
Definition: guid.h:35
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