19 #ifndef avro_Writer_hh__
20 #define avro_Writer_hh__
23 #include <boost/noncopyable.hpp>
27 #include "Validator.hh"
29 #include "buffer/Buffer.hh"
35 template<
class Val
idatorType>
43 void writeValue(
const Null &) {
47 void writeValue(
bool val) {
49 int8_t
byte = (val != 0);
50 buffer_.writeTo(
byte);
53 void writeValue(int32_t val) {
54 validator_.checkTypeExpected(
AVRO_INT);
56 std::array<uint8_t, 5> bytes;
57 size_t size = encodeInt32(val, bytes);
58 buffer_.writeTo(
reinterpret_cast<const char *
>(bytes.data()), size);
61 void writeValue(int64_t val) {
66 void writeValue(
float val) {
77 void writeValue(
double val) {
88 void writeValue(
const std::string &val) {
90 putBytes(val.c_str(), val.size());
93 void writeBytes(
const void *val,
size_t size) {
99 void writeFixed(
const uint8_t (&val)[N]) {
100 validator_.checkFixedSizeExpected(N);
101 buffer_.writeTo(
reinterpret_cast<const char *
>(val), N);
105 void writeFixed(
const std::array<uint8_t, N> &val) {
106 validator_.checkFixedSizeExpected(val.size());
107 buffer_.writeTo(
reinterpret_cast<const char *
>(val.data()), val.size());
113 validator_.setCount(1);
116 void writeRecordEnd() {
119 validator_.setCount(0);
122 void writeArrayBlock(int64_t size) {
127 void writeArrayEnd() {
131 void writeMapBlock(int64_t size) {
132 validator_.checkTypeExpected(
AVRO_MAP);
140 void writeUnion(int64_t choice) {
145 void writeEnum(int64_t choice) {
150 InputBuffer buffer()
const {
155 void putLong(int64_t val) {
157 std::array<uint8_t, 10> bytes;
158 size_t size = encodeInt64(val, bytes);
159 buffer_.writeTo(
reinterpret_cast<const char *
>(bytes.data()), size);
162 void putBytes(
const void *val,
size_t size) {
164 buffer_.writeTo(
reinterpret_cast<const char *
>(val), size);
167 void writeCount(int64_t count) {
169 validator_.setCount(count);
173 ValidatorType validator_;
174 OutputBuffer buffer_;
Functions for encoding and decoding integers with zigzag compression.
A ValidSchema is basically a non-mutable Schema that has passed some minimum of sanity checks.
Definition: ValidSchema.hh:40
Class for writing avro data to a stream.
Definition: Writer.hh:36
A bunch of templates and specializations for encoding and decoding specific types.
Definition: AvroParse.hh:30
@ AVRO_MAP
Definition: Types.hh:45
@ AVRO_FLOAT
Definition: Types.hh:37
@ AVRO_INT
Definition: Types.hh:35
@ AVRO_RECORD
Definition: Types.hh:42
@ AVRO_STRING
Definition: Types.hh:33
@ AVRO_LONG
Definition: Types.hh:36
@ AVRO_DOUBLE
Definition: Types.hh:38
@ AVRO_UNION
Definition: Types.hh:46
@ AVRO_BOOL
Definition: Types.hh:39
@ AVRO_ENUM
Definition: Types.hh:43
@ AVRO_BYTES
Definition: Types.hh:34
@ AVRO_ARRAY
Definition: Types.hh:44
@ AVRO_NULL
Definition: Types.hh:40
define a type to represent Avro Null in template functions
Definition: Types.hh:101