avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r788469 - in /hadoop/avro/trunk: ./ src/c++/ src/c++/api/ src/c++/impl/ src/c++/test/
Date Thu, 25 Jun 2009 19:12:46 GMT
Author: cutting
Date: Thu Jun 25 19:12:45 2009
New Revision: 788469

URL: http://svn.apache.org/viewvc?rev=788469&view=rev
Log:
AVRO-59.  C++: make serializer more generic.  Contributed by Scott Banachowski.

Added:
    hadoop/avro/trunk/src/c++/api/ValidatingWriter.hh
    hadoop/avro/trunk/src/c++/api/Writer.hh
    hadoop/avro/trunk/src/c++/impl/ValidatingWriter.cc
Modified:
    hadoop/avro/trunk/CHANGES.txt
    hadoop/avro/trunk/src/c++/Makefile
    hadoop/avro/trunk/src/c++/api/AvroParse.hh
    hadoop/avro/trunk/src/c++/api/AvroSerialize.hh
    hadoop/avro/trunk/src/c++/api/AvroTraits.hh
    hadoop/avro/trunk/src/c++/api/AvroTypes.hh
    hadoop/avro/trunk/src/c++/api/Serializer.hh
    hadoop/avro/trunk/src/c++/api/Types.hh
    hadoop/avro/trunk/src/c++/api/ValidatingSerializer.hh
    hadoop/avro/trunk/src/c++/impl/ValidatingSerializer.cc
    hadoop/avro/trunk/src/c++/test/testgen.cc
    hadoop/avro/trunk/src/c++/test/unittest.cc

Modified: hadoop/avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/CHANGES.txt?rev=788469&r1=788468&r2=788469&view=diff
==============================================================================
--- hadoop/avro/trunk/CHANGES.txt (original)
+++ hadoop/avro/trunk/CHANGES.txt Thu Jun 25 19:12:45 2009
@@ -79,6 +79,9 @@
     AVRO-36. Correctly encode and decode binary default values.
     (cutting)
 
+    AVRO-59.  C++: make serializer more generic.  (Scott Banachowski
+    via cutting)
+
   OPTIMIZATIONS
 
   BUG FIXES

Modified: hadoop/avro/trunk/src/c++/Makefile
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/Makefile?rev=788469&r1=788468&r2=788469&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/Makefile (original)
+++ hadoop/avro/trunk/src/c++/Makefile Thu Jun 25 19:12:45 2009
@@ -55,9 +55,6 @@
 $(OBJDIR)/lex.yy.o : parser/lex.yy.cc
 	$(CXX) $(CXXFLAGS)  -Wno-unused $(INCFLAGS) -c -o $@ $< 
 
-#$(OBJDIR)/parserlib.a : $(OBJDIR)/avro.tab.o $(OBJDIR)/lex.yy.o 
-	#ar ruc $@ $^ 
-
 testparser: test/testparser.cc $(OBJDIR)/avrolib.a 
 	$(CXX) $(CXXFLAGS) $(INCFLAGS) -o $@ $^ $(LIBS)
 

Modified: hadoop/avro/trunk/src/c++/api/AvroParse.hh
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/AvroParse.hh?rev=788469&r1=788468&r2=788469&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/AvroParse.hh (original)
+++ hadoop/avro/trunk/src/c++/api/AvroParse.hh Thu Jun 25 19:12:45 2009
@@ -2,7 +2,7 @@
 #define avro_AvroParse_hh__
 
 #include <boost/static_assert.hpp>
-#include "AvroTypes.hh"
+#include "AvroTraits.hh"
 
 /// \file
 ///

Modified: hadoop/avro/trunk/src/c++/api/AvroSerialize.hh
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/AvroSerialize.hh?rev=788469&r1=788468&r2=788469&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/AvroSerialize.hh (original)
+++ hadoop/avro/trunk/src/c++/api/AvroSerialize.hh Thu Jun 25 19:12:45 2009
@@ -2,7 +2,7 @@
 #define avro_AvroSerialize_hh__
 
 #include <boost/static_assert.hpp>
