Author: cutting
Date: Tue Jul 14 22:48:26 2009
New Revision: 794108
URL: http://svn.apache.org/viewvc?rev=794108&view=rev
Log:
AVRO-71. Make C++ deserializer more generic. Contributed by Scott Banachowski.
Added:
hadoop/avro/trunk/src/c++/api/Reader.hh
hadoop/avro/trunk/src/c++/api/ValidatingReader.hh (contents, props
changed)
- copied, changed from r794096,
hadoop/avro/trunk/src/c++/api/ValidatingParser.hh
hadoop/avro/trunk/src/c++/impl/ValidatingReader.cc (contents, props
changed)
- copied, changed from r794096,
hadoop/avro/trunk/src/c++/impl/ValidatingParser.cc
Removed:
hadoop/avro/trunk/src/c++/api/ValidatingParser.hh
hadoop/avro/trunk/src/c++/impl/ValidatingParser.cc
hadoop/avro/trunk/src/c++/impl/ValidatingSerializer.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/Parser.hh
hadoop/avro/trunk/src/c++/api/ValidatingWriter.hh
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=794108&r1=794107&r2=794108&view=diff
==============================================================================
--- hadoop/avro/trunk/CHANGES.txt (original)
+++ hadoop/avro/trunk/CHANGES.txt Tue Jul 14 22:48:26 2009
@@ -8,6 +8,9 @@
IMPROVEMENTS
+ AVRO-71. C++: make deserializer 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=794108&r1=794107&r2=794108&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/Makefile (original)
+++ hadoop/avro/trunk/src/c++/Makefile Tue Jul 14 22:48:26 2009
@@ -26,7 +26,7 @@
all : $(OBJDIR)/avrolib.a $(EXECS)
-CXXFLAGS = -Wall -g
+CXXFLAGS = -Wall -Werror -g
$(OBJDIR)/avrolib.a : $(OBJS) $(GENERATEDOBJS)
ar ruc $@ $^
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=794108&r1=794107&r2=794108&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/AvroParse.hh (original)
+++ hadoop/avro/trunk/src/c++/api/AvroParse.hh Tue Jul 14 22:48:26 2009
@@ -31,16 +31,16 @@
/// The main parse entry point function. Takes a parser (either validating or
/// plain) and the object that should receive the parsed data.
-template <typename Parser, typename T>
-void parse(Parser &p, T& val)
+template <typename Reader, typename T>
+void parse(Reader &p, T& val)
{
parse(p, val, is_serializable<T>());
}
/// Type trait should be set to is_serializable in otherwise force the
compiler to complain.
-template <typename Parser, typename T>
-void parse(Parser &p, T& val, const boost::false_type &)
+template <typename Reader, typename T>
+void parse(Reader &p, T& val, const boost::false_type &)
{
BOOST_STATIC_ASSERT(sizeof(T)==0);
}
@@ -49,43 +49,13 @@
// @{
-template <typename Parser>
-void parse(Parser &p, int32_t &val, const boost::true_type &) {
- val = p.getInt();
+template <typename Reader, typename T>
+void parse(Reader &p, T &val, const boost::true_type &) {
+ p.getValue(val);
}
-template <typename Parser>
-void parse(Parser &p, int64_t &val, const boost::true_type &) {
- val = p.getLong();
-}
-
-template <typename Parser>
-void parse(Parser &p, float &val, const boost::true_type &) {
- val = p.getFloat();
-}
-
-template <typename Parser>
-void parse(Parser &p, double &val, const boost::true_type &) {
- val = p.getDouble();
-}
-
-template <typename Parser>
-void parse(Parser &p, Null &, const boost::true_type &) {
- p.getNull();
-}
-
-template <typename Parser>
-void parse(Parser &p, bool &val, const boost::true_type &) {
- val = p.getBool();
-}
-
-template <typename Parser>
-void parse(Parser &p, std::string &val, const boost::true_type &) {
- p.getString(val);
-}
-
-template <typename Parser>
-void parse(Parser &p, std::vector<uint8_t> &val, const boost::true_type &) {
+template <typename Reader>
+void parse(Reader &p, std::vector<uint8_t> &val, const boost::true_type &) {
p.getBytes(&val);
}
Modified: hadoop/avro/trunk/src/c++/api/Parser.hh
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/Parser.hh?rev=794108&r1=794107&r2=794108&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/Parser.hh (original)
+++ hadoop/avro/trunk/src/c++/api/Parser.hh Tue Jul 14 22:48:26 2009
@@ -19,147 +19,124 @@
#ifndef avro_Parser_hh__
#define avro_Parser_hh__
-#include <stdint.h>
-#include <vector>
-#include <boost/noncopyable.hpp>
-
-#include "InputStreamer.hh"
-#include "Zigzag.hh"
+#include "Reader.hh"
+#include "ValidatingReader.hh"
namespace avro {
///
-/// Parses from an avro encoding to the requested type. Assumes the next item
-/// in the avro binary data is the expected type.
+/// Class that wraps a reader or ValidatingReade with an interface that uses
+/// explicit get* names instead of getValue
///
+template<class Reader>
class Parser : private boost::noncopyable
{
public:
+ // Constructor only works with Writer
explicit Parser(InputStreamer &in) :
- in_(in)
+ reader_(in)
+ {}
+
+ /// Constructor only works with ValidatingWriter
+ Parser(const ValidSchema &schema, InputStreamer &in) :
+ reader_(schema, in)
{}
- void getNull() {}
+ void getNull() {
+ Null null;
+ reader_.getValue(null);
+ }
bool getBool() {
- uint8_t ival = 0;
- in_.getByte(ival);
- return(ival != 0);
+ bool val;
+ reader_.getValue(val);
+ return val;
}
int32_t getInt() {
- uint32_t encoded = getVarInt();
- return decodeZigzag32(encoded);
+ int32_t val;
+ reader_.getValue(val);
+ return val;
}
int64_t getLong() {
- uint64_t encoded = getVarInt();
- return decodeZigzag64(encoded);
+ int64_t val;
+ reader_.getValue(val);
+ return val;
}
float getFloat() {
- union {
- float f;
- uint32_t i;
- } v;
- in_.getWord(v.i);
- return v.f;
+ float val;
+ reader_.getValue(val);
+ return val;
}
double getDouble() {
- union {
- double d;
- uint64_t i;
- } v;
- in_.getLongWord(v.i);
- return v.d;
+ double val;
+ reader_.getValue(val);
+ return val;
}
- void getBytes(std::vector<uint8_t> &val) {
- int64_t size = getLong();
-
- val.reserve(size);
- size_t bytes = 0;
- uint8_t bval = 0;
- while(bytes++ < static_cast<size_t>(size)) {
- in_.getByte(bval);
- val.push_back(bval);
- }
+ void getString(std::string &val) {
+ reader_.getValue(val);
}
- void getString(std::string &val) {
- int64_t size = getLong();
-
- val.reserve(size);
- size_t bytes = 0;
- uint8_t bval = 0;
- while(bytes++ < static_cast<size_t>(size)) {
- in_.getByte(bval);
- val.push_back(bval);
- }
+ void getBytes(std::vector<uint8_t> &val) {
+ reader_.getBytes(val);
}
void getFixed(std::vector<uint8_t> &val, size_t size) {
-
- val.reserve(size);
- size_t bytes = 0;
- uint8_t bval = 0;
- while(bytes++ < size) {
- in_.getByte(bval);
- val.push_back(bval);
- }
+ reader_.getFixed(val, size);
}
void getFixed(uint8_t *val, size_t size) {
-
- size_t bytes = 0;
- uint8_t bval = 0;
- while(bytes++ < size) {
- in_.getByte(bval);
- *val++ = bval;
- }
+ reader_.getFixed(val, size);
}
- void getRecord() { }
+ void getRecord() {
+ reader_.getRecord();
+ }
int64_t getArrayBlockSize() {
- return getLong();
+ return reader_.getArrayBlockSize();
}
int64_t getUnion() {
- return getLong();
+ return reader_.getUnion();
}
int64_t getEnum() {
- return getLong();
+ return reader_.getEnum();
}
int64_t getMapBlockSize() {
- return getLong();
+ return reader_.getMapBlockSize();
}
private:
- uint64_t getVarInt() {
- uint64_t encoded = 0;
- uint8_t val = 0;
- do {
- encoded <<= 8;
- in_.getByte(val);
- encoded |= (val & 0x7F);
-
- } while (val & 0x80);
-
- return encoded;
- }
+ friend Type nextType(Parser<ValidatingReader> &p);
+ friend bool getCurrentRecordName(Parser<ValidatingReader> &p, std::string
&name);
+ friend bool getNextFieldName(Parser<ValidatingReader> &p, std::string
&name);
- InputStreamer &in_;
+ Reader reader_;
};
+inline Type nextType(Parser<ValidatingReader> &p) {
+ return p.reader_.nextType();
+}
+
+inline bool getCurrentRecordName(Parser<ValidatingReader> &p, std::string
&name) {
+ return p.reader_.getCurrentRecordName(name);
+}
+
+inline bool getNextFieldName(Parser<ValidatingReader> &p, std::string &name) {
+ return p.reader_.getNextFieldName(name);
+}
} // namespace avro
Added: hadoop/avro/trunk/src/c++/api/Reader.hh
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/Reader.hh?rev=794108&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c++/api/Reader.hh (added)
+++ hadoop/avro/trunk/src/c++/api/Reader.hh Tue Jul 14 22:48:26 2009
@@ -0,0 +1,167 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef avro_Reader_hh__
+#define avro_Reader_hh__
+
+#include <stdint.h>
+#include <vector>
+#include <boost/noncopyable.hpp>
+
+#include "InputStreamer.hh"
+#include "Zigzag.hh"
+#include "Types.hh"
+
+namespace avro {
+
+///
+/// Parses from an avro encoding to the requested type. Assumes the next item
+/// in the avro binary data is the expected type.
+///
+
+class Reader : private boost::noncopyable
+{
+
+ public:
+
+ explicit Reader(InputStreamer &in) :
+ in_(in)
+ {}
+
+ void getValue(Null &) {}
+
+ void getValue(bool &val) {
+ uint8_t ival;
+ in_.getByte(ival);
+ val = (ival != 0);
+ }
+
+ void getValue(int32_t &val) {
+ uint32_t encoded = getVarInt();
+ val = decodeZigzag32(encoded);
+ }
+
+ void getValue(int64_t &val) {
+ uint64_t encoded = getVarInt();
+ val = decodeZigzag64(encoded);
+ }
+
+ void getValue(float &val) {
+ union {
+ float f;
+ uint32_t i;
+ } v;
+ in_.getWord(v.i);
+ val = v.f;
+ }
+
+ void getValue(double &val) {
+ union {
+ double d;
+ uint64_t i;
+ } v;
+ in_.getLongWord(v.i);
+ val = v.d;
+ }
+
+ void getValue(std::string &val) {
+ int64_t size = getSize();
+ val.reserve(size);
+ uint8_t bval;
+ for(size_t bytes = 0; bytes < static_cast<size_t>(size); bytes++) {
+ in_.getByte(bval);
+ val.push_back(bval);
+ }
+ }
+
+ void getBytes(std::vector<uint8_t> &val) {
+ int64_t size = getSize();
+
+ val.reserve(size);
+ uint8_t bval;
+ for(size_t bytes = 0; bytes < static_cast<size_t>(size); bytes++) {
+ in_.getByte(bval);
+ val.push_back(bval);
+ }
+ }
+
+
+ void getFixed(std::vector<uint8_t> &val, size_t size) {
+ val.reserve(size);
+ uint8_t bval;
+ for(size_t bytes = 0; bytes < size; bytes++) {
+ in_.getByte(bval);
+ val.push_back(bval);
+ }
+ }
+
+ void getFixed(uint8_t *val, size_t size) {
+ uint8_t bval;
+ for(size_t bytes = 0; bytes < size; bytes++) {
+ in_.getByte(bval);
+ *val++ = bval;
+ }
+ }
+
+ void getRecord() { }
+
+ int64_t getArrayBlockSize() {
+ return getSize();
+ }
+
+ int64_t getUnion() {
+ return getSize();
+ }
+
+ int64_t getEnum() {
+ return getSize();
+ }
+
+ int64_t getMapBlockSize() {
+ return getSize();
+ }
+
+ private:
+
+ int64_t getSize() {
+ int64_t size(0);
+ getValue(size);
+ return size;
+ }
+
+ uint64_t getVarInt() {
+ uint64_t encoded = 0;
+ uint8_t val = 0;
+ do {
+ encoded <<= 8;
+ in_.getByte(val);
+ encoded |= (val & 0x7F);
+
+ } while (val & 0x80);
+
+ return encoded;
+ }
+
+ InputStreamer &in_;
+
+};
+
+
+} // namespace avro
+
+#endif
Copied: hadoop/avro/trunk/src/c++/api/ValidatingReader.hh (from r794096,
hadoop/avro/trunk/src/c++/api/ValidatingParser.hh)
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/ValidatingReader.hh?p2=hadoop/avro/trunk/src/c%2B%2B/api/ValidatingReader.hh&p1=hadoop/avro/trunk/src/c%2B%2B/api/ValidatingParser.hh&r1=794096&r2=794108&rev=794108&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/ValidatingParser.hh (original)
+++ hadoop/avro/trunk/src/c++/api/ValidatingReader.hh Tue Jul 14 22:48:26 2009
@@ -16,15 +16,16 @@
* limitations under the License.
*/
-#ifndef avro_ValidatingParser_hh__
-#define avro_ValidatingParser_hh__
+#ifndef avro_ValidatingReader_hh__
+#define avro_ValidatingReader_hh__
#include <stdint.h>
#include <vector>
#include <boost/noncopyable.hpp>
-#include "Parser.hh"
+#include "Reader.hh"
#include "Validator.hh"
+#include "AvroTraits.hh"
namespace avro {
@@ -36,47 +37,45 @@
/// correct type is being asked for. If the user attempts to parse a type that
/// does not match what the schema says, an exception will be thrown.
///
-/// The ValidatingParser object can also be used to tell what the next type is,
+/// The ValidatingReader object can also be used to tell what the next type is,
/// so that callers can dynamically discover the contents. It also tells
/// the attribute names of the objects or their fields, if they exist.
///
-class ValidatingParser : private boost::noncopyable
+class ValidatingReader : private boost::noncopyable
{
public:
- explicit ValidatingParser(const ValidSchema &schema, InputStreamer &in);
+ explicit ValidatingReader(const ValidSchema &schema, InputStreamer &in);
- void getNull();
-
- bool getBool();
-
- int32_t getInt();
-
- int64_t getLong();
-
- float getFloat();
-
- double getDouble();
+ template<typename T>
+ void getValue(T &val) {
+ checkSafeToGet(type_to_avro<T>::type);
+ reader_.getValue(val);
+ validator_.advance();
+ }
- void getBytes(std::vector<uint8_t> &val);
+ void getBytes(std::vector<uint8_t> &val) {
+ checkSafeToGet(AVRO_BYTES);
+ validator_.advance();
+ reader_.getBytes(val);
+ }
void getFixed(uint8_t *val, size_t size) {
checkSafeToGet(AVRO_FIXED);
checkSizeExpected(size);
validator_.advance();
- parser_.getFixed(val, size);
+ reader_.getFixed(val, size);
}
void getFixed(std::vector<uint8_t> &val, size_t size) {
checkSafeToGet(AVRO_FIXED);
checkSizeExpected(size);
validator_.advance();
- parser_.getFixed(val, size);
+ reader_.getFixed(val, size);
}
- void getString(std::string &val);
void getRecord();
@@ -117,10 +116,9 @@
}
Validator validator_;
- Parser parser_;
+ Reader reader_;
};
-
} // namespace avro
#endif
Propchange: hadoop/avro/trunk/src/c++/api/ValidatingReader.hh
------------------------------------------------------------------------------
svn:mergeinfo =
Modified: 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=794108&r1=794107&r2=794108&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/ValidatingWriter.hh (original)
+++ hadoop/avro/trunk/src/c++/api/ValidatingWriter.hh Tue Jul 14 22:48:26 2009
@@ -91,7 +91,7 @@
}
}
- Validator validator_;
+ Validator validator_;
Writer writer_;
};
Copied: hadoop/avro/trunk/src/c++/impl/ValidatingReader.cc (from r794096,
hadoop/avro/trunk/src/c++/impl/ValidatingParser.cc)
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/impl/ValidatingReader.cc?p2=hadoop/avro/trunk/src/c%2B%2B/impl/ValidatingReader.cc&p1=hadoop/avro/trunk/src/c%2B%2B/impl/ValidatingParser.cc&r1=794096&r2=794108&rev=794108&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/impl/ValidatingParser.cc (original)
+++ hadoop/avro/trunk/src/c++/impl/ValidatingReader.cc Tue Jul 14 22:48:26 2009
@@ -18,101 +18,36 @@
#include <boost/static_assert.hpp>
-#include "ValidatingParser.hh"
+#include "ValidatingReader.hh"
#include "ValidSchema.hh"
#include "OutputStreamer.hh"
namespace avro {
-ValidatingParser::ValidatingParser(const ValidSchema &schema, InputStreamer
&in) :
+ValidatingReader::ValidatingReader(const ValidSchema &schema, InputStreamer
&in) :
validator_(schema),
- parser_(in)
+ reader_(in)
{ }
-void
-ValidatingParser::getNull()
-{
- checkSafeToGet(AVRO_NULL);
- validator_.advance();
- parser_.getNull();
-}
-
-int32_t
-ValidatingParser::getInt()
-{
- checkSafeToGet(AVRO_INT);
- int32_t val = parser_.getInt();
- validator_.advance();
- return val;
-}
-
-int64_t
-ValidatingParser::getLong()
-{
- checkSafeToGet(AVRO_LONG);
- int64_t val = parser_.getLong();
- validator_.advance();
- return val;
-}
-
-float
-ValidatingParser::getFloat()
-{
- checkSafeToGet(AVRO_FLOAT);
- validator_.advance();
- return parser_.getFloat();
-}
-
-double
-ValidatingParser::getDouble()
-{
- checkSafeToGet(AVRO_DOUBLE);
- validator_.advance();
- return parser_.getDouble();
-}
-
-bool
-ValidatingParser::getBool()
-{
- checkSafeToGet(AVRO_BOOL);
- validator_.advance();
- return parser_.getBool();
-}
-
-void
-ValidatingParser::getString(std::string &val)
-{
- checkSafeToGet(AVRO_STRING);
- validator_.advance();
- parser_.getString(val);
-}
-
-void
-ValidatingParser::getBytes(std::vector<uint8_t> &val)
-{
- checkSafeToGet(AVRO_BYTES);
- validator_.advance();
- parser_.getBytes(val);
-}
-
int64_t
-ValidatingParser::getCount()
+ValidatingReader::getCount()
{
checkSafeToGet(AVRO_LONG);
- int64_t val = parser_.getLong();
+ int64_t val;
+ reader_.getValue(val);
validator_.advanceWithCount(val);
return val;
}
void
-ValidatingParser::getRecord()
+ValidatingReader::getRecord()
{
checkSafeToGet(AVRO_RECORD);
validator_.advance();
}
int64_t
-ValidatingParser::getUnion()
+ValidatingReader::getUnion()
{
checkSafeToGet(AVRO_UNION);
validator_.advance();
@@ -120,7 +55,7 @@
}
int64_t
-ValidatingParser::getEnum()
+ValidatingReader::getEnum()
{
checkSafeToGet(AVRO_ENUM);
validator_.advance();
@@ -128,7 +63,7 @@
}
int64_t
-ValidatingParser::getMapBlockSize()
+ValidatingReader::getMapBlockSize()
{
checkSafeToGet(AVRO_MAP);
validator_.advance();
@@ -136,7 +71,7 @@
}
int64_t
-ValidatingParser::getArrayBlockSize()
+ValidatingReader::getArrayBlockSize()
{
checkSafeToGet(AVRO_ARRAY);
validator_.advance();
Propchange: hadoop/avro/trunk/src/c++/impl/ValidatingReader.cc
------------------------------------------------------------------------------
svn:mergeinfo =
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=794108&r1=794107&r2=794108&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/test/testgen.cc (original)
+++ hadoop/avro/trunk/src/c++/test/testgen.cc Tue Jul 14 22:48:26 2009
@@ -24,8 +24,10 @@
#include "OutputStreamer.hh"
#include "InputStreamer.hh"
#include "Serializer.hh"
-#include "Parser.hh"
-#include "ValidatingParser.hh"
+#include "Writer.hh"
+#include "ValidatingWriter.hh"
+#include "Reader.hh"
+#include "ValidatingReader.hh"
#include "ValidSchema.hh"
#include "Compiler.hh"
@@ -102,7 +104,7 @@
avrouser::RootRecord inRecord;
std::istringstream istring(ostring.str());
avro::IStreamer is(istring);
- avro::Parser p(is);
+ avro::Reader p(is);
avro::parse(p, inRecord);
checkOk(myRecord, inRecord);
@@ -119,7 +121,7 @@
avrouser::RootRecord inRecord;
std::istringstream istring(ostring.str());
avro::IStreamer is(istring);
- avro::ValidatingParser p(valid, is);
+ avro::ValidatingReader p(valid, is);
avro::parse(p, inRecord);
checkOk(myRecord, inRecord);
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=794108&r1=794107&r2=794108&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/test/unittest.cc (original)
+++ hadoop/avro/trunk/src/c++/test/unittest.cc Tue Jul 14 22:48:26 2009
@@ -28,7 +28,6 @@
#include "OutputStreamer.hh"
#include "Serializer.hh"
#include "Parser.hh"
-#include "ValidatingParser.hh"
#include "SymbolMap.hh"
#include "AvroSerialize.hh"
@@ -106,8 +105,8 @@
}
}
- template<typename Serial>
- void writeEncoding(Serial &s, int path)
+ template<typename Serializer>
+ void writeEncoding(Serializer &s, int path)
{
std::cout << "Record\n";
@@ -168,18 +167,18 @@
writeEncoding(s, path);
}
- void printNext(Parser &p) {
+ void printNext(Parser<Reader> &p) {
}
- void printNext(ValidatingParser &p)
+ void printNext(Parser<ValidatingReader> &p)
{
- std::cout << "Next: \"" << p.nextType();
+ std::cout << "Next: \"" << nextType(p);
std::string recordName;
std::string fieldName;
- if( p.getCurrentRecordName(recordName) ) {
+ if( getCurrentRecordName(p, recordName) ) {
std::cout << "\" record: \"" << recordName;
}
- if( p.getNextFieldName(fieldName) ) {
+ if( getNextFieldName(p, fieldName) ) {
std::cout << "\" field: \"" << fieldName;
}
std::cout << "\"\n";
@@ -270,7 +269,7 @@
void readRawData() {
std::ifstream in("test.avro");
IStreamer ins(in);
- Parser p(ins);
+ Parser<Reader> p(ins);
readData(p);
}
@@ -278,7 +277,7 @@
{
std::ifstream in("test.avro");
IStreamer ins(in);
- ValidatingParser p(schema_, ins);
+ Parser<ValidatingReader> p(schema_, ins);
readData(p);
}
@@ -436,7 +435,7 @@
void validatingParser(InputStreamer &is)
{
- ValidatingParser p(schema_, is);
+ Parser<ValidatingReader> p(schema_, is);
int64_t val = 0;
int64_t path = 0;
@@ -518,6 +517,7 @@
int main()
{
+ bool pass = true;
try {
TestEncoding test1;
test1.test();
@@ -536,7 +536,8 @@
}
catch (std::exception &e) {
std::cout << "Failed unit test due to exception: " << e.what() <<
std::endl;
+ pass = false;
}
- return 0;
+ return pass ? 0 : 1;
}