Author: sbanacho
Date: Wed Oct 28 20:23:47 2009
New Revision: 830750
URL: http://svn.apache.org/viewvc?rev=830750&view=rev
Log:
AVRO-157. Changes from code review comments.
Added:
hadoop/avro/trunk/src/c++/impl/CompilerNode.cc
Modified:
hadoop/avro/trunk/CHANGES.txt
hadoop/avro/trunk/src/c++/api/AvroParse.hh
hadoop/avro/trunk/src/c++/api/AvroSerialize.hh
hadoop/avro/trunk/src/c++/api/CompilerNode.hh
hadoop/avro/trunk/src/c++/api/InputStreamer.hh
hadoop/avro/trunk/src/c++/api/NodeConcepts.hh
hadoop/avro/trunk/src/c++/api/NodeImpl.hh
hadoop/avro/trunk/src/c++/api/OutputStreamer.hh
hadoop/avro/trunk/src/c++/api/Parser.hh
hadoop/avro/trunk/src/c++/api/Reader.hh
hadoop/avro/trunk/src/c++/api/Serializer.hh
hadoop/avro/trunk/src/c++/api/ValidatingReader.hh
hadoop/avro/trunk/src/c++/api/ValidatingWriter.hh
hadoop/avro/trunk/src/c++/api/Writer.hh
hadoop/avro/trunk/src/c++/impl/Node.cc
hadoop/avro/trunk/src/c++/impl/NodeImpl.cc
hadoop/avro/trunk/src/c++/impl/ValidatingReader.cc
hadoop/avro/trunk/src/c++/impl/ValidatingWriter.cc
hadoop/avro/trunk/src/c++/scripts/gen-cppcode.py
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=830750&r1=830749&r2=830750&view=diff
==============================================================================
--- hadoop/avro/trunk/CHANGES.txt (original)
+++ hadoop/avro/trunk/CHANGES.txt Wed Oct 28 20:23:47 2009
@@ -10,6 +10,8 @@
IMPROVEMENTS
+ AVRO-157. Changes from code review comments for C++. (sbanacho)
+
AVRO-168. Correct shared library versioning for C implementation (massie)
AVRO-142. Remove some Java unused fields and imports. Start
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=830750&r1=830749&r2=830750&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/AvroParse.hh (original)
+++ hadoop/avro/trunk/src/c++/api/AvroParse.hh Wed Oct 28 20:23:47 2009
@@ -51,12 +51,12 @@
template <typename Reader, typename T>
void parse(Reader &p, T &val, const boost::true_type &) {
- p.getValue(val);
+ p.readValue(val);
}
template <typename Reader>
void parse(Reader &p, std::vector<uint8_t> &val, const boost::true_type &) {
- p.getBytes(val);
+ p.readBytes(val);
}
// @}
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=830750&r1=830749&r2=830750&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/AvroSerialize.hh (original)
+++ hadoop/avro/trunk/src/c++/api/AvroSerialize.hh Wed Oct 28 20:23:47 2009
@@ -51,12 +51,12 @@
template <typename Writer, typename T>
void serialize(Writer &s, T val, const boost::true_type &) {
- s.putValue(val);
+ s.writeValue(val);
}
template <typename Writer>
void serialize(Writer &s, const std::vector<uint8_t> &val, const
boost::true_type &) {
- s.putBytes(&val[0], val.size());
+ s.writeBytes(&val[0], val.size());
}
// @}
Modified: hadoop/avro/trunk/src/c++/api/CompilerNode.hh
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/CompilerNode.hh?rev=830750&r1=830749&r2=830750&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/CompilerNode.hh (original)
+++ hadoop/avro/trunk/src/c++/api/CompilerNode.hh Wed Oct 28 20:23:47 2009
@@ -20,6 +20,7 @@
#define avro_CompilerNode_hh__
#include "NodeConcepts.hh"
+#include "Node.hh"
namespace avro {
@@ -99,7 +100,6 @@
// attribute used by fixed:
concepts::SingleAttribute<int> sizeAttribute_;
- //private:
// attributes used by records:
concepts::MultiAttribute<NodePtr> fieldsAttribute_;
concepts::MultiAttribute<std::string> fieldsNamesAttribute_;
@@ -121,6 +121,8 @@
};
+NodePtr nodeFromCompilerNode(CompilerNode &compilerNode);
+
} // namespace avro
#endif
Modified: hadoop/avro/trunk/src/c++/api/InputStreamer.hh
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/InputStreamer.hh?rev=830750&r1=830749&r2=830750&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/InputStreamer.hh (original)
+++ hadoop/avro/trunk/src/c++/api/InputStreamer.hh Wed Oct 28 20:23:47 2009
@@ -39,10 +39,10 @@
virtual ~InputStreamer()
{ }
- virtual size_t getByte(uint8_t &byte) = 0;
- virtual size_t getWord(uint32_t &word) = 0;
- virtual size_t getLongWord(uint64_t &word) = 0;
- virtual size_t getBytes(uint8_t *bytes, size_t size) = 0;
+ virtual size_t readByte(uint8_t &byte) = 0;
+ virtual size_t readWord(uint32_t &word) = 0;
+ virtual size_t readLongWord(uint64_t &word) = 0;
+ virtual size_t readBytes(uint8_t *bytes, size_t size) = 0;
};
@@ -61,24 +61,24 @@
is_(is)
{}
- size_t getByte(uint8_t &byte) {
+ size_t readByte(uint8_t &byte) {
char val;
is_.get(val);
byte = val;
return 1;
}
- size_t getWord(uint32_t &word) {
+ size_t readWord(uint32_t &word) {
is_.read(reinterpret_cast<char *>(&word), sizeof(word));
return is_.gcount();
}
- size_t getLongWord(uint64_t &word) {
+ size_t readLongWord(uint64_t &word) {
is_.read(reinterpret_cast<char *>(&word), sizeof(word));
return is_.gcount();
}
- size_t getBytes(uint8_t *bytes, size_t size) {
+ size_t readBytes(uint8_t *bytes, size_t size) {
is_.read(reinterpret_cast<char *>(bytes), size);
return is_.gcount();
}
Modified: hadoop/avro/trunk/src/c++/api/NodeConcepts.hh
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/NodeConcepts.hh?rev=830750&r1=830749&r2=830750&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/NodeConcepts.hh (original)
+++ hadoop/avro/trunk/src/c++/api/NodeConcepts.hh Wed Oct 28 20:23:47 2009
@@ -20,6 +20,7 @@
#define avro_NodeConcepts_hh__
#include <vector>
+#include "Exception.hh"
namespace avro {
@@ -48,25 +49,24 @@
{
static const bool hasAttribute = false;
- NoAttribute()
- {}
-
- // copy constructing from any attribute type is a no-op
- // template<typename T>
- NoAttribute(const NoAttribute<Attribute> &rhs)
- {}
-
size_t size() const {
return 0;
}
void add( const Attribute &attr) {
+ // There must be an add function for the generic NodeImpl, but the
+ // Node APIs ensure that it is never called, the throw here is
+ // just in case
throw Exception("This type does not have attribute");
}
const Attribute &get(size_t index = 0) const {
- static const Attribute empty = Attribute();
+ // There must be an get function for the generic NodeImpl, but the
+ // Node APIs ensure that it is never called, the throw here is
+ // just in case
throw Exception("This type does not have attribute");
+ // even though this code is unreachable the compiler requires it
+ static const Attribute empty = Attribute();
return empty;
}
@@ -85,15 +85,11 @@
attr_(rhs.attr_), size_(rhs.size_)
{ }
+ // copy constructing from a no attribute is allowed
SingleAttribute(const NoAttribute<Attribute> &rhs) :
attr_(), size_(0)
{ }
- // copy constructing from any other type is a no-op
- //template<typename T>
- //SingleAttribute(T&) : attr_(), size_(0)
- //{}
-
size_t size() const {
return size_;
}
@@ -160,7 +156,7 @@
return attrs_.at(index);
}
- Attribute &at(size_t index) {
+ Attribute &get(size_t index) {
return attrs_.at(index);
}
Modified: hadoop/avro/trunk/src/c++/api/NodeImpl.hh
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/NodeImpl.hh?rev=830750&r1=830749&r2=830750&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/NodeImpl.hh (original)
+++ hadoop/avro/trunk/src/c++/api/NodeImpl.hh Wed Oct 28 20:23:47 2009
@@ -22,7 +22,7 @@
#include <limits>
#include "Node.hh"
-#include "CompilerNode.hh"
+#include "NodeConcepts.hh"
namespace avro {
@@ -43,8 +43,10 @@
NodeImpl(Type type) :
Node(type),
+ nameAttribute_(),
leafAttributes_(),
- leafNameAttributes_()
+ leafNameAttributes_(),
+ sizeAttribute_()
{ }
NodeImpl(Type type,
@@ -60,7 +62,7 @@
{ }
bool hasName() const {
- return nameAttribute_.hasAttribute;
+ return NameConcept::hasAttribute;
}
void doSetName(const std::string &name) {
@@ -142,20 +144,10 @@
{
public:
- NodePrimitive(Type type) :
+ explicit NodePrimitive(Type type) :
NodeImplPrimitive(type)
{ }
- NodePrimitive(const CompilerNode &compilerNode) :
- NodeImplPrimitive(
- compilerNode.type(),
- NoName(),
- NoLeaves(),
- NoLeafNames(),
- NoSize()
- )
- { }
-
void printJson(std::ostream &os, int depth) const;
bool isValid() const {
@@ -171,14 +163,8 @@
NodeImplSymbolic(AVRO_SYMBOLIC)
{ }
- NodeSymbolic(const CompilerNode &compilerNode) :
- NodeImplSymbolic(
- AVRO_SYMBOLIC,
- compilerNode.nameAttribute_,
- NoLeaves(),
- NoLeafNames(),
- NoSize()
- )
+ explicit NodeSymbolic(const HasName &name) :
+ NodeImplSymbolic(AVRO_SYMBOLIC, name, NoLeaves(), NoLeafNames(),
NoSize())
{ }
void printJson(std::ostream &os, int depth) const;
@@ -197,14 +183,8 @@
NodeImplRecord(AVRO_RECORD)
{ }
- NodeRecord(const CompilerNode &compilerNode) :
- NodeImplRecord(
- AVRO_RECORD,
- compilerNode.nameAttribute_,
- compilerNode.fieldsAttribute_,
- compilerNode.fieldsNamesAttribute_,
- NoSize()
- )
+ NodeRecord(const HasName &name, const MultiLeaves &fields, const LeafNames
&fieldsNames) :
+ NodeImplRecord(AVRO_RECORD, name, fields, fieldsNames, NoSize())
{ }
void printJson(std::ostream &os, int depth) const;
@@ -226,17 +206,10 @@
NodeImplEnum(AVRO_ENUM)
{ }
- NodeEnum(const CompilerNode &compilerNode) :
- NodeImplEnum(
- AVRO_ENUM,
- compilerNode.nameAttribute_,
- NoLeaves(),
- compilerNode.symbolsAttribute_,
- NoSize()
- )
+ NodeEnum(const HasName &name, const LeafNames &symbols) :
+ NodeImplEnum(AVRO_ENUM, name, NoLeaves(), symbols, NoSize())
{ }
-
void printJson(std::ostream &os, int depth) const;
bool isValid() const {
@@ -255,17 +228,10 @@
NodeImplArray(AVRO_ARRAY)
{ }
- NodeArray(const CompilerNode &compilerNode) :
- NodeImplArray(
- AVRO_ARRAY,
- NoName(),
- compilerNode.itemsAttribute_,
- NoLeafNames(),
- NoSize()
- )
+ explicit NodeArray(const SingleLeaf &items) :
+ NodeImplArray(AVRO_ARRAY, NoName(), items, NoLeafNames(), NoSize())
{ }
-
void printJson(std::ostream &os, int depth) const;
bool isValid() const {
@@ -284,21 +250,15 @@
doAddLeaf(key);
}
- NodeMap(const CompilerNode &compilerNode) :
- NodeImplMap(
- AVRO_MAP,
- NoName(),
- compilerNode.valuesAttribute_,
- NoLeafNames(),
- NoSize()
- )
+ explicit NodeMap(const SingleLeaf &values) :
+ NodeImplMap(AVRO_MAP, NoName(), values, NoLeafNames(), NoSize())
{
// need to add the key for the map too
NodePtr key(new NodePrimitive(AVRO_STRING));
doAddLeaf(key);
// key goes before value
- std::swap(leafAttributes_.at(0), leafAttributes_.at(1));
+ std::swap(leafAttributes_.get(0), leafAttributes_.get(1));
}
void printJson(std::ostream &os, int depth) const;
@@ -316,17 +276,10 @@
NodeImplUnion(AVRO_UNION)
{ }
- NodeUnion(const CompilerNode &compilerNode) :
- NodeImplUnion(
- AVRO_UNION,
- NoName(),
- compilerNode.typesAttribute_,
- NoLeafNames(),
- NoSize()
- )
+ explicit NodeUnion(const MultiLeaves &types) :
+ NodeImplUnion(AVRO_UNION, NoName(), types, NoLeafNames(), NoSize())
{ }
-
void printJson(std::ostream &os, int depth) const;
bool isValid() const {
@@ -342,17 +295,10 @@
NodeImplFixed(AVRO_FIXED)
{ }
- NodeFixed(const CompilerNode &compilerNode) :
- NodeImplFixed(
- AVRO_FIXED,
- compilerNode.nameAttribute_,
- NoLeaves(),
- NoLeafNames(),
- compilerNode.sizeAttribute_
- )
+ NodeFixed(const HasName &name, const HasSize &size) :
+ NodeImplFixed(AVRO_FIXED, name, NoLeaves(), NoLeafNames(), size)
{ }
-
void printJson(std::ostream &os, int depth) const;
bool isValid() const {
@@ -367,7 +313,7 @@
inline void
NodeImpl<A,B,C,D>::setLeafToSymbolic(int index)
{
- if(!leafAttributes_.hasAttribute) {
+ if(!B::hasAttribute) {
throw Exception("Cannot change leaf node for nonexistent leaf");
}
NodePtr symbol(new NodeSymbolic);
@@ -385,14 +331,14 @@
if(hasName()) {
os << " " << nameAttribute_.get();
}
- if(sizeAttribute_.hasAttribute) {
+ if(D::hasAttribute) {
os << " " << sizeAttribute_.get();
}
os << '\n';
int count = leaves();
count = count ? count : names();
for(int i= 0; i < count; ++i) {
- if( leafNameAttributes_.hasAttribute ) {
+ if( C::hasAttribute ) {
os << "name " << nameAt(i) << '\n';
}
if( leafAttributes_.hasAttribute) {
@@ -404,8 +350,6 @@
}
}
-NodePtr nodeFromCompilerNode(CompilerNode &compilerNode);
-
} // namespace avro
#endif
Modified: hadoop/avro/trunk/src/c++/api/OutputStreamer.hh
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/OutputStreamer.hh?rev=830750&r1=830749&r2=830750&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/OutputStreamer.hh (original)
+++ hadoop/avro/trunk/src/c++/api/OutputStreamer.hh Wed Oct 28 20:23:47 2009
@@ -40,10 +40,10 @@
virtual ~OutputStreamer()
{ }
- virtual size_t putByte(uint8_t byte) = 0;
- virtual size_t putWord(uint32_t word) = 0;
- virtual size_t putLongWord(uint64_t word) = 0;
- virtual size_t putBytes(const uint8_t *bytes, size_t size) = 0;
+ virtual size_t writeByte(uint8_t byte) = 0;
+ virtual size_t writeWord(uint32_t word) = 0;
+ virtual size_t writeLongWord(uint64_t word) = 0;
+ virtual size_t writeBytes(const uint8_t *bytes, size_t size) = 0;
};
@@ -54,24 +54,24 @@
class ScreenStreamer : public OutputStreamer {
- size_t putByte(uint8_t byte) {
+ size_t writeByte(uint8_t byte) {
std::cout << "0x" << std::hex << static_cast<int32_t>(byte) <<
std::dec << " ";
return 1;
}
- size_t putWord(uint32_t word) {
- ScreenStreamer::putBytes(reinterpret_cast<uint8_t *>(&word),
sizeof(word));
+ size_t writeWord(uint32_t word) {
+ ScreenStreamer::writeBytes(reinterpret_cast<uint8_t *>(&word),
sizeof(word));
return sizeof(uint32_t);
}
- size_t putLongWord(uint64_t word) {
- ScreenStreamer::putBytes(reinterpret_cast<uint8_t *>(&word),
sizeof(word));
+ size_t writeLongWord(uint64_t word) {
+ ScreenStreamer::writeBytes(reinterpret_cast<uint8_t *>(&word),
sizeof(word));
return sizeof(uint64_t);
}
- size_t putBytes(const uint8_t *bytes, size_t size) {
+ size_t writeBytes(const uint8_t *bytes, size_t size) {
for (size_t i= 0; i < size; ++i) {
- ScreenStreamer::putByte(*bytes++);
+ ScreenStreamer::writeByte(*bytes++);
}
std::cout << std::endl;
return size;
@@ -95,22 +95,22 @@
os_(os)
{}
- size_t putByte(uint8_t byte) {
+ size_t writeByte(uint8_t byte) {
os_.put(byte);
return 1;
}
- size_t putWord(uint32_t word) {
+ size_t writeWord(uint32_t word) {
os_.write(reinterpret_cast<char *>(&word), sizeof(word));
return sizeof(uint32_t);
}
- size_t putLongWord(uint64_t word) {
+ size_t writeLongWord(uint64_t word) {
os_.write(reinterpret_cast<char *>(&word), sizeof(word));
return sizeof(uint64_t);
}
- size_t putBytes(const uint8_t *bytes, size_t size) {
+ size_t writeBytes(const uint8_t *bytes, size_t size) {
os_.write(reinterpret_cast<const char *>(bytes), size);
return size;
}
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=830750&r1=830749&r2=830750&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/Parser.hh (original)
+++ hadoop/avro/trunk/src/c++/api/Parser.hh Wed Oct 28 20:23:47 2009
@@ -45,82 +45,82 @@
reader_(schema, in)
{}
- void getNull() {
+ void readNull() {
Null null;
- reader_.getValue(null);
+ reader_.readValue(null);
}
- bool getBool() {
+ bool readBool() {
bool val;
- reader_.getValue(val);
+ reader_.readValue(val);
return val;
}
- int32_t getInt() {
+ int32_t readInt() {
int32_t val;
- reader_.getValue(val);
+ reader_.readValue(val);
return val;
}
- int64_t getLong() {
+ int64_t readLong() {
int64_t val;
- reader_.getValue(val);
+ reader_.readValue(val);
return val;
}
- float getFloat() {
+ float readFloat() {
float val;
- reader_.getValue(val);
+ reader_.readValue(val);
return val;
}
- double getDouble() {
+ double readDouble() {
double val;
- reader_.getValue(val);
+ reader_.readValue(val);
return val;
}
- void getString(std::string &val) {
- reader_.getValue(val);
+ void readString(std::string &val) {
+ reader_.readValue(val);
}
- void getBytes(std::vector<uint8_t> &val) {
- reader_.getBytes(val);
+ void readBytes(std::vector<uint8_t> &val) {
+ reader_.readBytes(val);
}
- void getFixed(std::vector<uint8_t> &val, size_t size) {
- reader_.getFixed(val, size);
+ void readFixed(std::vector<uint8_t> &val, size_t size) {
+ reader_.readFixed(val, size);
}
- void getFixed(uint8_t *val, size_t size) {
- reader_.getFixed(val, size);
+ void readFixed(uint8_t *val, size_t size) {
+ reader_.readFixed(val, size);
}
- void getRecord() {
- reader_.getRecord();
+ void readRecord() {
+ reader_.readRecord();
}
- int64_t getArrayBlockSize() {
- return reader_.getArrayBlockSize();
+ int64_t readArrayBlockSize() {
+ return reader_.readArrayBlockSize();
}
- int64_t getUnion() {
- return reader_.getUnion();
+ int64_t readUnion() {
+ return reader_.readUnion();
}
- int64_t getEnum() {
- return reader_.getEnum();
+ int64_t readEnum() {
+ return reader_.readEnum();
}
- int64_t getMapBlockSize() {
- return reader_.getMapBlockSize();
+ int64_t readMapBlockSize() {
+ return reader_.readMapBlockSize();
}
private:
friend Type nextType(Parser<ValidatingReader> &p);
- friend bool getCurrentRecordName(Parser<ValidatingReader> &p, std::string
&name);
- friend bool getNextFieldName(Parser<ValidatingReader> &p, std::string
&name);
+ friend bool currentRecordName(Parser<ValidatingReader> &p, std::string
&name);
+ friend bool nextFieldName(Parser<ValidatingReader> &p, std::string &name);
Reader reader_;
@@ -130,12 +130,12 @@
return p.reader_.nextType();
}
-inline bool getCurrentRecordName(Parser<ValidatingReader> &p, std::string
&name) {
- return p.reader_.getCurrentRecordName(name);
+inline bool currentRecordName(Parser<ValidatingReader> &p, std::string &name) {
+ return p.reader_.currentRecordName(name);
}
-inline bool getNextFieldName(Parser<ValidatingReader> &p, std::string &name) {
- return p.reader_.getNextFieldName(name);
+inline bool nextFieldName(Parser<ValidatingReader> &p, std::string &name) {
+ return p.reader_.nextFieldName(name);
}
} // namespace avro
Modified: 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=830750&r1=830749&r2=830750&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/Reader.hh (original)
+++ hadoop/avro/trunk/src/c++/api/Reader.hh Wed Oct 28 20:23:47 2009
@@ -43,113 +43,113 @@
in_(in)
{}
- void getValue(Null &) {}
+ void readValue(Null &) {}
- void getValue(bool &val) {
+ void readValue(bool &val) {
uint8_t ival;
- in_.getByte(ival);
+ in_.readByte(ival);
val = (ival != 0);
}
- void getValue(int32_t &val) {
- uint32_t encoded = getVarInt();
+ void readValue(int32_t &val) {
+ uint32_t encoded = readVarInt();
val = decodeZigzag32(encoded);
}
- void getValue(int64_t &val) {
- uint64_t encoded = getVarInt();
+ void readValue(int64_t &val) {
+ uint64_t encoded = readVarInt();
val = decodeZigzag64(encoded);
}
- void getValue(float &val) {
+ void readValue(float &val) {
union {
float f;
uint32_t i;
} v;
- in_.getWord(v.i);
+ in_.readWord(v.i);
val = v.f;
}
- void getValue(double &val) {
+ void readValue(double &val) {
union {
double d;
uint64_t i;
} v;
- in_.getLongWord(v.i);
+ in_.readLongWord(v.i);
val = v.d;
}
- void getValue(std::string &val) {
- int64_t size = getSize();
+ void readValue(std::string &val) {
+ int64_t size = readSize();
val.reserve(size);
uint8_t bval;
for(size_t bytes = 0; bytes < static_cast<size_t>(size); bytes++) {
- in_.getByte(bval);
+ in_.readByte(bval);
val.push_back(bval);
}
}
- void getBytes(std::vector<uint8_t> &val) {
- int64_t size = getSize();
+ void readBytes(std::vector<uint8_t> &val) {
+ int64_t size = readSize();
val.reserve(size);
uint8_t bval;
for(size_t bytes = 0; bytes < static_cast<size_t>(size); bytes++) {
- in_.getByte(bval);
+ in_.readByte(bval);
val.push_back(bval);
}
}
- void getFixed(std::vector<uint8_t> &val, size_t size) {
+ void readFixed(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);
+ in_.readByte(bval);
val.push_back(bval);
}
}
- void getFixed(uint8_t *val, size_t size) {
+ void readFixed(uint8_t *val, size_t size) {
uint8_t bval;
for(size_t bytes = 0; bytes < size; bytes++) {
- in_.getByte(bval);
+ in_.readByte(bval);
*val++ = bval;
}
}
- void getRecord() { }
+ void readRecord() { }
- int64_t getArrayBlockSize() {
- return getSize();
+ int64_t readArrayBlockSize() {
+ return readSize();
}
- int64_t getUnion() {
- return getSize();
+ int64_t readUnion() {
+ return readSize();
}
- int64_t getEnum() {
- return getSize();
+ int64_t readEnum() {
+ return readSize();
}
- int64_t getMapBlockSize() {
- return getSize();
+ int64_t readMapBlockSize() {
+ return readSize();
}
private:
- int64_t getSize() {
+ int64_t readSize() {
int64_t size(0);
- getValue(size);
+ readValue(size);
return size;
}
- uint64_t getVarInt() {
+ uint64_t readVarInt() {
uint64_t encoded = 0;
uint8_t val = 0;
int shift = 0;
do {
- in_.getByte(val);
+ in_.readByte(val);
uint64_t newbits = (val & 0x7f) << shift;
encoded |= newbits;
shift += 7;
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=830750&r1=830749&r2=830750&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/Serializer.hh (original)
+++ hadoop/avro/trunk/src/c++/api/Serializer.hh Wed Oct 28 20:23:47 2009
@@ -27,7 +27,7 @@
namespace avro {
/// Class that wraps a Writer or ValidatingWriter with an interface that uses
-/// explicit put* names instead of putValue
+/// explicit write* names instead of writeValue
template<class Writer>
class Serializer : private boost::noncopyable
@@ -45,68 +45,68 @@
writer_(schema, out)
{}
- void putNull() {
- writer_.putValue(Null());
+ void writeNull() {
+ writer_.writeValue(Null());
}
- void putBool(bool val) {
- writer_.putValue(val);
+ void writeBool(bool val) {
+ writer_.writeValue(val);
}
- void putInt(int32_t val) {
- writer_.putValue(val);
+ void writeInt(int32_t val) {
+ writer_.writeValue(val);
}
- void putLong(int64_t val) {
- writer_.putValue(val);
+ void writeLong(int64_t val) {
+ writer_.writeValue(val);
}
- void putFloat(float val) {
- writer_.putValue(val);
+ void writeFloat(float val) {
+ writer_.writeValue(val);
}
- void putDouble(double val) {
- writer_.putValue(val);
+ void writeDouble(double val) {
+ writer_.writeValue(val);
}
- void putBytes(const void *val, size_t size) {
- writer_.putBytes(val);
+ void writeBytes(const uint8_t *val, size_t size) {
+ writer_.writeBytes(val);
}
- void putFixed(const uint8_t *val, size_t size) {
- writer_.putFixed(val, size);
+ void writeFixed(const uint8_t *val, size_t size) {
+ writer_.writeFixed(val, size);
}
- void putString(const std::string &val) {
- writer_.putValue(val);
+ void writeString(const std::string &val) {
+ writer_.writeValue(val);
}
- void beginRecord() {
- writer_.beginRecord();
+ void writeRecord() {
+ writer_.writeRecord();
}
- void beginArrayBlock(int64_t size) {
- writer_.beginArrayBlock(size);
+ void writeArrayBlock(int64_t size) {
+ writer_.writeArrayBlock(size);
}
- void endArray() {
- writer_.endArray();
+ void writeArrayEnd() {
+ writer_.writeArrayEnd();
}
- void beginMapBlock(int64_t size) {
- writer_.beginMapBlock(size);
+ void writeMapBlock(int64_t size) {
+ writer_.writeMapBlock(size);
}
- void endMap() {
- writer_.endMap();
+ void writeMapEnd() {
+ writer_.writeMapEnd();
}
- void beginUnion(int64_t choice) {
- writer_.beginUnion(choice);
+ void writeUnion(int64_t choice) {
+ writer_.writeUnion(choice);
}
- void beginEnum(int64_t choice) {
- writer_.beginEnum(choice);
+ void writeEnum(int64_t choice) {
+ writer_.writeEnum(choice);
}
private:
Modified: hadoop/avro/trunk/src/c++/api/ValidatingReader.hh
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/ValidatingReader.hh?rev=830750&r1=830749&r2=830750&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/ValidatingReader.hh (original)
+++ hadoop/avro/trunk/src/c++/api/ValidatingReader.hh Wed Oct 28 20:23:47 2009
@@ -50,58 +50,58 @@
ValidatingReader(const ValidSchema &schema, InputStreamer &in);
template<typename T>
- void getValue(T &val) {
+ void readValue(T &val) {
checkSafeToGet(type_to_avro<T>::type);
- reader_.getValue(val);
+ reader_.readValue(val);
validator_.advance();
}
- void getBytes(std::vector<uint8_t> &val) {
+ void readBytes(std::vector<uint8_t> &val) {
checkSafeToGet(AVRO_BYTES);
validator_.advance();
- reader_.getBytes(val);
+ reader_.readBytes(val);
}
- void getFixed(uint8_t *val, size_t size) {
+ void readFixed(uint8_t *val, size_t size) {
checkSafeToGet(AVRO_FIXED);
checkSizeExpected(size);
validator_.advance();
- reader_.getFixed(val, size);
+ reader_.readFixed(val, size);
}
- void getFixed(std::vector<uint8_t> &val, size_t size) {
+ void readFixed(std::vector<uint8_t> &val, size_t size) {
checkSafeToGet(AVRO_FIXED);
checkSizeExpected(size);
validator_.advance();
- reader_.getFixed(val, size);
+ reader_.readFixed(val, size);
}
- void getRecord();
+ void readRecord();
- int64_t getArrayBlockSize();
+ int64_t readArrayBlockSize();
- int64_t getUnion();
+ int64_t readUnion();
- int64_t getEnum();
+ int64_t readEnum();
- int64_t getMapBlockSize();
+ int64_t readMapBlockSize();
Type nextType() const{
return validator_.nextTypeExpected();
}
- bool getCurrentRecordName(std::string &name) const {
+ bool currentRecordName(std::string &name) const {
return validator_.getCurrentRecordName(name);
}
- bool getNextFieldName(std::string &name) const {
+ bool nextFieldName(std::string &name) const {
return validator_.getNextFieldName(name);
}
private:
- int64_t getCount();
+ int64_t readCount();
void checkSafeToGet(Type type) const {
if(validator_.nextTypeExpected() != type) {
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=830750&r1=830749&r2=830750&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/ValidatingWriter.hh (original)
+++ hadoop/avro/trunk/src/c++/api/ValidatingWriter.hh Wed Oct 28 20:23:47 2009
@@ -42,42 +42,42 @@
ValidatingWriter(const ValidSchema &schema, OutputStreamer &out);
template<typename T>
- void putValue(T val) {
+ void writeValue(T val) {
checkSafeToPut(type_to_avro<T>::type);
- writer_.putValue(val);
+ writer_.writeValue(val);
validator_.advance();
}
- void putValue(const std::string &val) {
+ void writeValue(const std::string &val) {
checkSafeToPut(type_to_avro<std::string>::type);
- writer_.putValue(val);
+ writer_.writeValue(val);
validator_.advance();
}
- void putBytes(const void *val, size_t size);
+ void writeBytes(const uint8_t *val, size_t size);
- void putFixed(const uint8_t *val, size_t size) {
+ void writeFixed(const uint8_t *val, size_t size) {
checkSafeToPut(AVRO_FIXED);
checkSizeExpected(size);
- writer_.putFixed(val, size);
+ writer_.writeFixed(val, size);
validator_.advance();
}
- void beginRecord();
+ void writeRecord();
- void beginArrayBlock(int64_t size);
- void endArray();
+ void writeArrayBlock(int64_t size);
+ void writeArrayEnd();
- void beginMapBlock(int64_t size);
- void endMap();
+ void writeMapBlock(int64_t size);
+ void writeMapEnd();
- void beginUnion(int64_t choice);
+ void writeUnion(int64_t choice);
- void beginEnum(int64_t choice);
+ void writeEnum(int64_t choice);
private:
- void putCount(int64_t count);
+ void writeCount(int64_t count);
void checkSafeToPut(Type type) const {
if(! validator_.typeIsExpected(type)) {
Modified: 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=830750&r1=830749&r2=830750&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/Writer.hh (original)
+++ hadoop/avro/trunk/src/c++/api/Writer.hh Wed Oct 28 20:23:47 2009
@@ -38,82 +38,82 @@
out_(out)
{}
- void putValue(const Null &) {}
+ void writeValue(const Null &) {}
- void putValue(bool val) {
+ void writeValue(bool val) {
int8_t byte = (val != 0);
- out_.putByte(byte);
+ out_.writeByte(byte);
}
- void putValue(int32_t val) {
+ void writeValue(int32_t val) {
boost::array<uint8_t, 5> bytes;
size_t size = encodeInt32(val, bytes);
- out_.putBytes(bytes.data(), size);
+ out_.writeBytes(bytes.data(), size);
}
- void putValue(int64_t val) {
+ void writeValue(int64_t val) {
boost::array<uint8_t, 9> bytes;
size_t size = encodeInt64(val, bytes);
- out_.putBytes(bytes.data(), size);
+ out_.writeBytes(bytes.data(), size);
}
- void putValue(float val) {
+ void writeValue(float val) {
union {
float f;
int32_t i;
} v;
v.f = val;
- out_.putWord(v.i);
+ out_.writeWord(v.i);
}
- void putValue(double val) {
+ void writeValue(double val) {
union {
double d;
int64_t i;
} v;
v.d = val;
- out_.putLongWord(v.i);
+ out_.writeLongWord(v.i);
}
- void putValue(const std::string &val) {
- putBytes(reinterpret_cast<const uint8_t *>(val.c_str()), val.size());
+ void writeValue(const std::string &val) {
+ writeBytes(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 writeBytes(const uint8_t *val, size_t size) {
+ this->writeValue(static_cast<int64_t>(size));
+ out_.writeBytes(val, size);
}
- void putFixed(const uint8_t *val, size_t size) {
- out_.putBytes(val, size);
+ void writeFixed(const uint8_t *val, size_t size) {
+ out_.writeBytes(val, size);
}
- void beginRecord() {}
+ void writeRecord() {}
- void beginArrayBlock(int64_t size) {
- this->putValue(static_cast<int64_t>(size));
+ void writeArrayBlock(int64_t size) {
+ this->writeValue(static_cast<int64_t>(size));
}
- void endArray() {
- out_.putByte(0);
+ void writeArrayEnd() {
+ out_.writeByte(0);
}
- void beginMapBlock(int64_t size) {
- this->putValue(static_cast<int64_t>(size));
+ void writeMapBlock(int64_t size) {
+ this->writeValue(static_cast<int64_t>(size));
}
- void endMap() {
- out_.putByte(0);
+ void writeMapEnd() {
+ out_.writeByte(0);
}
- void beginUnion(int64_t choice) {
- this->putValue(static_cast<int64_t>(choice));
+ void writeUnion(int64_t choice) {
+ this->writeValue(static_cast<int64_t>(choice));
}
- void beginEnum(int64_t choice) {
- this->putValue(static_cast<int64_t>(choice));
+ void writeEnum(int64_t choice) {
+ this->writeValue(static_cast<int64_t>(choice));
}
private:
Added: hadoop/avro/trunk/src/c++/impl/CompilerNode.cc
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/impl/CompilerNode.cc?rev=830750&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c++/impl/CompilerNode.cc (added)
+++ hadoop/avro/trunk/src/c++/impl/CompilerNode.cc Wed Oct 28 20:23:47 2009
@@ -0,0 +1,73 @@
+/**
+ * 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.
+ */
+
+
+#include "CompilerNode.hh"
+#include "NodeImpl.hh"
+
+namespace avro {
+
+NodePtr
+nodeFromCompilerNode(CompilerNode &node)
+{
+ NodePtr ptr;
+
+ switch(node.type()) {
+
+ case AVRO_ARRAY:
+ ptr.reset ( new NodeArray(node.itemsAttribute_));
+ break;
+
+ case AVRO_ENUM:
+ ptr.reset ( new NodeEnum(node.nameAttribute_, node.symbolsAttribute_));
+ break;
+
+ case AVRO_FIXED:
+ ptr.reset ( new NodeFixed(node.nameAttribute_, node.sizeAttribute_));
+ break;
+
+ case AVRO_MAP:
+ ptr.reset ( new NodeMap(node.valuesAttribute_));
+ break;
+
+ case AVRO_RECORD:
+ ptr.reset ( new NodeRecord(node.nameAttribute_, node.fieldsAttribute_,
node.fieldsNamesAttribute_));
+ break;
+
+ case AVRO_UNION:
+ ptr.reset ( new NodeUnion(node.typesAttribute_));
+ break;
+
+ case AVRO_SYMBOLIC:
+ ptr.reset ( new NodeSymbolic(node.nameAttribute_));
+ break;
+
+ default:
+ if(isPrimitive(node.type())) {
+ ptr.reset ( new NodePrimitive(node.type()));
+ }
+ else {
+ throw Exception("Unknown type in nodeFromCompilerNode");
+ }
+ break;
+ }
+
+ return ptr;
+}
+
+} // namespace avro
Modified: hadoop/avro/trunk/src/c++/impl/Node.cc
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/impl/Node.cc?rev=830750&r1=830749&r2=830750&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/impl/Node.cc (original)
+++ hadoop/avro/trunk/src/c++/impl/Node.cc Wed Oct 28 20:23:47 2009
@@ -27,7 +27,7 @@
void
Node::checkName(const std::string &name) const
{
- static const boost::regex exp("[A-Za-z_][A-Za-z0-9_]*");
+ const boost::regex exp("[A-Za-z_][A-Za-z0-9_]*");
if(!name.empty() && !boost::regex_match(name, exp)) {
throw Exception("Names must match [A-Za-z_][A-Za-z0-9_]*");
}
Modified: hadoop/avro/trunk/src/c++/impl/NodeImpl.cc
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/impl/NodeImpl.cc?rev=830750&r1=830749&r2=830750&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/impl/NodeImpl.cc (original)
+++ hadoop/avro/trunk/src/c++/impl/NodeImpl.cc Wed Oct 28 20:23:47 2009
@@ -151,52 +151,4 @@
os << indent(--depth) << '}';
}
-NodePtr
-nodeFromCompilerNode(CompilerNode &node)
-{
- NodePtr ptr;
-
- switch(node.type()) {
-
- case AVRO_ARRAY:
- ptr.reset ( new NodeArray(node));
- break;
-
- case AVRO_ENUM:
- ptr.reset ( new NodeEnum(node));
- break;
-
- case AVRO_FIXED:
- ptr.reset ( new NodeFixed(node));
- break;
-
- case AVRO_MAP:
- ptr.reset ( new NodeMap(node));
- break;
-
- case AVRO_RECORD:
- ptr.reset ( new NodeRecord(node));
- break;
-
- case AVRO_UNION:
- ptr.reset ( new NodeUnion(node));
- break;
-
- case AVRO_SYMBOLIC:
- ptr.reset ( new NodeSymbolic(node));
- break;
-
- default:
- if(isPrimitive(node.type())) {
- ptr.reset ( new NodePrimitive(node.type()));
- }
- else {
- throw Exception("Unknown type in nodeFromCompilerNode");
- }
- break;
- }
-
- return ptr;
-}
-
} // namespace avro
Modified: hadoop/avro/trunk/src/c++/impl/ValidatingReader.cc
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/impl/ValidatingReader.cc?rev=830750&r1=830749&r2=830750&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/impl/ValidatingReader.cc (original)
+++ hadoop/avro/trunk/src/c++/impl/ValidatingReader.cc Wed Oct 28 20:23:47 2009
@@ -30,52 +30,52 @@
{ }
int64_t
-ValidatingReader::getCount()
+ValidatingReader::readCount()
{
checkSafeToGet(AVRO_LONG);
int64_t val;
- reader_.getValue(val);
+ reader_.readValue(val);
validator_.advanceWithCount(val);
return val;
}
void
-ValidatingReader::getRecord()
+ValidatingReader::readRecord()
{
checkSafeToGet(AVRO_RECORD);
validator_.advance();
}
int64_t
-ValidatingReader::getUnion()
+ValidatingReader::readUnion()
{
checkSafeToGet(AVRO_UNION);
validator_.advance();
- return getCount();
+ return readCount();
}
int64_t
-ValidatingReader::getEnum()
+ValidatingReader::readEnum()
{
checkSafeToGet(AVRO_ENUM);
validator_.advance();
- return getCount();
+ return readCount();
}
int64_t
-ValidatingReader::getMapBlockSize()
+ValidatingReader::readMapBlockSize()
{
checkSafeToGet(AVRO_MAP);
validator_.advance();
- return getCount();
+ return readCount();
}
int64_t
-ValidatingReader::getArrayBlockSize()
+ValidatingReader::readArrayBlockSize()
{
checkSafeToGet(AVRO_ARRAY);
validator_.advance();
- return getCount();
+ return readCount();
}
} // namespace avro
Modified: 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=830750&r1=830749&r2=830750&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/impl/ValidatingWriter.cc (original)
+++ hadoop/avro/trunk/src/c++/impl/ValidatingWriter.cc Wed Oct 28 20:23:47 2009
@@ -31,70 +31,70 @@
{ }
void
-ValidatingWriter::putBytes(const void *val, size_t size)
+ValidatingWriter::writeBytes(const uint8_t *val, size_t size)
{
checkSafeToPut(AVRO_BYTES);
- writer_.putBytes(val, size);
+ writer_.writeBytes(val, size);
validator_.advance();
}
void
-ValidatingWriter::putCount(int64_t count)
+ValidatingWriter::writeCount(int64_t count)
{
checkSafeToPut(AVRO_LONG);
- writer_.putValue(count);
+ writer_.writeValue(count);
validator_.advanceWithCount(count);
}
void
-ValidatingWriter::beginRecord()
+ValidatingWriter::writeRecord()
{
checkSafeToPut(AVRO_RECORD);
validator_.advance();
}
void
-ValidatingWriter::beginArrayBlock(int64_t size)
+ValidatingWriter::writeArrayBlock(int64_t size)
{
checkSafeToPut(AVRO_ARRAY);
validator_.advance();
- putCount(size);
+ writeCount(size);
}
void
-ValidatingWriter::endArray()
+ValidatingWriter::writeArrayEnd()
{
- beginArrayBlock(0);
+ writeArrayBlock(0);
}
void
-ValidatingWriter::beginMapBlock(int64_t size)
+ValidatingWriter::writeMapBlock(int64_t size)
{
checkSafeToPut(AVRO_MAP);
validator_.advance();
- putCount(size);
+ writeCount(size);
}
void
-ValidatingWriter::endMap()
+ValidatingWriter::writeMapEnd()
{
- beginMapBlock(0);
+ writeMapBlock(0);
}
void
-ValidatingWriter::beginUnion(int64_t choice)
+ValidatingWriter::writeUnion(int64_t choice)
{
checkSafeToPut(AVRO_UNION);
validator_.advance();
- putCount(choice);
+ writeCount(choice);
}
void
-ValidatingWriter::beginEnum(int64_t choice)
+ValidatingWriter::writeEnum(int64_t choice)
{
checkSafeToPut(AVRO_ENUM);
validator_.advance();
- putCount(choice);
+ writeCount(choice);
}
Modified: hadoop/avro/trunk/src/c++/scripts/gen-cppcode.py
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/scripts/gen-cppcode.py?rev=830750&r1=830749&r2=830750&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/scripts/gen-cppcode.py (original)
+++ hadoop/avro/trunk/src/c++/scripts/gen-cppcode.py Wed Oct 28 20:23:47 2009
@@ -60,13 +60,13 @@
template <typename Serializer>
void serialize(Serializer &s, const $name$ &val, const boost::true_type &) {
- s.beginRecord();
+ s.writeRecord();
$serializefields$
}
template <typename Parser>
void parse(Parser &p, $name$ &val, const boost::true_type &) {
- p.getRecord();
+ p.readRecord();
$parsefields$
}
'''
@@ -121,7 +121,7 @@
template <typename Serializer>
void serialize(Serializer &s, const $name$ &val, const boost::true_type &) {
- s.beginUnion(val.choice);
+ s.writeUnion(val.choice);
switch(val.choice) {
$switchserialize$
default :
@@ -131,7 +131,7 @@
template <typename Parser>
void parse(Parser &p, $name$ &val, const boost::true_type &) {
- val.choice = p.getUnion();
+ val.choice = p.readUnion();
switch(val.choice) {
$switchparse$
default :
@@ -196,12 +196,12 @@
template <typename Serializer>
void serialize(Serializer &s, const $name$ &val, const boost::true_type &) {
- s.beginEnum(val.value);
+ s.writeEnum(val.value);
}
template <typename Parser>
void parse(Parser &p, $name$ &val, const boost::true_type &) {
- val.value = static_cast<$name$::EnumSymbols>(p.getEnum());
+ val.value = static_cast<$name$::EnumSymbols>(p.readEnum());
}
'''
@@ -237,19 +237,19 @@
void serialize(Serializer &s, const $name$ &val, const boost::true_type &) {
const size_t size = val.value.size();
if(size) {
- s.beginArrayBlock(size);
+ s.writeArrayBlock(size);
for(size_t i = 0; i < size; ++i) {
serialize(s, val.value[i]);
}
}
- s.endArray();
+ s.writeArrayEnd();
}
template <typename Parser>
void parse(Parser &p, $name$ &val, const boost::true_type &) {
val.value.clear();
while(1) {
- int size = p.getArrayBlockSize();
+ int size = p.readArrayBlockSize();
if(size > 0) {
val.value.reserve(val.value.size() + size);
while (size-- > 0) {
@@ -293,7 +293,7 @@
template <typename Serializer>
void serialize(Serializer &s, const $name$ &val, const boost::true_type &) {
if(val.value.size()) {
- s.beginMapBlock(val.value.size());
+ s.writeMapBlock(val.value.size());
$name$::MapType::const_iterator iter = val.value.begin();
$name$::MapType::const_iterator end = val.value.end();
while(iter!=end) {
@@ -302,14 +302,14 @@
++iter;
}
}
- s.endMap();
+ s.writeMapEnd();
}
template <typename Parser>
void parse(Parser &p, $name$ &val, const boost::true_type &) {
val.value.clear();
while(1) {
- int size = p.getMapBlockSize();
+ int size = p.readMapBlockSize();
if(size > 0) {
while (size-- > 0) {
std::string key;
@@ -350,12 +350,12 @@
template <typename Serializer>
void serialize(Serializer &s, const $name$ &val, const boost::true_type &) {
- s.putFixed(val.value, $name$::fixedSize);
+ s.writeFixed(val.value, $name$::fixedSize);
}
template <typename Parser>
void parse(Parser &p, $name$ &val, const boost::true_type &) {
- p.getFixed(val.value, $name$::fixedSize);
+ p.readFixed(val.value, $name$::fixedSize);
}
'''
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=830750&r1=830749&r2=830750&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/test/unittest.cc (original)
+++ hadoop/avro/trunk/src/c++/test/unittest.cc Wed Oct 28 20:23:47 2009
@@ -82,26 +82,26 @@
template<typename Serializer>
void printUnion(Serializer &s, int path)
{
- s.beginUnion(path);
+ s.writeUnion(path);
if(path == 0) {
std::cout << "Null in union\n";
- s.putNull();
+ s.writeNull();
}
else if(path == 1) {
std::cout << "Map in union\n";
- s.beginMapBlock(2);
- s.putString("Foo");
- s.putInt(16);
- s.putString("Bar");
- s.putInt(17);
- s.beginMapBlock(1);
- s.putString("FooBar");
- s.putInt(18);
- s.endMap();
+ s.writeMapBlock(2);
+ s.writeString("Foo");
+ s.writeInt(16);
+ s.writeString("Bar");
+ s.writeInt(17);
+ s.writeMapBlock(1);
+ s.writeString("FooBar");
+ s.writeInt(18);
+ s.writeMapEnd();
}
else {
std::cout << "Float in union\n";
- s.putFloat(200.);
+ s.writeFloat(200.);
}
}
@@ -109,38 +109,38 @@
void writeEncoding(Serializer &s, int path)
{
std::cout << "Record\n";
- s.beginRecord();
- s.putInt(1000);
+ s.writeRecord();
+ s.writeInt(1000);
std::cout << "Map\n";
- s.beginMapBlock(2);
- s.putString(std::string("Foo"));
- s.putInt(16);
- s.putString(std::string("Bar"));
- s.putInt(17);
- s.endMap();
+ s.writeMapBlock(2);
+ s.writeString(std::string("Foo"));
+ s.writeInt(16);
+ s.writeString(std::string("Bar"));
+ s.writeInt(17);
+ s.writeMapEnd();
std::cout << "Array\n";
- s.beginArrayBlock(2);
- s.putDouble(100.0);
- s.putDouble(1000.0);
- s.endArray();
+ s.writeArrayBlock(2);
+ s.writeDouble(100.0);
+ s.writeDouble(1000.0);
+ s.writeArrayEnd();
std::cout << "Enum\n";
- s.beginEnum(3);
+ s.writeEnum(3);
std::cout << "Union\n";
printUnion(s, path);
std::cout << "Bool\n";
- s.putBool(true);
+ s.writeBool(true);
std::cout << "Fixed16\n";
- s.putFixed(fixeddata, 16);
+ s.writeFixed(fixeddata, 16);
std::cout << "Int\n";
- s.putInt(-3456);
+ s.writeInt(-3456);
}
void printEncoding() {
@@ -175,10 +175,10 @@
std::cout << "Next: \"" << nextType(p);
std::string recordName;
std::string fieldName;
- if( getCurrentRecordName(p, recordName) ) {
+ if( currentRecordName(p, recordName) ) {
std::cout << "\" record: \"" << recordName;
}
- if( getNextFieldName(p, fieldName) ) {
+ if( nextFieldName(p, fieldName) ) {
std::cout << "\" field: \"" << fieldName;
}
std::cout << "\"\n";
@@ -191,14 +191,14 @@
int64_t size = 0;
do {
printNext(p);
- size = p.getMapBlockSize();
+ size = p.readMapBlockSize();
std::cout << "Size " << size << '\n';
for(int32_t i=0; i < size; ++i) {
std::string key;
printNext(p);
- p.getString(key);
+ p.readString(key);
printNext(p);
- int32_t intval = p.getInt();
+ int32_t intval = p.readInt();
std::cout << key << ":" << intval << '\n';
}
} while (size != 0);
@@ -211,11 +211,11 @@
double d = 0.0;
do {
printNext(p);
- size = p.getArrayBlockSize();
+ size = p.readArrayBlockSize();
std::cout << "Size " << size << '\n';
for(int32_t i=0; i < size; ++i) {
printNext(p);
- d = p.getDouble();
+ d = p.readDouble();
std::cout << i << ":" << d << '\n';
}
} while(size != 0);
@@ -226,7 +226,7 @@
void readFixed(Parser &p) {
std::vector<uint8_t> input;
- p.getFixed(input, 16);
+ p.readFixed(input, 16);
for(int i=0; i< 16; ++i) {
std::cout << static_cast<int>(input[i]) << ' ';
@@ -238,10 +238,10 @@
void readData(Parser &p)
{
printNext(p);
- p.getRecord();
+ p.readRecord();
printNext(p);
- int64_t longval = p.getLong();
+ int64_t longval = p.readLong();
std::cout << longval << '\n';
BOOST_CHECK_EQUAL(longval, 1000);
@@ -249,16 +249,16 @@
readArray(p);
printNext(p);
- longval = p.getEnum();
+ longval = p.readEnum();
std::cout << "Enum choice " << longval << '\n';
printNext(p);
- longval = p.getUnion();
+ longval = p.readUnion();
std::cout << "Union path " << longval << '\n';
readMap(p);
printNext(p);
- bool boolval = p.getBool();
+ bool boolval = p.readBool();
std::cout << boolval << '\n';
BOOST_CHECK_EQUAL(boolval, true);
@@ -266,7 +266,7 @@
readFixed(p);
printNext(p);
- int32_t intval = p.getInt();
+ int32_t intval = p.readInt();
std::cout << intval << '\n';
BOOST_CHECK_EQUAL(intval, -3456);
}
@@ -400,32 +400,32 @@
{
std::cout << "No recurse\n";
Serializer<ValidatingWriter> s(schema_, os);
- s.beginRecord();
- s.putLong(1);
- s.beginUnion(0);
- s.putNull();
- s.putBool(true);
+ s.writeRecord();
+ s.writeLong(1);
+ s.writeUnion(0);
+ s.writeNull();
+ s.writeBool(true);
}
void serializeRecurse(OutputStreamer &os)
{
std::cout << "Recurse\n";
Serializer<ValidatingWriter> s(schema_, os);
- s.beginRecord();
- s.putLong(1);
- s.beginUnion(1);
+ s.writeRecord();
+ s.writeLong(1);
+ s.writeUnion(1);
{
- s.beginRecord();
- s.putLong(2);
- s.beginUnion(1);
+ s.writeRecord();
+ s.writeLong(2);
+ s.writeUnion(1);
{
- s.beginRecord();
- s.putLong(3);
- s.beginUnion(0);
+ s.writeRecord();
+ s.writeLong(3);
+ s.writeUnion(0);
}
- s.putNull();
+ s.writeNull();
}
- s.putBool(true);
+ s.writeBool(true);
}
void validatingParser(InputStreamer &is)
@@ -435,14 +435,14 @@
int64_t path = 0;
do {
- p.getRecord();
- val = p.getLong();
+ p.readRecord();
+ val = p.readLong();
std::cout << "longval = " << val << '\n';
- path = p.getUnion();
+ path = p.readUnion();
} while(path == 1);
- p.getNull();
- bool b = p.getBool();
+ p.readNull();
+ bool b = p.readBool();
std::cout << "bval = " << b << '\n';
}