| 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
31 #include "ignite/binary/binary_raw_reader.h"
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, int32_t len);
276
283 Timestamp ReadTimestamp(const char* fieldName);
284
296 int32_t ReadTimestampArray(const char* fieldName, Timestamp* res, int32_t len);
297
304 Time ReadTime(const char* fieldName);
305
317 int32_t ReadTimeArray(const char* fieldName, Time* res, int32_t len);
318
331 int32_t ReadString(const char* fieldName, char* res, int32_t len);
332
339 std::string ReadString(const char* fieldName)
340 {
341 int32_t len = ReadString(fieldName, NULL, 0);
342
343 if (len != -1)
344 {
345 ignite::common::FixedSizeArray<char> arr(len + 1);
346
347 ReadString(fieldName, arr.GetData(), static_cast<int32_t>(arr.GetSize()));
348
349 return std::string(arr.GetData());
350 }
351 else
352 return std::string();
353 }
354
366 BinaryStringArrayReader ReadStringArray(const char* fieldName);
367
374 BinaryEnumEntry ReadBinaryEnum(const char* fieldName);
375
387 template<typename T>
388 BinaryArrayReader<T> ReadArray(const char* fieldName)
389 {
390 int32_t size;
391
392 int32_t id = impl->ReadArray(fieldName, &size);
393
394 return BinaryArrayReader<T>(impl, id, size);
395 }
396
408 template<typename T>
409 BinaryCollectionReader<T> ReadCollection(const char* fieldName)
410 {
411 CollectionType::Type typ;
412 int32_t size;
413
414 int32_t id = impl->ReadCollection(fieldName, &typ, &size);
415
416 return BinaryCollectionReader<T>(impl, id, typ, size);
417 }
418
426 template<typename T, typename OutputIterator>
427 int32_t ReadCollection(const char* fieldName, OutputIterator out)
428 {
429 return impl->ReadCollection<T>(fieldName, out);
430 }
431
443 template<typename K, typename V>
444 BinaryMapReader<K, V> ReadMap(const char* fieldName)
445 {
446 MapType::Type typ;
447 int32_t size;
448
449 int32_t id = impl->ReadMap(fieldName, &typ, &size);
450
451 return BinaryMapReader<K, V>(impl, id, typ, size);
452 }
453
460 CollectionType::Type ReadCollectionType(const char* fieldName);
461
468 int32_t ReadCollectionSize(const char* fieldName);
469
478 template<typename T>
479 T ReadObject(const char* fieldName)
480 {
481 return impl->ReadObject<T>(fieldName);
482 }
483
491 template<typename T>
492 T ReadEnum(const char* fieldName)
493 {
494 return impl->ReadEnum<T>(fieldName);
495 }
496
502 BinaryRawReader RawReader();
503 private:
505 ignite::impl::binary::BinaryReaderImpl* impl;
506 };
507 }
508 }
509
510 #endif //_IGNITE_BINARY_BINARY_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::BinaryReader::ReadCollection
BinaryCollectionReader< T > ReadCollection(const char *fieldName)
Start collection read.
Definition: binary_reader.h:409
ignite::Guid
Global universally unique identifier (GUID).
Definition: guid.h:36
ignite::binary::BinaryCollectionReader
Binary collection reader.
Definition: binary_containers.h:468
ignite::binary::BinaryReader::ReadCollection
int32_t ReadCollection(const char *fieldName, OutputIterator out)
Read values and insert them to specified position.
Definition: binary_reader.h:427
ignite::binary::BinaryMapReader
Binary map reader.
Definition: binary_containers.h:561
ignite::binary::BinaryReader::ReadString
std::string ReadString(const char *fieldName)
Read string from the stream.
Definition: binary_reader.h:339
binary_raw_reader.h
ignite::binary::BinaryArrayReader
Binary array reader.
Definition: binary_containers.h:389
ignite::binary::BinaryReader::ReadObject
T ReadObject(const char *fieldName)
Read object.
Definition: binary_reader.h:479
date.h
ignite::binary::BinaryReader::ReadMap
BinaryMapReader< K, V > ReadMap(const char *fieldName)
Start map read.
Definition: binary_reader.h:444
ignite::binary::BinaryReader
Binary reader.
Definition: binary_reader.h:54
ignite::binary::BinaryEnumEntry
Binary enum entry.
Definition: binary_enum_entry.h:39
ignite::binary::BinaryReader::ReadArray
BinaryArrayReader< T > ReadArray(const char *fieldName)
Start array read.
Definition: binary_reader.h:388
ignite::Timestamp
Timestamp type.
Definition: timestamp.h:37
ignite::Date
Date type.
Definition: date.h:35
ignite::binary::BinaryReader::ReadEnum
T ReadEnum(const char *fieldName)
Read enum value.
Definition: binary_reader.h:492
ignite::binary::BinaryStringArrayReader
Binary string array reader.
Definition: binary_containers.h:297
ignite::binary::CollectionType::Type
Type
Definition: binary_consts.h:35
guid.h
timestamp.h