| Apache Ignite C++

binary_raw_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_RAW_WRITER
24 #define _IGNITE_BINARY_BINARY_RAW_WRITER
25
26 #include <stdint.h>
27
28 #include <ignite/common/common.h>
29
30 #include "ignite/impl/binary/binary_writer_impl.h"
31 #include "ignite/binary/binary_consts.h"
32 #include "ignite/binary/binary_containers.h"
33 #include "ignite/guid.h"
34 #include "ignite/date.h"
35 #include "ignite/timestamp.h"
36
37 namespace ignite
38 {
39 namespace impl
40 {
41 namespace binary
42 {
43 class BinaryUtils;
44 }
45 }
46 namespace binary
47 {
62 class IGNITE_IMPORT_EXPORT BinaryRawWriter
63 {
64 friend class ignite::impl::binary::BinaryUtils;
65 public:
73 BinaryRawWriter(ignite::impl::binary::BinaryWriterImpl* impl);
74
80 void WriteInt8(int8_t val);
81
88 void WriteInt8Array(const int8_t* val, int32_t len);
89
95 void WriteBool(bool val);
96
103 void WriteBoolArray(const bool* val, int32_t len);
104
110 void WriteInt16(int16_t val);
111
118 void WriteInt16Array(const int16_t* val, int32_t len);
119
125 void WriteUInt16(uint16_t val);
126
133 void WriteUInt16Array(const uint16_t* val, int32_t len);
134
140 void WriteInt32(int32_t val);
141
148 void WriteInt32Array(const int32_t* val, int32_t len);
149
155 void WriteInt64(int64_t val);
156
163 void WriteInt64Array(const int64_t* val, int32_t len);
164
170 void WriteFloat(float val);
171
178 void WriteFloatArray(const float* val, int32_t len);
179
185 void WriteDouble(double val);
186
193 void WriteDoubleArray(const double* val, int32_t len);
194
200 void WriteGuid(const Guid& val);
201
208 void WriteGuidArray(const Guid* val, int32_t len);
209
215 void WriteDate(const Date& val);
216
223 void WriteDateArray(const Date* val, int32_t len);
224
230 void WriteTimestamp(const Timestamp& val);
231
238 void WriteTimestampArray(const Timestamp* val, int32_t len);
239
245 void WriteTime(const Time& val);
246
253 void WriteTimeArray(const Time* val, int32_t len);
254
260 void WriteString(const char* val);
261
268 void WriteString(const char* val, int32_t len);
269
275 void WriteString(const std::string& val)
276 {
277 WriteString(val.c_str(), static_cast<int32_t>(val.size()));
278 }
279
291 BinaryStringArrayWriter WriteStringArray();
292
298 void WriteBinaryEnum(BinaryEnumEntry entry);
299
303 void WriteNull();
304
316 template<typename T>
317 BinaryArrayWriter<T> WriteArray()
318 {
319 int32_t id = impl->WriteArray();
320
321 return BinaryArrayWriter<T>(impl, id);
322 }
323
335 template<typename T>
336 BinaryCollectionWriter<T> WriteCollection()
337 {
338 return WriteCollection<T>(CollectionType::UNDEFINED);
339 }
340
353 template<typename T>
354 BinaryCollectionWriter<T> WriteCollection(CollectionType::Type typ)
355 {
356 int32_t id = impl->WriteCollection(typ);
357
358 return BinaryCollectionWriter<T>(impl, id);
359 }
360
367 template<typename InputIterator>
368 void WriteCollection(InputIterator first, InputIterator last)
369 {
370 impl->WriteCollection(first, last, CollectionType::UNDEFINED);
371 }
372
380 template<typename InputIterator>
381 void WriteCollection(InputIterator first, InputIterator last, CollectionType::Type typ)
382 {
383 impl->WriteCollection(first, last, typ);
384 }
385
397 template<typename K, typename V>
398 BinaryMapWriter<K, V> WriteMap()
399 {
400 return WriteMap<K, V>(MapType::UNDEFINED);
401 }
402
415 template<typename K, typename V>
416 BinaryMapWriter<K, V> WriteMap(MapType::Type typ)
417 {
418 int32_t id = impl->WriteMap(typ);
419
420 return BinaryMapWriter<K, V>(impl, id);
421 }
422
428 template<typename T>
429 void WriteObject(const T& val)
430 {
431 impl->WriteObject<T>(val);
432 }
433
441 template<typename T>
442 void WriteEnum(T val)
443 {
444 impl->WriteEnum(val);
445 }
446
447 private:
449 ignite::impl::binary::BinaryWriterImpl* impl;
450 };
451 }
452 }
453
454 #endif //_IGNITE_BINARY_BINARY_RAW_WRITER
ignite
Apache Ignite API.
Definition: cache.h:48
ignite::binary::BinaryRawWriter::WriteCollection
void WriteCollection(InputIterator first, InputIterator last)
Write values in interval [first, last).
Definition: binary_raw_writer.h:368
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::BinaryRawWriter::WriteEnum
void WriteEnum(T val)
Write binary enum entry.
Definition: binary_raw_writer.h:442
ignite::Guid
Global universally unique identifier (GUID).
Definition: guid.h:36
ignite::binary::BinaryRawWriter::WriteMap
BinaryMapWriter< K, V > WriteMap(MapType::Type typ)
Start map write.
Definition: binary_raw_writer.h:416
ignite::binary::MapType::UNDEFINED
@ UNDEFINED
Undefined.
Definition: binary_consts.h:74
binary_consts.h
ignite::binary::CollectionType::UNDEFINED
@ UNDEFINED
Undefined.
Definition: binary_consts.h:40
ignite::binary::BinaryRawWriter::WriteCollection
void WriteCollection(InputIterator first, InputIterator last, CollectionType::Type typ)
Write values in interval [first, last).
Definition: binary_raw_writer.h:381
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::WriteCollection
BinaryCollectionWriter< T > WriteCollection(CollectionType::Type typ)
Start collection write.
Definition: binary_raw_writer.h:354
date.h
ignite::binary::BinaryRawWriter
Binary raw writer.
Definition: binary_raw_writer.h:62
ignite::binary::BinaryRawWriter::WriteMap
BinaryMapWriter< K, V > WriteMap()
Start map write.
Definition: binary_raw_writer.h:398
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::BinaryRawWriter::WriteCollection
BinaryCollectionWriter< T > WriteCollection()
Start collection write.
Definition: binary_raw_writer.h:336
ignite::binary::BinaryMapWriter
Binary map writer.
Definition: binary_containers.h:241
ignite::binary::CollectionType::Type
Type
Definition: binary_consts.h:35
ignite::binary::BinaryRawWriter::WriteObject
void WriteObject(const T &val)
Write object.
Definition: binary_raw_writer.h:429
ignite::binary::BinaryRawWriter::WriteString
void WriteString(const std::string &val)
Write string.
Definition: binary_raw_writer.h:275
guid.h
binary_containers.h
timestamp.h
ignite::binary::BinaryRawWriter::WriteArray
BinaryArrayWriter< T > WriteArray()
Start array write.
Definition: binary_raw_writer.h:317