Serializer.hh

00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one
00003  * or more contributor license agreements.  See the NOTICE file
00004  * distributed with this work for additional information
00005  * regarding copyright ownership.  The ASF licenses this file
00006  * to you under the Apache License, Version 2.0 (the
00007  * "License"); you may not use this file except in compliance
00008  * with the License.  You may obtain a copy of the License at
00009  *
00010  *     http://www.apache.org/licenses/LICENSE-2.0
00011  *
00012  * Unless required by applicable law or agreed to in writing, software
00013  * distributed under the License is distributed on an "AS IS" BASIS,
00014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  * See the License for the specific language governing permissions and
00016  * limitations under the License.
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 } // namespace avro
00132 
00133 #endif