| 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"
32 #include "ignite/binary/binary_consts.h"
33 #include "ignite/binary/binary_containers.h"
34 #include "ignite/binary/binary_enum_entry.h"
35 #include "ignite/guid.h"
36 #include "ignite/date.h"
37 #include "ignite/timestamp.h"
38
39 namespace ignite
40 {
41 namespace binary
42 {
57 class IGNITE_IMPORT_EXPORT BinaryRawReader
58 {
59 public:
67 BinaryRawReader(ignite::impl::binary::BinaryReaderImpl* impl);
68
74 int8_t ReadInt8();
75
86 int32_t ReadInt8Array(int8_t* res, int32_t len);
87
93 bool ReadBool();
94
105 int32_t ReadBoolArray(bool* res, int32_t len);
106
112 int16_t ReadInt16();
113
124 int32_t ReadInt16Array(int16_t* res, int32_t len);
125
131 uint16_t ReadUInt16();
132
143 int32_t ReadUInt16Array(uint16_t* res, int32_t len);
144
150 int32_t ReadInt32();
151
162 int32_t ReadInt32Array(int32_t* res, int32_t len);
163
169 int64_t ReadInt64();
170
181 int32_t ReadInt64Array(int64_t* res, int32_t len);
182
188 float ReadFloat();
189
200 int32_t ReadFloatArray(float* res, int32_t len);
201
207 double ReadDouble();
208
219 int32_t ReadDoubleArray(double* res, int32_t len);
220
226 Guid ReadGuid();
227
238 int32_t ReadGuidArray(Guid* res, int32_t len);
239
245 Date ReadDate();
246
257 int32_t ReadDateArray(Date* res, int32_t len);
258
264 Timestamp ReadTimestamp();
265
276 int32_t ReadTimestampArray(Timestamp* res, int32_t len);
277
283 Time ReadTime();
284
295 int32_t ReadTimeArray(Time* res, int32_t len);
296
308 int32_t ReadString(char* res, int32_t len);
309
315 std::string ReadString()
316 {
317 std::string res;
318
319 ReadString(res);
320
321 return res;
322 }
323
329 void ReadString(std::string& dst)
330 {
331 int32_t len = ReadString(NULL, 0);
332
333 if (len != -1)
334 {
335 dst.resize(static_cast<size_t>(len));
336
337 ReadString(&dst[0], len);
338 }
339 else
340 dst.clear();
341 }
342
353 BinaryStringArrayReader ReadStringArray();
354
360 BinaryEnumEntry ReadBinaryEnum();
361
372 template<typename T>
373 BinaryArrayReader<T> ReadArray()
374 {
375 int32_t size;
376
377 int32_t id = impl->ReadArray(&size);
378
379 return BinaryArrayReader<T>(impl, id, size);
380 }
381
392 template<typename T>
393 BinaryCollectionReader<T> ReadCollection()
394 {
395 CollectionType::Type typ;
396 int32_t size;
397
398 int32_t id = impl->ReadCollection(&typ, &size);
399
400 return BinaryCollectionReader<T>(impl, id, typ, size);
401 }
402
409 template<typename T, typename OutputIterator>
410 int32_t ReadCollection(OutputIterator out)
411 {
412 return impl->ReadCollection<T>(out);
413 }
414
425 template<typename K, typename V>
426 BinaryMapReader<K, V> ReadMap()
427 {
428 MapType::Type typ;
429 int32_t size;
430
431 int32_t id = impl->ReadMap(&typ, &size);
432
433 return BinaryMapReader<K, V>(impl, id, typ, size);
434 }
435
441 CollectionType::Type ReadCollectionType();
442
448 int32_t ReadCollectionSize();
449
457 template<typename T>
458 T ReadObject()
459 {
460 return impl->ReadObject<T>();
461 }
462
470 template<typename T>
471 T ReadEnum()
472 {
473 return impl->ReadEnum<T>();
474 }
475
485 template<typename T>
486 bool TryReadObject(T& res)
487 {
488 if (impl->SkipIfNull())
489 return false;
490
491 res = impl->ReadObject<T>();
492
493 return true;
494 }
495
496 private:
498 ignite::impl::binary::BinaryReaderImpl* impl;
499 };
500 }
501 }
502
503 #endif //_IGNITE_BINARY_BINARY_RAW_READER
ignite::binary::BinaryRawReader
Binary raw reader.
Definition: binary_raw_reader.h:57
ignite
Apache Ignite API.
Definition: cache.h:48
ignite::binary::MapType::Type
Type
Definition: binary_consts.h:69
ignite::Time
Time type.
Definition: time.h:35
ignite::binary::BinaryRawReader::ReadMap
BinaryMapReader< K, V > ReadMap()
Start map read.
Definition: binary_raw_reader.h:426
ignite::Guid
Global universally unique identifier (GUID).
Definition: guid.h:36
ignite::binary::BinaryCollectionReader
Binary collection reader.
Definition: binary_containers.h:468
binary_consts.h
ignite::binary::BinaryMapReader
Binary map reader.
Definition: binary_containers.h:561
ignite::binary::BinaryRawReader::ReadCollection
int32_t ReadCollection(OutputIterator out)
Read values and insert them to specified position.
Definition: binary_raw_reader.h:410
binary_enum_entry.h
ignite::binary::BinaryRawReader::ReadCollection
BinaryCollectionReader< T > ReadCollection()
Start collection read.
Definition: binary_raw_reader.h:393
ignite::binary::BinaryRawReader::TryReadObject
bool TryReadObject(T &res)
Try read object.
Definition: binary_raw_reader.h:486
ignite::binary::BinaryRawReader::ReadObject
T ReadObject()
Read object.
Definition: binary_raw_reader.h:458
ignite::binary::BinaryRawReader::ReadArray
BinaryArrayReader< T > ReadArray()
Start array read.
Definition: binary_raw_reader.h:373
ignite::binary::BinaryArrayReader
Binary array reader.
Definition: binary_containers.h:389
date.h
ignite::binary::BinaryEnumEntry
Binary enum entry.
Definition: binary_enum_entry.h:39
ignite::Timestamp
Timestamp type.
Definition: timestamp.h:37
ignite::Date
Date type.
Definition: date.h:35
ignite::binary::BinaryStringArrayReader
Binary string array reader.
Definition: binary_containers.h:297
ignite::binary::BinaryRawReader::ReadString
std::string ReadString()
Read string from the stream.
Definition: binary_raw_reader.h:315
ignite::binary::CollectionType::Type
Type
Definition: binary_consts.h:35
ignite::binary::BinaryRawReader::ReadEnum
T ReadEnum()
Read enum value.
Definition: binary_raw_reader.h:471
guid.h
ignite::binary::BinaryRawReader::ReadString
void ReadString(std::string &dst)
Read string from the stream.
Definition: binary_raw_reader.h:329
binary_containers.h
timestamp.h