-#include "AvroTypes.hh"
+#include "AvroTraits.hh"
 
 /// \file
 ///
@@ -13,16 +13,16 @@
 /// The main serializer entry point function.  Takes a serializer (either validating or
 /// plain) and the object that should be serialized.
 
-template <typename Serializer, typename T>
-void serialize(Serializer &s, const T& val)
+template <typename Writer, typename T>
+void serialize(Writer &s, const T& val)
 {
     serialize(s, val, is_serializable<T>());
 }
 
 /// Type trait should be set to is_serializable in otherwise force the compiler to complain.
 
-template <typename Serializer, typename T>
-void serialize(Serializer &s, const T& val, const boost::false_type &)
+template <typename Writer, typename T>
+void serialize(Writer &s, const T& val, const boost::false_type &)
 {
     BOOST_STATIC_ASSERT(sizeof(T)==0);
 }
@@ -31,43 +31,13 @@
 
 // @{
 
-template <typename Serializer>
-void serialize(Serializer &s, int32_t val, const boost::true_type &) {
-    s.putInt(val);
+template <typename Writer, typename T>
+void serialize(Writer &s, T val, const boost::true_type &) {
+    s.putValue(val);
 }
 
-template <typename Serializer>
-void serialize(Serializer &s, int64_t val, const boost::true_type &) {
-    s.putLong(val);
-}
-
-template <typename Serializer>
-void serialize(Serializer &s, float val, const boost::true_type &) {
-    s.putFloat(val);
-}
-
-template <typename Serializer>
-void serialize(Serializer &s, double val, const boost::true_type &) {
-    s.putDouble(val);
-}
-
-template <typename Serializer>
-void serialize(Serializer &s, const Null &, const boost::true_type &) {
-    s.putNull();
-}
-
-template <typename Serializer>
-void serialize(Serializer &s, bool val, const boost::true_type &) {
-    s.putBool(val);
-}
-
-template <typename Serializer>
-void serialize(Serializer &s, const std::string &val, const boost::true_type &)
{
-    s.putString(val);
-}
-
-template <typename Serializer>
-void serialize(Serializer &s, const std::vector<uint8_t> &val, const boost::true_type
&) {
+template <typename Writer>
+void serialize(Writer &s, const std::vector<uint8_t> &val, const boost::true_type
&) {
     s.putBytes(&val[0], val.size());
 }
 

Modified: hadoop/avro/trunk/src/c++/api/AvroTraits.hh
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/AvroTraits.hh?rev=788469&r1=788468&r2=788469&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/AvroTraits.hh (original)
+++ hadoop/avro/trunk/src/c++/api/AvroTraits.hh Thu Jun 25 19:12:45 2009
@@ -3,6 +3,8 @@
 
 #include <boost/type_traits.hpp>
 
+#include "Types.hh"
+
 /// \file
 ///
 /// Define an is_serializable trait for types we can serialize natively. 
@@ -13,26 +15,29 @@
 template <typename T>
 struct is_serializable : public boost::false_type{};
 
-template <>
-struct is_serializable<int32_t> : public boost::true_type{};
-
-template <>
-struct is_serializable<int64_t> : public boost::true_type{};
-
-template <>
-struct is_serializable<float> : public boost::true_type{};
-
-template <>
-struct is_serializable<double> : public boost::true_type{};
-
-template <>
-struct is_serializable<bool> : public boost::true_type{};
-
-template <>
-struct is_serializable<std::string> : public boost::true_type{};
+template <typename T>
+struct type_to_avro {
+    static const Type type = AVRO_NUM_TYPES;
+};
+
+#define DEFINE_PRIMITIVE(CTYPE, AVROTYPE) \
+template <> \
+struct is_serializable<CTYPE> : public boost::true_type{}; \
+\
+template <> \
+struct type_to_avro<CTYPE> { \
+    static const Type type = AVROTYPE; \
+};
+
+DEFINE_PRIMITIVE(int32_t, AVRO_INT)
+DEFINE_PRIMITIVE(int64_t, AVRO_LONG)
+DEFINE_PRIMITIVE(float, AVRO_FLOAT)
+DEFINE_PRIMITIVE(double, AVRO_DOUBLE)
+DEFINE_PRIMITIVE(bool, AVRO_BOOL)
+DEFINE_PRIMITIVE(Null, AVRO_NULL)
+DEFINE_PRIMITIVE(std::string, AVRO_STRING)
+DEFINE_PRIMITIVE(std::vector<uint8_t>, AVRO_BYTES)
 
-template <>
-struct is_serializable<std::vector<uint8_t > > : public boost::true_type{};
 
 } // namespace avro
 

Modified: hadoop/avro/trunk/src/c++/api/AvroTypes.hh
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/AvroTypes.hh?rev=788469&r1=788468&r2=788469&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/AvroTypes.hh (original)
+++ hadoop/avro/trunk/src/c++/api/AvroTypes.hh Thu Jun 25 19:12:45 2009
@@ -1,19 +0,0 @@
-#ifndef avro_AvroTypes_hh__
-#define avro_AvroTypes_hh__
-
-#include <boost/static_assert.hpp>
-#include "AvroTraits.hh"
-
-namespace avro {
-
-/// Null is an empty struct, convenient for representing null type in generic functions.
-
-struct Null {};
-
-template <>
-struct is_serializable<Null> : public boost::true_type{};
-
-
-} // namespace avro
-
-#endif

Modified: hadoop/avro/trunk/src/c++/api/Serializer.hh
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/Serializer.hh?rev=788469&r1=788468&r2=788469&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/Serializer.hh (original)
+++ hadoop/avro/trunk/src/c++/api/Serializer.hh Thu Jun 25 19:12:45 2009
@@ -3,105 +3,97 @@
 
 #include <boost/noncopyable.hpp>
 
-#include "OutputStreamer.hh"
-#include "Zigzag.hh"
+#include "Writer.hh"
+#include "ValidatingWriter.hh"
 
 namespace avro {
 
-/// Class for writing avro data to a stream.
+/// Class that wraps a Writer or ValidatingWriter with an interface that uses
+/// explicit put* names instead of putValue
 
+template<class Writer>
 class Serializer : private boost::noncopyable
 {
 
   public:
 
+    /// Constructor only works with Writer
     explicit Serializer(OutputStreamer &out) :
-        out_(out)
+        writer_(out)
     {}
 
-    void putNull() {}
+    /// Constructor only works with ValidatingWriter
+    Serializer(const ValidSchema &schema, OutputStreamer &out) :
+        writer_(schema, out)
+    {}
+
+    void putNull() {
+        writer_.putValue(Null());
+    }
 
     void putBool(bool val) {
-        int8_t byte = (val != 0);
-        out_.putByte(byte);
+        writer_.putValue(val);
     }
 
     void putInt(int32_t val) {
-        boost::array<uint8_t, 5> bytes;
-        size_t size = encodeInt32(val, bytes);
-        out_.putBytes(bytes.data(), size);
+        writer_.putValue(val);
     }
 
     void putLong(int64_t val) {
-        boost::array<uint8_t, 9> bytes;
-        size_t size = encodeInt64(val, bytes);
-        out_.putBytes(bytes.data(), size);
+        writer_.putValue(val);
     }
 
     void putFloat(float val) {
-        union {
-            float f;
-            int32_t i;
-        } v;
-    
-        v.f = val;
-        out_.putWord(v.i);
+        writer_.putValue(val);
     }
 
     void putDouble(double val) {
-        union {
-            double d;
-            int64_t i;
-        } v;
-        
-        v.d = val;
-        out_.putLongWord(v.i);
+        writer_.putValue(val);
     }
 
-    void putBytes(const uint8_t *val, size_t size) {
-        this->putLong(size);
-        out_.putBytes(val, size);
+    void putBytes(const void *val, size_t size) {
+        writer_.putBytes(val);
     }
 
     void putFixed(const uint8_t *val, size_t size) {
-        out_.putBytes(val, size);
+        writer_.putFixed(val, size);
     }
 
     void putString(const std::string &val) {
-        putBytes(reinterpret_cast<const uint8_t *>(val.c_str()), val.size());
+        writer_.putValue(val);
     }
 
-    /* here for compatibility with ValidatingSerializer in templates: */
-
-    void beginRecord() {}
+    void beginRecord() {
+        writer_.beginRecord();
+    }
 
     void beginArrayBlock(int64_t size) {
-        putLong(size);
+        writer_.beginArrayBlock(size);
     }
 
     void endArray() {
-        putLong(0);
+        writer_.endArray();
     }
 
     void beginMapBlock(int64_t size) {
-        putLong(size);
+        writer_.beginMapBlock(size);
     }
 
     void endMap() {
-        putLong(0);
+        writer_.endMap();
     }
 
     void beginUnion(int64_t choice) {
-        putLong(choice);
+        writer_.beginUnion(choice);
     }
 
     void beginEnum(int64_t choice) {
-        putLong(choice);
+        writer_.beginEnum(choice);
     }
 
   private:
 
-    OutputStreamer &out_;
+    Writer writer_;
 
 };
 

Modified: hadoop/avro/trunk/src/c++/api/Types.hh
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/Types.hh?rev=788469&r1=788468&r2=788469&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/Types.hh (original)
+++ hadoop/avro/trunk/src/c++/api/Types.hh Thu Jun 25 19:12:45 2009
@@ -42,6 +42,9 @@
 
 std::ostream &operator<< (std::ostream &os, const avro::Type type);
 
+/// define a type to identify Null in template functions
+struct Null {};
+
 } // namespace avro
 
 

Modified: hadoop/avro/trunk/src/c++/api/ValidatingSerializer.hh
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/ValidatingSerializer.hh?rev=788469&r1=788468&r2=788469&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/ValidatingSerializer.hh (original)
+++ hadoop/avro/trunk/src/c++/api/ValidatingSerializer.hh Thu Jun 25 19:12:45 2009
@@ -1,83 +0,0 @@
-#ifndef avro_ValidatingSerializer_hh__
-#define avro_ValidatingSerializer_hh__
-
-#include <boost/noncopyable.hpp>
-
-#include "Serializer.hh"
-#include "Validator.hh"
-
-namespace avro {
-
-class ValidSchema;
-class OutputStreamer;
-
-/// This class walks the parse tree as data is being serialized, and throws if
-/// attempt to serialize a data type does not match the type expected in the
-/// schema.
-
-class ValidatingSerializer : private boost::noncopyable
-{
-
-  public:
-
-    ValidatingSerializer(const ValidSchema &schema, OutputStreamer &out);
-
-    void putNull();
-
-    void putBool(bool val);
-
-    void putInt(int32_t val);
-
-    void putLong(int64_t val);
-
-    void putFloat(float val);
-
-    void putDouble(double val);
-
-    void putString(const std::string &val);
-
-    void putBytes(const uint8_t *val, size_t size);
-
-    void putFixed(const uint8_t *val, size_t size) {
-        checkSafeToPut(AVRO_FIXED);
-        checkSizeExpected(size);
-        serializer_.putFixed(val, size);
-        validator_.advance();
-    }
-
-    void beginRecord();
-
-    void beginArrayBlock(int64_t size);
-    void endArray();
-
-    void beginMapBlock(int64_t size);
-    void endMap();
-
-    void beginUnion(int64_t choice);
-
-    void beginEnum(int64_t choice);
-
-  private:
-
-    void putCount(int64_t count);
-
-    void checkSafeToPut(Type type) const {
-        if(! validator_.typeIsExpected(type)) {
-            throw Exception("Type does not match schema");
-        }
-    }
-
-    void checkSizeExpected(int size) const {
-        if(validator_.nextSizeExpected() != size) {
-            throw Exception("Wrong size of for fixed");
-        }
-    }
-
-    Validator  validator_;
-    Serializer serializer_;
-
-};
-
-} // namespace avro
-
-#endif

Added: hadoop/avro/trunk/src/c++/api/ValidatingWriter.hh
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/ValidatingWriter.hh?rev=788469&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c++/api/ValidatingWriter.hh (added)
+++ hadoop/avro/trunk/src/c++/api/ValidatingWriter.hh Thu Jun 25 19:12:45 2009
@@ -0,0 +1,83 @@
+#ifndef avro_ValidatingWriter_hh__
+#define avro_ValidatingWriter_hh__
+
+#include <boost/noncopyable.hpp>
+
+#include "Writer.hh"
+#include "Validator.hh"
+#include "AvroTraits.hh"
+
+namespace avro {
+
+class ValidSchema;
+class OutputStreamer;
+
+/// This class walks the parse tree as data is being serialized, and throws if
+/// attempt to serialize a data type does not match the type expected in the
+/// schema.
+
+class ValidatingWriter : private boost::noncopyable
+{
+
+  public:
+
+    ValidatingWriter(const ValidSchema &schema, OutputStreamer &out);
+
+    template<typename T>
+    void putValue(T val) {
+        checkSafeToPut(type_to_avro<T>::type);
+        writer_.putValue(val);
+        validator_.advance();
+    }
+
+    void putValue(const std::string &val) {
+        checkSafeToPut(type_to_avro<std::string>::type);
+        writer_.putValue(val);
+        validator_.advance();
+    }
+
+    void putBytes(const void *val, size_t size);
+
+    void putFixed(const uint8_t *val, size_t size) {
+        checkSafeToPut(AVRO_FIXED);
+        checkSizeExpected(size);
+        writer_.putFixed(val, size);
+        validator_.advance();
+    }
+
+    void beginRecord();
+
+    void beginArrayBlock(int64_t size);
+    void endArray();
+
+    void beginMapBlock(int64_t size);
+    void endMap();
+
+    void beginUnion(int64_t choice);
+
+    void beginEnum(int64_t choice);
+
+  private:
+
+    void putCount(int64_t count);
+
+    void checkSafeToPut(Type type) const {
+        if(! validator_.typeIsExpected(type)) {
+            throw Exception("Type does not match schema");
+        }
+    }
+
+    void checkSizeExpected(int size) const {
+        if(validator_.nextSizeExpected() != size) {
+            throw Exception("Wrong size of for fixed");
+        }
+    }
+
+    Validator  validator_;
+    Writer writer_;
+
+};
+
+} // namespace avro
+
+#endif

Added: hadoop/avro/trunk/src/c++/api/Writer.hh
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/Writer.hh?rev=788469&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c++/api/Writer.hh (added)
+++ hadoop/avro/trunk/src/c++/api/Writer.hh Thu Jun 25 19:12:45 2009
@@ -0,0 +1,109 @@
+#ifndef avro_Writer_hh__
+#define avro_Writer_hh__
+
+#include <boost/noncopyable.hpp>
+
+#include "OutputStreamer.hh"
+#include "Zigzag.hh"
+#include "Types.hh"
+
+namespace avro {
+
+/// Class for writing avro data to a stream.
+
+class Writer : private boost::noncopyable
+{
+
+  public:
+
+    explicit Writer(OutputStreamer &out) :
+        out_(out)
+    {}
+
+    void putValue(const Null &) {}
+
+    void putValue(bool val) {
+        int8_t byte = (val != 0);
+        out_.putByte(byte);
+    }
+
+    void putValue(int32_t val) {
+        boost::array<uint8_t, 5> bytes;
+        size_t size = encodeInt32(val, bytes);
+        out_.putBytes(bytes.data(), size);
+    }
+
+    void putValue(int64_t val) {
+        boost::array<uint8_t, 9> bytes;
+        size_t size = encodeInt64(val, bytes);
+        out_.putBytes(bytes.data(), size);
+    }
+
+    void putValue(float val) {
+        union {
+            float f;
+            int32_t i;
+        } v;
+    
+        v.f = val;
+        out_.putWord(v.i);
+    }
+
+    void putValue(double val) {
+        union {
+            double d;
+            int64_t i;
+        } v;
+        
+        v.d = val;
+        out_.putLongWord(v.i);
+    }
+
+    void putValue(const std::string &val) {
+        putBytes(reinterpret_cast<const uint8_t *>(val.c_str()), val.size());
+    }
+
+    void putBytes(const void *val, size_t size) {
+        this->putValue(static_cast<int64_t>(size));
+        out_.putBytes(reinterpret_cast<const uint8_t *>(val), size);
+    }
+
+    void putFixed(const uint8_t *val, size_t size) {
+        out_.putBytes(val, size);
+    }
+
+    void beginRecord() {}
+
+    void beginArrayBlock(int64_t size) {
+        this->putValue(static_cast<int64_t>(size));
+    }
+
+    void endArray() {
+        out_.putByte(0);
+    }
+
+    void beginMapBlock(int64_t size) {
+        this->putValue(static_cast<int64_t>(size));
+    }
+
+    void endMap() {
+        out_.putByte(0);
+    }
+
+    void beginUnion(int64_t choice) {
+        this->putValue(static_cast<int64_t>(choice));
+    }
+
+    void beginEnum(int64_t choice) {
+        this->putValue(static_cast<int64_t>(choice));
+    }
+
+  private:
+
+    OutputStreamer &out_;
+
+};
+
+} // namespace avro
+
+#endif

Modified: hadoop/avro/trunk/src/c++/impl/ValidatingSerializer.cc
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/impl/ValidatingSerializer.cc?rev=788469&r1=788468&r2=788469&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/impl/ValidatingSerializer.cc (original)
+++ hadoop/avro/trunk/src/c++/impl/ValidatingSerializer.cc Thu Jun 25 19:12:45 2009
@@ -1,139 +0,0 @@
-#include <boost/static_assert.hpp>
-
-#include "ValidatingSerializer.hh"
-#include "ValidSchema.hh"
-#include "OutputStreamer.hh"
-
-namespace avro {
-
-ValidatingSerializer::ValidatingSerializer(const ValidSchema &schema, OutputStreamer
&out) :
-    validator_(schema),
-    serializer_(out)
-{ }
-
-void
-ValidatingSerializer::putNull()
-{ 
-    checkSafeToPut(AVRO_NULL);
-    serializer_.putNull();
-    validator_.advance();
-}
-
-void
-ValidatingSerializer::putInt(int32_t val)
-{
-    checkSafeToPut(AVRO_INT);
-    serializer_.putInt(val);
-    validator_.advance();
-}
-
-void
-ValidatingSerializer::putLong(int64_t val)
-{
-    checkSafeToPut(AVRO_LONG);
-    serializer_.putLong(val);
-    validator_.advance();
-}
-
-
-void
-ValidatingSerializer::putFloat(float val)
-{
-    checkSafeToPut(AVRO_FLOAT);
-    serializer_.putFloat(val);
-    validator_.advance();
-}
-
-void
-ValidatingSerializer::putDouble(double val)
-{
-    checkSafeToPut(AVRO_DOUBLE);
-    serializer_.putDouble(val);
-    validator_.advance();
-}
-
-void
-ValidatingSerializer::putBool(bool val)
-{
-    checkSafeToPut(AVRO_BOOL);
-    serializer_.putBool(val);
-    validator_.advance();
-}
-
-void
-ValidatingSerializer::putString(const std::string &val)
-{
-    checkSafeToPut(AVRO_STRING);
-    serializer_.putString(val);
-    validator_.advance();
-}
-
-void
-ValidatingSerializer::putBytes(const uint8_t *val, size_t size)
-{
-    checkSafeToPut(AVRO_BYTES);
-    serializer_.putBytes(val, size);
-    validator_.advance();
-}
-
-void 
-ValidatingSerializer::putCount(int64_t count)
-{
-    checkSafeToPut(AVRO_LONG);
-    serializer_.putLong(count);
-    validator_.advanceWithCount(count);
-}
-
-void 
-ValidatingSerializer::beginRecord()
-{
-    checkSafeToPut(AVRO_RECORD);
-    validator_.advance();
-}
-
-void 
-ValidatingSerializer::beginArrayBlock(int64_t size)
-{
-    checkSafeToPut(AVRO_ARRAY);
-    validator_.advance();
-    putCount(size);
-}
-
-void 
-ValidatingSerializer::endArray()
-{
-    beginArrayBlock(0);
-}
-
-void 
-ValidatingSerializer::beginMapBlock(int64_t size)
-{
-    checkSafeToPut(AVRO_MAP);
-    validator_.advance();
-    putCount(size);
-}
-
-void 
-ValidatingSerializer::endMap()
-{
-    beginMapBlock(0);
-}
-
-void 
-ValidatingSerializer::beginUnion(int64_t choice)
-{
-    checkSafeToPut(AVRO_UNION);
-    validator_.advance();
-    putCount(choice);
-}
-
-void 
-ValidatingSerializer::beginEnum(int64_t choice)
-{
-    checkSafeToPut(AVRO_ENUM);
-    validator_.advance();
-    putCount(choice);
-}
-
-
-} // namepspace avro

Added: hadoop/avro/trunk/src/c++/impl/ValidatingWriter.cc
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/impl/ValidatingWriter.cc?rev=788469&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c++/impl/ValidatingWriter.cc (added)
+++ hadoop/avro/trunk/src/c++/impl/ValidatingWriter.cc Thu Jun 25 19:12:45 2009
@@ -0,0 +1,83 @@
+#include <boost/static_assert.hpp>
+
+#include "ValidatingWriter.hh"
+#include "ValidSchema.hh"
+#include "OutputStreamer.hh"
+#include "AvroTraits.hh"
+
+namespace avro {
+
+ValidatingWriter::ValidatingWriter(const ValidSchema &schema, OutputStreamer &out)
:
+    validator_(schema),
+    writer_(out)
+{ }
+
+void
+ValidatingWriter::putBytes(const void *val, size_t size)
+{
+    checkSafeToPut(AVRO_BYTES);
+    writer_.putBytes(val, size);
+    validator_.advance();
+}
+
+void 
+ValidatingWriter::putCount(int64_t count)
+{
+    checkSafeToPut(AVRO_LONG);
+    writer_.putValue(count);
+    validator_.advanceWithCount(count);
+}
+
+void 
+ValidatingWriter::beginRecord()
+{
+    checkSafeToPut(AVRO_RECORD);
+    validator_.advance();
+}
+
+void 
+ValidatingWriter::beginArrayBlock(int64_t size)
+{
+    checkSafeToPut(AVRO_ARRAY);
+    validator_.advance();
+    putCount(size);
+}
+
+void 
+ValidatingWriter::endArray()
+{
+    beginArrayBlock(0);
+}
+
+void 
+ValidatingWriter::beginMapBlock(int64_t size)
+{
+    checkSafeToPut(AVRO_MAP);
+    validator_.advance();
+    putCount(size);
+}
+
+void 
+ValidatingWriter::endMap()
+{
+    beginMapBlock(0);
+}
+
+void 
+ValidatingWriter::beginUnion(int64_t choice)
+{
+    checkSafeToPut(AVRO_UNION);
+    validator_.advance();
+    putCount(choice);
+}
+
+void 
+ValidatingWriter::beginEnum(int64_t choice)
+{
+    checkSafeToPut(AVRO_ENUM);
+    validator_.advance();
+    putCount(choice);
+}
+
+
+} // namepspace avro

Modified: hadoop/avro/trunk/src/c++/test/testgen.cc
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/test/testgen.cc?rev=788469&r1=788468&r2=788469&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/test/testgen.cc (original)
+++ hadoop/avro/trunk/src/c++/test/testgen.cc Thu Jun 25 19:12:45 2009
@@ -7,7 +7,6 @@
 #include "OutputStreamer.hh"
 #include "InputStreamer.hh"
 #include "Serializer.hh"
-#include "ValidatingSerializer.hh"
 #include "Parser.hh"
 #include "ValidatingParser.hh"
 #include "ValidSchema.hh"
@@ -16,17 +15,17 @@
 void serialize(const avrouser::RootRecord &rec) 
 {
     avro::ScreenStreamer os;
-    avro::Serializer s (os);
+    avro::Writer writer(os);
 
-    avro::serialize(s, rec);
+    avro::serialize(writer, rec);
 }
 
 void serializeValid(const avro::ValidSchema &valid, const avrouser::RootRecord &rec)

 {
     avro::ScreenStreamer os;
-    avro::ValidatingSerializer s (valid, os);
+    avro::ValidatingWriter writer(valid, os);
 
-    avro::serialize(s, rec);
+    avro::serialize(writer, rec);
 }
 
 void checkArray(const avrouser::Array_of_double &a1, const avrouser::Array_of_double
&a2) 
@@ -79,7 +78,7 @@
 {
     std::ostringstream ostring;
     avro::OStreamer os(ostring);
-    avro::Serializer s (os);
+    avro::Writer s (os);
 
     avro::serialize(s, myRecord); 
 
@@ -96,7 +95,7 @@
 {
     std::ostringstream ostring;
     avro::OStreamer os(ostring);
-    avro::ValidatingSerializer s (valid, os);
+    avro::ValidatingWriter s (valid, os);
 
     avro::serialize(s, myRecord);
 

Modified: hadoop/avro/trunk/src/c++/test/unittest.cc
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/test/unittest.cc?rev=788469&r1=788468&r2=788469&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/test/unittest.cc (original)
+++ hadoop/avro/trunk/src/c++/test/unittest.cc Thu Jun 25 19:12:45 2009
@@ -10,7 +10,6 @@
 #include "OutputStreamer.hh"
 #include "Serializer.hh"
 #include "Parser.hh"
-#include "ValidatingSerializer.hh"
 #include "ValidatingParser.hh"
 #include "SymbolMap.hh"
 
@@ -131,7 +130,7 @@
     void printEncoding() {
         std::cout << "Encoding\n";
         ScreenStreamer os;
-        Serializer s(os);
+        Serializer<Writer> s(os);
         writeEncoding(s, 0);
     }
 
@@ -139,7 +138,7 @@
     {
         std::cout << "Validating Encoding " << path << "\n";
         ScreenStreamer os;
-        ValidatingSerializer s(schema_, os);
+        Serializer<ValidatingWriter> s(schema_, os);
         writeEncoding(s, path);
     }
 
@@ -147,7 +146,7 @@
     {
         std::ofstream out("test.avro");
         OStreamer os(out);
-        ValidatingSerializer s(schema_, os);
+        Serializer<ValidatingWriter> s(schema_, os);
         writeEncoding(s, path);
     }
 
@@ -388,7 +387,7 @@
     void serializeNoRecurse(OutputStreamer &os)
     {
         std::cout << "No recurse\n";
-        ValidatingSerializer s(schema_, os);
+        Serializer<ValidatingWriter> s(schema_, os);
         s.beginRecord();
         s.putLong(1);
         s.beginUnion(0);
@@ -399,7 +398,7 @@
     void serializeRecurse(OutputStreamer &os)
     {
         std::cout << "Recurse\n";
-        ValidatingSerializer s(schema_, os);
+        Serializer<ValidatingWriter> s(schema_, os);
         s.beginRecord();
         s.putLong(1);
         s.beginUnion(1);
@@ -489,13 +488,12 @@
         float   f   = 200.0;
 
         ScreenStreamer os;
-        Serializer s(os);
+        Writer writer(os);
 
-        serialize(s, val);
-        serialize(s, Null());
-        serialize(s, f);
+        serialize(writer, val);
+        serialize(writer, Null());
+        serialize(writer, f);
         
-
     }
 };
 



Mime
View raw message