Author: sbanacho
Date: Wed Nov 25 05:08:20 2009
New Revision: 883978
URL: http://svn.apache.org/viewvc?rev=883978&view=rev
Log:
AVRO-234. C++ code cleanup.
Added:
hadoop/avro/trunk/src/c++/api/Layout.hh
hadoop/avro/trunk/src/c++/api/Resolver.hh
- copied, changed from r883976,
hadoop/avro/trunk/src/c++/api/Instruction.hh
hadoop/avro/trunk/src/c++/api/ResolverSchema.hh
hadoop/avro/trunk/src/c++/api/ResolvingReader.hh
hadoop/avro/trunk/src/c++/impl/Resolver.cc
- copied, changed from r883976,
hadoop/avro/trunk/src/c++/impl/Instruction.cc
hadoop/avro/trunk/src/c++/impl/ResolverSchema.cc
Removed:
hadoop/avro/trunk/src/c++/api/Instruction.hh
hadoop/avro/trunk/src/c++/impl/Instruction.cc
Modified:
hadoop/avro/trunk/CHANGES.txt
hadoop/avro/trunk/src/c++/MainPage.dox
hadoop/avro/trunk/src/c++/README.txt
hadoop/avro/trunk/src/c++/api/AvroParse.hh
hadoop/avro/trunk/src/c++/api/Boost.hh
hadoop/avro/trunk/src/c++/impl/NodeImpl.cc
hadoop/avro/trunk/src/c++/scripts/gen-cppcode.py
hadoop/avro/trunk/src/c++/test/testgen.cc
Modified: hadoop/avro/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/CHANGES.txt?rev=883978&r1=883977&r2=883978&view=diff
==============================================================================
--- hadoop/avro/trunk/CHANGES.txt (original)
+++ hadoop/avro/trunk/CHANGES.txt Wed Nov 25 05:08:20 2009
@@ -104,6 +104,8 @@
AVRO-233. Elaborate Java tool API. (Philip Zeyliger via cutting)
AVRO-236. Add protocol support to avroj induce tool. (cutting)
+
+ AVRO-234. C++ code cleanup. (sbanacho)
OPTIMIZATIONS
Modified: hadoop/avro/trunk/src/c++/MainPage.dox
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/MainPage.dox?rev=883978&r1=883977&r2=883978&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/MainPage.dox (original)
+++ hadoop/avro/trunk/src/c++/MainPage.dox Wed Nov 25 05:08:20 2009
@@ -335,9 +335,9 @@
may be used to read the data, even if the data was written with a
different schema.</P>
<P>In example.hh, this indexing structure looks like:</P>
-<PRE>class complex_Offsets : public avro::CompoundOffset {
+<PRE>class complex_Layout : public avro::CompoundOffset {
public:
- complex_Offsets(size_t offset) :
+ complex_Layout(size_t offset) :
CompoundOffset(offset)
{
add(new avro::Offset(offset + offsetof(complex, real)));
@@ -353,24 +353,23 @@
<PRE>void dynamicCast(const avro::ValidSchema &writerSchema,
const avro::ValidSchema &readerSchema) {
- // Instantiate the Offsets object
- avro::OffsetPtr offsets (new Math::complex_Offsets(0));
+ // Instantiate the Layout object
+ Math::complex_Layout layout;
- // Create a dynamic parser that is aware of my type's layout, and both
schemas
- avro::DynamicParser dynamicParser =
- avro::buildDynamicParser(writerSchema, readerSchema, offsets);
+ // Create a schema parser that is aware of my type's layout, and both
schemas
+ avro::ResolverSchema resolverSchema(writerSchema, readerSchema, layout);
// Setup the reader
std::istringstream is(data);
avro::IStreamer istreamer(is);
- avro::ValidatingReader r(writerSchema_, is);
+ avro::ResolvingReader reader(resolverSchema, is);
Math::complex c;
// Do the parse
- dynamicParser->parse(r, reinterpret_cast<uint8_t *>(&c));
+ avro::parse(reader, c);
- // At this point, the ostringstream âosâ stores the serialized data!
+ // At this point, c is populated with the deserialized data!
}
</PRE>
Modified: hadoop/avro/trunk/src/c++/README.txt
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/README.txt?rev=883978&r1=883977&r2=883978&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/README.txt (original)
+++ hadoop/avro/trunk/src/c++/README.txt Wed Nov 25 05:08:20 2009
@@ -23,9 +23,8 @@
objects of the same data types, and the code to serialize and parse
it.
-What's missing: Defaults are not yet supported. Resolving schema
-conflicts is not yet supported. And the file and rpc containers are
-not yet implemented. Documentation, sparse.
+What's missing: Defaults are not yet supported. And the file and rpc
+containers are not yet implemented. Documentation, sparse.
INSTRUCTIONS
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=883978&r1=883977&r2=883978&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/AvroParse.hh (original)
+++ hadoop/avro/trunk/src/c++/api/AvroParse.hh Wed Nov 25 05:08:20 2009
@@ -21,6 +21,7 @@
#include <boost/static_assert.hpp>
#include "AvroTraits.hh"
+#include "ResolvingReader.hh"
/// \file
///
@@ -37,6 +38,12 @@
parse(p, val, is_serializable<T>());
}
+template <typename T>
+void parse(ResolvingReader &p, T& val)
+{
+ translatingParse(p, val, is_serializable<T>());
+}
+
/// Type trait should be set to is_serializable in otherwise force the
compiler to complain.
template <typename Reader, typename T>
@@ -45,10 +52,17 @@
BOOST_STATIC_ASSERT(sizeof(T)==0);
}
-/// The remainder of the file includes default implementations for
serializable types.
+template <typename Reader, typename T>
+void translatingParse(Reader &p, T& val, const boost::false_type &)
+{
+ BOOST_STATIC_ASSERT(sizeof(T)==0);
+}
// @{
+/// The remainder of the file includes default implementations for
serializable types.
+
+
template <typename Reader, typename T>
void parse(Reader &p, T &val, const boost::true_type &) {
p.readValue(val);
@@ -59,6 +73,11 @@
p.readBytes(val);
}
+template<typename T>
+void translatingParse(ResolvingReader &p, T& val, const boost::true_type &) {
+ p.parse(val);
+}
+
// @}
} // namespace avro
Modified: hadoop/avro/trunk/src/c++/api/Boost.hh
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/Boost.hh?rev=883978&r1=883977&r2=883978&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/Boost.hh (original)
+++ hadoop/avro/trunk/src/c++/api/Boost.hh Wed Nov 25 05:08:20 2009
@@ -99,6 +99,9 @@
size_t size() const {
return ptrs_.size();
}
+ void reserve(size_t elems) {
+ ptrs_.reserve(elems);
+ }
private:
std::vector<T *> ptrs_;
};
Added: hadoop/avro/trunk/src/c++/api/Layout.hh
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/Layout.hh?rev=883978&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c++/api/Layout.hh (added)
+++ hadoop/avro/trunk/src/c++/api/Layout.hh Wed Nov 25 05:08:20 2009
@@ -0,0 +1,84 @@
+
+/**
+ * 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_Layout_hh__
+#define avro_Layout_hh__
+
+#include <boost/noncopyable.hpp>
+#include "Boost.hh"
+
+/// \file Layout.hh
+///
+
+namespace avro {
+
+class Layout : private boost::noncopyable {
+
+ protected:
+
+ Layout(size_t offset = 0) :
+ offset_(offset)
+ {}
+
+ public:
+
+ size_t offset() const {
+ return offset_;
+ }
+
+ virtual ~Layout() {}
+
+ private:
+
+ const size_t offset_;
+};
+
+class PrimitiveLayout : public Layout {
+
+ public:
+
+ PrimitiveLayout(size_t offset = 0) :
+ Layout(offset)
+ {}
+};
+
+class CompoundLayout : public Layout {
+
+ public:
+
+ CompoundLayout(size_t offset = 0) :
+ Layout(offset)
+ {}
+
+ void add(Layout *layout) {
+ layouts_.push_back(layout);
+ }
+
+ const Layout &at (size_t idx) const {
+ return layouts_.at(idx);
+ }
+
+ private:
+
+ boost::ptr_vector<Layout> layouts_;
+};
+
+} // namespace avro
+
+#endif
Copied: hadoop/avro/trunk/src/c++/api/Resolver.hh (from r883976,
hadoop/avro/trunk/src/c++/api/Instruction.hh)
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/Resolver.hh?p2=hadoop/avro/trunk/src/c%2B%2B/api/Resolver.hh&p1=hadoop/avro/trunk/src/c%2B%2B/api/Instruction.hh&r1=883976&r2=883978&rev=883978&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/Instruction.hh (original)
+++ hadoop/avro/trunk/src/c++/api/Resolver.hh Wed Nov 25 05:08:20 2009
@@ -17,77 +17,38 @@
* limitations under the License.
*/
-#ifndef avro_Instruction_hh__
-#define avro_Instruction_hh__
+#ifndef avro_Resolver_hh__
+#define avro_Resolver_hh__
#include <boost/noncopyable.hpp>
-#include <boost/shared_ptr.hpp>
#include <stdint.h>
-#include "Boost.hh"
-/// \file Instruction.hh
+/// \file Resolver.hh
///
namespace avro {
-
-class ValidatingReader;
-class ValidSchema;
-
-class Offset : public boost::noncopyable {
-
- public:
-
- Offset(size_t offset) :
- offset_(offset)
- {}
-
- virtual ~Offset() {}
-
- size_t offset() const {
- return offset_;
- }
-
- private:
-
- const size_t offset_;
-};
-class CompoundOffset : public Offset {
+class Reader;
+class ValidSchema;
+class Layout;
+
+class Resolver : private boost::noncopyable
+{
public:
- CompoundOffset(size_t offset) :
- Offset(offset)
- {}
-
- void add(Offset * setter) {
- setters_.push_back(setter);
- }
-
- const Offset &at (size_t idx) const {
- return setters_.at(idx);
- }
+ virtual void parse(Reader &reader, uint8_t *address) const = 0;
+ virtual ~Resolver() {}
- private:
-
- typedef boost::ptr_vector<Offset> Offsets;
- Offsets setters_;
};
-typedef boost::shared_ptr<Offset> OffsetPtr;
-
-class Instruction
-{
-
- public:
+Resolver *constructResolver(
+ const ValidSchema &rwriterSchema,
+ const ValidSchema &readerSchema,
+ const Layout &readerLayout
+ );
- virtual void parse(ValidatingReader &reader, uint8_t *address) const = 0;
- virtual ~Instruction() {}
-
-};
-typedef boost::shared_ptr<Instruction> DynamicParser;
-DynamicParser buildDynamicParser(const ValidSchema &writer, const ValidSchema
&reader, const OffsetPtr &offset);
} // namespace avro
Added: hadoop/avro/trunk/src/c++/api/ResolverSchema.hh
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/ResolverSchema.hh?rev=883978&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c++/api/ResolverSchema.hh (added)
+++ hadoop/avro/trunk/src/c++/api/ResolverSchema.hh Wed Nov 25 05:08:20 2009
@@ -0,0 +1,56 @@
+
+/**
+ * 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_ResolverSchema_hh__
+#define avro_ResolverSchema_hh__
+
+#include <boost/noncopyable.hpp>
+#include <boost/shared_ptr.hpp>
+#include <stdint.h>
+#include "Boost.hh"
+
+/// \file ResolverSchema.hh
+///
+
+namespace avro {
+
+class ValidSchema;
+class Reader;
+class Layout;
+class Resolver;
+
+class ResolverSchema {
+
+ public:
+
+ ResolverSchema(const ValidSchema &writer, const ValidSchema &reader, const
Layout &readerLayout);
+
+ private:
+
+ friend class ResolvingReader;
+
+ void parse(Reader &reader, uint8_t *address);
+
+ boost::shared_ptr<Resolver> resolver_;
+
+};
+
+} // namespace avro
+
+#endif
Added: hadoop/avro/trunk/src/c++/api/ResolvingReader.hh
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/ResolvingReader.hh?rev=883978&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c++/api/ResolvingReader.hh (added)
+++ hadoop/avro/trunk/src/c++/api/ResolvingReader.hh Wed Nov 25 05:08:20 2009
@@ -0,0 +1,56 @@
+
+/**
+ * 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_ResolvingReader_hh__
+#define avro_ResolvingReader_hh__
+
+#include <stdint.h>
+#include <boost/noncopyable.hpp>
+
+#include "ResolverSchema.hh"
+#include "Reader.hh"
+
+namespace avro {
+
+class InputStreamer;
+
+class ResolvingReader : private boost::noncopyable
+{
+
+ public:
+
+ ResolvingReader(const ResolverSchema &schema, InputStreamer &in) :
+ reader_(in),
+ schema_(schema)
+ {}
+
+ template<typename T>
+ void parse(T &object) {
+ schema_.parse(reader_, reinterpret_cast<uint8_t *>(&object));
+ }
+
+ private:
+
+ Reader reader_;
+ ResolverSchema schema_;
+};
+
+} // namespace avro
+
+#endif
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=883978&r1=883977&r2=883978&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/impl/NodeImpl.cc (original)
+++ hadoop/avro/trunk/src/c++/impl/NodeImpl.cc Wed Nov 25 05:08:20 2009
@@ -273,7 +273,7 @@
os << "{\n";
os << indent(depth+1) << "\"type\": \"array\",\n";
os << indent(depth+1) << "\"items\": ";
- leafAttributes_.get()->printJson(os, depth);
+ leafAttributes_.get()->printJson(os, depth+1);
os << '\n';
os << indent(depth) << '}';
}
@@ -284,7 +284,7 @@
os << "{\n";
os << indent(depth+1) <<"\"type\": \"map\",\n";
os << indent(depth+1) << "\"values\": ";
- leafAttributes_.get(1)->printJson(os, depth);
+ leafAttributes_.get(1)->printJson(os, depth+1);
os << '\n';
os << indent(depth) << '}';
}
Copied: hadoop/avro/trunk/src/c++/impl/Resolver.cc (from r883976,
hadoop/avro/trunk/src/c++/impl/Instruction.cc)
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/impl/Resolver.cc?p2=hadoop/avro/trunk/src/c%2B%2B/impl/Resolver.cc&p1=hadoop/avro/trunk/src/c%2B%2B/impl/Instruction.cc&r1=883976&r2=883978&rev=883978&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/impl/Instruction.cc (original)
+++ hadoop/avro/trunk/src/c++/impl/Resolver.cc Wed Nov 25 05:08:20 2009
@@ -17,17 +17,19 @@
* limitations under the License.
*/
-#include "Instruction.hh"
+#include "Resolver.hh"
+#include "Layout.hh"
#include "NodeImpl.hh"
#include "ValidSchema.hh"
-#include "ValidatingReader.hh"
+#include "Reader.hh"
#include "Boost.hh"
+#include "AvroTraits.hh"
namespace avro {
-class DynamicBuilder;
-typedef boost::shared_ptr<Instruction> InstructionPtr;
-typedef boost::ptr_vector<Instruction> InstructionPtrVector;
+class ResolverFactory;
+typedef boost::shared_ptr<Resolver> ResolverPtr;
+typedef boost::ptr_vector<Resolver> ResolverPtrVector;
// #define DEBUG_VERBOSE
@@ -43,15 +45,15 @@
#endif
template<typename T>
-class PrimitiveSkipper : public Instruction
+class PrimitiveSkipper : public Resolver
{
public:
PrimitiveSkipper() :
- Instruction()
+ Resolver()
{}
- virtual void parse(ValidatingReader &reader, uint8_t *address) const
+ virtual void parse(Reader &reader, uint8_t *address) const
{
T val;
reader.readValue(val);
@@ -60,16 +62,16 @@
};
template<typename T>
-class PrimitiveParser : public Instruction
+class PrimitiveParser : public Resolver
{
public:
- PrimitiveParser(const Offset &offset) :
- Instruction(),
+ PrimitiveParser(const PrimitiveLayout &offset) :
+ Resolver(),
offset_(offset.offset())
{}
- virtual void parse(ValidatingReader &reader, uint8_t *address) const
+ virtual void parse(Reader &reader, uint8_t *address) const
{
T* location = reinterpret_cast<T *> (address + offset_);
reader.readValue(*location);
@@ -82,23 +84,23 @@
};
template<typename WT, typename RT>
-class PrimitivePromoter : public Instruction
+class PrimitivePromoter : public Resolver
{
public:
- PrimitivePromoter(const Offset &offset) :
- Instruction(),
+ PrimitivePromoter(const PrimitiveLayout &offset) :
+ Resolver(),
offset_(offset.offset())
{}
- virtual void parse(ValidatingReader &reader, uint8_t *address) const
+ virtual void parse(Reader &reader, uint8_t *address) const
{
parseIt<WT>(reader, address);
}
private:
- void parseIt(ValidatingReader &reader, uint8_t *address, const
boost::true_type &) const
+ void parseIt(Reader &reader, uint8_t *address, const boost::true_type &)
const
{
WT val;
reader.readValue(val);
@@ -107,11 +109,11 @@
DEBUG_OUT("Promoting " << val);
}
- void parseIt(ValidatingReader &reader, uint8_t *address, const
boost::false_type &) const
+ void parseIt(Reader &reader, uint8_t *address, const boost::false_type &)
const
{ }
template<typename T>
- void parseIt(ValidatingReader &reader, uint8_t *address) const
+ void parseIt(Reader &reader, uint8_t *address) const
{
parseIt(reader, address, is_promotable<T>());
}
@@ -120,15 +122,15 @@
};
template <>
-class PrimitiveSkipper<std::vector<uint8_t> > : public Instruction
+class PrimitiveSkipper<std::vector<uint8_t> > : public Resolver
{
public:
PrimitiveSkipper() :
- Instruction()
+ Resolver()
{}
- virtual void parse(ValidatingReader &reader, uint8_t *address) const
+ virtual void parse(Reader &reader, uint8_t *address) const
{
std::vector<uint8_t> val;
reader.readBytes(val);
@@ -137,16 +139,16 @@
};
template <>
-class PrimitiveParser<std::vector<uint8_t> > : public Instruction
+class PrimitiveParser<std::vector<uint8_t> > : public Resolver
{
public:
- PrimitiveParser(const Offset &offset) :
- Instruction(),
+ PrimitiveParser(const PrimitiveLayout &offset) :
+ Resolver(),
offset_(offset.offset())
{}
- virtual void parse(ValidatingReader &reader, uint8_t *address) const
+ virtual void parse(Reader &reader, uint8_t *address) const
{
std::vector<uint8_t> *location = reinterpret_cast<std::vector<uint8_t>
*> (address + offset_);
reader.readBytes(*location);
@@ -158,60 +160,60 @@
size_t offset_;
};
-class RecordSkipper : public Instruction
+class RecordSkipper : public Resolver
{
public:
- RecordSkipper(DynamicBuilder &builder, const NodePtr &writer);
+ RecordSkipper(ResolverFactory &factory, const NodePtr &writer);
- virtual void parse(ValidatingReader &reader, uint8_t *address) const
+ virtual void parse(Reader &reader, uint8_t *address) const
{
DEBUG_OUT("Skipping record");
reader.readRecord();
- size_t steps = instructions_.size();
+ size_t steps = resolvers_.size();
for(size_t i = 0; i < steps; ++i) {
- instructions_[i].parse(reader, address);
+ resolvers_[i].parse(reader, address);
}
}
protected:
- InstructionPtrVector instructions_;
+ ResolverPtrVector resolvers_;
};
-class RecordParser : public Instruction
+class RecordParser : public Resolver
{
public:
- virtual void parse(ValidatingReader &reader, uint8_t *address) const
+ virtual void parse(Reader &reader, uint8_t *address) const
{
DEBUG_OUT("Reading record");
reader.readRecord();
- size_t steps = instructions_.size();
+ size_t steps = resolvers_.size();
for(size_t i = 0; i < steps; ++i) {
- instructions_[i].parse(reader, address);
+ resolvers_[i].parse(reader, address);
}
}
- RecordParser(DynamicBuilder &builder, const NodePtr &writer, const NodePtr
&reader, const CompoundOffset &offsets);
+ RecordParser(ResolverFactory &factory, const NodePtr &writer, const
NodePtr &reader, const CompoundLayout &offsets);
protected:
- InstructionPtrVector instructions_;
+ ResolverPtrVector resolvers_;
};
-class MapSkipper : public Instruction
+class MapSkipper : public Resolver
{
public:
- MapSkipper(DynamicBuilder &builder, const NodePtr &writer);
+ MapSkipper(ResolverFactory &factory, const NodePtr &writer);
- virtual void parse(ValidatingReader &reader, uint8_t *address) const
+ virtual void parse(Reader &reader, uint8_t *address) const
{
DEBUG_OUT("Skipping map");
@@ -221,26 +223,26 @@
size = reader.readMapBlockSize();
for(int64_t i = 0; i < size; ++i) {
reader.readValue(key);
- instruction_->parse(reader, address);
+ resolver_->parse(reader, address);
}
} while (size != 0);
}
protected:
- InstructionPtr instruction_;
+ ResolverPtr resolver_;
};
-class MapParser : public Instruction
+class MapParser : public Resolver
{
public:
typedef uint8_t *(*GenericMapSetter)(uint8_t *map, const std::string &key);
- MapParser(DynamicBuilder &builder, const NodePtr &writer, const NodePtr
&reader, const CompoundOffset &offsets);
+ MapParser(ResolverFactory &factory, const NodePtr &writer, const NodePtr
&reader, const CompoundLayout &offsets);
- virtual void parse(ValidatingReader &reader, uint8_t *address) const
+ virtual void parse(Reader &reader, uint8_t *address) const
{
DEBUG_OUT("Reading map");
@@ -257,25 +259,25 @@
// create a new map entry and get the address
uint8_t *location = (*setter)(mapAddress, key);
- instruction_->parse(reader, location);
+ resolver_->parse(reader, location);
}
} while (size != 0);
}
protected:
- InstructionPtr instruction_;
+ ResolverPtr resolver_;
size_t offset_;
size_t setFuncOffset_;
};
-class ArraySkipper : public Instruction
+class ArraySkipper : public Resolver
{
public:
- ArraySkipper(DynamicBuilder &builder, const NodePtr &writer);
+ ArraySkipper(ResolverFactory &factory, const NodePtr &writer);
- virtual void parse(ValidatingReader &reader, uint8_t *address) const
+ virtual void parse(Reader &reader, uint8_t *address) const
{
DEBUG_OUT("Skipping array");
@@ -283,25 +285,25 @@
do {
size = reader.readArrayBlockSize();
for(int64_t i = 0; i < size; ++i) {
- instruction_->parse(reader, address);
+ resolver_->parse(reader, address);
}
} while (size != 0);
}
protected:
- InstructionPtr instruction_;
+ ResolverPtr resolver_;
};
typedef uint8_t *(*GenericArraySetter)(uint8_t *array);
-class ArrayParser : public Instruction
+class ArrayParser : public Resolver
{
public:
- ArrayParser(DynamicBuilder &builder, const NodePtr &writer, const NodePtr
&reader, const CompoundOffset &offsets);
+ ArrayParser(ResolverFactory &factory, const NodePtr &writer, const NodePtr
&reader, const CompoundLayout &offsets);
- virtual void parse(ValidatingReader &reader, uint8_t *address) const
+ virtual void parse(Reader &reader, uint8_t *address) const
{
DEBUG_OUT("Reading array");
@@ -315,7 +317,7 @@
for(int64_t i = 0; i < size; ++i) {
// create a new map entry and get the address
uint8_t *location = (*setter)(arrayAddress);
- instruction_->parse(reader, location);
+ resolver_->parse(reader, location);
}
} while (size != 0);
}
@@ -323,30 +325,30 @@
protected:
ArrayParser() :
- Instruction()
+ Resolver()
{}
- InstructionPtr instruction_;
+ ResolverPtr resolver_;
size_t offset_;
size_t setFuncOffset_;
};
-class EnumSkipper : public Instruction
+class EnumSkipper : public Resolver
{
public:
- EnumSkipper(DynamicBuilder &builder, const NodePtr &writer) :
- Instruction()
+ EnumSkipper(ResolverFactory &factory, const NodePtr &writer) :
+ Resolver()
{ }
- virtual void parse(ValidatingReader &reader, uint8_t *address) const
+ virtual void parse(Reader &reader, uint8_t *address) const
{
int64_t val = reader.readEnum();
DEBUG_OUT("Skipping enum" << val);
}
};
-class EnumParser : public Instruction
+class EnumParser : public Resolver
{
public:
@@ -354,8 +356,8 @@
VAL
};
- EnumParser(DynamicBuilder &builder, const NodePtr &writer, const NodePtr
&reader, const CompoundOffset &offsets) :
- Instruction(),
+ EnumParser(ResolverFactory &factory, const NodePtr &writer, const NodePtr
&reader, const CompoundLayout &offsets) :
+ Resolver(),
offset_(offsets.at(0).offset()),
readerSize_(reader->names())
{
@@ -371,7 +373,7 @@
}
}
- virtual void parse(ValidatingReader &reader, uint8_t *address) const
+ virtual void parse(Reader &reader, uint8_t *address) const
{
int64_t val = reader.readEnum();
assert(static_cast<size_t>(val) < mapping_.size());
@@ -391,34 +393,34 @@
};
-class UnionSkipper : public Instruction
+class UnionSkipper : public Resolver
{
public:
- UnionSkipper(DynamicBuilder &builder, const NodePtr &writer);
+ UnionSkipper(ResolverFactory &factory, const NodePtr &writer);
- virtual void parse(ValidatingReader &reader, uint8_t *address) const
+ virtual void parse(Reader &reader, uint8_t *address) const
{
DEBUG_OUT("Skipping union");
int64_t choice = reader.readUnion();
- instructions_[choice].parse(reader, address);
+ resolvers_[choice].parse(reader, address);
}
protected:
- InstructionPtrVector instructions_;
+ ResolverPtrVector resolvers_;
};
-class UnionParser : public Instruction
+class UnionParser : public Resolver
{
public:
typedef uint8_t *(*GenericUnionSetter)(uint8_t *, int64_t);
- UnionParser(DynamicBuilder &builder, const NodePtr &writer, const NodePtr
&reader, const CompoundOffset &offsets);
+ UnionParser(ResolverFactory &factory, const NodePtr &writer, const NodePtr
&reader, const CompoundLayout &offsets);
- virtual void parse(ValidatingReader &reader, uint8_t *address) const
+ virtual void parse(Reader &reader, uint8_t *address) const
{
DEBUG_OUT("Reading union");
int64_t writerChoice = reader.readUnion();
@@ -429,47 +431,47 @@
uint8_t *value = reinterpret_cast<uint8_t *> (address + offset_);
uint8_t *location = (*setter)(value, *readerChoice);
- instructions_[writerChoice].parse(reader, location);
+ resolvers_[writerChoice].parse(reader, location);
}
protected:
- InstructionPtrVector instructions_;
+ ResolverPtrVector resolvers_;
std::vector<int64_t> choiceMapping_;
size_t offset_;
size_t choiceOffset_;
size_t setFuncOffset_;
};
-class UnionToNonUnionParser : public Instruction
+class UnionToNonUnionParser : public Resolver
{
public:
typedef uint8_t *(*GenericUnionSetter)(uint8_t *, int64_t);
- UnionToNonUnionParser(DynamicBuilder &builder, const NodePtr &writer,
const NodePtr &reader, const Offset &offsets);
+ UnionToNonUnionParser(ResolverFactory &factory, const NodePtr &writer,
const NodePtr &reader, const Layout &offsets);
- virtual void parse(ValidatingReader &reader, uint8_t *address) const
+ virtual void parse(Reader &reader, uint8_t *address) const
{
DEBUG_OUT("Reading union to non-union");
int64_t choice = reader.readUnion();
- instructions_[choice].parse(reader, address);
+ resolvers_[choice].parse(reader, address);
}
protected:
- InstructionPtrVector instructions_;
+ ResolverPtrVector resolvers_;
};
-class NonUnionToUnionParser : public Instruction
+class NonUnionToUnionParser : public Resolver
{
public:
typedef uint8_t *(*GenericUnionSetter)(uint8_t *, int64_t);
- NonUnionToUnionParser(DynamicBuilder &builder, const NodePtr &writer,
const NodePtr &reader, const CompoundOffset &offsets);
+ NonUnionToUnionParser(ResolverFactory &factory, const NodePtr &writer,
const NodePtr &reader, const CompoundLayout &offsets);
- virtual void parse(ValidatingReader &reader, uint8_t *address) const
+ virtual void parse(Reader &reader, uint8_t *address) const
{
DEBUG_OUT("Reading non-union to union");
@@ -479,29 +481,29 @@
uint8_t *value = reinterpret_cast<uint8_t *> (address + offset_);
uint8_t *location = (*setter)(value, choice_);
- instruction_->parse(reader, location);
+ resolver_->parse(reader, location);
}
protected:
- InstructionPtr instruction_;
+ ResolverPtr resolver_;
size_t choice_;
size_t offset_;
size_t choiceOffset_;
size_t setFuncOffset_;
};
-class FixedSkipper : public Instruction
+class FixedSkipper : public Resolver
{
public:
- FixedSkipper(DynamicBuilder &builder, const NodePtr &writer) :
- Instruction()
+ FixedSkipper(ResolverFactory &factory, const NodePtr &writer) :
+ Resolver()
{
size_ = writer->fixedSize();
}
- virtual void parse(ValidatingReader &reader, uint8_t *address) const
+ virtual void parse(Reader &reader, uint8_t *address) const
{
DEBUG_OUT("Skipping fixed");
uint8_t val[size_];
@@ -514,18 +516,18 @@
};
-class FixedParser : public Instruction
+class FixedParser : public Resolver
{
public:
- FixedParser(DynamicBuilder &builder, const NodePtr &writer, const NodePtr
&reader, const CompoundOffset &offsets) :
- Instruction()
+ FixedParser(ResolverFactory &factory, const NodePtr &writer, const NodePtr
&reader, const CompoundLayout &offsets) :
+ Resolver()
{
size_ = writer->fixedSize();
offset_ = offsets.at(0).offset();
}
- virtual void parse(ValidatingReader &reader, uint8_t *address) const
+ virtual void parse(Reader &reader, uint8_t *address) const
{
DEBUG_OUT("Reading fixed");
uint8_t *location = reinterpret_cast<uint8_t *> (address + offset_);
@@ -540,20 +542,20 @@
};
-class DynamicBuilder : public boost::noncopyable {
+class ResolverFactory : private boost::noncopyable {
template<typename T>
- Instruction*
- buildPrimitiveSkipper(const NodePtr &writer)
+ Resolver*
+ constructPrimitiveSkipper(const NodePtr &writer)
{
return new PrimitiveSkipper<T>();
}
template<typename T>
- Instruction*
- buildPrimitive(const NodePtr &writer, const NodePtr &reader, const Offset
&offset)
+ Resolver*
+ constructPrimitive(const NodePtr &writer, const NodePtr &reader, const
Layout &offset)
{
- Instruction *instruction;
+ Resolver *instruction;
SchemaResolution match = writer->resolve(*reader);
@@ -561,20 +563,24 @@
instruction = new PrimitiveSkipper<T>();
}
else if (reader->type() == AVRO_UNION) {
- const CompoundOffset &compoundOffset = static_cast<const
CompoundOffset &>(offset);
- instruction = new NonUnionToUnionParser(*this, writer, reader,
compoundOffset);
+ const CompoundLayout &compoundLayout = static_cast<const
CompoundLayout &>(offset);
+ instruction = new NonUnionToUnionParser(*this, writer, reader,
compoundLayout);
}
else if (match == RESOLVE_MATCH) {
- instruction = new PrimitiveParser<T>(offset);
+ const PrimitiveLayout &primitiveLayout = static_cast<const
PrimitiveLayout &>(offset);
+ instruction = new PrimitiveParser<T>(primitiveLayout);
}
else if(match == RESOLVE_PROMOTABLE_TO_LONG) {
- instruction = new PrimitivePromoter<T, int64_t>(offset);
+ const PrimitiveLayout &primitiveLayout = static_cast<const
PrimitiveLayout &>(offset);
+ instruction = new PrimitivePromoter<T, int64_t>(primitiveLayout);
}
else if(match == RESOLVE_PROMOTABLE_TO_FLOAT) {
- instruction = new PrimitivePromoter<T, float>(offset);
+ const PrimitiveLayout &primitiveLayout = static_cast<const
PrimitiveLayout &>(offset);
+ instruction = new PrimitivePromoter<T, float>(primitiveLayout);
}
else if(match == RESOLVE_PROMOTABLE_TO_DOUBLE) {
- instruction = new PrimitivePromoter<T, double>(offset);
+ const PrimitiveLayout &primitiveLayout = static_cast<const
PrimitiveLayout &>(offset);
+ instruction = new PrimitivePromoter<T, double>(primitiveLayout);
}
else {
assert(0);
@@ -583,18 +589,18 @@
}
template<typename Skipper>
- Instruction*
- buildCompoundSkipper(const NodePtr &writer)
+ Resolver*
+ constructCompoundSkipper(const NodePtr &writer)
{
return new Skipper(*this, writer);
}
template<typename Parser, typename Skipper>
- Instruction*
- buildCompound(const NodePtr &writer, const NodePtr &reader, const Offset
&offset)
+ Resolver*
+ constructCompound(const NodePtr &writer, const NodePtr &reader, const
Layout &offset)
{
- Instruction *instruction;
+ Resolver *instruction;
SchemaResolution match = RESOLVE_NO_MATCH;
@@ -604,15 +610,15 @@
instruction = new Skipper(*this, writer);
}
else if(writer->type() != AVRO_UNION && reader->type() == AVRO_UNION) {
- const CompoundOffset &compoundOffset = dynamic_cast<const
CompoundOffset &>(offset);
- instruction = new NonUnionToUnionParser(*this, writer, reader,
compoundOffset);
+ const CompoundLayout &compoundLayout = dynamic_cast<const
CompoundLayout &>(offset);
+ instruction = new NonUnionToUnionParser(*this, writer, reader,
compoundLayout);
}
else if(writer->type() == AVRO_UNION && reader->type() != AVRO_UNION) {
instruction = new UnionToNonUnionParser(*this, writer, reader,
offset);
}
else {
- const CompoundOffset &compoundOffset = dynamic_cast<const
CompoundOffset &>(offset);
- instruction = new Parser(*this, writer, reader, compoundOffset);
+ const CompoundLayout &compoundLayout = dynamic_cast<const
CompoundLayout &>(offset);
+ instruction = new Parser(*this, writer, reader, compoundLayout);
}
return instruction;
@@ -620,11 +626,11 @@
public:
- Instruction *
- build(const NodePtr &writer, const NodePtr &reader, const Offset &offset)
+ Resolver *
+ construct(const NodePtr &writer, const NodePtr &reader, const Layout
&offset)
{
- typedef Instruction* (DynamicBuilder::*BuilderFunc)(const NodePtr
&writer, const NodePtr &reader, const Offset &offset);
+ typedef Resolver* (ResolverFactory::*BuilderFunc)(const NodePtr
&writer, const NodePtr &reader, const Layout &offset);
NodePtr currentWriter = (writer->type() == AVRO_SYMBOLIC) ?
resolveSymbol(writer) : writer;
@@ -633,20 +639,20 @@
resolveSymbol(reader) : reader;
static const BuilderFunc funcs[] = {
- &DynamicBuilder::buildPrimitive<std::string>,
- &DynamicBuilder::buildPrimitive<std::vector<uint8_t> >,
- &DynamicBuilder::buildPrimitive<int32_t>,
- &DynamicBuilder::buildPrimitive<int64_t>,
- &DynamicBuilder::buildPrimitive<float>,
- &DynamicBuilder::buildPrimitive<double>,
- &DynamicBuilder::buildPrimitive<bool>,
- &DynamicBuilder::buildPrimitive<Null>,
- &DynamicBuilder::buildCompound<RecordParser, RecordSkipper>,
- &DynamicBuilder::buildCompound<EnumParser, EnumSkipper>,
- &DynamicBuilder::buildCompound<ArrayParser, ArraySkipper>,
- &DynamicBuilder::buildCompound<MapParser, MapSkipper>,
- &DynamicBuilder::buildCompound<UnionParser, UnionSkipper>,
- &DynamicBuilder::buildCompound<FixedParser, FixedSkipper>
+ &ResolverFactory::constructPrimitive<std::string>,
+ &ResolverFactory::constructPrimitive<std::vector<uint8_t> >,
+ &ResolverFactory::constructPrimitive<int32_t>,
+ &ResolverFactory::constructPrimitive<int64_t>,
+ &ResolverFactory::constructPrimitive<float>,
+ &ResolverFactory::constructPrimitive<double>,
+ &ResolverFactory::constructPrimitive<bool>,
+ &ResolverFactory::constructPrimitive<Null>,
+ &ResolverFactory::constructCompound<RecordParser, RecordSkipper>,
+ &ResolverFactory::constructCompound<EnumParser, EnumSkipper>,
+ &ResolverFactory::constructCompound<ArrayParser, ArraySkipper>,
+ &ResolverFactory::constructCompound<MapParser, MapSkipper>,
+ &ResolverFactory::constructCompound<UnionParser, UnionSkipper>,
+ &ResolverFactory::constructCompound<FixedParser, FixedSkipper>
};
BOOST_STATIC_ASSERT( (sizeof(funcs)/sizeof(BuilderFunc)) ==
(AVRO_NUM_TYPES) );
@@ -657,30 +663,30 @@
return ((this)->*(func))(currentWriter, currentReader, offset);
}
- Instruction *
+ Resolver *
skipper(const NodePtr &writer)
{
- typedef Instruction* (DynamicBuilder::*BuilderFunc)(const NodePtr
&writer);
+ typedef Resolver* (ResolverFactory::*BuilderFunc)(const NodePtr
&writer);
NodePtr currentWriter = (writer->type() == AVRO_SYMBOLIC) ?
writer->leafAt(0) : writer;
static const BuilderFunc funcs[] = {
- &DynamicBuilder::buildPrimitiveSkipper<std::string>,
- &DynamicBuilder::buildPrimitiveSkipper<std::vector<uint8_t> >,
- &DynamicBuilder::buildPrimitiveSkipper<int32_t>,
- &DynamicBuilder::buildPrimitiveSkipper<int64_t>,
- &DynamicBuilder::buildPrimitiveSkipper<float>,
- &DynamicBuilder::buildPrimitiveSkipper<double>,
- &DynamicBuilder::buildPrimitiveSkipper<bool>,
- &DynamicBuilder::buildPrimitiveSkipper<Null>,
- &DynamicBuilder::buildCompoundSkipper<RecordSkipper>,
- &DynamicBuilder::buildCompoundSkipper<EnumSkipper>,
- &DynamicBuilder::buildCompoundSkipper<ArraySkipper>,
- &DynamicBuilder::buildCompoundSkipper<MapSkipper>,
- &DynamicBuilder::buildCompoundSkipper<UnionSkipper>,
- &DynamicBuilder::buildCompoundSkipper<FixedSkipper>
+ &ResolverFactory::constructPrimitiveSkipper<std::string>,
+ &ResolverFactory::constructPrimitiveSkipper<std::vector<uint8_t> >,
+ &ResolverFactory::constructPrimitiveSkipper<int32_t>,
+ &ResolverFactory::constructPrimitiveSkipper<int64_t>,
+ &ResolverFactory::constructPrimitiveSkipper<float>,
+ &ResolverFactory::constructPrimitiveSkipper<double>,
+ &ResolverFactory::constructPrimitiveSkipper<bool>,
+ &ResolverFactory::constructPrimitiveSkipper<Null>,
+ &ResolverFactory::constructCompoundSkipper<RecordSkipper>,
+ &ResolverFactory::constructCompoundSkipper<EnumSkipper>,
+ &ResolverFactory::constructCompoundSkipper<ArraySkipper>,
+ &ResolverFactory::constructCompoundSkipper<MapSkipper>,
+ &ResolverFactory::constructCompoundSkipper<UnionSkipper>,
+ &ResolverFactory::constructCompoundSkipper<FixedSkipper>
};
BOOST_STATIC_ASSERT( (sizeof(funcs)/sizeof(BuilderFunc)) ==
(AVRO_NUM_TYPES) );
@@ -690,44 +696,25 @@
return ((this)->*(func))(currentWriter);
}
-
- DynamicBuilder(const ValidSchema &writer, const ValidSchema &reader, const
OffsetPtr &offset) :
- dparser_(build(writer.root(), reader.root(), *offset))
- { }
-
- DynamicParser
- build()
- {
- return dparser_;
- }
-
- private:
-
- DynamicParser dparser_;
-
};
-DynamicParser buildDynamicParser(const ValidSchema &writer, const ValidSchema
&reader, const OffsetPtr &offset)
-{
- DynamicBuilder b(writer, reader, offset);
- return b.build();
-}
-
-RecordSkipper::RecordSkipper(DynamicBuilder &builder, const NodePtr &writer) :
- Instruction()
+RecordSkipper::RecordSkipper(ResolverFactory &factory, const NodePtr &writer) :
+ Resolver()
{
size_t leaves = writer->leaves();
+ resolvers_.reserve(leaves);
for(size_t i = 0; i < leaves; ++i) {
const NodePtr &w = writer->leafAt(i);
- instructions_.push_back(builder.skipper(w));
+ resolvers_.push_back(factory.skipper(w));
}
}
-RecordParser::RecordParser(DynamicBuilder &builder, const NodePtr &writer,
const NodePtr &reader, const CompoundOffset &offsets) :
- Instruction()
+RecordParser::RecordParser(ResolverFactory &factory, const NodePtr &writer,
const NodePtr &reader, const CompoundLayout &offsets) :
+ Resolver()
{
size_t leaves = writer->leaves();
+ resolvers_.reserve(leaves);
for(size_t i = 0; i < leaves; ++i) {
const NodePtr &w = writer->leafAt(i);
@@ -739,45 +726,46 @@
if(found) {
const NodePtr &r = reader->leafAt(readerIndex);
- instructions_.push_back(builder.build(w, r,
offsets.at(readerIndex)));
+ resolvers_.push_back(factory.construct(w, r,
offsets.at(readerIndex)));
}
else {
- instructions_.push_back(builder.skipper(w));
+ resolvers_.push_back(factory.skipper(w));
}
}
}
-MapSkipper::MapSkipper(DynamicBuilder &builder, const NodePtr &writer) :
- Instruction(),
- instruction_(builder.skipper(writer->leafAt(1)))
+MapSkipper::MapSkipper(ResolverFactory &factory, const NodePtr &writer) :
+ Resolver(),
+ resolver_(factory.skipper(writer->leafAt(1)))
{ }
-MapParser::MapParser(DynamicBuilder &builder, const NodePtr &writer, const
NodePtr &reader, const CompoundOffset &offsets) :
- Instruction(),
- instruction_(builder.build(writer->leafAt(1), reader->leafAt(1),
offsets.at(1))),
+MapParser::MapParser(ResolverFactory &factory, const NodePtr &writer, const
NodePtr &reader, const CompoundLayout &offsets) :
+ Resolver(),
+ resolver_(factory.construct(writer->leafAt(1), reader->leafAt(1),
offsets.at(1))),
offset_(offsets.offset()),
setFuncOffset_( offsets.at(0).offset())
{ }
-ArraySkipper::ArraySkipper(DynamicBuilder &builder, const NodePtr &writer) :
- Instruction(),
- instruction_(builder.skipper(writer->leafAt(0)))
+ArraySkipper::ArraySkipper(ResolverFactory &factory, const NodePtr &writer) :
+ Resolver(),
+ resolver_(factory.skipper(writer->leafAt(0)))
{ }
-ArrayParser::ArrayParser(DynamicBuilder &builder, const NodePtr &writer, const
NodePtr &reader, const CompoundOffset &offsets) :
- Instruction(),
- instruction_(builder.build(writer->leafAt(0), reader->leafAt(0),
offsets.at(1))),
+ArrayParser::ArrayParser(ResolverFactory &factory, const NodePtr &writer,
const NodePtr &reader, const CompoundLayout &offsets) :
+ Resolver(),
+ resolver_(factory.construct(writer->leafAt(0), reader->leafAt(0),
offsets.at(1))),
offset_(offsets.offset()),
setFuncOffset_(offsets.at(0).offset())
{ }
-UnionSkipper::UnionSkipper(DynamicBuilder &builder, const NodePtr &writer) :
- Instruction()
+UnionSkipper::UnionSkipper(ResolverFactory &factory, const NodePtr &writer) :
+ Resolver()
{
size_t leaves = writer->leaves();
+ resolvers_.reserve(leaves);
for(size_t i = 0; i < leaves; ++i) {
const NodePtr &w = writer->leafAt(i);
- instructions_.push_back(builder.skipper(w));
+ resolvers_.push_back(factory.skipper(w));
}
}
@@ -814,14 +802,16 @@
};
-UnionParser::UnionParser(DynamicBuilder &builder, const NodePtr &writer, const
NodePtr &reader, const CompoundOffset &offsets) :
- Instruction(),
+UnionParser::UnionParser(ResolverFactory &factory, const NodePtr &writer,
const NodePtr &reader, const CompoundLayout &offsets) :
+ Resolver(),
offset_(offsets.offset()),
choiceOffset_(offsets.at(0).offset()),
setFuncOffset_(offsets.at(1).offset())
{
size_t leaves = writer->leaves();
+ resolvers_.reserve(leaves);
+ choiceMapping_.reserve(leaves);
for(size_t i = 0; i < leaves; ++i) {
// for each writer, we need a schema match for the reader
@@ -831,20 +821,20 @@
SchemaResolution match = checkUnionMatch(w, reader, index);
if(match == RESOLVE_NO_MATCH) {
- instructions_.push_back(builder.skipper(w));
+ resolvers_.push_back(factory.skipper(w));
// push back a non-sensical number
choiceMapping_.push_back(reader->leaves());
}
else {
const NodePtr &r = reader->leafAt(index);
- instructions_.push_back(builder.build(w, r, offsets.at(index+2)));
+ resolvers_.push_back(factory.construct(w, r, offsets.at(index+2)));
choiceMapping_.push_back(index);
}
}
}
-NonUnionToUnionParser::NonUnionToUnionParser(DynamicBuilder &builder, const
NodePtr &writer, const NodePtr &reader, const CompoundOffset &offsets) :
- Instruction(),
+NonUnionToUnionParser::NonUnionToUnionParser(ResolverFactory &factory, const
NodePtr &writer, const NodePtr &reader, const CompoundLayout &offsets) :
+ Resolver(),
offset_(offsets.offset()),
choiceOffset_(offsets.at(0).offset()),
setFuncOffset_(offsets.at(1).offset())
@@ -852,17 +842,26 @@
SchemaResolution bestMatch = checkUnionMatch(writer, reader, choice_);
assert(bestMatch != RESOLVE_NO_MATCH);
- instruction_.reset(builder.build(writer, reader->leafAt(choice_),
offsets.at(choice_+2)));
+ resolver_.reset(factory.construct(writer, reader->leafAt(choice_),
offsets.at(choice_+2)));
}
-UnionToNonUnionParser::UnionToNonUnionParser(DynamicBuilder &builder, const
NodePtr &writer, const NodePtr &reader, const Offset &offsets) :
- Instruction()
+UnionToNonUnionParser::UnionToNonUnionParser(ResolverFactory &factory, const
NodePtr &writer, const NodePtr &reader, const Layout &offsets) :
+ Resolver()
{
size_t leaves = writer->leaves();
+ resolvers_.reserve(leaves);
for(size_t i = 0; i < leaves; ++i) {
const NodePtr &w = writer->leafAt(i);
- instructions_.push_back(builder.build(w, reader, offsets));
+ resolvers_.push_back(factory.construct(w, reader, offsets));
}
}
+Resolver *constructResolver(const ValidSchema &writerSchema,
+ const ValidSchema &readerSchema,
+ const Layout &readerLayout)
+{
+ ResolverFactory factory;
+ return factory.construct(writerSchema.root(), readerSchema.root(),
readerLayout);
+}
+
} // namespace avro
Added: hadoop/avro/trunk/src/c++/impl/ResolverSchema.cc
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/impl/ResolverSchema.cc?rev=883978&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c++/impl/ResolverSchema.cc (added)
+++ hadoop/avro/trunk/src/c++/impl/ResolverSchema.cc Wed Nov 25 05:08:20 2009
@@ -0,0 +1,39 @@
+
+/**
+ * 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 "ResolverSchema.hh"
+#include "Resolver.hh"
+#include "ValidSchema.hh"
+
+namespace avro {
+
+ResolverSchema::ResolverSchema(
+ const ValidSchema &writerSchema,
+ const ValidSchema &readerSchema,
+ const Layout &readerLayout) :
+ resolver_(constructResolver(writerSchema, readerSchema, readerLayout))
+{ }
+
+void
+ResolverSchema::parse(Reader &reader, uint8_t *address)
+{
+ resolver_->parse(reader, address);
+}
+
+} // namespace avro
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=883978&r1=883977&r2=883978&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/scripts/gen-cppcode.py (original)
+++ hadoop/avro/trunk/src/c++/scripts/gen-cppcode.py Wed Nov 25 05:08:20 2009
@@ -27,7 +27,7 @@
#include "Exception.hh"
#include "AvroSerialize.hh"
#include "AvroParse.hh"
-#include "Instruction.hh"
+#include "Layout.hh"
'''
typeToC= { 'int' : 'int32_t', 'long' :'int64_t', 'float' : 'float', 'double' :
'double',
@@ -53,23 +53,23 @@
addForwardDeclare(args[1])
return (args[1], args[1])
-def addOffset(name, type, var) :
+def addLayout(name, type, var) :
result = ' add(new $offsetType$(offset + offsetof($name$,
$var$)));\n'
result = result.replace('$name$', name)
if typeToC.has_key(type) :
- offsetType = 'avro::Offset'
+ offsetType = 'avro::PrimitiveLayout'
else :
- offsetType = type+ '_Offsets'
+ offsetType = type+ '_Layout'
result = result.replace('$offsetType$', offsetType)
result = result.replace('$var$', var)
return result;
-def addSimpleOffset(type) :
- result = ' add(new $offsetType$(0));\n'
+def addSimpleLayout(type) :
+ result = ' add(new $offsetType$);\n'
if typeToC.has_key(type) :
- offsetType = 'avro::Offset'
+ offsetType = 'avro::PrimitiveLayout'
else :
- offsetType = type+ '_Offsets'
+ offsetType = type+ '_Layout'
return result.replace('$offsetType$', offsetType)
recordfieldTemplate = '$type$ $name$\n'
@@ -93,10 +93,10 @@
$parsefields$
}
-class $name$_Offsets : public avro::CompoundOffset {
+class $name$_Layout : public avro::CompoundLayout {
public:
- $name$_Offsets(size_t offset) :
- CompoundOffset(offset)
+ $name$_Layout(size_t offset = 0) :
+ CompoundLayout(offset)
{
$offsetlist$ }
};
@@ -125,7 +125,7 @@
serializefields += ' serialize(s, val.' + fieldname + ');\n'
initlist += ' ' + fieldname + '(),\n'
parsefields += ' parse(p, val.' + fieldname + ');\n'
- offsetlist += addOffset(typename, fieldtype, fieldname)
+ offsetlist += addLayout(typename, fieldtype, fieldname)
structDef = structDef.replace('$initializers$', initlist)
structDef = structDef.replace('$recordfields$', fields)
structDef = structDef.replace('$serializefields$', serializefields)
@@ -193,13 +193,13 @@
}
}
-class $name$_Offsets : public avro::CompoundOffset {
+class $name$_Layout : public avro::CompoundLayout {
public:
- $name$_Offsets(size_t offset) :
- CompoundOffset(offset)
+ $name$_Layout(size_t offset = 0) :
+ CompoundLayout(offset)
{
- add(new Offset(offset + offsetof($name$, choice)));
- add(new Offset(offset + offsetof($name$, genericSetter)));
+ add(new avro::PrimitiveLayout(offset + offsetof($name$, choice)));
+ add(new avro::PrimitiveLayout(offset + offsetof($name$,
genericSetter)));
$offsetlist$ }
};
'''
@@ -251,7 +251,7 @@
setters += setter
switch = switcher
switches += switch.replace('$N$', str(i))
- offsetlist += addSimpleOffset(name)
+ offsetlist += addSimpleLayout(name)
i+= 1
structDef = structDef.replace('$name$', typename)
structDef = structDef.replace('$typedeflist$', uniontypes)
@@ -286,12 +286,12 @@
val.value = static_cast<$name$::EnumSymbols>(p.readEnum());
}
-class $name$_Offsets : public avro::CompoundOffset {
+class $name$_Layout : public avro::CompoundLayout {
public:
- $name$_Offsets(size_t offset) :
- CompoundOffset(offset)
+ $name$_Layout(size_t offset = 0) :
+ CompoundLayout(offset)
{
- add(new Offset(offset + offsetof($name$, value)));
+ add(new avro::PrimitiveLayout(offset + offsetof($name$, value)));
}
};
'''
@@ -372,12 +372,12 @@
}
}
-class $name$_Offsets : public avro::CompoundOffset {
+class $name$_Layout : public avro::CompoundLayout {
public:
- $name$_Offsets(size_t offset) :
- CompoundOffset(offset)
+ $name$_Layout(size_t offset = 0) :
+ CompoundLayout(offset)
{
- add(new Offset(offset + offsetof($name$, genericSetter)));
+ add(new avro::PrimitiveLayout(offset + offsetof($name$,
genericSetter)));
$offsetlist$ }
};
'''
@@ -386,7 +386,7 @@
structDef = arrayTemplate
line = getNextLine()
arraytype, typename = processType(line)
- offsetlist = addSimpleOffset(typename)
+ offsetlist = addSimpleLayout(typename)
typename = 'Array_of_' + typename
structDef = structDef.replace('$name$', typename)
@@ -458,12 +458,12 @@
}
}
-class $name$_Offsets : public avro::CompoundOffset {
+class $name$_Layout : public avro::CompoundLayout {
public:
- $name$_Offsets(size_t offset) :
- CompoundOffset(offset)
+ $name$_Layout(size_t offset = 0) :
+ CompoundLayout(offset)
{
- add(new Offset(offset + offsetof($name$, genericSetter)));
+ add(new avro::PrimitiveLayout(offset + offsetof($name$,
genericSetter)));
$offsetlist$ }
};
'''
@@ -474,7 +474,7 @@
line = getNextLine()
maptype, typename = processType(line);
- offsetlist = addSimpleOffset(typename)
+ offsetlist = addSimpleLayout(typename)
typename = 'Map_of_' + typename
structDef = structDef.replace('$name$', typename)
@@ -508,12 +508,12 @@
p.readFixed(val.value);
}
-class $name$_Offsets : public avro::CompoundOffset {
+class $name$_Layout : public avro::CompoundLayout {
public:
- $name$_Offsets(size_t offset) :
- CompoundOffset(offset)
+ $name$_Layout(size_t offset = 0) :
+ CompoundLayout(offset)
{
- add(new Offset(offset + offsetof($name$, value)));
+ add(new avro::PrimitiveLayout(offset + offsetof($name$, value)));
}
};
'''
@@ -545,12 +545,12 @@
p.readValue(val.value);
}
-class $name$_Offsets : public avro::CompoundOffset {
+class $name$_Layout : public avro::CompoundLayout {
public:
- $name$_Offsets(size_t offset) :
- CompoundOffset(offset)
+ $name$_Layout(size_t offset = 0) :
+ CompoundLayout(offset)
{
- add(new Offset(offset + offsetof($name$, value)));
+ add(new avro::PrimitiveLayout(offset + offsetof($name$, value)));
}
};
'''
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=883978&r1=883977&r2=883978&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/test/testgen.cc (original)
+++ hadoop/avro/trunk/src/c++/test/testgen.cc Wed Nov 25 05:08:20 2009
@@ -34,7 +34,8 @@
#include "Node.hh"
#include "ValidSchema.hh"
#include "Compiler.hh"
-#include "Instruction.hh"
+#include "ResolvingReader.hh"
+#include "ResolverSchema.hh"
std::string gWriter ("jsonschemas/bigrecord");
std::string gReader ("jsonschemas/bigrecord2");
@@ -483,25 +484,26 @@
return ostring.str();
}
- void parseData(const std::string &data, avro::DynamicParser &dynamicParser)
+ void parseData(const std::string &data, avro::ResolverSchema &xSchema)
{
std::istringstream istring(data);
avro::IStreamer is(istring);
- avro::ValidatingReader r(writerSchema_, is);
+ avro::ResolvingReader r(xSchema, is);
- dynamicParser->parse(r, reinterpret_cast<uint8_t *>(&readRecord_));
+ avro::parse(r, readRecord_);
}
void test()
{
std::cout << "Running schema resolution tests\n";
- avro::OffsetPtr settersRootRecord ( new
testgen2::RootRecord_Offsets(0));
- avro::DynamicParser dynamicParser = buildDynamicParser(writerSchema_,
readerSchema_, settersRootRecord);
+ testgen2::RootRecord_Layout layout;
+
+ avro::ResolverSchema xSchema(writerSchema_, readerSchema_, layout);
printRecord(writeRecord_);
std::string writtenData = serializeWriteRecordToString();
- parseData(writtenData, dynamicParser);
+ parseData(writtenData, xSchema);
printRecord(readRecord_);