19 #ifndef avro_Writer_hh__ 20 #define avro_Writer_hh__ 23 #include <boost/noncopyable.hpp> 26 #include "buffer/Buffer.hh" 29 #include "Validator.hh" 35 template<
class Val
idatorType>
47 void writeValue(
const Null &) {
51 void writeValue(
bool val) {
53 int8_t byte = (val != 0);
54 buffer_.writeTo(byte);
57 void writeValue(int32_t val) {
58 validator_.checkTypeExpected(
AVRO_INT);
59 std::array<uint8_t, 5> bytes;
60 size_t size = encodeInt32(val, bytes);
61 buffer_.writeTo(reinterpret_cast<const char *>(bytes.data()), size);
64 void writeValue(int64_t val) {
69 void writeValue(
float val) {
80 void writeValue(
double val) {
91 void writeValue(
const std::string &val) {
93 putBytes(val.c_str(), val.size());
96 void writeBytes(
const void *val,
size_t size) {
102 void writeFixed(
const uint8_t (&val)[N]) {
103 validator_.checkFixedSizeExpected(N);
104 buffer_.writeTo(reinterpret_cast<const char *>(val), N);
108 void writeFixed(
const std::array<uint8_t, N> &val) {
109 validator_.checkFixedSizeExpected(val.size());
110 buffer_.writeTo(reinterpret_cast<const char *>(val.data()), val.size());
116 validator_.setCount(1);
119 void writeRecordEnd() {
122 validator_.setCount(0);
125 void writeArrayBlock(int64_t size) {
130 void writeArrayEnd() {
134 void writeMapBlock(int64_t size) {
135 validator_.checkTypeExpected(
AVRO_MAP);
143 void writeUnion(int64_t choice) {
148 void writeEnum(int64_t choice) {
153 InputBuffer buffer()
const {
159 void putLong(int64_t val) {
160 std::array<uint8_t, 10> bytes;
161 size_t size = encodeInt64(val, bytes);
162 buffer_.writeTo(reinterpret_cast<const char *>(bytes.data()), size);
165 void putBytes(
const void *val,
size_t size) {
167 buffer_.writeTo(reinterpret_cast<const char *>(val), size);
170 void writeCount(int64_t count) {
172 validator_.setCount(count);
176 ValidatorType validator_;
177 OutputBuffer buffer_;
A bunch of templates and specializations for encoding and decoding specific types.
Definition: AvroParse.hh:30
Class for writing avro data to a stream.
Definition: Writer.hh:36
Functions for encoding and decoding integers with zigzag compression.
define a type to identify Null in template functions
Definition: Types.hh:102
A ValidSchema is basically a non-mutable Schema that has passed some minumum of sanity checks...
Definition: ValidSchema.hh:40