Avro C++
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 "Config.hh"
00025 #include "Writer.hh"
00026 
00027 namespace avro {
00028 
00031 
00032 template<class Writer>
00033 class Serializer : private boost::noncopyable
00034 {
00035 
00036   public:
00037 
00039     explicit Serializer() :
00040         writer_()
00041     {}
00042 
00044     Serializer(const ValidSchema &schema) :
00045         writer_(schema)
00046     {}
00047 
00048     void writeNull() {
00049         writer_.writeValue(Null());
00050     }
00051 
00052     void writeBool(bool val) {
00053         writer_.writeValue(val);
00054     }
00055 
00056     void writeInt(int32_t val) {
00057         writer_.writeValue(val);
00058     }
00059 
00060     void writeLong(int64_t val) {
00061         writer_.writeValue(val);
00062     }
00063 
00064     void writeFloat(float val) {
00065         writer_.writeValue(val);
00066     }
00067 
00068     void writeDouble(double val) {
00069         writer_.writeValue(val);
00070     }
00071 
00072     void writeBytes(const void *val, size_t size) {
00073         writer_.writeBytes(val);
00074     }
00075 
00076     template <size_t N>
00077     void writeFixed(const uint8_t (&val)[N]) {
00078         writer_.writeFixed(val);
00079     }
00080 
00081     template <size_t N>
00082     void writeFixed(const boost::array<uint8_t, N> &val) {
00083         writer_.writeFixed(val);
00084     }
00085 
00086     void writeString(const std::string &val) {
00087         writer_.writeValue(val);
00088     }
00089 
00090     void writeRecord() {
00091         writer_.writeRecord();
00092     }
00093 
00094     void writeRecordEnd() {
00095         writer_.writeRecordEnd();
00096     }
00097 
00098     void writeArrayBlock(int64_t size) {
00099         writer_.writeArrayBlock(size);
00100     }
00101 
00102     void writeArrayEnd() {
00103         writer_.writeArrayEnd();
00104     }
00105 
00106     void writeMapBlock(int64_t size) {
00107         writer_.writeMapBlock(size);
00108     }
00109 
00110     void writeMapEnd() {
00111         writer_.writeMapEnd();
00112     }
00113 
00114     void writeUnion(int64_t choice) {
00115         writer_.writeUnion(choice);
00116     }
00117 
00118     void writeEnum(int64_t choice) {
00119         writer_.writeEnum(choice);
00120     }
00121 
00122     InputBuffer buffer() const {
00123         return writer_.buffer();
00124     }
00125 
00126   private:
00127 
00128     Writer writer_;
00129 
00130 };
00131 
00132 } // namespace avro
00133 
00134 #endif