19 #ifndef avro_Writer_hh__
20 #define avro_Writer_hh__
22 #include <boost/noncopyable.hpp>
25 #include "buffer/Buffer.hh"
28 #include "Validator.hh"
34 template<
class Val
idatorType>
46 void writeValue(
const Null &) {
50 void writeValue(
bool val) {
52 int8_t byte = (val != 0);
53 buffer_.writeTo(byte);
56 void writeValue(int32_t val) {
57 validator_.checkTypeExpected(
AVRO_INT);
58 boost::array<uint8_t, 5> bytes;
59 size_t size = encodeInt32(val, bytes);
60 buffer_.writeTo(reinterpret_cast<const char *>(bytes.data()), size);
63 void writeValue(int64_t val) {
68 void writeValue(
float val) {
79 void writeValue(
double val) {
90 void writeValue(
const std::string &val) {
92 putBytes(val.c_str(), val.size());
95 void writeBytes(
const void *val,
size_t size) {
101 void writeFixed(
const uint8_t (&val)[N]) {
102 validator_.checkFixedSizeExpected(N);
103 buffer_.writeTo(reinterpret_cast<const char *>(val), N);
107 void writeFixed(
const boost::array<uint8_t, N> &val) {
108 validator_.checkFixedSizeExpected(val.size());
109 buffer_.writeTo(reinterpret_cast<const char *>(val.data()), val.size());
115 validator_.setCount(1);
118 void writeRecordEnd() {
121 validator_.setCount(0);
124 void writeArrayBlock(int64_t size) {
129 void writeArrayEnd() {
133 void writeMapBlock(int64_t size) {
134 validator_.checkTypeExpected(
AVRO_MAP);
142 void writeUnion(int64_t choice) {
147 void writeEnum(int64_t choice) {
152 InputBuffer buffer()
const {
158 void putLong(int64_t val) {
159 boost::array<uint8_t, 10> bytes;
160 size_t size = encodeInt64(val, bytes);
161 buffer_.writeTo(reinterpret_cast<const char *>(bytes.data()), size);
164 void putBytes(
const void *val,
size_t size) {
166 buffer_.writeTo(reinterpret_cast<const char *>(val), size);
169 void writeCount(int64_t count) {
171 validator_.setCount(count);
175 ValidatorType validator_;
176 OutputBuffer buffer_;
A bunch of templates and specializations for encoding and decoding specific types.
Definition: AvroParse.hh:31
Class for writing avro data to a stream.
Definition: Writer.hh:35
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