00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef avro_Serializer_hh__
00020 #define avro_Serializer_hh__
00021
00022 #include <boost/noncopyable.hpp>
00023
00024 #include "Writer.hh"
00025
00026 namespace avro {
00027
00030
00031 template<class Writer>
00032 class Serializer : private boost::noncopyable
00033 {
00034
00035 public:
00036
00038 explicit Serializer() :
00039 writer_()
00040 {}
00041
00043 Serializer(const ValidSchema &schema) :
00044 writer_(schema)
00045 {}
00046
00047 void writeNull() {
00048 writer_.writeValue(Null());
00049 }
00050
00051 void writeBool(bool val) {
00052 writer_.writeValue(val);
00053 }
00054
00055 void writeInt(int32_t val) {
00056 writer_.writeValue(val);
00057 }
00058
00059 void writeLong(int64_t val) {
00060 writer_.writeValue(val);
00061 }
00062
00063 void writeFloat(float val) {
00064 writer_.writeValue(val);
00065 }
00066
00067 void writeDouble(double val) {
00068 writer_.writeValue(val);
00069 }
00070
00071 void writeBytes(const void *val, size_t size) {
00072 writer_.writeBytes(val);
00073 }
00074
00075 template <size_t N>
00076 void writeFixed(const uint8_t (&val)[N]) {
00077 writer_.writeFixed(val);
00078 }
00079
00080 template <size_t N>
00081 void writeFixed(const boost::array<uint8_t, N> &val) {
00082 writer_.writeFixed(val);
00083 }
00084
00085 void writeString(const std::string &val) {
00086 writer_.writeValue(val);
00087 }
00088
00089 void writeRecord() {
00090 writer_.writeRecord();
00091 }
00092
00093 void writeRecordEnd() {
00094 writer_.writeRecordEnd();
00095 }
00096
00097 void writeArrayBlock(int64_t size) {
00098 writer_.writeArrayBlock(size);
00099 }
00100
00101 void writeArrayEnd() {
00102 writer_.writeArrayEnd();
00103 }
00104
00105 void writeMapBlock(int64_t size) {
00106 writer_.writeMapBlock(size);
00107 }
00108
00109 void writeMapEnd() {
00110 writer_.writeMapEnd();
00111 }
00112
00113 void writeUnion(int64_t choice) {
00114 writer_.writeUnion(choice);
00115 }
00116
00117 void writeEnum(int64_t choice) {
00118 writer_.writeEnum(choice);
00119 }
00120
00121 InputBuffer buffer() const {
00122 return writer_.buffer();
00123 }
00124
00125 private:
00126
00127 Writer writer_;
00128
00129 };
00130
00131 }
00132
00133 #endif