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_;