| Apache Ignite C++

binary_writer.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_WRITER
24 #define _IGNITE_BINARY_BINARY_WRITER
25
26 #include <string>
27 #include <stdint.h>
28
29 #include <ignite/common/common.h>
30
31 #include "ignite/binary/binary_raw_writer.h"
32
33 namespace ignite
34 {
35 namespace binary
36 {
51 class IGNITE_IMPORT_EXPORT BinaryWriter
52 {
53 public:
61 BinaryWriter(impl::binary::BinaryWriterImpl* impl);
62
69 void WriteInt8(const char* fieldName, int8_t val);
70
78 void WriteInt8Array(const char* fieldName, const int8_t* val, int32_t len);
79
86 void WriteBool(const char* fieldName, bool val);
87
95 void WriteBoolArray(const char* fieldName, const bool* val, int32_t len);
96
103 void WriteInt16(const char* fieldName, int16_t val);
104
112 void WriteInt16Array(const char* fieldName, const int16_t* val, int32_t len);
113
120 void WriteUInt16(const char* fieldName, uint16_t val);
121
129 void WriteUInt16Array(const char* fieldName, const uint16_t* val, int32_t len);
130
137 void WriteInt32(const char* fieldName, int32_t val);
138
146 void WriteInt32Array(const char* fieldName, const int32_t* val, int32_t len);
147
154 void WriteInt64(const char* fieldName, int64_t val);
155
163 void WriteInt64Array(const char* fieldName, const int64_t* val, int32_t len);
164
171 void WriteFloat(const char* fieldName, float val);
172
180 void WriteFloatArray(const char* fieldName, const float* val, int32_t len);
181
188 void WriteDouble(const char* fieldName, double val);
189
197 void WriteDoubleArray(const char* fieldName, const double* val, int32_t len);
198
205 void WriteGuid(const char* fieldName, const Guid& val);
206
214 void WriteGuidArray(const char* fieldName, const Guid* val, int32_t len);
215
222 void WriteDate(const char* fieldName, const Date& val);
223
231 void WriteDateArray(const char* fieldName, const Date* val, int32_t len);
232
239 void WriteTimestamp(const char* fieldName, const Timestamp& val);
240
248 void WriteTimestampArray(const char* fieldName, const Timestamp* val, int32_t len);
249
256 void WriteTime(const char* fieldName, const Time& val);
257
265 void WriteTimeArray(const char* fieldName, const Time* val, int32_t len);
266
273 void WriteString(const char* fieldName, const char* val);
274
282 void WriteString(const char* fieldName, const char* val, int32_t len);
283
290 void WriteString(const char* fieldName, const std::string& val)
291 {
292 WriteString(fieldName, val.c_str());
293 }
294
307 BinaryStringArrayWriter WriteStringArray(const char* fieldName);
308
315 void WriteBinaryEnum(const char* fieldName, BinaryEnumEntry entry);
316
322 void WriteNull(const char* fieldName);
323
336 template<typename T>
337 BinaryArrayWriter<T> WriteArray(const char* fieldName)
338 {
339 int32_t id = impl->WriteArray(fieldName);
340
341 return BinaryArrayWriter<T>(impl, id);
342 }
343
356 template<typename T>
357 BinaryCollectionWriter<T> WriteCollection(const char* fieldName)
358 {
359 return WriteCollection<T>(fieldName, CollectionType::UNDEFINED);
360 }
361
375 template<typename T>
376 BinaryCollectionWriter<T> WriteCollection(const char* fieldName, CollectionType::Type typ)
377 {
378 int32_t id = impl->WriteCollection(fieldName, typ);
379
380 return BinaryCollectionWriter<T>(impl, id);
381 }
382
390 template<typename InputIterator>
391 void WriteCollection(const char* fieldName, InputIterator first, InputIterator last)
392 {
393 WriteCollection(fieldName, first, last, CollectionType::UNDEFINED);
394 }
395
404 template<typename InputIterator>
405 void WriteCollection(const char* fieldName, InputIterator first, InputIterator last, CollectionType::Type typ)
406 {
407 impl->WriteCollection(fieldName, first, last, typ);
408 }
409
422 template<typename K, typename V>
423 BinaryMapWriter<K, V> WriteMap(const char* fieldName)
424 {
425 return WriteMap<K, V>(fieldName, MapType::UNDEFINED);
426 }
427
441 template<typename K, typename V>
442 BinaryMapWriter<K, V> WriteMap(const char* fieldName, MapType::Type typ)
443 {
444 int32_t id = impl->WriteMap(fieldName, typ);
445
446 return BinaryMapWriter<K, V>(impl, id);
447 }
448
455 template<typename T>
456 void WriteObject(const char* fieldName, const T& val)
457 {
458 impl->WriteObject<T>(fieldName, val);
459 }
460
469 template<typename T>
470 void WriteEnum(const char* fieldName, T val)
471 {
472 impl->WriteEnum(fieldName, val);
473 }
474
480 BinaryRawWriter RawWriter();
481 private:
483 ignite::impl::binary::BinaryWriterImpl* impl;
484 };
485 }
486 }
487
488 #endif //_IGNITE_BINARY_BINARY_WRITER
ignite::binary::BinaryWriter
Binary writer.
Definition: binary_writer.h:51
ignite
Apache Ignite API.
Definition: cache.h:48
ignite::binary::BinaryStringArrayWriter
Binary string array writer.
Definition: binary_containers.h:48
ignite::binary::MapType::Type
Type
Definition: binary_consts.h:69
ignite::Time
Time type.
Definition: time.h:35
ignite::binary::BinaryWriter::WriteMap
BinaryMapWriter< K, V > WriteMap(const char *fieldName, MapType::Type typ)
Start map write.
Definition: binary_writer.h:442
ignite::Guid
Global universally unique identifier (GUID).
Definition: guid.h:36
ignite::binary::BinaryWriter::WriteCollection
void WriteCollection(const char *fieldName, InputIterator first, InputIterator last)
Write values in interval [first, last).
Definition: binary_writer.h:391
ignite::binary::BinaryWriter::WriteObject
void WriteObject(const char *fieldName, const T &val)
Write object.
Definition: binary_writer.h:456
ignite::binary::MapType::UNDEFINED
@ UNDEFINED
Undefined.
Definition: binary_consts.h:74
ignite::binary::BinaryWriter::WriteString
void WriteString(const char *fieldName, const std::string &val)
Write string.
Definition: binary_writer.h:290
ignite::binary::CollectionType::UNDEFINED
@ UNDEFINED
Undefined.
Definition: binary_consts.h:40
ignite::binary::BinaryWriter::WriteArray
BinaryArrayWriter< T > WriteArray(const char *fieldName)
Start array write.
Definition: binary_writer.h:337
ignite::binary::BinaryWriter::WriteCollection
BinaryCollectionWriter< T > WriteCollection(const char *fieldName, CollectionType::Type typ)
Start collection write.
Definition: binary_writer.h:376
ignite::binary::BinaryWriter::WriteCollection
BinaryCollectionWriter< T > WriteCollection(const char *fieldName)
Start collection write.
Definition: binary_writer.h:357
ignite::binary::BinaryArrayWriter
Binary array writer.
Definition: binary_containers.h:121
ignite::binary::BinaryCollectionWriter
Binary collection writer.
Definition: binary_containers.h:182
ignite::binary::BinaryRawWriter
Binary raw writer.
Definition: binary_raw_writer.h:62
ignite::binary::BinaryEnumEntry
Binary enum entry.
Definition: binary_enum_entry.h:39
ignite::binary::BinaryWriter::WriteCollection
void WriteCollection(const char *fieldName, InputIterator first, InputIterator last, CollectionType::Type typ)
Write values in interval [first, last).
Definition: binary_writer.h:405
ignite::Timestamp
Timestamp type.
Definition: timestamp.h:37
ignite::Date
Date type.
Definition: date.h:35
ignite::binary::BinaryWriter::WriteMap
BinaryMapWriter< K, V > WriteMap(const char *fieldName)
Start map write.
Definition: binary_writer.h:423
ignite::binary::BinaryMapWriter
Binary map writer.
Definition: binary_containers.h:241
ignite::binary::CollectionType::Type
Type
Definition: binary_consts.h:35
ignite::binary::BinaryWriter::WriteEnum
void WriteEnum(const char *fieldName, T val)
Write enum entry.
Definition: binary_writer.h:470
binary_raw_writer.h