Tagging 1.5.2-rc0.
git-svn-id: https://svn.apache.org/repos/asf/avro/tags/release-1.5.2-rc0@1142087 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/doc/src/content/xdocs/idl.xml b/doc/src/content/xdocs/idl.xml
index e8466bb..3badddd 100644
--- a/doc/src/content/xdocs/idl.xml
+++ b/doc/src/content/xdocs/idl.xml
@@ -302,9 +302,6 @@
<p>All Java-style comments are supported within a Avro IDL file. Any text following
<code>//</code> on a line is ignored, as is any text between <code>/*</code> and
<code>*/</code>, possibly spanning multiple lines.</p>
- <p>Comments that begin with <code>/**</code> are used as the
- documentation string for the type or field definition that
- follows the comment.</p>
</section>
<section id="minutiae_escaping">
<title>Escaping Identifiers</title>
diff --git a/doc/src/content/xdocs/spec.xml b/doc/src/content/xdocs/spec.xml
index 44df4b4..be4a90d 100644
--- a/doc/src/content/xdocs/spec.xml
+++ b/doc/src/content/xdocs/spec.xml
@@ -695,16 +695,7 @@
</p>
</section>
</section>
- <section>
- <title>Optional Codecs</title>
- <section>
- <title>snappy</title>
- <p>The "snappy" codec uses
- Google's <a href="http://code.google.com/p/snappy/">Snappy</a>
- compression library. Each compressed block is followed
- by its 4-byte, big-endian CRC32 checksum.</p>
- </section>
- </section>
+
</section>
<section>
diff --git a/lang/c++/CMakeLists.txt b/lang/c++/CMakeLists.txt
index 7f20fd1..d1ca7b0 100644
--- a/lang/c++/CMakeLists.txt
+++ b/lang/c++/CMakeLists.txt
@@ -34,18 +34,15 @@
project (Avro-cpp)
-find_package (Boost 1.38 COMPONENTS regex filesystem system program_options)
+find_package (Boost 1.38 COMPONENTS regex filesystem system)
include_directories (api ${BUILD_DIRECTORY})
-
-add_library (avrocpp SHARED
+add_library (avrocpp SHARED impl/Compiler.cc
impl/Compiler.cc impl/CompilerNode.cc impl/Node.cc
impl/NodeImpl.cc impl/Resolver.cc impl/ResolverSchema.cc impl/Schema.cc
impl/Types.cc impl/Validator.cc impl/ValidSchema.cc impl/Zigzag.cc
impl/BinaryEncoder.cc impl/BinaryDecoder.cc
impl/Stream.cc impl/FileStream.cc
- impl/Generic.cc
- impl/DataFile.cc
impl/parsing/Symbol.cc
impl/parsing/ValidatingCodec.cc
impl/parsing/JsonCodec.cc
@@ -83,49 +80,13 @@
add_custom_command (OUTPUT ${BUILD_DIRECTORY}/AvroYacc.cc
COMMAND bison --defines=AvroYacc.hh -o AvroYacc.cc ../parser/AvroYacc.yy
WORKING_DIRECTORY ${BUILD_DIRECTORY})
-
add_custom_command (OUTPUT ${BUILD_DIRECTORY}/AvroLex.cc
COMMAND flex -oAvroLex.cc ../parser/AvroLex.ll
WORKING_DIRECTORY ${BUILD_DIRECTORY})
-add_custom_target (bigrecord_hh
- COMMAND avrogencpp -i jsonschemas/bigrecord
- -o ${BUILD_DIRECTORY}/bigrecord.hh -n testgen
- DEPENDS avrogencpp)
-
-add_custom_target (bigrecord2_hh
- COMMAND avrogencpp -i jsonschemas/bigrecord2
- -o ${BUILD_DIRECTORY}/bigrecord2.hh -n testgen2
- DEPENDS avrogencpp)
-
-add_custom_target (union_array_union_hh
- COMMAND avrogencpp -i jsonschemas/union_array_union
- -o ${BUILD_DIRECTORY}/union_array_union.hh -n uau
- DEPENDS avrogencpp)
-
-add_custom_target (union_map_union_hh
- COMMAND avrogencpp -i jsonschemas/union_map_union
- -o ${BUILD_DIRECTORY}/union_map_union.hh -n umu
- DEPENDS avrogencpp)
-
-add_custom_target (recursive_hh
- COMMAND avrogencpp -i jsonschemas/recursive
- -o ${BUILD_DIRECTORY}/recursive.hh -n rec
- DEPENDS avrogencpp)
-
-add_custom_target (reuse_hh
- COMMAND avrogencpp -i jsonschemas/reuse
- -o ${BUILD_DIRECTORY}/reuse.hh -n reu
- DEPENDS avrogencpp)
-
-add_custom_target (circulardep_hh
- COMMAND avrogencpp -i jsonschemas/circulardep
- -o ${BUILD_DIRECTORY}/circulardep.hh -n reu
- DEPENDS avrogencpp)
-
macro (test name)
add_executable (${name} test/${name}.cc)
- target_link_libraries (${name} avrocpp ${Boost_LIBRARIES})
+ target_link_libraries (${name} avrocpp boost_regex-mt)
endmacro (test)
test(buffertest)
@@ -137,24 +98,9 @@
add_executable (StreamTests test/StreamTests.cc)
target_link_libraries (StreamTests avrocpp ${Boost_LIBRARIES})
-add_executable (SpecificTests test/SpecificTests.cc)
-target_link_libraries (SpecificTests avrocpp ${Boost_LIBRARIES})
-
-add_executable (avrogencpp impl/avrogencpp.cc)
-target_link_libraries (avrogencpp avrocpp ${Boost_LIBRARIES})
-
add_executable (testgentest test/testgen.cc)
add_dependencies (testgentest testgen testgen2)
-target_link_libraries (testgentest avrocpp ${Boost_LIBRARIES})
-
-add_executable (AvrogencppTests test/AvrogencppTests.cc)
-add_dependencies (AvrogencppTests bigrecord_hh bigrecord2_hh
- union_array_union_hh union_map_union_hh recursive_hh reuse_hh
- circulardep_hh)
-target_link_libraries (AvrogencppTests avrocpp ${BOOST_LIBRARIES})
-
-add_executable (DataFileTests test/DataFileTests.cc)
-target_link_libraries (DataFileTests avrocpp ${Boost_LIBRARIES})
+target_link_libraries (testgentest avrocpp boost_regex-mt)
include (InstallRequiredSystemLibraries)
diff --git a/lang/c++/Makefile.am b/lang/c++/Makefile.am
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/lang/c++/Makefile.am
diff --git a/lang/c++/api/DataFile.hh b/lang/c++/api/DataFile.hh
deleted file mode 100644
index d73b18b..0000000
--- a/lang/c++/api/DataFile.hh
+++ /dev/null
@@ -1,287 +0,0 @@
-/**
- * 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_DataFile_hh__
-#define avro_DataFile_hh__
-
-#include "Encoder.hh"
-#include "buffer/Buffer.hh"
-#include "ValidSchema.hh"
-#include "Specific.hh"
-#include "Stream.hh"
-
-#include <map>
-#include <string>
-#include <vector>
-
-#include "boost/array.hpp"
-#include "boost/utility.hpp"
-
-namespace avro {
-
-typedef boost::array<uint8_t, 16> DataFileSync;
-
-/**
- * Type-independent portion of DataFileWriter.
- * At any given point in time, at most one file can be written using
- * this object.
- */
-class DataFileWriterBase : boost::noncopyable {
- const std::string filename_;
- const ValidSchema schema_;
- const EncoderPtr encoderPtr_;
- const size_t syncInterval_;
-
- std::auto_ptr<OutputStream> stream_;
- std::auto_ptr<OutputStream> buffer_;
- const DataFileSync sync_;
- int64_t objectCount_;
-
- typedef std::map<std::string, std::vector<uint8_t> > Metadata;
-
- Metadata metadata_;
-
- static std::auto_ptr<OutputStream> makeStream(const char* filename);
- static DataFileSync makeSync();
-
- void writeHeader();
- void setMetadata(const std::string& key, const std::string& value);
-
- /**
- * Generates a sync marker in the file.
- */
- void sync();
-
-public:
- Encoder& encoder() const { return *encoderPtr_; }
-
- void syncIfNeeded();
-
- void incr() {
- ++objectCount_;
- }
- /**
- * Constructs a data file writer with the given sync interval and name.
- */
- DataFileWriterBase(const char* filename, const ValidSchema& schema,
- size_t syncInterval);
-
- ~DataFileWriterBase();
- /**
- * Closes the current file. Once closed this datafile object cannot be
- * used for writing any more.
- */
- void close();
-
- /**
- * Returns the schema for this data file.
- */
- const ValidSchema& schema() const { return schema_; }
-
- /**
- * Flushes any unwritten data into the file.
- */
- void flush();
-};
-
-/**
- * An Avro datafile that can store objects of type T.
- */
-template <typename T>
-class DataFileWriter : boost::noncopyable {
- std::auto_ptr<DataFileWriterBase> base_;
-public:
- /**
- * Constructs a new data file.
- */
- DataFileWriter(const char* filename, const ValidSchema& schema,
- size_t syncInterval = 16 * 1024) :
- base_(new DataFileWriterBase(filename, schema, syncInterval)) { }
-
- /**
- * Writes the given piece of data into the file.
- */
- void write(const T& datum) {
- base_->syncIfNeeded();
- avro::encode(base_->encoder(), datum);
- base_->incr();
- }
-
- /**
- * Closes the current file. Once closed this datafile object cannot be
- * used for writing any more.
- */
- void close() { base_->close(); }
-
- /**
- * Returns the schema for this data file.
- */
- const ValidSchema& schema() const { return base_->schema(); }
-
- /**
- * Flushes any unwritten data into the file.
- */
- void flush() { base_->flush(); }
-};
-
-class DataFileReaderBase : boost::noncopyable {
- const std::string filename_;
- const std::auto_ptr<InputStream> stream_;
- const DecoderPtr decoder_;
- int64_t objectCount_;
-
- ValidSchema readerSchema_;
- ValidSchema dataSchema_;
- DecoderPtr dataDecoder_;
- std::auto_ptr<InputStream> dataStream_;
- typedef std::map<std::string, std::vector<uint8_t> > Metadata;
-
- Metadata metadata_;
- DataFileSync sync_;
-
- void readHeader();
-
- bool readDataBlock();
-public:
- Decoder& decoder() { return *dataDecoder_; }
-
- /**
- * Returns true if and only if there is more to read.
- */
- bool hasMore();
-
- void decr() { --objectCount_; }
-
- /**
- * Constructs the reader for the given file and the reader is
- * expected to use the schema that is used with data.
- * This function should be called exactly once after constructing
- * the DataFileReaderBase object.
- */
- DataFileReaderBase(const char* filename);
-
- /**
- * Initializes the reader so that the reader and writer schemas
- * are the same.
- */
- void init();
-
- /**
- * Initializes the reader to read objects according to the given
- * schema. This gives an opportinity for the reader to see the schema
- * in the data file before deciding the right schema to use for reading.
- * This must be called exactly once after constructing the
- * DataFileReaderBase object.
- */
- void init(const ValidSchema& readerSchema);
-
- /**
- * Returns the schema for this object.
- */
- const ValidSchema& readerSchema() { return readerSchema_; }
-
- /**
- * Returns the schema stored with the data file.
- */
- const ValidSchema& dataSchema() { return dataSchema_; }
-
- /**
- * Closes the reader. No further operation is possible on this reader.
- */
- void close();
-};
-
-template <typename T>
-class DataFileReader : boost::noncopyable {
- std::auto_ptr<DataFileReaderBase> base_;
-public:
- /**
- * Constructs the reader for the given file and the reader is
- * expected to use the given schema.
- */
- DataFileReader(const char* filename, const ValidSchema& readerSchema) :
- base_(new DataFileReaderBase(filename)) {
- base_->init(readerSchema);
- }
-
- /**
- * Constructs the reader for the given file and the reader is
- * expected to use the schema that is used with data.
- */
- DataFileReader(const char* filename) :
- base_(new DataFileReaderBase(filename)) {
- base_->init();
- }
-
-
- /**
- * Constructs a reader using the reader base. This form of constructor
- * allows the user to examine the schema of a given file and then
- * decide to use the right type of data to be desrialize. Without this
- * the user must know the type of data for the template _before_
- * he knows the schema within the file.
- * The schema present in the data file will be used for reading
- * from this reader.
- */
- DataFileReader(std::auto_ptr<DataFileReaderBase> base) : base_(base) {
- base_->init();
- }
-
- /**
- * Constructs a reader using the reader base. This form of constructor
- * allows the user to examine the schema of a given file and then
- * decide to use the right type of data to be desrialize. Without this
- * the user must know the type of data for the template _before_
- * he knows the schema within the file.
- * The argument readerSchema will be used for reading
- * from this reader.
- */
- DataFileReader(std::auto_ptr<DataFileReaderBase> base,
- const ValidSchema& readerSchema) : base_(base) {
- base_->init(readerSchema);
- }
-
- bool read(T& datum) {
- if (base_->hasMore()) {
- base_->decr();
- avro::decode(base_->decoder(), datum);
- return true;
- }
- return false;
- }
-
- /**
- * Returns the schema for this object.
- */
- const ValidSchema& readerSchema() { return base_->readerSchema(); }
-
- /**
- * Returns the schema stored with the data file.
- */
- const ValidSchema& dataSchema() { return base_->dataSchema(); }
-
- /**
- * Closes the reader. No further operation is possible on this reader.
- */
- void close() { return base_->close(); }
-};
-
-} // namespace avro
-#endif
-
-
diff --git a/lang/c++/api/Generic.hh b/lang/c++/api/Generic.hh
deleted file mode 100644
index f6ec134..0000000
--- a/lang/c++/api/Generic.hh
+++ /dev/null
@@ -1,278 +0,0 @@
-/**
- * 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_Generic_hh__
-#define avro_Generic_hh__
-
-#include <vector>
-#include <map>
-#include <string>
-
-#include <boost/any.hpp>
-#include <boost/utility.hpp>
-
-#include "Node.hh"
-#include "Types.hh"
-#include "Encoder.hh"
-#include "Decoder.hh"
-#include "ValidSchema.hh"
-
-namespace avro {
-
-class GenericDatum {
- Type type_;
- boost::any value_;
-
- GenericDatum(Type t) : type_(t) { }
-
- template <typename T>
- GenericDatum(Type t, const T& v) : type_(t), value_(v) { }
-
-public:
- Type type() const {
- return type_;
- }
-
- template<typename T>
- const T& value() const {
- return *boost::any_cast<T>(&value_);
- }
-
- template<typename T>
- T& value() {
- return *boost::any_cast<T>(&value_);
- }
-
- /// Makes a new AVRO_NULL datum.
- GenericDatum() : type_(AVRO_NULL) { }
-
- /// Makes a new AVRO_BOOL datum whose value is of type bool.
- GenericDatum(bool v) : type_(AVRO_BOOL), value_(v) { }
-
- /// Makes a new AVRO_INT datum whose value is of type int32_t.
- GenericDatum(int32_t v) : type_(AVRO_INT), value_(v) { }
-
- /// Makes a new AVRO_LONG datum whose value is of type int64_t.
- GenericDatum(int64_t v) : type_(AVRO_LONG), value_(v) { }
-
- /// Makes a new AVRO_FLOAT datum whose value is of type float.
- GenericDatum(float v) : type_(AVRO_FLOAT), value_(v) { }
-
- /// Makes a new AVRO_DOUBLE datum whose value is of type double.
- GenericDatum(double v) : type_(AVRO_DOUBLE), value_(v) { }
-
- /// Makes a new AVRO_STRING datum whose value is of type std::string.
- GenericDatum(const std::string& v) : type_(AVRO_STRING), value_(v) { }
-
- /// Makes a new AVRO_BYTES datum whose value is of type
- /// std::vector<uint8_t>.
- GenericDatum(const std::vector<uint8_t>& v) :
- type_(AVRO_BYTES), value_(v) { }
-
- GenericDatum(const NodePtr& schema);
-};
-
-class GenericContainer {
- const NodePtr schema_;
-protected:
- GenericContainer(const NodePtr& s) : schema_(s) { }
-
- static void assertSameType(const GenericDatum& v, const NodePtr& n);
- static void assertType(const NodePtr& schema, Type type,
- const char* message);
-public:
- /// Returns the schema for this object
- const NodePtr& schema() const {
- return schema_;
- }
-};
-
-class GenericRecord : public GenericContainer {
- std::vector<GenericDatum> fields_;
-public:
- GenericRecord(const NodePtr& schema);
-
- size_t fieldCount() const {
- return fields_.size();
- }
-
- const GenericDatum& fieldAt(size_t pos) const {
- return fields_[pos];
- }
-
- GenericDatum& fieldAt(size_t pos) {
- return fields_[pos];
- }
-
- void setFieldAt(size_t pos, const GenericDatum& v) {
- assertSameType(v, schema()->leafAt(pos));
- fields_[pos] = v;
- }
-};
-
-class GenericArray : public GenericContainer {
-public:
- typedef std::vector<GenericDatum> Value;
-
- GenericArray(const NodePtr& schema) : GenericContainer(schema) {
- if (schema->type() != AVRO_ARRAY) {
- throw Exception("Schema is not an array");
- }
- }
-
- const Value& value() const {
- return value_;
- }
-
- Value& value() {
- return value_;
- }
-private:
- Value value_;
-};
-
-class GenericMap : public GenericContainer {
-public:
- typedef std::vector<std::pair<std::string, GenericDatum> > Value;
-
- GenericMap(const NodePtr& schema) : GenericContainer(schema) {
- assertType(schema, AVRO_MAP, "Schema is not a map");
- }
-
- const Value& value() const {
- return value_;
- }
-
- Value& value() {
- return value_;
- }
-private:
- Value value_;
-};
-
-class GenericEnum : public GenericContainer {
- size_t value_;
-public:
- GenericEnum(const NodePtr& schema) : GenericContainer(schema), value_(0) {
- }
-
- const std::string& symbol(size_t n) {
- if (n < schema()->names()) {
- return schema()->nameAt(n);
- }
- throw Exception("Not as many symbols");
- }
-
- size_t index(const std::string& symbol) const {
- size_t result;
- if (schema()->nameIndex(symbol, result)) {
- return result;
- }
- throw Exception("No such symbol");
- }
-
- size_t set(const std::string& symbol) {
- return value_ = index(symbol);
- }
-
- void set(size_t n) {
- if (n < schema()->names()) {
- value_ = n;
- return;
- }
- throw Exception("Not as many symbols");
- }
-
- size_t value() const {
- return value_;
- }
-
- const std::string& symbol() const {
- return schema()->nameAt(value_);
- }
-};
-
-class GenericFixed : public GenericContainer {
- std::vector<uint8_t> value_;
-public:
- GenericFixed(const NodePtr& schema) : GenericContainer(schema) {
- value_.resize(schema->fixedSize());
- }
-
- const std::vector<uint8_t>& value() const {
- return value_;
- }
-
- std::vector<uint8_t>& value() {
- return value_;
- }
-};
-
-
-class GenericReader : boost::noncopyable {
- const ValidSchema schema_;
- const bool isResolving_;
- const DecoderPtr decoder_;
-
- static void read(GenericDatum& datum, const NodePtr& n, Decoder& d,
- bool isResolving);
-public:
- GenericReader(const ValidSchema& s, const DecoderPtr& decoder);
- GenericReader(const ValidSchema& writerSchema,
- const ValidSchema& readerSchema, const DecoderPtr& decoder);
-
- void read(GenericDatum& datum) const;
-
- /**
- * Reads a generic datum from the stream, using the given schema.
- */
- static void read(Decoder& d, GenericDatum& g, const ValidSchema& s);
-};
-
-
-class GenericWriter : boost::noncopyable {
- const ValidSchema schema_;
- const EncoderPtr encoder_;
-
- static void write(const GenericDatum& datum, const NodePtr& n, Encoder& e);
-public:
- GenericWriter(const ValidSchema& s, const EncoderPtr& encoder);
-
- void write(const GenericDatum& datum) const;
-
- /**
- * Writes a generic datum on to the stream, using the given schema.
- */
- static void write(Encoder& e, const GenericDatum& g, const ValidSchema& s);
-};
-
-template <typename T> struct codec_traits;
-
-template <> struct codec_traits<std::pair<ValidSchema, GenericDatum> > {
- static void encode(Encoder& e,
- const std::pair<ValidSchema, GenericDatum>& p) {
- GenericWriter::write(e, p.second, p.first);
- }
-
- static void decode(Decoder& d, std::pair<ValidSchema, GenericDatum>& p) {
- GenericReader::read(d, p.second, p.first);
- }
-};
-} // namespace avro
-#endif
-
diff --git a/lang/c++/api/Specific.hh b/lang/c++/api/Specific.hh
deleted file mode 100644
index 5a32b53..0000000
--- a/lang/c++/api/Specific.hh
+++ /dev/null
@@ -1,207 +0,0 @@
-/**
- * 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_Codec_hh__
-#define avro_Codec_hh__
-
-#include <string>
-#include <vector>
-#include <map>
-#include <algorithm>
-
-#include "boost/array.hpp"
-
-#include "Encoder.hh"
-#include "Decoder.hh"
-
-/**
- * A bunch of templates and specializations for encoding and decoding
- * specific types.
- *
- * Primitive AVRO types BOOLEAN, INT, LONG, FLOAT, DOUBLE, STRING and BYTES
- * get decoded to and encoded from C++ types bool, int32_t, int64_t, float,
- * double, std::string and std::vector<uint8_t> respectively. In addition,
- * std::vector<T> for aribtrary type T gets encoded as an Avro array of T.
- * Similarly, std::map<std::string, T> for arbitrary type T gets encoded
- * as an Avro map with value type T.
- *
- * Users can have their custom types encoded/decoded by specializing
- * avro::codec_traits class for their types.
- */
-namespace avro {
-
-template <typename T> void encode(Encoder& e, const T& t);
-template <typename T> void decode(Decoder& d, T& t);
-
-template <typename T>
-struct codec_traits {
-};
-
-template <> struct codec_traits<bool> {
- static void encode(Encoder& e, bool b) {
- e.encodeBool(b);
- }
-
- static void decode(Decoder& d, bool& b) {
- b = d.decodeBool();
- }
-};
-
-template <> struct codec_traits<int32_t> {
- static void encode(Encoder& e, int32_t i) {
- e.encodeInt(i);
- }
-
- static void decode(Decoder& d, int32_t& i) {
- i = d.decodeInt();
- }
-};
-
-template <> struct codec_traits<int64_t> {
- static void encode(Encoder& e, int64_t l) {
- e.encodeLong(l);
- }
-
- static void decode(Decoder& d, int64_t& l) {
- l = d.decodeLong();
- }
-};
-
-template <> struct codec_traits<float> {
- static void encode(Encoder& e, float f) {
- e.encodeFloat(f);
- }
-
- static void decode(Decoder& d, float& f) {
- f = d.decodeFloat();
- }
-};
-
-template <> struct codec_traits<double> {
- static void encode(Encoder& e, double d) {
- e.encodeDouble(d);
- }
-
- static void decode(Decoder& d, double& dbl) {
- dbl = d.decodeDouble();
- }
-};
-
-template <> struct codec_traits<std::string> {
- static void encode(Encoder& e, const std::string& s) {
- e.encodeString(s);
- }
-
- static void decode(Decoder& d, std::string& s) {
- s = d.decodeString();
- }
-};
-
-template <> struct codec_traits<std::vector<uint8_t> > {
- static void encode(Encoder& e, const std::vector<uint8_t>& b) {
- e.encodeBytes(b);
- }
-
- static void decode(Decoder& d, std::vector<uint8_t>& s) {
- d.decodeBytes(s);
- }
-};
-
-template <size_t N> struct codec_traits<boost::array<uint8_t, N> > {
- static void encode(Encoder& e, const boost::array<uint8_t, N>& b) {
- e.encodeFixed(&b[0], N);
- }
-
- static void decode(Decoder& d, boost::array<uint8_t, N>& s) {
- std::vector<uint8_t> v(N);
- d.decodeFixed(N, v);
- std::copy(&v[0], &v[0] + N, &s[0]);
- }
-};
-
-template <typename T> struct codec_traits<std::vector<T> > {
- static void encode(Encoder& e, const std::vector<T>& b) {
- e.arrayStart();
- if (! b.empty()) {
- e.setItemCount(b.size());
- for (typename std::vector<T>::const_iterator it = b.begin();
- it != b.end(); ++it) {
- e.startItem();
- avro::encode(e, *it);
- }
- }
- e.arrayEnd();
- }
-
- static void decode(Decoder& d, std::vector<T>& s) {
- s.clear();
- for (size_t n = d.arrayStart(); n != 0; n = d.arrayNext()) {
- for (size_t i = 0; i < n; ++i) {
- T t;
- avro::decode(d, t);
- s.push_back(t);
- }
- }
- }
-};
-
-template <typename T> struct codec_traits<std::map<std::string, T> > {
- static void encode(Encoder& e, const std::map<std::string, T>& b) {
- e.mapStart();
- if (! b.empty()) {
- e.setItemCount(b.size());
- for (typename std::map<std::string, T>::const_iterator
- it = b.begin();
- it != b.end(); ++it) {
- e.startItem();
- avro::encode(e, it->first);
- avro::encode(e, it->second);
- }
- }
- e.mapEnd();
- }
-
- static void decode(Decoder& d, std::map<std::string, T>& s) {
- s.clear();
- for (size_t n = d.mapStart(); n != 0; n = d.mapNext()) {
- for (size_t i = 0; i < n; ++i) {
- std::string k;
- avro::decode(d, k);
- T t;
- avro::decode(d, t);
- s[k] = t;
- }
- }
- }
-};
-
-template <typename T>
-void encode(Encoder& e, const T& t) {
- codec_traits<T>::encode(e, t);
-}
-
-template <typename T>
-void decode(Decoder& d, T& t) {
- codec_traits<T>::decode(d, t);
-}
-
-} // namespace avro
-#endif // avro_Codec_hh__
-
-
-
diff --git a/lang/c++/api/Stream.hh b/lang/c++/api/Stream.hh
index 53dc891..d6c5fed 100644
--- a/lang/c++/api/Stream.hh
+++ b/lang/c++/api/Stream.hh
@@ -136,7 +136,6 @@
const uint8_t* end_;
StreamReader() : in_(0), next_(0), end_(0) { }
- StreamReader(InputStream& in) : in_(0), next_(0), end_(0) { reset(in); }
void reset(InputStream& is) {
if (in_ != 0) {
@@ -210,7 +209,6 @@
uint8_t* end_;
StreamWriter() : out_(0), next_(0), end_(0) { }
- StreamWriter(OutputStream& out) : out_(0), next_(0), end_(0) { reset(out); }
void reset(OutputStream& os) {
if (out_ != 0) {
@@ -262,22 +260,6 @@
out_->flush();
}
};
-
-/**
- * A convenience function to copy all the contents of an input stream into
- * an output stream.
- */
-inline void copy(InputStream& in, OutputStream& out)
-{
- const uint8_t *p = 0;
- size_t n = 0;
- StreamWriter w(out);
- while (in.next(&p, &n)) {
- w.writeBytes(p, n);
- }
- w.flush();
-}
-
} // namespace avro
#endif
diff --git a/lang/c++/build.sh b/lang/c++/build.sh
index 6d66023..8090bc3 100755
--- a/lang/c++/build.sh
+++ b/lang/c++/build.sh
@@ -82,9 +82,6 @@
./build/testgentest
./build/CodecTests
./build/StreamTests
- ./build/SpecificTests
- ./build/AvrogencppTests
- ./build/DataFileTests
;;
dist)
diff --git a/lang/c++/impl/DataFile.cc b/lang/c++/impl/DataFile.cc
deleted file mode 100644
index 37955b4..0000000
--- a/lang/c++/impl/DataFile.cc
+++ /dev/null
@@ -1,324 +0,0 @@
-/**
- * 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 "DataFile.hh"
-#include "Compiler.hh"
-#include "Exception.hh"
-
-#include <sstream>
-
-#include <boost/random/mersenne_twister.hpp>
-
-namespace avro {
-using std::auto_ptr;
-using std::ostringstream;
-using std::istringstream;
-using std::vector;
-using std::copy;
-using std::string;
-
-using boost::array;
-
-const string AVRO_SCHEMA_KEY("avro.schema");
-const string AVRO_CODEC_KEY("avro.codec");
-const string AVRO_NULL_CODEC("null");
-
-const size_t minSyncInterval = 32;
-const size_t maxSyncInterval = 1u << 30;
-const size_t defaultSyncInterval = 16 * 1024;
-
-static string toString(const ValidSchema& schema)
-{
- ostringstream oss;
- schema.toJson(oss);
- return oss.str();
-}
-
-DataFileWriterBase::DataFileWriterBase(const char* filename,
- const ValidSchema& schema, size_t syncInterval) :
- filename_(filename), schema_(schema), encoderPtr_(binaryEncoder()),
- syncInterval_(syncInterval),
- stream_(fileOutputStream(filename)),
- buffer_(memoryOutputStream()),
- sync_(makeSync()), objectCount_(0)
-{
- if (syncInterval < minSyncInterval || syncInterval > maxSyncInterval) {
- throw Exception(boost::format("Invalid sync interval: %1%. "
- "Should be between %2% and %3%") % syncInterval %
- minSyncInterval % maxSyncInterval);
- }
- setMetadata(AVRO_CODEC_KEY, AVRO_NULL_CODEC);
-
- setMetadata(AVRO_SCHEMA_KEY, toString(schema));
-
- writeHeader();
- encoderPtr_->init(*buffer_);
-}
-
-DataFileWriterBase::~DataFileWriterBase()
-{
- if (stream_.get()) {
- close();
- }
-}
-
-void DataFileWriterBase::close()
-{
- flush();
- stream_.reset();
-}
-
-void DataFileWriterBase::sync()
-{
- encoderPtr_->flush();
-
- encoderPtr_->init(*stream_);
- avro::encode(*encoderPtr_, objectCount_);
- int64_t byteCount = buffer_->byteCount();
- avro::encode(*encoderPtr_, byteCount);
- encoderPtr_->flush();
-
- auto_ptr<InputStream> in = memoryInputStream(*buffer_);
- copy(*in, *stream_);
-
- encoderPtr_->init(*stream_);
- avro::encode(*encoderPtr_, sync_);
- encoderPtr_->flush();
-
-
- buffer_ = memoryOutputStream();
- encoderPtr_->init(*buffer_);
- objectCount_ = 0;
-}
-
-void DataFileWriterBase::syncIfNeeded()
-{
- encoderPtr_->flush();
- if (buffer_->byteCount() >= syncInterval_) {
- sync();
- }
-}
-
-void DataFileWriterBase::flush()
-{
- sync();
-}
-
-boost::mt19937 random(time(0));
-
-DataFileSync DataFileWriterBase::makeSync()
-{
- DataFileSync sync;
- for (size_t i = 0; i < sync.size(); ++i) {
- sync[i] = random();
- }
- return sync;
-}
-
-typedef array<uint8_t, 4> Magic;
-static Magic magic = { 'O', 'b', 'j', '\x01' };
-
-void DataFileWriterBase::writeHeader()
-{
- encoderPtr_->init(*stream_);
- avro::encode(*encoderPtr_, magic);
- avro::encode(*encoderPtr_, metadata_);
- avro::encode(*encoderPtr_, sync_);
- encoderPtr_->flush();
-}
-
-void DataFileWriterBase::setMetadata(const string& key, const string& value)
-{
- vector<uint8_t> v(value.size());
- copy(value.begin(), value.end(), v.begin());
- metadata_[key] = v;
-}
-
-DataFileReaderBase::DataFileReaderBase(const char* filename) :
- filename_(filename), stream_(fileInputStream(filename)),
- decoder_(binaryDecoder()), objectCount_(0)
-{
- readHeader();
-}
-
-void DataFileReaderBase::init()
-{
- readerSchema_ = dataSchema_;
- dataDecoder_ = binaryDecoder();
- readDataBlock();
-}
-
-void DataFileReaderBase::init(const ValidSchema& readerSchema)
-{
- readerSchema_ = readerSchema;
- dataDecoder_ = (toString(readerSchema_) != toString(dataSchema_)) ?
- resolvingDecoder(dataSchema_, readerSchema_, binaryDecoder()) :
- binaryDecoder();
- readDataBlock();
-}
-
-static void drain(InputStream& in)
-{
- const uint8_t *p = 0;
- size_t n = 0;
- while (in.next(&p, &n));
-}
-
-char hex(unsigned int x)
-{
- return x + (x < 10 ? '0' : ('a' - 10));
-}
-
-std::ostream& operator << (std::ostream& os, const DataFileSync& s)
-{
- for (size_t i = 0; i < s.size(); ++i) {
- os << hex(s[i] / 16) << hex(s[i] % 16) << ' ';
- }
- os << std::endl;
- return os;
-}
-
-
-bool DataFileReaderBase::hasMore()
-{
- if (objectCount_ != 0) {
- return true;
- }
- dataDecoder_->init(*dataStream_);
- drain(*dataStream_);
- DataFileSync s;
- decoder_->init(*stream_);
- avro::decode(*decoder_, s);
- if (s != sync_) {
- throw Exception("Sync mismatch");
- }
- return readDataBlock();
-}
-
-class BoundedInputStream : public InputStream {
- InputStream& in_;
- size_t limit_;
-
- bool next(const uint8_t** data, size_t* len) {
- if (limit_ != 0 && in_.next(data, len)) {
- if (*len > limit_) {
- in_.backup(*len - limit_);
- *len = limit_;
- }
- limit_ -= *len;
- return true;
- }
- return false;
- }
-
- void backup(size_t len) {
- in_.backup(len);
- limit_ += len;
- }
-
- void skip(size_t len) {
- if (len > limit_) {
- len = limit_;
- }
- in_.skip(len);
- limit_ -= len;
- }
-
- size_t byteCount() const {
- return in_.byteCount();
- }
-
-public:
- BoundedInputStream(InputStream& in, size_t limit) :
- in_(in), limit_(limit) { }
-};
-
-auto_ptr<InputStream> boundedInputStream(InputStream& in, size_t limit)
-{
- return auto_ptr<InputStream>(new BoundedInputStream(in, limit));
-}
-
-bool DataFileReaderBase::readDataBlock()
-{
- decoder_->init(*stream_);
- const uint8_t* p = 0;
- size_t n = 0;
- if (! stream_->next(&p, &n)) {
- return false;
- }
- stream_->backup(n);
- avro::decode(*decoder_, objectCount_);
- int64_t byteCount;
- avro::decode(*decoder_, byteCount);
- decoder_->init(*stream_);
-
- auto_ptr<InputStream> st = boundedInputStream(*stream_, byteCount);
- dataDecoder_->init(*st);
- dataStream_ = st;
- return true;
-}
-
-void DataFileReaderBase::close()
-{
-}
-
-static string toString(const vector<uint8_t>& v)
-{
- string result;
- result.resize(v.size());
- copy(v.begin(), v.end(), result.begin());
- return result;
-}
-
-static ValidSchema makeSchema(const vector<uint8_t>& v)
-{
- istringstream iss(toString(v));
- ValidSchema vs;
- compileJsonSchema(iss, vs);
- return ValidSchema(vs);
-}
-
-void DataFileReaderBase::readHeader()
-{
- decoder_->init(*stream_);
- Magic m;
- avro::decode(*decoder_, m);
- if (magic != m) {
- throw Exception("Invalid data file. Magic does not match: "
- + filename_);
- }
- avro::decode(*decoder_, metadata_);
- Metadata::const_iterator it = metadata_.find(AVRO_SCHEMA_KEY);
- if (it == metadata_.end()) {
- throw Exception("No schema in metadata");
- }
-
- dataSchema_ = makeSchema(it->second);
- if (! readerSchema_.root()) {
- readerSchema_ = dataSchema();
- }
-
- it = metadata_.find(AVRO_CODEC_KEY);
- if (it != metadata_.end() && toString(it->second) != AVRO_NULL_CODEC) {
- throw Exception("Unknown codec in data file: " + toString(it->second));
- }
-
- avro::decode(*decoder_, sync_);
-}
-
-} // namespace avro
diff --git a/lang/c++/impl/FileStream.cc b/lang/c++/impl/FileStream.cc
index 6ec6220..36d837b 100644
--- a/lang/c++/impl/FileStream.cc
+++ b/lang/c++/impl/FileStream.cc
@@ -113,17 +113,16 @@
size_t available_;
size_t byteCount_;
- // Invaiant: byteCount_ == byteswritten + bufferSize_ - available_;
bool next(uint8_t** data, size_t* len) {
if (available_ == 0) {
flush();
}
*data = next_;
*len = available_;
+ byteCount_ += available_;
next_ += available_;
byteCount_ += available_;
available_ = 0;
- return true;
}
void backup(size_t len) {
@@ -151,7 +150,7 @@
buffer_(new uint8_t[bufferSize]),
out_(::open(filename, O_WRONLY | O_CREAT | O_BINARY, 0644)),
next_(buffer_),
- available_(bufferSize_), byteCount_(0) { }
+ available_(bufferSize_) { }
~FileOutputStream() {
if (out_ >= 0) {
diff --git a/lang/c++/impl/Generic.cc b/lang/c++/impl/Generic.cc
deleted file mode 100644
index cb115e3..0000000
--- a/lang/c++/impl/Generic.cc
+++ /dev/null
@@ -1,437 +0,0 @@
-/**
- * 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 "Generic.hh"
-#include "NodeImpl.hh"
-#include <sstream>
-
-namespace avro {
-
-using std::string;
-using std::vector;
-using std::ostringstream;
-
-typedef vector<uint8_t> bytes;
-
-void GenericContainer::assertType(const NodePtr& schema, Type type,
- const char* message)
-{
- if (schema->type() != type) {
- throw Exception(message);
- }
-}
-
-GenericDatum::GenericDatum(const NodePtr& schema) : type_(schema->type())
-{
- if (type_ == AVRO_SYMBOLIC) {
- type_ = static_cast<NodeSymbolic&>(*schema).type();
- }
- switch (type_) {
- case AVRO_NULL:
- break;
- case AVRO_BOOL:
- value_ = bool();
- break;
- case AVRO_INT:
- value_ = int32_t();
- break;
- case AVRO_LONG:
- value_ = int64_t();
- break;
- case AVRO_FLOAT:
- value_ = float();
- break;
- case AVRO_DOUBLE:
- value_ = double();
- break;
- case AVRO_STRING:
- value_ = string();
- break;
- case AVRO_BYTES:
- value_ = vector<uint8_t>();
- break;
- case AVRO_FIXED:
- value_ = GenericFixed(schema);
- break;
- case AVRO_RECORD:
- value_ = GenericRecord(schema);
- break;
- case AVRO_ENUM:
- value_ = GenericEnum(schema);
- break;
- case AVRO_ARRAY:
- value_ = GenericArray(schema);
- break;
- case AVRO_MAP:
- value_ = GenericMap(schema);
- break;
- case AVRO_UNION:
- throw Exception("Generic datum cannot be a union");
- default:
- throw Exception(boost::format("Unknown schema type %1%") %
- toString(type_));
- }
-}
-
-GenericRecord::GenericRecord(const NodePtr& schema) : GenericContainer(schema) {
- fields_.resize(schema->leaves());
-}
-
-GenericReader::GenericReader(const ValidSchema& s, const DecoderPtr& decoder) :
- schema_(s), isResolving_(dynamic_cast<ResolvingDecoder*>(&(*decoder)) != 0),
- decoder_(decoder)
-{
-}
-
-GenericReader::GenericReader(const ValidSchema& writerSchema,
- const ValidSchema& readerSchema, const DecoderPtr& decoder) :
- schema_(readerSchema),
- isResolving_(true),
- decoder_(resolvingDecoder(writerSchema, readerSchema, decoder))
-{
-}
-
-void GenericReader::read(GenericDatum& datum) const
-{
- read(datum, schema_.root(), *decoder_, isResolving_);
-}
-
-static void ensureType(GenericDatum& datum, const NodePtr& n)
-{
- if (datum.type() != n->type()) {
- switch (n->type()) {
- case AVRO_NULL:
- datum = GenericDatum();
- break;
- case AVRO_BOOL:
- datum = bool();
- break;
- case AVRO_INT:
- datum = int32_t();
- break;
- case AVRO_LONG:
- datum = int64_t();
- break;
- case AVRO_FLOAT:
- datum = float();
- break;
- case AVRO_DOUBLE:
- datum = double();
- break;
- case AVRO_STRING:
- datum = string();
- break;
- case AVRO_BYTES:
- datum = bytes();
- break;
- case AVRO_FIXED:
- case AVRO_RECORD:
- case AVRO_ENUM:
- case AVRO_ARRAY:
- case AVRO_MAP:
- datum = n;
- break;
- case AVRO_UNION:
- break;
- default:
- throw Exception("Unknown schema type");
- }
- }
-}
-
-void GenericReader::read(GenericDatum& datum, const NodePtr& n, Decoder& d,
- bool isResolving)
-{
- NodePtr nn = n;
- if (nn->type() == AVRO_UNION) {
- size_t r = d.decodeUnionIndex();
- nn = nn->leafAt(r);
- }
- if (nn->type() == AVRO_SYMBOLIC) {
- nn = static_cast<NodeSymbolic&>(*nn).getNode();
- }
- ensureType(datum, nn);
- switch (nn->type()) {
- case AVRO_NULL:
- d.decodeNull();
- break;
- case AVRO_BOOL:
- datum.value<bool>() = d.decodeBool();
- break;
- case AVRO_INT:
- datum.value<int32_t>() = d.decodeInt();
- break;
- case AVRO_LONG:
- datum.value<int64_t>() = d.decodeLong();
- break;
- case AVRO_FLOAT:
- datum.value<float>() = d.decodeFloat();
- break;
- case AVRO_DOUBLE:
- datum.value<double>() = d.decodeDouble();
- break;
- case AVRO_STRING:
- d.decodeString(datum.value<string>());
- break;
- case AVRO_BYTES:
- d.decodeBytes(datum.value<bytes>());
- break;
- case AVRO_FIXED:
- d.decodeFixed(nn->fixedSize(), datum.value<GenericFixed>().value());
- break;
- case AVRO_RECORD:
- {
- GenericRecord& r = datum.value<GenericRecord>();
- size_t c = nn->leaves();
- if (isResolving) {
- std::vector<size_t> fo =
- static_cast<ResolvingDecoder&>(d).fieldOrder();
- for (size_t i = 0; i < c; ++i) {
- read(r.fieldAt(fo[i]), nn->leafAt(fo[i]), d, isResolving);
- }
- } else {
- for (size_t i = 0; i < c; ++i) {
- read(r.fieldAt(i), nn->leafAt(i), d, isResolving);
- }
- }
- }
- break;
- case AVRO_ENUM:
- datum.value<GenericEnum>().set(d.decodeEnum());
- break;
- case AVRO_ARRAY:
- {
- vector<GenericDatum>& r = datum.value<GenericArray>().value();
- r.resize(0);
- size_t start = 0;
- for (size_t m = d.arrayStart(); m != 0; m = d.arrayNext()) {
- r.resize(r.size() + m);
- for (; start < r.size(); ++start) {
- read(r[start], nn->leafAt(0), d, isResolving);
- }
- }
- }
- break;
- case AVRO_MAP:
- {
- GenericMap::Value& r = datum.value<GenericMap>().value();
- r.resize(0);
- size_t start = 0;
- for (size_t m = d.mapStart(); m != 0; m = d.mapNext()) {
- r.resize(r.size() + m);
- for (; start < r.size(); ++start) {
- d.decodeString(r[start].first);
- read(r[start].second, nn->leafAt(1), d, isResolving);
- }
- }
- }
- break;
- default:
- throw Exception("Unknown schema type");
- }
-}
-
-void GenericReader::read(Decoder& d, GenericDatum& g, const ValidSchema& s)
-{
- read(g, s.root(), d, dynamic_cast<ResolvingDecoder*>(&d) != 0);
-}
-
-static void typeMismatch(Type t, Type u)
-{
- throw Exception(boost::format("Type mismatch %1% v %2%") %
- toString(t) % toString(u));
-}
-
-template <typename T>
-bool hasSameName(const GenericDatum& datum, const NodePtr& n)
-{
- const T& c = datum.value<T>();
- return c.schema()->name() == n->name();
-}
-
-template <typename T>
-void assertSameType(const GenericDatum& datum, const NodePtr& n)
-{
- const T& c = datum.value<T>();
- if (c.schema() != n) {
- typeMismatch(c.schema()->type(), n->type());
- }
-}
-
-static void assertType(const GenericDatum& datum, const NodePtr& n)
-{
- if (datum.type() == n->type()) {
- switch (n->type()) {
- case AVRO_FIXED:
- assertSameType<GenericFixed>(datum, n);
- return;
- case AVRO_RECORD:
- assertSameType<GenericRecord>(datum, n);
- return;
- case AVRO_ENUM:
- assertSameType<GenericEnum>(datum, n);
- return;
- case AVRO_NULL:
- case AVRO_BOOL:
- case AVRO_INT:
- case AVRO_LONG:
- case AVRO_FLOAT:
- case AVRO_DOUBLE:
- case AVRO_STRING:
- case AVRO_BYTES:
- case AVRO_ARRAY:
- case AVRO_MAP:
- return;
- }
- }
- typeMismatch(datum.type(), n->type());
-}
-
-GenericWriter::GenericWriter(const ValidSchema& s, const EncoderPtr& encoder) :
- schema_(s), encoder_(encoder)
-{
-}
-
-void GenericWriter::write(const GenericDatum& datum) const
-{
- write(datum, schema_.root(), *encoder_);
-}
-
-static size_t selectBranch(const GenericDatum& datum, const NodePtr& n)
-{
- size_t c = n->leaves();
- for (size_t i = 0; i < c; ++i) {
- const NodePtr& nn = n->leafAt(i);
- if (datum.type() == nn->type()) {
- switch (datum.type()) {
- case AVRO_FIXED:
- if (hasSameName<GenericFixed>(datum, nn)) return i;
- break;
- case AVRO_RECORD:
- if (hasSameName<GenericRecord>(datum, nn)) return i;
- break;
- case AVRO_ENUM:
- if (hasSameName<GenericEnum>(datum, nn)) return i;
- break;
- default:
- return i;
- }
- }
- }
- ostringstream oss;
- n->printJson(oss, 0);
- throw Exception(boost::format("No match for %1% in %2%") %
- toString(datum.type()) % oss.str());
-}
-
-void GenericWriter::write(const GenericDatum& datum,
- const NodePtr& n, Encoder& e)
-{
- NodePtr nn = n;
- if (nn->type() == AVRO_UNION) {
- size_t br = selectBranch(datum, nn);
- e.encodeUnionIndex(br);
- nn = nn->leafAt(br);
- }
- if (nn->type() == AVRO_SYMBOLIC) {
- nn = static_cast<NodeSymbolic&>(*nn).getNode();
- }
- assertType(datum, nn);
- switch (nn->type()) {
- case AVRO_NULL:
- e.encodeNull();
- break;
- case AVRO_BOOL:
- e.encodeBool(datum.value<bool>());
- break;
- case AVRO_INT:
- e.encodeInt(datum.value<int32_t>());
- break;
- case AVRO_LONG:
- e.encodeLong(datum.value<int64_t>());
- break;
- case AVRO_FLOAT:
- e.encodeFloat(datum.value<float>());
- break;
- case AVRO_DOUBLE:
- e.encodeDouble(datum.value<double>());
- break;
- case AVRO_STRING:
- e.encodeString(datum.value<string>());
- break;
- case AVRO_BYTES:
- e.encodeBytes(datum.value<bytes>());
- break;
- case AVRO_FIXED:
- e.encodeFixed(datum.value<GenericFixed>().value());
- break;
- case AVRO_RECORD:
- {
- const GenericRecord& r = datum.value<GenericRecord>();
- size_t c = nn->leaves();
- for (size_t i = 0; i < c; ++i) {
- write(r.fieldAt(i), nn->leafAt(i), e);
- }
- }
- break;
- case AVRO_ENUM:
- e.encodeEnum(datum.value<GenericEnum>().value());
- break;
- case AVRO_ARRAY:
- {
- const GenericArray::Value& r = datum.value<GenericArray>().value();
- e.arrayStart();
- if (! r.empty()) {
- e.setItemCount(r.size());
- for (GenericArray::Value::const_iterator it = r.begin();
- it != r.end(); ++it) {
- e.startItem();
- write(*it, nn->leafAt(0), e);
- }
- }
- e.arrayEnd();
- }
- break;
- case AVRO_MAP:
- {
- const GenericMap::Value& r = datum.value<GenericMap>().value();
- e.mapStart();
- if (! r.empty()) {
- e.setItemCount(r.size());
- for (GenericMap::Value::const_iterator it = r.begin();
- it != r.end(); ++it) {
- e.startItem();
- e.encodeString(it->first);
- write(it->second, nn->leafAt(1), e);
- }
- }
- e.mapEnd();
- }
- break;
- default:
- throw Exception("Unknown schema type");
- }
-}
-
-void GenericWriter::write(Encoder& e, const GenericDatum& g,
- const ValidSchema& s)
-{
- write(g, s.root(), e);
-}
-
-} // namespace avro
diff --git a/lang/c++/impl/avrogencpp.cc b/lang/c++/impl/avrogencpp.cc
deleted file mode 100644
index 0f4470f..0000000
--- a/lang/c++/impl/avrogencpp.cc
+++ /dev/null
@@ -1,678 +0,0 @@
-/**
- * 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 <ctype.h>
-#include <sys/time.h>
-#include <iostream>
-#include <fstream>
-#include <map>
-#include <set>
-
-#include <boost/lexical_cast.hpp>
-#include <boost/program_options.hpp>
-
-#include <boost/random/mersenne_twister.hpp>
-#include <boost/random/uniform_int.hpp>
-#include <boost/random/variate_generator.hpp>
-
-#include "Compiler.hh"
-#include "ValidSchema.hh"
-#include "NodeImpl.hh"
-
-using std::ostream;
-using std::ifstream;
-using std::ofstream;
-using std::map;
-using std::set;
-using std::string;
-using std::vector;
-using avro::NodePtr;
-using avro::resolveSymbol;
-
-using boost::lexical_cast;
-
-using avro::ValidSchema;
-using avro::compileJsonSchema;
-
-struct PendingSetterGetter {
- string structName;
- string type;
- string name;
- size_t idx;
-
- PendingSetterGetter(const string& sn, const string& t,
- const string& n, size_t i) :
- structName(sn), type(t), name(n), idx(i) { }
-};
-
-struct PendingConstructor {
- string structName;
- string memberName;
- bool initMember;
- PendingConstructor(const string& sn, const string& n, bool im) :
- structName(sn), memberName(n), initMember(im) { }
-};
-
-class CodeGen {
- size_t unionNumber_;
- std::ostream& os_;
- bool inNamespace_;
- const std::string ns_;
- const std::string headerFile_;
- const std::string schemaFile_;
- boost::mt19937 random_;
-
- vector<PendingSetterGetter> pendingGettersAndSetters;
- vector<PendingConstructor> pendingConstructors;
-
- map<NodePtr, string> done;
- set<NodePtr> doing;
-
- std::string guard();
- std::string fullname(const string& name) const;
- std::string generateEnumType(const NodePtr& n);
- std::string cppTypeOf(const NodePtr& n);
- std::string generateRecordType(const NodePtr& n);
- std::string unionName();
- std::string generateUnionType(const NodePtr& n);
- std::string generateType(const NodePtr& n);
- std::string generateDeclaration(const NodePtr& n);
- std::string doGenerateType(const NodePtr& n);
- void generateEnumTraits(const NodePtr& n);
- void generateTraits(const NodePtr& n);
- void generateRecordTraits(const NodePtr& n);
- void generateUnionTraits(const NodePtr& n);
- void emitCopyright();
-public:
- CodeGen(std::ostream& os, std::string& ns,
- std::string& schemaFile, std::string& headerFile) :
- unionNumber_(0), os_(os), inNamespace_(false), ns_(ns),
- schemaFile_(schemaFile), headerFile_(headerFile),
- random_(::time(0)) { }
- void generate(const ValidSchema& schema);
-};
-
-string CodeGen::fullname(const string& name) const
-{
- return ns_.empty() ? name : (ns_ + "::" + name);
-}
-
-string CodeGen::generateEnumType(const NodePtr& n)
-{
- os_ << "enum " << n->name() << " {\n";
- size_t c = n->names();
- for (int i = 0; i < c; ++i) {
- os_ << " " << n->nameAt(i) << ",\n";
- }
- os_ << "};\n\n";
- return n->name();
-}
-
-string CodeGen::cppTypeOf(const NodePtr& n)
-{
- switch (n->type()) {
- case avro::AVRO_STRING:
- return "std::string";
- case avro::AVRO_BYTES:
- return "std::vector<uint8_t>";
- case avro::AVRO_INT:
- return "int32_t";
- case avro::AVRO_LONG:
- return "int64_t";
- case avro::AVRO_FLOAT:
- return "float";
- case avro::AVRO_DOUBLE:
- return "double";
- case avro::AVRO_BOOL:
- return "bool";
- case avro::AVRO_RECORD:
- case avro::AVRO_ENUM:
- return inNamespace_ ? n->name() : fullname(n->name());
- case avro::AVRO_ARRAY:
- return "std::vector<" + cppTypeOf(n->leafAt(0)) + " >";
- case avro::AVRO_MAP:
- return "std::map<std::string, " + cppTypeOf(n->leafAt(1)) + " >";
- case avro::AVRO_FIXED:
- return "boost::array<uint8_t, " +
- lexical_cast<string>(n->fixedSize()) + ">";
- case avro::AVRO_SYMBOLIC:
- return cppTypeOf(resolveSymbol(n));
- default:
- return "$Undefined$";
- }
-}
-
-static string cppNameOf(const NodePtr& n)
-{
- switch (n->type()) {
- case avro::AVRO_NULL:
- return "null";
- case avro::AVRO_STRING:
- return "string";
- case avro::AVRO_BYTES:
- return "bytes";
- case avro::AVRO_INT:
- return "int";
- case avro::AVRO_LONG:
- return "long";
- case avro::AVRO_FLOAT:
- return "float";
- case avro::AVRO_DOUBLE:
- return "double";
- case avro::AVRO_BOOL:
- return "bool";
- case avro::AVRO_RECORD:
- case avro::AVRO_ENUM:
- case avro::AVRO_FIXED:
- return n->name();
- case avro::AVRO_ARRAY:
- return "array";
- case avro::AVRO_MAP:
- return "map";
- case avro::AVRO_SYMBOLIC:
- return cppNameOf(resolveSymbol(n));
- default:
- return "$Undefined$";
- }
-}
-
-string CodeGen::generateRecordType(const NodePtr& n)
-{
- size_t c = n->leaves();
- vector<string> types;
- for (int i = 0; i < c; ++i) {
- types.push_back(generateType(n->leafAt(i)));
- }
-
- map<NodePtr, string>::const_iterator it = done.find(n);
- if (it != done.end()) {
- return it->second;
- }
-
- os_ << "struct " << n->name() << " {\n";
- for (int i = 0; i < c; ++i) {
- os_ << " " << types[i]
- << " " << n->nameAt(i) << ";\n";
- }
- os_ << "};\n\n";
- return n->name();
-}
-
-void makeCanonical(string& s, bool foldCase)
-{
- for (string::iterator it = s.begin(); it != s.end(); ++it) {
- if (isalpha(*it)) {
- if (foldCase) {
- *it = toupper(*it);
- }
- } else if (! isdigit(*it)) {
- *it = '_';
- }
- }
-}
-
-string CodeGen::unionName()
-{
- string s = schemaFile_;
- string::size_type n = s.find_last_of("/\\");
- if (n != string::npos) {
- s = s.substr(n);
- }
- makeCanonical(s, false);
-
- return s + "_Union__" + boost::lexical_cast<string>(unionNumber_++) + "__";
-}
-
-static void generateGetterAndSetter(ostream& os,
- const string& structName, const string& type, const string& name,
- size_t idx)
-{
- string sn = " " + structName + "::";
-
- os << "inline\n";
-
- os << type << sn << "get_" << name << "() const {\n"
- << " if (idx_ != " << idx << ") {\n"
- << " throw avro::Exception(\"Invalid type for "
- << "union\");\n"
- << " }\n"
- << " return boost::any_cast<" << type << " >(value_);\n"
- << "}\n\n";
-
- os << "void" << sn << "set_" << name
- << "(const " << type << "& v) {\n"
- << " idx_ = " << idx << ";\n"
- << " value_ = v;\n"
- << "}\n\n";
-}
-
-static void generateConstructor(ostream& os,
- const string& structName, bool initMember,
- const string& type) {
- os << "inline " << structName << "::" << structName << "() : idx_(0)";
- if (initMember) {
- os << ", value_(" << type << "())";
- }
- os << " { }\n";
-}
-
-/**
- * Generates a type for union and emits the code.
- * Since unions can encounter names that are not fully defined yet,
- * such names must be declared and the inline functions deferred until all
- * types are fully defined.
- */
-string CodeGen::generateUnionType(const NodePtr& n)
-{
- size_t c = n->leaves();
- vector<string> types;
- vector<string> names;
-
- set<NodePtr>::const_iterator it = doing.find(n);
- if (it != doing.end()) {
- for (size_t i = 0; i < c; ++i) {
- const NodePtr& nn = n->leafAt(i);
- types.push_back(generateDeclaration(nn));
- names.push_back(cppNameOf(nn));
- }
- } else {
- doing.insert(n);
- for (size_t i = 0; i < c; ++i) {
- const NodePtr& nn = n->leafAt(i);
- types.push_back(generateType(nn));
- names.push_back(cppNameOf(nn));
- }
- doing.erase(n);
- }
- if (done.find(n) != done.end()) {
- return done[n];
- }
-
- const string result = unionName();
-
- os_ << "struct " << result << " {\n"
- << "private:\n"
- << " size_t idx_;\n"
- << " boost::any value_;\n"
- << "public:\n"
- << " size_t idx() const { return idx_; }\n";
-
- for (size_t i = 0; i < c; ++i) {
- const NodePtr& nn = n->leafAt(i);
- if (nn->type() == avro::AVRO_NULL) {
- os_ << " void set_null() {\n"
- << " idx_ = " << i << ";\n"
- << " value_ = boost::any();\n"
- << " }\n";
- } else {
- const string& type = types[i];
- const string& name = names[i];
- os_ << " " << type << " get_" << name << "() const;\n"
- " void set_" << name << "(const " << type << "& v);\n";
- pendingGettersAndSetters.push_back(
- PendingSetterGetter(result, type, name, i));
- }
- }
-
- os_ << " " << result << "();\n";
- pendingConstructors.push_back(PendingConstructor(result, types[0],
- n->leafAt(0)->type() != avro::AVRO_NULL));
- os_ << "};\n\n";
-
- return result;
-}
-
-/**
- * Returns the type for the given schema node and emits code to os.
- */
-string CodeGen::generateType(const NodePtr& n)
-{
- NodePtr nn = (n->type() == avro::AVRO_SYMBOLIC) ? resolveSymbol(n) : n;
-
- map<NodePtr, string>::const_iterator it = done.find(nn);
- if (it != done.end()) {
- return it->second;
- }
- string result = doGenerateType(nn);
- done[nn] = result;
- return result;
-}
-
-string CodeGen::doGenerateType(const NodePtr& n)
-{
- switch (n->type()) {
- case avro::AVRO_STRING:
- case avro::AVRO_BYTES:
- case avro::AVRO_INT:
- case avro::AVRO_LONG:
- case avro::AVRO_FLOAT:
- case avro::AVRO_DOUBLE:
- case avro::AVRO_BOOL:
- case avro::AVRO_NULL:
- case avro::AVRO_FIXED:
- return cppTypeOf(n);
- case avro::AVRO_ARRAY:
- return "std::vector<" + generateType(n->leafAt(0)) + " >";
- case avro::AVRO_MAP:
- return "std::map<std::string, " + generateType(n->leafAt(1)) + " >";
- case avro::AVRO_RECORD:
- return generateRecordType(n);
- case avro::AVRO_ENUM:
- return generateEnumType(n);
- case avro::AVRO_UNION:
- return generateUnionType(n);
- }
- return "$Undefuned$";
-}
-
-string CodeGen::generateDeclaration(const NodePtr& n)
-{
- NodePtr nn = (n->type() == avro::AVRO_SYMBOLIC) ? resolveSymbol(n) : n;
- switch (nn->type()) {
- case avro::AVRO_STRING:
- case avro::AVRO_BYTES:
- case avro::AVRO_INT:
- case avro::AVRO_LONG:
- case avro::AVRO_FLOAT:
- case avro::AVRO_DOUBLE:
- case avro::AVRO_BOOL:
- case avro::AVRO_NULL:
- case avro::AVRO_FIXED:
- return cppTypeOf(nn);
- case avro::AVRO_ARRAY:
- return "std::vector<" + generateDeclaration(nn->leafAt(0)) + " >";
- case avro::AVRO_MAP:
- return "std::map<std::string, " +
- generateDeclaration(nn->leafAt(1)) + " >";
- case avro::AVRO_RECORD:
- os_ << "struct " << cppTypeOf(nn) << ";\n";
- return cppTypeOf(nn);
- case avro::AVRO_ENUM:
- return generateEnumType(nn);
- case avro::AVRO_UNION:
- // FIXME: When can this happen?
- return generateUnionType(nn);
- }
- return "$Undefuned$";
-}
-
-void CodeGen::generateEnumTraits(const NodePtr& n)
-{
- string fn = fullname(n->name());
- os_ << "template<> struct codec_traits<" << fn << "> {\n"
- << " static void encode(Encoder& e, " << fn << " v) {\n"
- << " e.encodeEnum(v);\n"
- << " }\n"
- << " static void decode(Decoder& d, " << fn << "& v) {\n"
- << " v = static_cast<" << fn << ">(d.decodeEnum());\n"
- << " }\n"
- << "};\n\n";
-}
-
-void CodeGen::generateRecordTraits(const NodePtr& n)
-{
- size_t c = n->leaves();
- for (int i = 0; i < c; ++i) {
- generateTraits(n->leafAt(i));
- }
-
- string fn = fullname(n->name());
- os_ << "template<> struct codec_traits<" << fn << "> {\n"
- << " static void encode(Encoder& e, const " << fn << "& v) {\n";
-
- for (size_t i = 0; i < c; ++i) {
- os_ << " avro::encode(e, v." << n->nameAt(i) << ");\n";
- }
-
- os_ << " }\n"
- << " static void decode(Decoder& d, " << fn << "& v) {\n";
-
- for (size_t i = 0; i < c; ++i) {
- os_ << " avro::decode(d, v." << n->nameAt(i) << ");\n";
- }
-
- os_ << " }\n"
- << "};\n\n";
-}
-
-void CodeGen::generateUnionTraits(const NodePtr& n)
-{
- size_t c = n->leaves();
-
- for (size_t i = 0; i < c; ++i) {
- const NodePtr& nn = n->leafAt(i);
- generateTraits(nn);
- }
-
- string name = done[n];
- string fn = fullname(name);
-
- os_ << "template<> struct codec_traits<" << fn << "> {\n"
- << " static void encode(Encoder& e, " << fn << " v) {\n"
- << " e.encodeUnionIndex(v.idx());\n"
- << " switch (v.idx()) {\n";
-
- for (size_t i = 0; i < c; ++i) {
- const NodePtr& nn = n->leafAt(i);
- os_ << " case " << i << ":\n";
- if (nn->type() == avro::AVRO_NULL) {
- os_ << " e.encodeNull();\n";
- } else {
- os_ << " avro::encode(e, v.get_" << cppNameOf(nn)
- << "());\n";
- }
- os_ << " break;\n";
- }
-
- os_ << " }\n"
- << " }\n"
- << " static void decode(Decoder& d, " << fn << "& v) {\n"
- << " size_t n = d.decodeUnionIndex();\n"
- << " if (n >= " << c << ") { throw avro::Exception(\""
- "Union index too big\"); }\n"
- << " switch (n) {\n";
-
- for (size_t i = 0; i < c; ++i) {
- const NodePtr& nn = n->leafAt(i);
- os_ << " case " << i << ":\n";
- if (nn->type() == avro::AVRO_NULL) {
- os_ << " d.decodeNull();\n"
- << " v.set_null();\n";
- } else {
- os_ << " {\n"
- << " " << cppTypeOf(nn) << " vv;\n"
- << " avro::decode(d, vv);\n"
- << " v.set_" << cppNameOf(nn) << "(vv);\n"
- << " }\n";
- }
- os_ << " break;\n";
- }
- os_ << " }\n"
- << " }\n"
- << "};\n\n";
-}
-
-void CodeGen::generateTraits(const NodePtr& n)
-{
- switch (n->type()) {
- case avro::AVRO_STRING:
- case avro::AVRO_BYTES:
- case avro::AVRO_INT:
- case avro::AVRO_LONG:
- case avro::AVRO_FLOAT:
- case avro::AVRO_DOUBLE:
- case avro::AVRO_BOOL:
- case avro::AVRO_NULL:
- break;
- case avro::AVRO_RECORD:
- generateRecordTraits(n);
- break;
- case avro::AVRO_ENUM:
- generateEnumTraits(n);
- break;
- case avro::AVRO_ARRAY:
- case avro::AVRO_MAP:
- generateTraits(n->leafAt(n->type() == avro::AVRO_ARRAY ? 0 : 1));
- break;
- case avro::AVRO_UNION:
- generateUnionTraits(n);
- break;
- case avro::AVRO_FIXED:
- break;
- }
-}
-
-void CodeGen::emitCopyright()
-{
- os_ <<
- "/**\n"
- " * Licensed to the Apache Software Foundation (ASF) under one\n"
- " * or more contributor license agreements. See the NOTICE file\n"
- " * distributed with this work for additional information\n"
- " * regarding copyright ownership. The ASF licenses this file\n"
- " * to you under the Apache License, Version 2.0 (the\n"
- " * \"License\"); you may not use this file except in compliance\n"
- " * with the License. You may obtain a copy of the License at\n"
- " *\n"
- " * http://www.apache.org/licenses/LICENSE-2.0\n"
- " *\n"
- " * Unless required by applicable law or agreed to in writing, "
- "software\n"
- " * distributed under the License is distributed on an "
- "\"AS IS\" BASIS,\n"
- " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express "
- "or implied.\n"
- " * See the License for the specific language governing "
- "permissions and\n"
- " * limitations under the License.\n"
- " */\n\n\n";
-}
-
-string CodeGen::guard()
-{
- string h = headerFile_;
- makeCanonical(h, true);
- return h + "_" + lexical_cast<string>(random_()) + "__H_";
-}
-
-void CodeGen::generate(const ValidSchema& schema)
-{
- emitCopyright();
-
- string h = guard();
-
- os_ << "#ifndef " << h << "\n";
- os_ << "#define " << h << "\n\n\n";
-
- os_ << "#include \"boost/any.hpp\"\n"
- << "#include \"Specific.hh\"\n"
- << "#include \"Encoder.hh\"\n"
- << "#include \"Decoder.hh\"\n";
-
- if (! ns_.empty()) {
- os_ << "namespace " << ns_ << " {\n";
- inNamespace_ = true;
- }
-
- const NodePtr& root = schema.root();
- generateType(root);
-
- for (vector<PendingSetterGetter>::const_iterator it =
- pendingGettersAndSetters.begin();
- it != pendingGettersAndSetters.end(); ++it) {
- generateGetterAndSetter(os_, it->structName, it->type, it->name,
- it->idx);
- }
-
- for (vector<PendingConstructor>::const_iterator it =
- pendingConstructors.begin();
- it != pendingConstructors.end(); ++it) {
- generateConstructor(os_, it->structName,
- it->initMember, it->memberName);
- }
-
- if (! ns_.empty()) {
- inNamespace_ = false;
- os_ << "}\n";
- }
-
- os_ << "namespace avro {\n";
-
- unionNumber_ = 0;
-
- generateTraits(root);
-
- os_ << "}\n";
-
- os_ << "#endif\n";
- os_.flush();
-
-}
-
-namespace po = boost::program_options;
-
-string NS("namespace");
-string OUT("output");
-string IN("input");
-
-int main(int argc, char** argv)
-{
- po::options_description desc("Allowed options");
- desc.add_options()
- ("help,h", "produce help message")
- ("namespace,n", po::value<string>(), "set namespace for generated code")
- ("input,i", po::value<string>(), "input file")
- ("output,o", po::value<string>(), "output file to generate");
-
- po::variables_map vm;
- po::store(po::parse_command_line(argc, argv, desc), vm);
- po::notify(vm);
-
-
- if (vm.count("help") || vm.count(IN) == 0 || vm.count(OUT) == 0) {
- std::cout << desc << std::endl;
- return 1;
- }
-
- string ns = vm.count(NS) > 0 ? vm[NS].as<string>() : string();
- string outf = vm[OUT].as<string>();
- string inf = vm[IN].as<string>();
- try {
- ValidSchema schema;
-
- if (! inf.empty()) {
- ifstream in(inf.c_str());
- compileJsonSchema(in, schema);
- } else {
- compileJsonSchema(std::cin, schema);
- }
-
- if (! outf.empty()) {
- ofstream out(outf.c_str());
- CodeGen(out, ns, inf, outf).generate(schema);
- } else {
- CodeGen(std::cout, ns, inf, outf).generate(schema);
- }
- return 0;
- } catch (std::exception &e) {
- std::cerr << "Failed to parse or compile schema: "
- << e.what() << std::endl;
- return 1;
- }
-
-}
diff --git a/lang/c++/impl/parsing/ResolvingDecoder.cc b/lang/c++/impl/parsing/ResolvingDecoder.cc
index 82f7174..2e04ea3 100644
--- a/lang/c++/impl/parsing/ResolvingDecoder.cc
+++ b/lang/c++/impl/parsing/ResolvingDecoder.cc
@@ -450,7 +450,6 @@
void ResolvingDecoderImpl<P>::init(InputStream& is)
{
base_->init(is);
- parser_.reset();
}
template <typename P>
diff --git a/lang/c++/impl/parsing/Symbol.hh b/lang/c++/impl/parsing/Symbol.hh
index 4a5e625..e99625b 100644
--- a/lang/c++/impl/parsing/Symbol.hh
+++ b/lang/c++/impl/parsing/Symbol.hh
@@ -693,12 +693,6 @@
parsingStack.push(s);
}
- void reset() {
- while (parsingStack.size() > 1) {
- parsingStack.pop();
- }
- }
-
};
} // namespace parsing
diff --git a/lang/c++/jsonschemas/circulardep b/lang/c++/jsonschemas/circulardep
deleted file mode 100644
index a5d1a48..0000000
--- a/lang/c++/jsonschemas/circulardep
+++ /dev/null
@@ -1,33 +0,0 @@
-{
- "type" : "record",
- "name" : "Item",
- "fields" : [ {
- "name" : "id",
- "type" : "string",
- "ctor" : "true"
- },
- {
- "name" : "entities",
- "type" :
- [ "null", {
- "type" : "record",
- "name" : "Information",
- "fields" : [ {
- "name" : "id",
- "type" : "string"
- }, {
- "name" : "externalItem",
- "type" : "Item"
- }, {
- "name" : "innerUnion",
- "type" : ["int", "double"]
- }
- ]
-
- }
- ]
-
- }
-]
-}
-
diff --git a/lang/c++/jsonschemas/recursive b/lang/c++/jsonschemas/recursive
deleted file mode 100644
index 6542701..0000000
--- a/lang/c++/jsonschemas/recursive
+++ /dev/null
@@ -1,9 +0,0 @@
-{
- "type": "record",
- "name": "LongList",
- "aliases": ["LinkedLongs"],
- "fields" : [
- { "name": "value", "type": "long" },
- { "name": "next", "type": ["LongList", "null"] }
- ]
-}
diff --git a/lang/c++/jsonschemas/reuse b/lang/c++/jsonschemas/reuse
deleted file mode 100644
index d6487f4..0000000
--- a/lang/c++/jsonschemas/reuse
+++ /dev/null
@@ -1,14 +0,0 @@
-{
- "type": "record",
- "name": "outer",
- "fields" : [
- { "name": "f1", "type":
- {"type": "record", "name": "F",
- "fields": [
- { "name": "g1", "type": "boolean" },
- { "name": "g2", "type": "int" }
- ]
- } },
- { "name": "f2", "type": "F" }
- ]
-}
diff --git a/lang/c++/jsonschemas/union_array_union b/lang/c++/jsonschemas/union_array_union
deleted file mode 100644
index 0f85142..0000000
--- a/lang/c++/jsonschemas/union_array_union
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "type": "record",
- "name": "r1",
- "fields" : [
- {"name": "id", "type": "string"},
- {"name": "val", "type": [{"type": "array", "items": {"name": "r3", "type": "record", "fields": [{"name": "name", "type": "string"}, {"name": "data", "type": "bytes"}, {"name": "rev", "type": ["string", "null"]}]}}, "null"]}
- ]
-}
diff --git a/lang/c++/jsonschemas/union_map_union b/lang/c++/jsonschemas/union_map_union
deleted file mode 100644
index 5258c09..0000000
--- a/lang/c++/jsonschemas/union_map_union
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "type": "record",
- "name": "r1",
- "fields" : [
- {"name": "id", "type": "string"},
- {"name": "val", "type": [{"type": "map", "values": {"name": "r3", "type": "record", "fields": [{"name": "name", "type": "string"}, {"name": "data", "type": "bytes"}, {"name": "rev", "type": ["string", "null"]}]}}, "null"]}
- ]
-}
diff --git a/lang/c++/parser/AvroLex.ll b/lang/c++/parser/AvroLex.ll
index a666d86..4f13a22 100644
--- a/lang/c++/parser/AvroLex.ll
+++ b/lang/c++/parser/AvroLex.ll
@@ -109,7 +109,7 @@
<READFIELD>\"name\"{delim}\" yy_push_state(READFIELDNAME);
<READFIELD>\} yy_pop_state(); return AVRO_LEX_FIELD_END;
<READFIELD>, return yytext[0];
-<READFIELD>\"{avrotext}\"+{delim} yy_push_state(READMETADATA); return AVRO_LEX_METADATA;
+<READFIELD>{avrotext}+{delim} yy_push_state(READMETADATA); return AVRO_LEX_METADATA;
<READFIELD>{ws} ;
<READFIELDS>\{ yy_push_state(READFIELD); return AVRO_LEX_FIELD;
@@ -158,7 +158,7 @@
<INOBJECT>\"symbols\"{delim}\[ yy_push_state(READSYMBOLS); return AVRO_LEX_SYMBOLS;
<INOBJECT>, return yytext[0];
<INOBJECT>\} yy_pop_state(); return yytext[0];
-<INOBJECT>\"{avrotext}+\"{delim} yy_push_state(READMETADATA); return AVRO_LEX_METADATA;
+<INOBJECT>{avrotext}+{delim} yy_push_state(READMETADATA); return AVRO_LEX_METADATA;
<INOBJECT>{ws} ;
<STARTTYPE>\" yy_pop_state(); yy_push_state(READTYPE);
diff --git a/lang/c++/test/AvrogencppTests.cc b/lang/c++/test/AvrogencppTests.cc
deleted file mode 100644
index a13a526..0000000
--- a/lang/c++/test/AvrogencppTests.cc
+++ /dev/null
@@ -1,194 +0,0 @@
-/**
- * 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 "bigrecord.hh"
-#include "bigrecord2.hh"
-#include "union_array_union.hh"
-#include "union_map_union.hh"
-#include "recursive.hh"
-#include "circulardep.hh"
-#include "reuse.hh"
-#include "Compiler.hh"
-
-#include <fstream>
-#include <boost/test/included/unit_test_framework.hpp>
-
-using std::auto_ptr;
-using std::map;
-using std::string;
-using std::vector;
-using std::ifstream;
-
-using avro::ValidSchema;
-using avro::OutputStream;
-using avro::InputStream;
-using avro::Encoder;
-using avro::Decoder;
-using avro::EncoderPtr;
-using avro::DecoderPtr;
-using avro::memoryInputStream;
-using avro::memoryOutputStream;
-using avro::binaryEncoder;
-using avro::validatingEncoder;
-using avro::binaryDecoder;
-using avro::validatingDecoder;
-
-void setRecord(testgen::RootRecord &myRecord)
-{
- uint8_t fixed[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
-
- myRecord.mylong = 212;
- myRecord.nestedrecord.inval1 = std::numeric_limits<double>::min();
- myRecord.nestedrecord.inval2 = "hello world";
- myRecord.nestedrecord.inval3 = std::numeric_limits<int32_t>::max();
-
- myRecord.mymap["one"] = 100;
- myRecord.mymap["two"] = 200;
-
- myRecord.myarray.push_back(3434.9);
- myRecord.myarray.push_back(7343.9);
- myRecord.myarray.push_back(-63445.9);
- myRecord.myenum = testgen::one;
-
- map<string, int32_t> m;
- m["one"] = 1;
- m["two"] = 2;
- myRecord.myunion.set_map(m);
-
- vector<uint8_t> v;
- v.push_back(1);
- v.push_back(2);
- myRecord.anotherunion.set_bytes(v);
-
- myRecord.mybool = true;
- myRecord.anothernested.inval1 = std::numeric_limits<double>::max();
- myRecord.anothernested.inval2 = "goodbye world";
- myRecord.anothernested.inval3 = std::numeric_limits<int32_t>::min();
- memcpy(&myRecord.myfixed[0], fixed, myRecord.myfixed.size());
- myRecord.anotherint = 4534;
- myRecord.bytes.push_back(10);
- myRecord.bytes.push_back(20);
-}
-
-void check(const testgen::RootRecord& r1, const testgen::RootRecord& r2)
-{
- BOOST_CHECK_EQUAL(r1.mylong, r2.mylong);
- BOOST_CHECK_EQUAL(r1.nestedrecord.inval1, r2.nestedrecord.inval1);
- BOOST_CHECK_EQUAL(r1.nestedrecord.inval2, r2.nestedrecord.inval2);
- BOOST_CHECK_EQUAL(r1.nestedrecord.inval3, r2.nestedrecord.inval3);
- BOOST_CHECK(r1.mymap == r2.mymap);
- BOOST_CHECK(r1.myarray == r2.myarray);
- BOOST_CHECK_EQUAL(r1.myunion.idx(), r2.myunion.idx());
- BOOST_CHECK(r1.myunion.get_map() == r2.myunion.get_map());
- BOOST_CHECK_EQUAL(r1.anotherunion.idx(), r2.anotherunion.idx());
- BOOST_CHECK(r1.anotherunion.get_bytes() == r2.anotherunion.get_bytes());
- BOOST_CHECK_EQUAL(r1.mybool, r2.mybool);
- BOOST_CHECK_EQUAL(r1.anothernested.inval1, r2.anothernested.inval1);
- BOOST_CHECK_EQUAL(r1.anothernested.inval2, r2.anothernested.inval2);
- BOOST_CHECK_EQUAL(r1.anothernested.inval3, r2.anothernested.inval3);
- BOOST_CHECK_EQUAL_COLLECTIONS(r1.myfixed.begin(), r1.myfixed.end(),
- r2.myfixed.begin(), r2.myfixed.end());
- BOOST_CHECK_EQUAL(r1.anotherint, r2.anotherint);
- BOOST_CHECK_EQUAL_COLLECTIONS(r1.bytes.begin(), r1.bytes.end(),
- r2.bytes.begin(), r2.bytes.end());
-}
-
-void testEncoding()
-{
- ValidSchema s;
- ifstream ifs("jsonschemas/bigrecord");
- compileJsonSchema(ifs, s);
- auto_ptr<OutputStream> os = memoryOutputStream();
- EncoderPtr e = validatingEncoder(s, binaryEncoder());
- e->init(*os);
- testgen::RootRecord t1;
- setRecord(t1);
- avro::encode(*e, t1);
- e->flush();
-
- DecoderPtr d = validatingDecoder(s, binaryDecoder());
- auto_ptr<InputStream> is = memoryInputStream(*os);
- d->init(*is);
- testgen::RootRecord t2;
- avro::decode(*d, t2);
-
- check(t2, t1);
-}
-
-void setRecord(uau::r1& r)
-{
-}
-
-void check(const uau::r1& r1, const uau::r1& r2)
-{
-
-}
-
-void setRecord(umu::r1& r)
-{
-}
-
-void check(const umu::r1& r1, const umu::r1& r2)
-{
-
-}
-
-template <typename T> struct schemaFilename { };
-template <> struct schemaFilename<uau::r1> {
- static const char value[];
-};
-const char schemaFilename<uau::r1>::value[] = "jsonschemas/union_array_union";
-template <> struct schemaFilename<umu::r1> {
- static const char value[];
-};
-const char schemaFilename<umu::r1>::value[] = "jsonschemas/union_map_union";
-
-template<typename T>
-void testEncoding2()
-{
- ValidSchema s;
- ifstream ifs(schemaFilename<T>::value);
- compileJsonSchema(ifs, s);
-
- auto_ptr<OutputStream> os = memoryOutputStream();
- EncoderPtr e = validatingEncoder(s, binaryEncoder());
- e->init(*os);
- T t1;
- setRecord(t1);
- avro::encode(*e, t1);
- e->flush();
-
- DecoderPtr d = validatingDecoder(s, binaryDecoder());
- auto_ptr<InputStream> is = memoryInputStream(*os);
- d->init(*is);
- T t2;
- avro::decode(*d, t2);
-
- check(t2, t1);
-}
-
-boost::unit_test::test_suite*
-init_unit_test_suite(int argc, char* argv[])
-{
- boost::unit_test::test_suite* ts = BOOST_TEST_SUITE("Code generator tests");
- ts->add(BOOST_TEST_CASE(testEncoding));
- ts->add(BOOST_TEST_CASE(testEncoding2<uau::r1>));
- ts->add(BOOST_TEST_CASE(testEncoding2<umu::r1>));
- return ts;
-}
-
diff --git a/lang/c++/test/CodecTests.cc b/lang/c++/test/CodecTests.cc
index 76fe25a..b9cb555 100644
--- a/lang/c++/test/CodecTests.cc
+++ b/lang/c++/test/CodecTests.cc
@@ -22,7 +22,6 @@
#include "Decoder.hh"
#include "Compiler.hh"
#include "ValidSchema.hh"
-#include "Generic.hh"
#include <stdint.h>
#include <vector>
@@ -54,14 +53,6 @@
* To test Json encoder and decoder, we use the same technqiue with only
* one difference - we use JsonEncoder and JsonDecoder.
*
- * We also use the same infrastructure to test GenericReader and GenericWriter.
- * In this case, avro binary is generated in the standard way. It is read
- * into a GenericDatum, which in turn is written out. This newly serialized
- * data is decoded in the standard way to check that it is what is written. The
- * last step won't work if there is schema for reading is different from
- * that for writing. This is because any reordering of fields would have
- * got fixed by the GenericDatum's decoding and encoding step.
- *
* For most tests, the data is generated at random.
*/
@@ -620,7 +611,7 @@
<< " schema: " << td.schema
<< " calls: " << td.calls
<< " skip-level: " << skipLevel << std::endl;
- */
+ */
BOOST_TEST_CHECKPOINT("Test: " << testNo << ' '
<< " schema: " << td.schema
<< " calls: " << td.calls
@@ -745,128 +736,6 @@
td.incorrectCalls, v, p), Exception);
}
-template<typename CodecFactory>
-void testGeneric(const TestData& td) {
- static int testNo = 0;
- testNo++;
-
- ValidSchema vs = makeValidSchema(td.schema);
-
- for (unsigned int i = 0; i < count; ++i) {
- vector<string> v;
- auto_ptr<OutputStream> p;
- testEncoder(CodecFactory::newEncoder(vs), td.calls, v, p);
- // dump(*p);
- DecoderPtr d1 = CodecFactory::newDecoder(vs);
- auto_ptr<InputStream> in1 = memoryInputStream(*p);
- d1->init(*in1);
- GenericReader gr(vs, d1);
- GenericDatum datum;
- gr.read(datum);
-
- EncoderPtr e2 = CodecFactory::newEncoder(vs);
- auto_ptr<OutputStream> ob = memoryOutputStream();
- e2->init(*ob);
-
- GenericWriter gw(vs, e2);
- gw.write(datum);
- e2->flush();
-
- BOOST_TEST_CHECKPOINT("Test: " << testNo << ' '
- << " schema: " << td.schema
- << " calls: " << td.calls);
- auto_ptr<InputStream> in2 = memoryInputStream(*ob);
- testDecoder(CodecFactory::newDecoder(vs), v, *in2,
- td.calls, td.depth);
- }
-}
-
-template<typename CodecFactory>
-void testGenericResolving(const TestData3& td) {
- static int testNo = 0;
- testNo++;
-
- BOOST_TEST_CHECKPOINT("Test: " << testNo << ' '
- << " writer schema: " << td.writerSchema
- << " writer calls: " << td.writerCalls
- << " reader schema: " << td.readerSchema
- << " reader calls: " << td.readerCalls);
-
- ValidSchema wvs = makeValidSchema(td.writerSchema);
- ValidSchema rvs = makeValidSchema(td.readerSchema);
-
- for (unsigned int i = 0; i < count; ++i) {
- vector<string> v;
- auto_ptr<OutputStream> p;
- testEncoder(CodecFactory::newEncoder(wvs), td.writerCalls, v, p);
- // dump(*p);
- DecoderPtr d1 = CodecFactory::newDecoder(wvs);
- auto_ptr<InputStream> in1 = memoryInputStream(*p);
- d1->init(*in1);
-
- GenericReader gr(wvs, rvs, d1);
- GenericDatum datum;
- gr.read(datum);
-
- EncoderPtr e2 = CodecFactory::newEncoder(rvs);
- auto_ptr<OutputStream> ob = memoryOutputStream();
- e2->init(*ob);
-
- GenericWriter gw(rvs, e2);
- gw.write(datum);
- e2->flush();
-
- BOOST_TEST_CHECKPOINT("Test: " << testNo << ' '
- << " writer-schemai " << td.writerSchema
- << " writer-calls: " << td.writerCalls
- << " reader-schema: " << td.readerSchema
- << " calls: " << td.readerCalls);
- auto_ptr<InputStream> in2 = memoryInputStream(*ob);
- testDecoder(CodecFactory::newDecoder(rvs), v, *in2,
- td.readerCalls, td.depth);
- }
-}
-
-template<typename CodecFactory>
-void testGenericResolving2(const TestData4& td) {
- static int testNo = 0;
- testNo++;
-
- BOOST_TEST_CHECKPOINT("Test: " << testNo << ' '
- << " writer schema: " << td.writerSchema
- << " writer calls: " << td.writerCalls
- << " reader schema: " << td.readerSchema
- << " reader calls: " << td.readerCalls);
-
- ValidSchema wvs = makeValidSchema(td.writerSchema);
- ValidSchema rvs = makeValidSchema(td.readerSchema);
-
- const vector<string> wd = mkValues(td.writerValues);
-
- auto_ptr<OutputStream> p = generate(*CodecFactory::newEncoder(wvs),
- td.writerCalls, wd);
- // dump(*p);
- DecoderPtr d1 = CodecFactory::newDecoder(wvs);
- auto_ptr<InputStream> in1 = memoryInputStream(*p);
- d1->init(*in1);
-
- GenericReader gr(wvs, rvs, d1);
- GenericDatum datum;
- gr.read(datum);
-
- EncoderPtr e2 = CodecFactory::newEncoder(rvs);
- auto_ptr<OutputStream> ob = memoryOutputStream();
- e2->init(*ob);
-
- GenericWriter gw(rvs, e2);
- gw.write(datum);
- e2->flush();
- // We cannot verify with the reader calls because they are for
- // the resolving decoder and hence could be in a different order than
- // the "normal" data.
-}
-
-
static const TestData data[] = {
{ "\"null\"", "N", 1 },
{ "\"boolean\"", "B", 1 },
@@ -1393,10 +1262,6 @@
testCodecResolving2, data4);
ADD_TESTS(ts, ValidatingEncoderResolvingDecoderFactory,
testCodecResolving2, data4);
-
- ADD_TESTS(ts, ValidatingCodecFactory, testGeneric, data);
- ADD_TESTS(ts, ValidatingCodecFactory, testGenericResolving, data3);
- ADD_TESTS(ts, ValidatingCodecFactory, testGenericResolving2, data4);
}
} // namespace parsing
diff --git a/lang/c++/test/DataFileTests.cc b/lang/c++/test/DataFileTests.cc
deleted file mode 100644
index cfe96bc..0000000
--- a/lang/c++/test/DataFileTests.cc
+++ /dev/null
@@ -1,366 +0,0 @@
-/**
- * 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 <boost/test/included/unit_test_framework.hpp>
-#include <boost/test/unit_test.hpp>
-#include <boost/filesystem.hpp>
-
-#include <sstream>
-
-#include "DataFile.hh"
-#include "Generic.hh"
-#include "Stream.hh"
-#include "Compiler.hh"
-
-using std::auto_ptr;
-using std::string;
-using std::pair;
-using std::vector;
-using std::map;
-using std::istringstream;
-using std::ostringstream;
-
-using boost::array;
-using boost::shared_ptr;
-using boost::unit_test::test_suite;
-
-
-using avro::ValidSchema;
-using avro::GenericDatum;
-using avro::GenericRecord;
-
-template <typename T>
-struct Complex {
- T re;
- T im;
- Complex() : re(0), im(0) { }
- Complex(T r, T i) : re(r), im(i) { }
-};
-
-struct Integer {
- int64_t re;
- Integer() : re(0) { }
- Integer(int64_t r) : re(r) { }
-};
-
-typedef Complex<int64_t> ComplexInteger;
-typedef Complex<double> ComplexDouble;
-
-struct Double {
- double re;
- Double() : re(0) { }
- Double(double r) : re(r) { }
-};
-
-namespace avro {
-
-template <typename T> struct codec_traits<Complex<T> > {
- static void encode(Encoder& e, const Complex<T>& c) {
- avro::encode(e, c.re);
- avro::encode(e, c.im);
- }
-
- static void decode(Decoder& d, Complex<T>& c) {
- avro::decode(d, c.re);
- avro::decode(d, c.im);
- }
-};
-
-template <> struct codec_traits<Integer> {
- static void decode(Decoder& d, Integer& c) {
- avro::decode(d, c.re);
- }
-};
-
-template <> struct codec_traits<Double> {
- static void decode(Decoder& d, Double& c) {
- avro::decode(d, c.re);
- }
-};
-
-}
-
-static ValidSchema makeValidSchema(const char* schema)
-{
- istringstream iss(schema);
- ValidSchema vs;
- compileJsonSchema(iss, vs);
- return ValidSchema(vs);
-}
-
-static const char sch[] = "{\"type\": \"record\","
- "\"name\":\"ComplexInteger\", \"fields\": ["
- "{\"name\":\"re\", \"type\":\"long\"},"
- "{\"name\":\"im\", \"type\":\"long\"}"
- "]}";
-static const char isch[] = "{\"type\": \"record\","
- "\"name\":\"ComplexInteger\", \"fields\": ["
- "{\"name\":\"re\", \"type\":\"long\"}"
- "]}";
-static const char dsch[] = "{\"type\": \"record\","
- "\"name\":\"ComplexDouble\", \"fields\": ["
- "{\"name\":\"re\", \"type\":\"double\"},"
- "{\"name\":\"im\", \"type\":\"double\"}"
- "]}";
-static const char dblsch[] = "{\"type\": \"record\","
- "\"name\":\"ComplexDouble\", \"fields\": ["
- "{\"name\":\"re\", \"type\":\"double\"}"
- "]}";
-
-
-string toString(const ValidSchema& s)
-{
- ostringstream oss;
- s.toJson(oss);
- return oss.str();
-}
-
-class DataFileTest {
- const char* filename;
- const ValidSchema writerSchema;
- const ValidSchema readerSchema;
-
-public:
- DataFileTest(const char* f, const char* wsch, const char* rsch) :
- filename(f), writerSchema(makeValidSchema(wsch)),
- readerSchema(makeValidSchema(rsch)) { }
-
- typedef pair<ValidSchema, GenericDatum> Pair;
-
- void testCleanup() {
- BOOST_CHECK(boost::filesystem::remove(filename));
- }
-
- void testWrite() {
- avro::DataFileWriter<ComplexInteger> df(filename, writerSchema, 100);
- int64_t re = 3;
- int64_t im = 5;
- for (int i = 0; i < 1000; ++i, re *= im, im += 3) {
- ComplexInteger c(re, im);
- df.write(c);
- }
- df.close();
- }
-
- void testWriteGeneric() {
- avro::DataFileWriter<Pair> df(filename, writerSchema, 100);
- int64_t re = 3;
- int64_t im = 5;
- Pair p(writerSchema, GenericDatum());
-
- GenericDatum& c = p.second;
- c = GenericDatum(writerSchema.root());
- GenericRecord& r = c.value<GenericRecord>();
-
- for (int i = 0; i < 1000; ++i, re *= im, im += 3) {
- r.fieldAt(0) = re;
- r.fieldAt(1) = im;
- df.write(p);
- }
- df.close();
- }
-
- void testWriteDouble() {
- avro::DataFileWriter<ComplexDouble> df(filename, writerSchema, 100);
- double re = 3.0;
- double im = 5.0;
- for (int i = 0; i < 1000; ++i, re += im - 0.7, im += 3.1) {
- ComplexDouble c(re, im);
- df.write(c);
- }
- df.close();
- }
-
- void testReadFull() {
- avro::DataFileReader<ComplexInteger> df(filename, writerSchema);
- int i = 0;
- ComplexInteger ci;
- int64_t re = 3;
- int64_t im = 5;
- while (df.read(ci)) {
- BOOST_CHECK_EQUAL(ci.re, re);
- BOOST_CHECK_EQUAL(ci.im, im);
- re *= im;
- im += 3;
- ++i;
- }
- BOOST_CHECK_EQUAL(i, 1000);
- }
-
- void testReadProjection() {
- avro::DataFileReader<Integer> df(filename, readerSchema);
- int i = 0;
- Integer integer;
- int64_t re = 3;
- int64_t im = 5;
- while (df.read(integer)) {
- BOOST_CHECK_EQUAL(integer.re, re);
- re *= im;
- im += 3;
- ++i;
- }
- BOOST_CHECK_EQUAL(i, 1000);
- }
-
- void testReaderGeneric() {
- avro::DataFileReader<Pair> df(filename, writerSchema);
- int i = 0;
- Pair p(writerSchema, GenericDatum());
- int64_t re = 3;
- int64_t im = 5;
-
- const GenericDatum& ci = p.second;
- while (df.read(p)) {
- BOOST_REQUIRE_EQUAL(ci.type(), avro::AVRO_RECORD);
- const GenericRecord& r = ci.value<GenericRecord>();
- const size_t n = 2;
- BOOST_REQUIRE_EQUAL(r.fieldCount(), n);
- const GenericDatum& f0 = r.fieldAt(0);
- BOOST_REQUIRE_EQUAL(f0.type(), avro::AVRO_LONG);
- BOOST_CHECK_EQUAL(f0.value<int64_t>(), re);
-
- const GenericDatum& f1 = r.fieldAt(1);
- BOOST_REQUIRE_EQUAL(f1.type(), avro::AVRO_LONG);
- BOOST_CHECK_EQUAL(f1.value<int64_t>(), im);
- re *= im;
- im += 3;
- ++i;
- }
- BOOST_CHECK_EQUAL(i, 1000);
- }
-
- void testReaderGenericProjection() {
- avro::DataFileReader<Pair> df(filename, readerSchema);
- int i = 0;
- Pair p(readerSchema, GenericDatum());
- int64_t re = 3;
- int64_t im = 5;
-
- const GenericDatum& ci = p.second;
- while (df.read(p)) {
- BOOST_REQUIRE_EQUAL(ci.type(), avro::AVRO_RECORD);
- const GenericRecord& r = ci.value<GenericRecord>();
- const size_t n = 1;
- BOOST_REQUIRE_EQUAL(r.fieldCount(), n);
- const GenericDatum& f0 = r.fieldAt(0);
- BOOST_REQUIRE_EQUAL(f0.type(), avro::AVRO_LONG);
- BOOST_CHECK_EQUAL(f0.value<int64_t>(), re);
-
- re *= im;
- im += 3;
- ++i;
- }
- BOOST_CHECK_EQUAL(i, 1000);
- }
-
- void testReadDouble() {
- avro::DataFileReader<ComplexDouble> df(filename, writerSchema);
- int i = 0;
- ComplexDouble ci;
- double re = 3.0;
- double im = 5.0;
- while (df.read(ci)) {
- BOOST_CHECK_CLOSE(ci.re, re, 0.0001);
- BOOST_CHECK_CLOSE(ci.im, im, 0.0001);
- re += (im - 0.7);
- im += 3.1;
- ++i;
- }
- BOOST_CHECK_EQUAL(i, 1000);
- }
-
- /**
- * Constructs the DataFileReader in two steps.
- */
- void testReadDoubleTwoStep() {
- auto_ptr<avro::DataFileReaderBase>
- base(new avro::DataFileReaderBase(filename));
- avro::DataFileReader<ComplexDouble> df(base);
- BOOST_CHECK_EQUAL(toString(writerSchema), toString(df.readerSchema()));
- BOOST_CHECK_EQUAL(toString(writerSchema), toString(df.dataSchema()));
- int i = 0;
- ComplexDouble ci;
- double re = 3.0;
- double im = 5.0;
- while (df.read(ci)) {
- BOOST_CHECK_CLOSE(ci.re, re, 0.0001);
- BOOST_CHECK_CLOSE(ci.im, im, 0.0001);
- re += (im - 0.7);
- im += 3.1;
- ++i;
- }
- BOOST_CHECK_EQUAL(i, 1000);
- }
-
- /**
- * Constructs the DataFileReader in two steps using a different
- * reader schema.
- */
- void testReadDoubleTwoStepProject() {
- auto_ptr<avro::DataFileReaderBase>
- base(new avro::DataFileReaderBase(filename));
- avro::DataFileReader<Double> df(base, readerSchema);
-
- BOOST_CHECK_EQUAL(toString(readerSchema), toString(df.readerSchema()));
- BOOST_CHECK_EQUAL(toString(writerSchema), toString(df.dataSchema()));
- int i = 0;
- Double ci;
- double re = 3.0;
- double im = 5.0;
- while (df.read(ci)) {
- BOOST_CHECK_CLOSE(ci.re, re, 0.0001);
- re += (im - 0.7);
- im += 3.1;
- ++i;
- }
- BOOST_CHECK_EQUAL(i, 1000);
- }
-};
-
-void addReaderTests(test_suite* ts, const shared_ptr<DataFileTest>& t)
-{
- ts->add(BOOST_CLASS_TEST_CASE(&DataFileTest::testReadFull, t));
- ts->add(BOOST_CLASS_TEST_CASE(&DataFileTest::testReadProjection, t));
- ts->add(BOOST_CLASS_TEST_CASE(&DataFileTest::testReaderGeneric, t));
- ts->add(BOOST_CLASS_TEST_CASE(&DataFileTest::testReaderGenericProjection,
- t));
- ts->add(BOOST_CLASS_TEST_CASE(&DataFileTest::testCleanup, t));
-
-}
-
-test_suite*
-init_unit_test_suite( int argc, char* argv[] )
-{
- test_suite* ts= BOOST_TEST_SUITE("DataFile tests");
- shared_ptr<DataFileTest> t1(new DataFileTest("test1.df", sch, isch));
- ts->add(BOOST_CLASS_TEST_CASE(&DataFileTest::testWrite, t1));
- addReaderTests(ts, t1);
-
- shared_ptr<DataFileTest> t2(new DataFileTest("test2.df", sch, isch));
- ts->add(BOOST_CLASS_TEST_CASE(&DataFileTest::testWriteGeneric, t2));
- addReaderTests(ts, t2);
-
- shared_ptr<DataFileTest> t3(new DataFileTest("test3.df", dsch, dblsch));
- ts->add(BOOST_CLASS_TEST_CASE(&DataFileTest::testWriteDouble, t3));
- ts->add(BOOST_CLASS_TEST_CASE(&DataFileTest::testReadDouble, t3));
- ts->add(BOOST_CLASS_TEST_CASE(&DataFileTest::testReadDoubleTwoStep, t3));
- ts->add(BOOST_CLASS_TEST_CASE(&DataFileTest::testReadDoubleTwoStepProject,
- t3));
- ts->add(BOOST_CLASS_TEST_CASE(&DataFileTest::testCleanup, t3));
- return ts;
-}
diff --git a/lang/c++/test/SpecificTests.cc b/lang/c++/test/SpecificTests.cc
deleted file mode 100644
index de29363..0000000
--- a/lang/c++/test/SpecificTests.cc
+++ /dev/null
@@ -1,200 +0,0 @@
-/**
- * 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 <boost/test/included/unit_test_framework.hpp>
-#include <boost/test/unit_test.hpp>
-
-#include "Specific.hh"
-#include "Stream.hh"
-
-using std::auto_ptr;
-using std::string;
-using std::vector;
-using std::map;
-using boost::array;
-
-namespace avro {
-
-class C {
- int32_t i_;
- int64_t l_;
-public:
- C() : i_(0), l_(0) { }
- C(int32_t i, int64_t l) : i_(i), l_(l) { }
- int32_t i() const { return i_; }
- int64_t l() const { return l_; }
- void i(int32_t ii) { i_ = ii; }
- void l(int64_t ll) { l_ = ll; }
-
- bool operator==(const C& oth) const {
- return i_ == oth.i_ && l_ == oth.l_;
- }
-};
-
-template <> struct codec_traits<C> {
- static void encode(Encoder& e, const C& c) {
- e.encodeInt(c.i());
- e.encodeLong(c.l());
- }
-
- static void decode(Decoder& d, C& c) {
- c.i(d.decodeInt());
- c.l(d.decodeLong());
- }
-};
-
-namespace specific {
-
-class Test {
- auto_ptr<OutputStream> os;
- EncoderPtr e;
- DecoderPtr d;
-public:
- Test() : os(memoryOutputStream()), e(binaryEncoder()), d(binaryDecoder()) {
- e->init(*os);
- }
-
- template <typename T> void encode(const T& t) {
- avro::encode(*e, t);
- e->flush();
- }
-
- template <typename T> void decode(T& t) {
- auto_ptr<InputStream> is = memoryInputStream(*os);
- d->init(*is);
- avro::decode(*d, t);
- }
-};
-
-template <typename T> T encodeAndDecode(const T& t)
-{
- Test tst;
-
- tst.encode(t);
-
- T actual = T();
-
- tst.decode(actual);
- return actual;
-}
-
-void testBool()
-{
- bool b = encodeAndDecode(true);
- BOOST_CHECK_EQUAL(b, true);
-}
-
-void testInt()
-{
- int32_t n = 10;
- int32_t b = encodeAndDecode(n);
- BOOST_CHECK_EQUAL(b, n);
-}
-
-void testLong()
-{
- int64_t n = -109;
- int64_t b = encodeAndDecode(n);
- BOOST_CHECK_EQUAL(b, n);
-}
-
-void testFloat()
-{
- float n = 10.19;
- float b = encodeAndDecode(n);
- BOOST_CHECK_CLOSE(b, n, 0.00001);
-}
-
-void testDouble()
-{
- double n = 10.00001;
- double b = encodeAndDecode(n);
- BOOST_CHECK_CLOSE(b, n, 0.00000001);
-}
-
-void testString()
-{
- string n = "abc";
- string b = encodeAndDecode(n);
- BOOST_CHECK_EQUAL(b, n);
-}
-
-void testBytes()
-{
- uint8_t values[] = { 1, 7, 23, 47, 83 };
- vector<uint8_t> n(values, values + 5);
- vector<uint8_t> b = encodeAndDecode(n);
- BOOST_CHECK_EQUAL_COLLECTIONS(b.begin(), b.end(), n.begin(), n.end());
-}
-
-void testFixed()
-{
- array<uint8_t, 5> n = { 1, 7, 23, 47, 83 };
- array<uint8_t, 5> b = encodeAndDecode(n);
- BOOST_CHECK_EQUAL_COLLECTIONS(b.begin(), b.end(), n.begin(), n.end());
-}
-
-void testArray()
-{
- int32_t values[] = { 101, 709, 409, 34 };
- vector<int32_t> n(values, values + 4);
- vector<int32_t> b = encodeAndDecode(n);
-
- BOOST_CHECK_EQUAL_COLLECTIONS(b.begin(), b.end(), n.begin(), n.end());
-}
-
-void testMap()
-{
- map<string, int32_t> n;
- n["a"] = 1;
- n["b"] = 101;
-
- map<string, int32_t> b = encodeAndDecode(n);
-
- BOOST_CHECK(b == n);
-}
-
-void testCustom()
-{
- C n(10, 1023);
- C b = encodeAndDecode(n);
- BOOST_CHECK(b == n);
-}
-
-}
-}
-
-boost::unit_test::test_suite*
-init_unit_test_suite( int argc, char* argv[] )
-{
- using namespace boost::unit_test;
-
- test_suite* ts= BOOST_TEST_SUITE("Specific tests");
- ts->add(BOOST_TEST_CASE(avro::specific::testBool));
- ts->add(BOOST_TEST_CASE(avro::specific::testInt));
- ts->add(BOOST_TEST_CASE(avro::specific::testLong));
- ts->add(BOOST_TEST_CASE(avro::specific::testFloat));
- ts->add(BOOST_TEST_CASE(avro::specific::testDouble));
- ts->add(BOOST_TEST_CASE(avro::specific::testString));
- ts->add(BOOST_TEST_CASE(avro::specific::testBytes));
- ts->add(BOOST_TEST_CASE(avro::specific::testFixed));
- ts->add(BOOST_TEST_CASE(avro::specific::testArray));
- ts->add(BOOST_TEST_CASE(avro::specific::testMap));
- ts->add(BOOST_TEST_CASE(avro::specific::testCustom));
- return ts;
-}
diff --git a/lang/c/CMakeLists.txt b/lang/c/CMakeLists.txt
index f758bb2..e831498 100644
--- a/lang/c/CMakeLists.txt
+++ b/lang/c/CMakeLists.txt
@@ -19,28 +19,7 @@
cmake_minimum_required(VERSION 2.4)
project(AvroC)
enable_testing()
-
-#-----------------------------------------------------------------------
-# Retrieve the current version number
-
-execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/version.sh project
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
- RESULT_VARIABLE AVRO_VERSION_RESULT
- OUTPUT_VARIABLE AVRO_VERSION
- OUTPUT_STRIP_TRAILING_WHITESPACE)
-if(AVRO_VERSION_RESULT)
- message(FATAL_ERROR "Cannot determine Avro version number")
-endif(AVRO_VERSION_RESULT)
-
-execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/version.sh libtool
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
- RESULT_VARIABLE LIBAVRO_VERSION_RESULT
- OUTPUT_VARIABLE LIBAVRO_VERSION
- OUTPUT_STRIP_TRAILING_WHITESPACE)
-if(LIBAVRO_VERSION_RESULT)
- message(FATAL_ERROR "Cannot determine libavro version number")
-endif(LIBAVRO_VERSION_RESULT)
-
+file(READ "${CMAKE_CURRENT_SOURCE_DIR}/../../share/VERSION.txt" AVRO_VERSION)
if(APPLE)
set(CMAKE_OSX_ARCHITECTURES "ppc;i386;x86_64" CACHE STRING "Build architectures for Mac OS X" FORCE)
@@ -56,7 +35,6 @@
add_subdirectory(src)
add_subdirectory(examples)
add_subdirectory(tests)
-add_subdirectory(docs)
add_custom_target(pretty
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_SOURCE_DIR}/cmake_pretty.cmake")
diff --git a/lang/c/docs/CMakeLists.txt b/lang/c/docs/CMakeLists.txt
deleted file mode 100644
index 92d3961..0000000
--- a/lang/c/docs/CMakeLists.txt
+++ /dev/null
@@ -1,51 +0,0 @@
-#
-# 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.
-#
-
-set (AVRO_DOC_SRC
- index.txt
-)
-
-# TODO(dln): Use FindAsciidoc script instead.
-message(STATUS "Searching for asciidoc...")
-find_program(ASCIIDOC_EXECUTABLE asciidoc)
-find_program(SOURCE_HIGHLIGHT_EXECUTABLE source-highlight)
-
-if (ASCIIDOC_EXECUTABLE AND SOURCE_HIGHLIGHT_EXECUTABLE)
- foreach(_file ${AVRO_DOC_SRC})
- get_filename_component(_file_we ${_file} NAME_WE)
- set(_file_path "${CMAKE_CURRENT_SOURCE_DIR}/${_file}")
- set(_html_out "${_file_we}.html")
- add_custom_command(
- OUTPUT "${_html_out}"
- COMMAND ${ASCIIDOC_EXECUTABLE}
- -a avro_version=${AVRO_VERSION}
- -a libavro_version=${LIBAVRO_VERSION}
- -a toc
- --unsafe -n -o "${_html_out}" "${_file_path}"
- DEPENDS "${_file_path}"
- COMMENT "asciidoc ${_file}"
- )
- add_custom_target("${_file_we}_html" ALL echo -n
- DEPENDS "${_file}" "${_html_out}"
- )
- endforeach(_file)
-else(ASCIIDOC_EXECUTABLE AND SOURCE_HIGHLIGHT_EXECUTABLE)
- message(WARNING "asciidoc not found. HTML documentation will *NOT* be built.")
-endif(ASCIIDOC_EXECUTABLE AND SOURCE_HIGHLIGHT_EXECUTABLE)
-
diff --git a/lang/c/examples/CMakeLists.txt b/lang/c/examples/CMakeLists.txt
index c8c782f..17ad7f8 100644
--- a/lang/c/examples/CMakeLists.txt
+++ b/lang/c/examples/CMakeLists.txt
@@ -20,6 +20,3 @@
add_executable(quickstop quickstop.c)
target_link_libraries(quickstop avro-static)
-add_test(quickstop
- ${CMAKE_COMMAND} -E chdir ${AvroC_SOURCE_DIR}/examples
- ${CMAKE_CURRENT_BINARY_DIR}/quickstop)
diff --git a/lang/c/examples/quickstop.c b/lang/c/examples/quickstop.c
index 285c22a..6bce2db 100644
--- a/lang/c/examples/quickstop.c
+++ b/lang/c/examples/quickstop.c
@@ -82,7 +82,7 @@
avro_datum_decref(phone_datum);
avro_datum_decref(person);
- //fprintf(stdout, "Successfully added %s, %s id=%"PRId64"\n", last, first, id);
+ fprintf(stdout, "Successfully added %s, %s id=%"PRId64"\n", last, first, id);
}
int print_person(avro_file_reader_t db, avro_schema_t reader_schema)
@@ -134,7 +134,6 @@
avro_schema_t projection_schema, first_name_schema, phone_schema;
int64_t i;
const char *dbname = "quickstop.db";
- char number[15] = {0};
/* Initialize the schema structure from JSON */
init_schema();
@@ -147,18 +146,13 @@
fprintf(stderr, "There was an error creating %s\n", dbname);
exit(EXIT_FAILURE);
}
-
- /* Add lots of people to the database */
- for (i = 0; i < 1000; i++)
- {
- sprintf(number, "(%d)", (int)i);
- add_person(db, "Dante", "Hicks", number, 32);
- add_person(db, "Randal", "Graves", "(555) 123-5678", 30);
- add_person(db, "Veronica", "Loughran", "(555) 123-0987", 28);
- add_person(db, "Caitlin", "Bree", "(555) 123-2323", 27);
- add_person(db, "Bob", "Silent", "(555) 123-6422", 29);
- add_person(db, "Jay", "???", number, 26);
- }
+ /* Add people to the database */
+ add_person(db, "Dante", "Hicks", "(555) 123-4567", 32);
+ add_person(db, "Randal", "Graves", "(555) 123-5678", 30);
+ add_person(db, "Veronica", "Loughran", "(555) 123-0987", 28);
+ add_person(db, "Caitlin", "Bree", "(555) 123-2323", 27);
+ add_person(db, "Bob", "Silent", "(555) 123-6422", 29);
+ add_person(db, "Jay", "???", "(555) 123-9182", 26);
avro_file_writer_close(db);
fprintf(stdout, "\nNow let's read all the records back out\n");
diff --git a/lang/c/src/CMakeLists.txt b/lang/c/src/CMakeLists.txt
index 8cb1f7f..5ad8837 100644
--- a/lang/c/src/CMakeLists.txt
+++ b/lang/c/src/CMakeLists.txt
@@ -67,17 +67,12 @@
source_group(Avro FILES ${AVRO_SRC})
source_group(Jansson FILES ${JANSSON_SRC})
-# The version.sh script gives us a SOVERSION that uses colon as a
-# separator; we need periods.
-
-string(REPLACE ":" "." LIBAVRO_DOT_VERSION ${LIBAVRO_VERSION})
-
add_library(avro-static STATIC ${AVRO_SRC} ${JANSSON_SRC})
set_target_properties(avro-static PROPERTIES OUTPUT_NAME avro)
add_library(avro-shared SHARED ${AVRO_SRC} ${JANSSON_SRC})
set_target_properties(avro-shared PROPERTIES
OUTPUT_NAME avro
- SOVERSION ${LIBAVRO_DOT_VERSION})
+ SOVERSION ${AVRO_VERSION})
install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/avro.h
diff --git a/lang/c/src/avro_private.h b/lang/c/src/avro_private.h
index c72008e..ea4cad6 100644
--- a/lang/c/src/avro_private.h
+++ b/lang/c/src/avro_private.h
@@ -33,7 +33,6 @@
rval = call; \
if (rval) { \
avro_set_error(__VA_ARGS__); \
- return rval; \
} \
}
@@ -42,7 +41,6 @@
rval = call; \
if (rval) { \
avro_prefix_error(__VA_ARGS__); \
- return rval; \
} \
}
diff --git a/lang/c/src/datafile.c b/lang/c/src/datafile.c
index dcf4296..a514f59 100644
--- a/lang/c/src/datafile.c
+++ b/lang/c/src/datafile.c
@@ -40,7 +40,6 @@
avro_writer_t writer;
char sync[16];
int block_count;
- size_t block_size;
avro_writer_t datum_writer;
char datum_buffer[16 * 1024];
};
@@ -316,14 +315,15 @@
int rval;
if (w->block_count) {
+ int64_t blocklen = avro_writer_tell(w->datum_writer);
/* Write the block count */
check_prefix(rval, enc->write_long(w->writer, w->block_count),
"Cannot write file block count: ");
/* Write the block length */
- check_prefix(rval, enc->write_long(w->writer, w->block_size),
+ check_prefix(rval, enc->write_long(w->writer, blocklen),
"Cannot write file block size: ");
/* Write the block */
- check_prefix(rval, avro_write(w->writer, w->datum_buffer, w->block_size),
+ check_prefix(rval, avro_write(w->writer, w->datum_buffer, blocklen),
"Cannot write file block: ");
/* Write the sync marker */
check_prefix(rval, write_sync(w),
@@ -331,7 +331,6 @@
/* Reset the datum writer */
avro_writer_reset(w->datum_writer);
w->block_count = 0;
- w->block_size = 0;
}
return 0;
}
@@ -355,7 +354,6 @@
}
}
w->block_count++;
- w->block_size = avro_writer_tell(w->datum_writer);
return 0;
}
diff --git a/lang/c/version.sh b/lang/c/version.sh
index ed8db43..fe6c5fc 100755
--- a/lang/c/version.sh
+++ b/lang/c/version.sh
@@ -18,7 +18,7 @@
# libavro_binary_age = 0
# libavro_interface_age = 0
#
-libavro_micro_version=22
+libavro_micro_version=21
libavro_interface_age=0
libavro_binary_age=0
diff --git a/lang/csharp/.gitignore b/lang/csharp/.gitignore
deleted file mode 100644
index a42fae7..0000000
--- a/lang/csharp/.gitignore
+++ /dev/null
@@ -1,22 +0,0 @@
-# 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.
-
-/build
-/*.user
-/*.suo
-/_ReSharper.Avro
-/src/apache/codegen/obj
-/src/apache/main/obj
-/src/apache/test/obj
diff --git a/lang/csharp/Avro.nunit b/lang/csharp/Avro.nunit
deleted file mode 100644
index 25e85c8..0000000
--- a/lang/csharp/Avro.nunit
+++ /dev/null
@@ -1,15 +0,0 @@
-<NUnitProject>
- <Settings activeconfig="Release" />
- <Config name="Debug" binpathtype="Auto">
- <assembly path="build/test/Debug/Avro.test.dll" />
- <assembly path="build/test/Debug/Avro.dll" />
- <assembly path="lib/main/Newtonsoft.Json.dll" />
- <assembly path="lib/test/nunit.framework.dll" />
- </Config>
- <Config name="Release" binpathtype="Auto">
- <assembly path="build/test/Release/Avro.test.dll" />
- <assembly path="build/test/Release/Avro.dll" />
- <assembly path="lib/main/Newtonsoft.Json.dll" />
- <assembly path="lib/test/nunit.framework.dll" />
- </Config>
-</NUnitProject>
diff --git a/lang/csharp/Avro.sln b/lang/csharp/Avro.sln
deleted file mode 100644
index 80cc85f..0000000
--- a/lang/csharp/Avro.sln
+++ /dev/null
@@ -1,55 +0,0 @@
-Microsoft Visual Studio Solution File, Format Version 11.00
-# Visual Studio 2010
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avro.main", "src\apache\main\Avro.main.csproj", "{A0A5CA3C-F58C-4D07-98B0-2C7B62AB20F0}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avro.test", "src\apache\test\Avro.test.csproj", "{911D56AB-587B-4E5F-B5EA-D47D8A46F1FA}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avro.codegen", "src\apache\codegen\Avro.codegen.csproj", "{BF0D313C-1AA3-4900-B277-B0F5F9DDCDA8}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Debug|Mixed Platforms = Debug|Mixed Platforms
- Debug|x86 = Debug|x86
- Release|Any CPU = Release|Any CPU
- Release|Mixed Platforms = Release|Mixed Platforms
- Release|x86 = Release|x86
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {A0A5CA3C-F58C-4D07-98B0-2C7B62AB20F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {A0A5CA3C-F58C-4D07-98B0-2C7B62AB20F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {A0A5CA3C-F58C-4D07-98B0-2C7B62AB20F0}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
- {A0A5CA3C-F58C-4D07-98B0-2C7B62AB20F0}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
- {A0A5CA3C-F58C-4D07-98B0-2C7B62AB20F0}.Debug|x86.ActiveCfg = Debug|Any CPU
- {A0A5CA3C-F58C-4D07-98B0-2C7B62AB20F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {A0A5CA3C-F58C-4D07-98B0-2C7B62AB20F0}.Release|Any CPU.Build.0 = Release|Any CPU
- {A0A5CA3C-F58C-4D07-98B0-2C7B62AB20F0}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
- {A0A5CA3C-F58C-4D07-98B0-2C7B62AB20F0}.Release|Mixed Platforms.Build.0 = Release|Any CPU
- {A0A5CA3C-F58C-4D07-98B0-2C7B62AB20F0}.Release|x86.ActiveCfg = Release|Any CPU
- {911D56AB-587B-4E5F-B5EA-D47D8A46F1FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {911D56AB-587B-4E5F-B5EA-D47D8A46F1FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {911D56AB-587B-4E5F-B5EA-D47D8A46F1FA}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
- {911D56AB-587B-4E5F-B5EA-D47D8A46F1FA}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
- {911D56AB-587B-4E5F-B5EA-D47D8A46F1FA}.Debug|x86.ActiveCfg = Debug|Any CPU
- {911D56AB-587B-4E5F-B5EA-D47D8A46F1FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {911D56AB-587B-4E5F-B5EA-D47D8A46F1FA}.Release|Any CPU.Build.0 = Release|Any CPU
- {911D56AB-587B-4E5F-B5EA-D47D8A46F1FA}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
- {911D56AB-587B-4E5F-B5EA-D47D8A46F1FA}.Release|Mixed Platforms.Build.0 = Release|Any CPU
- {911D56AB-587B-4E5F-B5EA-D47D8A46F1FA}.Release|x86.ActiveCfg = Release|Any CPU
- {BF0D313C-1AA3-4900-B277-B0F5F9DDCDA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {BF0D313C-1AA3-4900-B277-B0F5F9DDCDA8}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {BF0D313C-1AA3-4900-B277-B0F5F9DDCDA8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
- {BF0D313C-1AA3-4900-B277-B0F5F9DDCDA8}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
- {BF0D313C-1AA3-4900-B277-B0F5F9DDCDA8}.Debug|x86.ActiveCfg = Debug|x86
- {BF0D313C-1AA3-4900-B277-B0F5F9DDCDA8}.Debug|x86.Build.0 = Debug|x86
- {BF0D313C-1AA3-4900-B277-B0F5F9DDCDA8}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {BF0D313C-1AA3-4900-B277-B0F5F9DDCDA8}.Release|Any CPU.Build.0 = Release|Any CPU
- {BF0D313C-1AA3-4900-B277-B0F5F9DDCDA8}.Release|Mixed Platforms.ActiveCfg = Release|x86
- {BF0D313C-1AA3-4900-B277-B0F5F9DDCDA8}.Release|Mixed Platforms.Build.0 = Release|x86
- {BF0D313C-1AA3-4900-B277-B0F5F9DDCDA8}.Release|x86.ActiveCfg = Release|x86
- {BF0D313C-1AA3-4900-B277-B0F5F9DDCDA8}.Release|x86.Build.0 = Release|x86
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
-EndGlobal
diff --git a/lang/csharp/Avro.snk b/lang/csharp/Avro.snk
deleted file mode 100644
index ad2c010..0000000
--- a/lang/csharp/Avro.snk
+++ /dev/null
Binary files differ
diff --git a/lang/csharp/README b/lang/csharp/README
deleted file mode 100644
index e822b8a..0000000
--- a/lang/csharp/README
+++ /dev/null
@@ -1,34 +0,0 @@
-1. Building Avro for .NET
-
-a. Windows
-
-Prerequisites
- Microsoft Visual C# Express 2010
-
-To build open Avro.sln solution in VC# Express 2010 and build from there.
-
-b. Linux
-
-Prerequisites
- Mono 2.6 or above.
-
-For Ubuntu Lucid Lynx, mono that comes with it is 2.4. To install mono 2.6
-follow the procedure described at http://badgerports.org/
-
-To build issue the command:
-$ cd lang/csharp
-
-then
-
-$ CONFIGURATION=Release TARGETFRAMEWORKVERSION=3.5 xbuild Avro.sln
-
-or
-
-$ CONFIGURATION=Debug TARGETFRAMEWORKVERSION=3.5 xbuild Avro.sln
-
-2. Unit tests
-
-This is a common procedure for both Windows and Linux.
-
-To run unit-tests, please install NUnit 2.5 or above. From within the NUnit
-GUI, open the project Avro.nunit and run the tests.
diff --git a/lang/csharp/build.sh b/lang/csharp/build.sh
deleted file mode 100755
index 4283b3c..0000000
--- a/lang/csharp/build.sh
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/bin/bash
-
-# 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.
-
-set -e # exit on error
-set -x
-
-case "$1" in
-
- test)
- CONFIGURATION=Release TARGETFRAMEWORKVERSION=3.5 xbuild
- nunit-console Avro.nunit
- ;;
-
- clean)
- rm -rf src/apache/{main,test,codegen}/obj
- rm -rf build
- ;;
-
- *)
- echo "Usage: $0 {test|clean}"
- exit 1
-esac
-
-exit 0
diff --git a/lang/csharp/lib/main/Newtonsoft.Json.dll b/lang/csharp/lib/main/Newtonsoft.Json.dll
deleted file mode 100644
index 4703b89..0000000
--- a/lang/csharp/lib/main/Newtonsoft.Json.dll
+++ /dev/null
Binary files differ
diff --git a/lang/csharp/lib/main/log4net.dll b/lang/csharp/lib/main/log4net.dll
deleted file mode 100644
index ffc57e1..0000000
--- a/lang/csharp/lib/main/log4net.dll
+++ /dev/null
Binary files differ
diff --git a/lang/csharp/lib/test/nunit.framework.dll b/lang/csharp/lib/test/nunit.framework.dll
deleted file mode 100644
index 639dbb0..0000000
--- a/lang/csharp/lib/test/nunit.framework.dll
+++ /dev/null
Binary files differ
diff --git a/lang/csharp/src/apache/codegen/Avro.codegen.csproj b/lang/csharp/src/apache/codegen/Avro.codegen.csproj
deleted file mode 100644
index e6198f9..0000000
--- a/lang/csharp/src/apache/codegen/Avro.codegen.csproj
+++ /dev/null
@@ -1,168 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- 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.
--->
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>8.0.30703</ProductVersion>
- <SchemaVersion>2.0</SchemaVersion>
- <ProjectGuid>{BF0D313C-1AA3-4900-B277-B0F5F9DDCDA8}</ProjectGuid>
- <OutputType>Exe</OutputType>
- <AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>Avro.codegen</RootNamespace>
- <AssemblyName>avrogen</AssemblyName>
- <TargetFrameworkVersion Condition=" '$(TargetFrameworkVersion)' == '' ">v4.0</TargetFrameworkVersion>
- <TargetFrameworkProfile>Client</TargetFrameworkProfile>
- <FileAlignment>512</FileAlignment>
- <IsWebBootstrapper>false</IsWebBootstrapper>
- <FileUpgradeFlags>
- </FileUpgradeFlags>
- <OldToolsVersion>3.5</OldToolsVersion>
- <UpgradeBackupLocation />
- <PublishUrl>publish\</PublishUrl>
- <Install>true</Install>
- <InstallFrom>Disk</InstallFrom>
- <UpdateEnabled>false</UpdateEnabled>
- <UpdateMode>Foreground</UpdateMode>
- <UpdateInterval>7</UpdateInterval>
- <UpdateIntervalUnits>Days</UpdateIntervalUnits>
- <UpdatePeriodically>false</UpdatePeriodically>
- <UpdateRequired>false</UpdateRequired>
- <MapFileExtensions>true</MapFileExtensions>
- <ApplicationRevision>0</ApplicationRevision>
- <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
- <UseApplicationTrust>false</UseApplicationTrust>
- <BootstrapperEnabled>true</BootstrapperEnabled>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
- <PlatformTarget>AnyCPU</PlatformTarget>
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>..\..\..\build\codegen\Debug\</OutputPath>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <PlatformTarget>AnyCPU</PlatformTarget>
- <DebugType>none</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>..\..\..\build\codegen\Release\</OutputPath>
- <DefineConstants>
- </DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
- <DebugSymbols>true</DebugSymbols>
- <OutputPath>..\..\..\build\codegen\Debug\</OutputPath>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
- <DebugType>full</DebugType>
- <PlatformTarget>AnyCPU</PlatformTarget>
- <CodeAnalysisLogFile>..\..\..\build\codegen\Debug\avrogen.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile>
- <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
- <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
- <ErrorReport>prompt</ErrorReport>
- <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
- <CodeAnalysisRuleSetDirectories>;C:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
- <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
- <CodeAnalysisRuleDirectories>;C:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
- <CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
- <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
- <OutputPath>..\..\..\build\codegen\Release\</OutputPath>
- <DefineConstants>
- </DefineConstants>
- <Optimize>true</Optimize>
- <DebugType>none</DebugType>
- <PlatformTarget>AnyCPU</PlatformTarget>
- <CodeAnalysisLogFile>..\..\..\build\codegen\Release\avrogen.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile>
- <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
- <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
- <ErrorReport>prompt</ErrorReport>
- <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
- <CodeAnalysisRuleSetDirectories>;C:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
- <CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
- <CodeAnalysisRuleDirectories>;C:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
- <CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
- <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
- <OutputPath>..\..\..\build\codegen\Release\</OutputPath>
- </PropertyGroup>
- <PropertyGroup>
- <SignAssembly>true</SignAssembly>
- </PropertyGroup>
- <PropertyGroup>
- <AssemblyOriginatorKeyFile>..\..\..\Avro.snk</AssemblyOriginatorKeyFile>
- </PropertyGroup>
- <ItemGroup>
- <Reference Include="System" />
- <Reference Include="System.Core" />
- <Reference Include="System.Xml.Linq" />
- <Reference Include="System.Data.DataSetExtensions" />
- <Reference Include="Microsoft.CSharp" />
- <Reference Include="System.Data" />
- <Reference Include="System.Xml" />
- </ItemGroup>
- <ItemGroup>
- <Compile Include="AvroGen.cs" />
- <Compile Include="Properties\AssemblyInfo.cs" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\main\Avro.main.csproj">
- <Project>{A0A5CA3C-F58C-4D07-98B0-2C7B62AB20F0}</Project>
- <Name>Avro.main</Name>
- </ProjectReference>
- </ItemGroup>
- <ItemGroup>
- <BootstrapperPackage Include=".NETFramework,Version=v3.5,Profile=Client">
- <Visible>False</Visible>
- <ProductName>Microsoft .NET Framework 4 Client Profile %28x86 and x64%29</ProductName>
- <Install>true</Install>
- </BootstrapperPackage>
- <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
- <Visible>False</Visible>
- <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
- <Install>false</Install>
- </BootstrapperPackage>
- <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
- <Visible>False</Visible>
- <ProductName>.NET Framework 3.5 SP1</ProductName>
- <Install>false</Install>
- </BootstrapperPackage>
- <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
- <Visible>False</Visible>
- <ProductName>Windows Installer 3.1</ProductName>
- <Install>true</Install>
- </BootstrapperPackage>
- </ItemGroup>
- <ItemGroup>
- <None Include="app.config" />
- </ItemGroup>
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
- <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
- Other similar extension points exist, see Microsoft.Common.targets.
- <Target Name="BeforeBuild">
- </Target>
- <Target Name="AfterBuild">
- </Target>
- -->
-</Project>
\ No newline at end of file
diff --git a/lang/csharp/src/apache/codegen/AvroGen.cs b/lang/csharp/src/apache/codegen/AvroGen.cs
deleted file mode 100644
index 9f35d2d..0000000
--- a/lang/csharp/src/apache/codegen/AvroGen.cs
+++ /dev/null
@@ -1,84 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace Avro
-{
- class AvroGen
- {
- static void Main(string[] args)
- {
- if (args.Length != 3)
- {
- Usage();
- return;
- }
- if (args[0] == "-p")
- GenProtocol(args[1], args[2]);
- else if (args[0] == "-s")
- GenSchema(args[1], args[2]);
- else
- Usage();
- }
-
- static void Usage()
- {
- Console.WriteLine("Usage:\navrogen -p <protocolfile> <outputdir>\navrogen -s <schemafile> <outputdir>");
- return;
- }
- static void GenProtocol(string infile, string outdir)
- {
- try
- {
- string text = System.IO.File.ReadAllText(infile);
- Protocol protocol = Protocol.Parse(text);
-
- CodeGen codegen = new CodeGen();
- codegen.AddProtocol(protocol);
-
- codegen.GenerateCode();
- codegen.WriteTypes(outdir);
- }
- catch (Exception ex)
- {
- Console.WriteLine("Exception occurred. " + ex.Message);
- }
- }
- static void GenSchema(string infile, string outdir)
- {
- try
- {
- string text = System.IO.File.ReadAllText(infile);
- Schema schema = Schema.Parse(text);
-
- CodeGen codegen = new CodeGen();
- codegen.AddSchema(schema);
-
- codegen.GenerateCode();
- codegen.WriteTypes(outdir);
- }
- catch (Exception ex)
- {
- Console.WriteLine("Exception occurred. " + ex.Message);
- }
- }
- }
-}
diff --git a/lang/csharp/src/apache/codegen/Properties/AssemblyInfo.cs b/lang/csharp/src/apache/codegen/Properties/AssemblyInfo.cs
deleted file mode 100644
index 7e02216..0000000
--- a/lang/csharp/src/apache/codegen/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * 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.
- */
-
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("Avro.codegen")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("Bank of America")]
-[assembly: AssemblyProduct("Avro.codegen")]
-[assembly: AssemblyCopyright("Copyright © Bank of America 2011")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("3ccfcbf4-bdf9-4f75-8d5a-ab476bb4408f")]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/lang/csharp/src/apache/codegen/app.config b/lang/csharp/src/apache/codegen/app.config
deleted file mode 100755
index 9a102d6..0000000
--- a/lang/csharp/src/apache/codegen/app.config
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0"?>
-<!--
- 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.
--->
-<configuration>
-<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/></startup></configuration>
diff --git a/lang/csharp/src/apache/main/Avro.main.csproj b/lang/csharp/src/apache/main/Avro.main.csproj
deleted file mode 100644
index cd4b542..0000000
--- a/lang/csharp/src/apache/main/Avro.main.csproj
+++ /dev/null
@@ -1,161 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- 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.
--->
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>8.0.30703</ProductVersion>
- <SchemaVersion>2.0</SchemaVersion>
- <ProjectGuid>{A0A5CA3C-F58C-4D07-98B0-2C7B62AB20F0}</ProjectGuid>
- <OutputType>Library</OutputType>
- <AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>Avro</RootNamespace>
- <AssemblyName>Avro</AssemblyName>
- <TargetFrameworkVersion Condition=" '$(TargetFrameworkVersion)' == '' ">v4.0</TargetFrameworkVersion>
- <FileAlignment>512</FileAlignment>
- <TargetFrameworkProfile>Client</TargetFrameworkProfile>
- <FileUpgradeFlags>
- </FileUpgradeFlags>
- <OldToolsVersion>3.5</OldToolsVersion>
- <UpgradeBackupLocation />
- <PublishUrl>publish\</PublishUrl>
- <Install>true</Install>
- <InstallFrom>Disk</InstallFrom>
- <UpdateEnabled>false</UpdateEnabled>
- <UpdateMode>Foreground</UpdateMode>
- <UpdateInterval>7</UpdateInterval>
- <UpdateIntervalUnits>Days</UpdateIntervalUnits>
- <UpdatePeriodically>false</UpdatePeriodically>
- <UpdateRequired>false</UpdateRequired>
- <MapFileExtensions>true</MapFileExtensions>
- <ApplicationRevision>0</ApplicationRevision>
- <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
- <IsWebBootstrapper>false</IsWebBootstrapper>
- <UseApplicationTrust>false</UseApplicationTrust>
- <BootstrapperEnabled>true</BootstrapperEnabled>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>..\..\..\build\main\Debug\</OutputPath>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugType>none</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>..\..\..\build\main\Release\</OutputPath>
- <DefineConstants>
- </DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
- </PropertyGroup>
- <PropertyGroup>
- <SignAssembly>true</SignAssembly>
- </PropertyGroup>
- <PropertyGroup>
- <AssemblyOriginatorKeyFile>..\..\..\Avro.snk</AssemblyOriginatorKeyFile>
- </PropertyGroup>
- <ItemGroup>
- <Reference Include="log4net">
- <HintPath>..\..\..\lib\main\log4net.dll</HintPath>
- </Reference>
- <Reference Include="Newtonsoft.Json">
- <HintPath>..\..\..\lib\main\Newtonsoft.Json.dll</HintPath>
- </Reference>
- <Reference Include="System" />
- </ItemGroup>
- <ItemGroup>
- <Compile Include="CodeGen\AvroRuntimeException.cs" />
- <Compile Include="CodeGen\CodeGen.cs" />
- <Compile Include="CodeGen\CodeGenException.cs" />
- <Compile Include="CodeGen\CodeGenUtil.cs" />
- <Compile Include="Generic\DatumReader.cs" />
- <Compile Include="Generic\DatumWriter.cs" />
- <Compile Include="Generic\GenericEnum.cs" />
- <Compile Include="Generic\GenericFixed.cs" />
- <Compile Include="Generic\GenericReader.cs" />
- <Compile Include="Generic\GenericRecord.cs" />
- <Compile Include="Generic\GenericWriter.cs" />
- <Compile Include="IO\BinaryDecoder.cs" />
- <Compile Include="IO\BinaryEncoder.cs" />
- <Compile Include="IO\Decoder.cs" />
- <Compile Include="IO\Encoder.cs" />
- <Compile Include="IO\Resolver.cs" />
- <Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="Protocol\Message.cs" />
- <Compile Include="Protocol\Protocol.cs" />
- <Compile Include="Protocol\ProtocolParseException.cs" />
- <Compile Include="Schema\ArraySchema.cs" />
- <Compile Include="Schema\AvroException.cs" />
- <Compile Include="Schema\AvroTypeException.cs" />
- <Compile Include="Schema\EnumSchema.cs" />
- <Compile Include="Schema\Field.cs" />
- <Compile Include="Schema\FixedSchema.cs" />
- <Compile Include="Schema\JsonHelper.cs" />
- <Compile Include="Schema\MapSchema.cs" />
- <Compile Include="Schema\NamedSchema.cs" />
- <Compile Include="Schema\PrimitiveSchema.cs" />
- <Compile Include="Schema\Property.cs" />
- <Compile Include="Schema\RecordSchema.cs" />
- <Compile Include="Schema\Schema.cs" />
- <Compile Include="Schema\SchemaName.cs" />
- <Compile Include="Schema\SchemaParseException.cs" />
- <Compile Include="Schema\UnionSchema.cs" />
- <Compile Include="Schema\UnnamedSchema.cs" />
- <Compile Include="Specific\ObjectCreator.cs" />
- <Compile Include="Specific\SpecificFixed.cs" />
- <Compile Include="Specific\SpecificReader.cs" />
- <Compile Include="Specific\SpecificWriter.cs" />
- <Compile Include="Specific\SpecificRecord.cs" />
- </ItemGroup>
- <ItemGroup>
- <BootstrapperPackage Include=".NETFramework,Version=v3.5">
- <Visible>False</Visible>
- <ProductName>Microsoft .NET Framework 4 %28x86 and x64%29</ProductName>
- <Install>true</Install>
- </BootstrapperPackage>
- <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
- <Visible>False</Visible>
- <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
- <Install>false</Install>
- </BootstrapperPackage>
- <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
- <Visible>False</Visible>
- <ProductName>.NET Framework 3.5 SP1</ProductName>
- <Install>false</Install>
- </BootstrapperPackage>
- <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
- <Visible>False</Visible>
- <ProductName>Windows Installer 3.1</ProductName>
- <Install>true</Install>
- </BootstrapperPackage>
- </ItemGroup>
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
- <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
- Other similar extension points exist, see Microsoft.Common.targets.
- <Target Name="BeforeBuild">
- </Target>
- <Target Name="AfterBuild">
- </Target>
- -->
-</Project>
\ No newline at end of file
diff --git a/lang/csharp/src/apache/main/CodeGen/AvroRuntimeException.cs b/lang/csharp/src/apache/main/CodeGen/AvroRuntimeException.cs
deleted file mode 100644
index 857a438..0000000
--- a/lang/csharp/src/apache/main/CodeGen/AvroRuntimeException.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace Avro
-{
- public class AvroRuntimeException : AvroException
- {
- public AvroRuntimeException(string s)
- : base(s)
- {
-
- }
- public AvroRuntimeException(string s, Exception inner)
- : base(s, inner)
- {
-
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/CodeGen/CodeGen.cs b/lang/csharp/src/apache/main/CodeGen/CodeGen.cs
deleted file mode 100644
index 75e9f5a..0000000
--- a/lang/csharp/src/apache/main/CodeGen/CodeGen.cs
+++ /dev/null
@@ -1,659 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.CodeDom;
-using System.CodeDom.Compiler;
-using Microsoft.CSharp;
-using System.IO;
-
-namespace Avro
-{
- public class CodeGen
- {
- /// <summary>
- /// Object that contains all the generated types
- /// </summary>
- public CodeCompileUnit CompileUnit { get; private set; }
-
- /// <summary>
- /// List of schemas to generate code for
- /// </summary>
- public IList<Schema> Schemas { get; private set; }
-
- /// <summary>
- /// List of protocols to generate code for
- /// </summary>
- public IList<Protocol> Protocols { get; private set; }
-
- /// <summary>
- /// List of generated namespaces
- /// </summary>
- protected Dictionary<string, CodeNamespace> namespaceLookup = new Dictionary<string, CodeNamespace>(StringComparer.Ordinal);
-
- /// <summary>
- /// Default constructor
- /// </summary>
- public CodeGen()
- {
- this.Schemas = new List<Schema>();
- this.Protocols = new List<Protocol>();
- }
-
- /// <summary>
- /// Adds a protocol object to generate code for
- /// </summary>
- /// <param name="protocol">protocol object</param>
- public virtual void AddProtocol(Protocol protocol)
- {
- Protocols.Add(protocol);
- }
-
- /// <summary>
- /// Adds a schema object to generate code for
- /// </summary>
- /// <param name="schema">schema object</param>
- public virtual void AddSchema(Schema schema)
- {
- Schemas.Add(schema);
- }
-
- /// <summary>
- /// Adds a namespace object for the given name into the dictionary if it doesn't exist yet
- /// </summary>
- /// <param name="name">name of namespace</param>
- /// <returns></returns>
- protected virtual CodeNamespace addNamespace(string name)
- {
- if (string.IsNullOrEmpty(name))
- throw new ArgumentNullException("name", "name cannot be null.");
-
- CodeNamespace ns = null;
-
- if (!namespaceLookup.TryGetValue(name, out ns))
- {
- ns = new CodeNamespace(CodeGenUtil.Instance.Mangle(name));
- foreach (CodeNamespaceImport nci in CodeGenUtil.Instance.NamespaceImports)
- ns.Imports.Add(nci);
-
- CompileUnit.Namespaces.Add(ns);
- namespaceLookup.Add(name, ns);
- }
- return ns;
- }
-
- /// <summary>
- /// Generates code for the given protocol and schema objects
- /// </summary>
- /// <returns>CodeCompileUnit object</returns>
- public virtual CodeCompileUnit GenerateCode()
- {
- CompileUnit = new CodeCompileUnit();
-
- processSchemas();
- processProtocols();
-
- return CompileUnit;
- }
-
- /// <summary>
- /// Generates code for the schema objects
- /// </summary>
- protected virtual void processSchemas()
- {
- foreach (Schema schema in this.Schemas)
- {
- SchemaNames names = generateNames(schema);
- foreach (KeyValuePair<SchemaName, NamedSchema> sn in names)
- {
- switch (sn.Value.Tag)
- {
- case Schema.Type.Enumeration: processEnum(sn.Value); break;
- case Schema.Type.Fixed: processFixed(sn.Value); break;
- case Schema.Type.Record: processRecord(sn.Value); break;
- case Schema.Type.Error: processRecord(sn.Value); break;
- default:
- throw new CodeGenException("Names in schema should only be of type NamedSchema, type found " + sn.Value.Tag);
- }
- }
- }
- }
-
- /// <summary>
- /// Generates code for the protocol objects
- /// </summary>
- protected virtual void processProtocols()
- {
- foreach (Protocol protocol in Protocols)
- {
- SchemaNames names = generateNames(protocol);
- foreach (KeyValuePair<SchemaName, NamedSchema> sn in names)
- {
- switch (sn.Value.Tag)
- {
- case Schema.Type.Enumeration: processEnum(sn.Value); break;
- case Schema.Type.Fixed: processFixed(sn.Value); break;
- case Schema.Type.Record: processRecord(sn.Value); break;
- case Schema.Type.Error: processRecord(sn.Value); break;
- default:
- throw new CodeGenException("Names in protocol should only be of type NamedSchema, type found " + sn.Value.Tag);
- }
- }
- }
- }
-
- /// <summary>
- /// Generate list of named schemas from given protocol
- /// </summary>
- /// <param name="protocol">protocol to process</param>
- /// <returns></returns>
- protected virtual SchemaNames generateNames(Protocol protocol)
- {
- var names = new SchemaNames();
- foreach (Schema schema in protocol.Types)
- addName(schema, names);
- return names;
- }
-
- /// <summary>
- /// Generate list of named schemas from given schema
- /// </summary>
- /// <param name="schema">schema to process</param>
- /// <returns></returns>
- protected virtual SchemaNames generateNames(Schema schema)
- {
- var names = new SchemaNames();
- addName(schema, names);
- return names;
- }
-
- /// <summary>
- /// Recursively search the given schema for named schemas and adds them to the given container
- /// </summary>
- /// <param name="schema">schema object to search</param>
- /// <param name="names">list of named schemas</param>
- protected virtual void addName(Schema schema, SchemaNames names)
- {
- NamedSchema ns = schema as NamedSchema;
- if (null != ns) if (names.Contains(ns.SchemaName)) return;
-
- switch (schema.Tag)
- {
- case Schema.Type.Null:
- case Schema.Type.Boolean:
- case Schema.Type.Int:
- case Schema.Type.Long:
- case Schema.Type.Float:
- case Schema.Type.Double:
- case Schema.Type.Bytes:
- case Schema.Type.String:
- break;
-
- case Schema.Type.Enumeration:
- case Schema.Type.Fixed:
- names.Add(ns);
- break;
-
- case Schema.Type.Record:
- case Schema.Type.Error:
- var rs = schema as RecordSchema;
- names.Add(rs);
- foreach (Field field in rs.Fields)
- addName(field.Schema, names);
- break;
-
- case Schema.Type.Array:
- var asc = schema as ArraySchema;
- addName(asc.ItemSchema, names);
- break;
-
- case Schema.Type.Map:
- var ms = schema as MapSchema;
- addName(ms.ValueSchema, names);
- break;
-
- case Schema.Type.Union:
- var us = schema as UnionSchema;
- foreach (Schema usc in us.Schemas)
- addName(usc, names);
- break;
-
- default:
- throw new CodeGenException("Unable to add name for " + schema.Name + " type " + schema.Tag);
- }
- }
-
- /// <summary>
- /// Creates a class declaration for fixed schema
- /// </summary>
- /// <param name="schema">fixed schema</param>
- /// <param name="ns">namespace object</param>
- protected virtual void processFixed(Schema schema)
- {
- FixedSchema fixedSchema = schema as FixedSchema;
- if (null == fixedSchema) throw new CodeGenException("Unable to cast schema into a fixed");
-
- CodeTypeDeclaration ctd = new CodeTypeDeclaration();
- ctd.Name = CodeGenUtil.Instance.Mangle(fixedSchema.Name);
- ctd.IsClass = true;
- ctd.IsPartial = true;
- ctd.Attributes = MemberAttributes.Public;
- ctd.BaseTypes.Add("SpecificFixed");
-
- // create static schema field
- createSchemaField(schema, ctd, true);
-
- // Add Size field
- string sizefname = "fixedSize";
- var ctrfield = new CodeTypeReference(typeof(uint));
- var codeField = new CodeMemberField(ctrfield, sizefname);
- codeField.Attributes = MemberAttributes.Private | MemberAttributes.Static;
- codeField.InitExpression = new CodePrimitiveExpression(fixedSchema.Size);
- ctd.Members.Add(codeField);
-
- // Add Size property
- var fieldRef = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), sizefname);
- var property = new CodeMemberProperty();
- property.Attributes = MemberAttributes.Public | MemberAttributes.Static;
- property.Name = "FixedSize";
- property.Type = ctrfield;
- property.GetStatements.Add(new CodeMethodReturnStatement(new CodeTypeReferenceExpression(schema.Name + "." + sizefname)));
- ctd.Members.Add(property);
-
- // create constructor to initiate base class SpecificFixed
- CodeConstructor cc = new CodeConstructor();
- cc.Attributes = MemberAttributes.Public;
- cc.BaseConstructorArgs.Add(new CodeVariableReferenceExpression(sizefname));
- ctd.Members.Add(cc);
-
- string nspace = fixedSchema.Namespace;
- if (string.IsNullOrEmpty(nspace))
- throw new CodeGenException("Namespace required for enum schema " + fixedSchema.Name);
- CodeNamespace codens = addNamespace(nspace);
- codens.Types.Add(ctd);
- }
-
- /// <summary>
- /// Creates an enum declaration
- /// </summary>
- /// <param name="schema">enum schema</param>
- /// <param name="ns">namespace</param>
- protected virtual void processEnum(Schema schema)
- {
- EnumSchema enumschema = schema as EnumSchema;
- if (null == enumschema) throw new CodeGenException("Unable to cast schema into an enum");
-
- CodeTypeDeclaration ctd = new CodeTypeDeclaration(CodeGenUtil.Instance.Mangle(enumschema.Name));
- ctd.IsEnum = true;
- ctd.Attributes = MemberAttributes.Public;
-
- foreach (string symbol in enumschema.Symbols)
- {
- if (CodeGenUtil.Instance.ReservedKeywords.Contains(symbol))
- throw new CodeGenException("Enum symbol " + symbol + " is a C# reserved keyword");
- CodeMemberField field = new CodeMemberField(typeof(int), symbol);
- ctd.Members.Add(field);
- }
-
- string nspace = enumschema.Namespace;
- if (string.IsNullOrEmpty(nspace))
- throw new CodeGenException("Namespace required for enum schema " + enumschema.Name);
- CodeNamespace codens = addNamespace(nspace);
-
- codens.Types.Add(ctd);
- }
-
- /// <summary>
- /// Creates a class declaration
- /// </summary>
- /// <param name="schema">record schema</param>
- /// <param name="ns">namespace</param>
- /// <returns></returns>
- protected virtual CodeTypeDeclaration processRecord(Schema schema)
- {
- RecordSchema recordSchema = schema as RecordSchema;
- if (null == recordSchema) throw new CodeGenException("Unable to cast schema into a record");
-
- // declare the class
- var ctd = new CodeTypeDeclaration(CodeGenUtil.Instance.Mangle(recordSchema.Name));
- ctd.BaseTypes.Add("ISpecificRecord");
- ctd.Attributes = MemberAttributes.Public;
- ctd.IsClass = true;
- ctd.IsPartial = true;
-
- createSchemaField(schema, ctd, false);
-
- // declare Get() to be used by the Writer classes
- var cmmGet = new CodeMemberMethod();
- cmmGet.Name = "Get";
- cmmGet.Attributes = MemberAttributes.Public;
- cmmGet.ReturnType = new CodeTypeReference("System.Object");
- cmmGet.Parameters.Add(new CodeParameterDeclarationExpression(typeof(int), "fieldPos"));
- StringBuilder getFieldStmt = new StringBuilder("switch (fieldPos)\n\t\t\t{\n");
-
- // declare Put() to be used by the Reader classes
- var cmmPut = new CodeMemberMethod();
- cmmPut.Name = "Put";
- cmmPut.Attributes = MemberAttributes.Public;
- cmmPut.ReturnType = new CodeTypeReference(typeof(void));
- cmmPut.Parameters.Add(new CodeParameterDeclarationExpression(typeof(int), "fieldPos"));
- cmmPut.Parameters.Add(new CodeParameterDeclarationExpression("System.Object", "fieldValue"));
- var putFieldStmt = new StringBuilder("switch (fieldPos)\n\t\t\t{\n");
-
- foreach (Field field in recordSchema.Fields)
- {
- // Determine type of field
- bool nullibleEnum = false;
- string baseType = getType(field.Schema, false, ref nullibleEnum);
- var ctrfield = new CodeTypeReference(baseType);
-
- // Create field
- string privFieldName = string.Concat("_", field.Name);
- var codeField = new CodeMemberField(ctrfield, privFieldName);
- codeField.Attributes = MemberAttributes.Private;
-
- // Process field documentation if it exist and add to the field
- CodeCommentStatement propertyComment = null;
- if (!string.IsNullOrEmpty(field.Documentation))
- {
- propertyComment = createDocComment(field.Documentation);
- if (null != propertyComment)
- codeField.Comments.Add(propertyComment);
- }
-
- // Add field to class
- ctd.Members.Add(codeField);
-
- // Create reference to the field - this.fieldname
- var fieldRef = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), privFieldName);
- var mangledName = CodeGenUtil.Instance.Mangle(field.Name);
-
- // Create field property with get and set methods
- var property = new CodeMemberProperty();
- property.Attributes = MemberAttributes.Public | MemberAttributes.Final;
- property.Name = mangledName;
- property.Type = ctrfield;
- property.GetStatements.Add(new CodeMethodReturnStatement(fieldRef));
- property.SetStatements.Add(new CodeAssignStatement(fieldRef, new CodePropertySetValueReferenceExpression()));
- if (null != propertyComment)
- property.Comments.Add(propertyComment);
-
- // Add field property to class
- ctd.Members.Add(property);
-
- // add to Get()
- getFieldStmt.Append("\t\t\tcase ");
- getFieldStmt.Append(field.Pos);
- getFieldStmt.Append(": return this.");
- getFieldStmt.Append(mangledName);
- getFieldStmt.Append(";\n");
-
- // add to Put()
- putFieldStmt.Append("\t\t\tcase ");
- putFieldStmt.Append(field.Pos);
- putFieldStmt.Append(": this.");
- putFieldStmt.Append(mangledName);
-
- if (nullibleEnum)
- {
- putFieldStmt.Append(" = fieldValue == null ? (");
- putFieldStmt.Append(baseType);
- putFieldStmt.Append(")null : (");
-
- string type = baseType.Remove(0, 16); // remove System.Nullable<
- type = type.Remove(type.Length - 1); // remove >
-
- putFieldStmt.Append(type);
- putFieldStmt.Append(")fieldValue; break;\n");
- }
- else
- {
- putFieldStmt.Append(" = (");
- putFieldStmt.Append(baseType);
- putFieldStmt.Append(")fieldValue; break;\n");
- }
- }
-
- // end switch block for Get()
- getFieldStmt.Append("\t\t\tdefault: throw new AvroRuntimeException(\"Bad index \" + fieldPos + \" in Get()\");\n\t\t\t}");
- var cseGet = new CodeSnippetExpression(getFieldStmt.ToString());
- cmmGet.Statements.Add(cseGet);
- ctd.Members.Add(cmmGet);
-
- // end switch block for Put()
- putFieldStmt.Append("\t\t\tdefault: throw new AvroRuntimeException(\"Bad index \" + fieldPos + \" in Put()\");\n\t\t\t}");
- var csePut = new CodeSnippetExpression(putFieldStmt.ToString());
- cmmPut.Statements.Add(csePut);
- ctd.Members.Add(cmmPut);
-
- string nspace = recordSchema.Namespace;
- if (string.IsNullOrEmpty(nspace))
- throw new CodeGenException("Namespace required for record schema " + recordSchema.Name);
- CodeNamespace codens = addNamespace(nspace);
-
- codens.Types.Add(ctd);
-
- return ctd;
- }
-
- /// <summary>
- /// Gets the string representation of the schema's data type
- /// </summary>
- /// <param name="schema">schema</param>
- /// <param name="nullible">flag to indicate union with null</param>
- /// <returns></returns>
- internal static string getType(Schema schema, bool nullible, ref bool nullibleEnum)
- {
- switch (schema.Tag)
- {
- case Schema.Type.Null:
- return "System.Object";
- case Schema.Type.Boolean:
- if (nullible) return "System.Nullable<bool>";
- else return typeof(bool).ToString();
- case Schema.Type.Int:
- if (nullible) return "System.Nullable<int>";
- else return typeof(int).ToString();
- case Schema.Type.Long:
- if (nullible) return "System.Nullable<long>";
- else return typeof(long).ToString();
- case Schema.Type.Float:
- if (nullible) return "System.Nullable<float>";
- else return typeof(float).ToString();
- case Schema.Type.Double:
- if (nullible) return "System.Nullable<double>";
- else return typeof(double).ToString();
-
- case Schema.Type.Bytes:
- return typeof(byte[]).ToString();
- case Schema.Type.String:
- return typeof(string).ToString();
-
- case Schema.Type.Enumeration:
- var namedSchema = schema as NamedSchema;
- if (null == namedSchema)
- throw new CodeGenException("Unable to cast schema into a named schema");
- if (nullible)
- {
- nullibleEnum = true;
- return "System.Nullable<" + CodeGenUtil.Instance.Mangle(namedSchema.Fullname) + ">";
- }
- else return CodeGenUtil.Instance.Mangle(namedSchema.Fullname);
-
- case Schema.Type.Fixed:
- case Schema.Type.Record:
- case Schema.Type.Error:
- namedSchema = schema as NamedSchema;
- if (null == namedSchema)
- throw new CodeGenException("Unable to cast schema into a named schema");
- return CodeGenUtil.Instance.Mangle(namedSchema.Fullname);
-
- case Schema.Type.Array:
- var arraySchema = schema as ArraySchema;
- if (null == arraySchema)
- throw new CodeGenException("Unable to cast schema into an array schema");
-
- return "IList<" + getType(arraySchema.ItemSchema, false, ref nullibleEnum) + ">";
-
- case Schema.Type.Map:
- var mapSchema = schema as MapSchema;
- if (null == mapSchema)
- throw new CodeGenException("Unable to cast schema into a map schema");
- return "IDictionary<string," + getType(mapSchema.ValueSchema, false, ref nullibleEnum) + ">";
-
- case Schema.Type.Union:
- var unionSchema = schema as UnionSchema;
- if (null == unionSchema)
- throw new CodeGenException("Unable to cast schema into a union schema");
- Schema nullibleType = getNullableType(unionSchema);
- if (null == nullibleType)
- return CodeGenUtil.Object;
- else
- return getType(nullibleType, true, ref nullibleEnum);
- }
- throw new CodeGenException("Unable to generate CodeTypeReference for " + schema.Name + " type " + schema.Tag);
- }
-
- /// <summary>
- /// Gets the schema of a union with null
- /// </summary>
- /// <param name="schema">union schema</param>
- /// <returns>schema that is nullible</returns>
- public static Schema getNullableType(UnionSchema schema)
- {
- Schema ret = null;
- if (schema.Count == 2)
- {
- bool nullable = false;
- foreach (Schema childSchema in schema.Schemas)
- {
- if (childSchema.Tag == Schema.Type.Null)
- nullable = true;
- else
- ret = childSchema;
- }
- if (!nullable)
- ret = null;
- }
- return ret;
- }
-
- /// <summary>
- /// Creates the static schema field for class types
- /// </summary>
- /// <param name="schema">schema</param>
- /// <param name="ctd">CodeTypeDeclaration for the class</param>
- protected virtual void createSchemaField(Schema schema, CodeTypeDeclaration ctd, bool overrideFlag)
- {
- // create schema field
- var ctrfield = new CodeTypeReference("Schema");
- string schemaFname = "_SCHEMA";
- var codeField = new CodeMemberField(ctrfield, schemaFname);
- codeField.Attributes = MemberAttributes.Private | MemberAttributes.Static;
- // create function call Schema.Parse(json)
- var cpe = new CodePrimitiveExpression(schema.ToString());
- var cmie = new CodeMethodInvokeExpression(
- new CodeMethodReferenceExpression(new CodeTypeReferenceExpression(typeof(Schema)), "Parse"),
- new CodeExpression[] { cpe });
- codeField.InitExpression = cmie;
- ctd.Members.Add(codeField);
-
- // create property to get static schema field
- var property = new CodeMemberProperty();
- property.Attributes = MemberAttributes.Public;
- if (overrideFlag) property.Attributes |= MemberAttributes.Override;
- property.Name = "Schema";
- property.Type = ctrfield;
-
- property.GetStatements.Add(new CodeMethodReturnStatement(new CodeTypeReferenceExpression(ctd.Name + "." + schemaFname)));
- ctd.Members.Add(property);
- }
-
- /// <summary>
- /// Creates an XML documentation for the given comment
- /// </summary>
- /// <param name="comment">comment</param>
- /// <returns>CodeCommentStatement object</returns>
- protected virtual CodeCommentStatement createDocComment(string comment)
- {
- string text = string.Format("<summary>\r\n {0}\r\n </summary>", comment);
- return new CodeCommentStatement(text, true);
- }
-
- /// <summary>
- /// Writes the generated compile unit into one file
- /// </summary>
- /// <param name="outputFile">name of output file to write to</param>
- public virtual void WriteCompileUnit(string outputFile)
- {
- var cscp = new CSharpCodeProvider();
-
- var opts = new CodeGeneratorOptions();
- opts.BracingStyle = "C";
- opts.IndentString = "\t";
- opts.BlankLinesBetweenMembers = false;
-
- using (var outfile = new StreamWriter(outputFile))
- {
- cscp.GenerateCodeFromCompileUnit(CompileUnit, outfile, opts);
- }
- }
-
- /// <summary>
- /// Writes each types in each namespaces into individual files
- /// </summary>
- /// <param name="outputdir">name of directory to write to</param>
- public virtual void WriteTypes(string outputdir)
- {
- var cscp = new CSharpCodeProvider();
-
- var opts = new CodeGeneratorOptions();
- opts.BracingStyle = "C";
- opts.IndentString = "\t";
- opts.BlankLinesBetweenMembers = false;
-
- CodeNamespaceCollection nsc = CompileUnit.Namespaces;
- for (int i = 0; i < nsc.Count; i++)
- {
- var ns = nsc[i];
-
- string dir = outputdir + "\\" + CodeGenUtil.Instance.UnMangle(ns.Name).Replace('.', '\\');
- Directory.CreateDirectory(dir);
-
- var new_ns = new CodeNamespace(ns.Name);
- new_ns.Comments.Add(CodeGenUtil.Instance.FileComment);
- foreach (CodeNamespaceImport nci in CodeGenUtil.Instance.NamespaceImports)
- new_ns.Imports.Add(nci);
-
- var types = ns.Types;
- for (int j = 0; j < types.Count; j++)
- {
- var ctd = types[j];
- string file = dir + "\\" + CodeGenUtil.Instance.UnMangle(ctd.Name) + ".cs";
- using (var writer = new StreamWriter(file, false))
- {
- new_ns.Types.Add(ctd);
- cscp.GenerateCodeFromNamespace(new_ns, writer, opts);
- new_ns.Types.Remove(ctd);
- }
- }
- }
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/CodeGen/CodeGenException.cs b/lang/csharp/src/apache/main/CodeGen/CodeGenException.cs
deleted file mode 100644
index 025d769..0000000
--- a/lang/csharp/src/apache/main/CodeGen/CodeGenException.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace Avro
-{
- class CodeGenException : AvroException
- {
- public CodeGenException(string s)
- : base(s)
- {
-
- }
- public CodeGenException(string s, Exception inner)
- : base(s, inner)
- {
-
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/CodeGen/CodeGenUtil.cs b/lang/csharp/src/apache/main/CodeGen/CodeGenUtil.cs
deleted file mode 100644
index 68b83d8..0000000
--- a/lang/csharp/src/apache/main/CodeGen/CodeGenUtil.cs
+++ /dev/null
@@ -1,105 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.CodeDom;
-
-namespace Avro
-{
- /// <summary>
- /// A singleton class containing data used by codegen
- /// </summary>
- public sealed class CodeGenUtil
- {
- private static readonly CodeGenUtil instance = new CodeGenUtil();
- public static CodeGenUtil Instance { get { return instance; } }
-
- public CodeNamespaceImport[] NamespaceImports { get; private set; }
- public CodeCommentStatement FileComment { get; private set; }
- public HashSet<string> ReservedKeywords { get; private set; }
- private const char At = '@';
- private const char Dot = '.';
- public const string Object = "System.Object";
-
- private CodeGenUtil()
- {
- NamespaceImports = new CodeNamespaceImport[] {
- new CodeNamespaceImport("System"),
- new CodeNamespaceImport("System.Collections.Generic"),
- new CodeNamespaceImport("System.Text"),
- new CodeNamespaceImport("Avro"),
- new CodeNamespaceImport("Avro.Specific") };
-
- FileComment = new CodeCommentStatement(
-@"------------------------------------------------------------------------------
- <auto-generated>
- Generated by " + System.AppDomain.CurrentDomain.FriendlyName + ", version " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version + @"
- Changes to this file may cause incorrect behavior and will be lost if code
- is regenerated
- </auto-generated>
- ------------------------------------------------------------------------------");
-
- // Visual Studio 2010 http://msdn.microsoft.com/en-us/library/x53a06bb.aspx
- ReservedKeywords = new HashSet<string>() {
- "abstract","as", "base", "bool", "break", "byte", "case", "catch", "char", "checked", "class",
- "const", "continue", "decimal", "default", "delegate", "do", "double", "else", "enum", "event",
- "explicit", "extern", "false", "finally", "fixed", "float", "for", "foreach", "goto", "if",
- "implicit", "in", "int", "interface", "internal", "is", "lock", "long", "namespace", "new",
- "null", "object", "operator", "out", "override", "params", "private", "protected", "public",
- "readonly", "ref", "return", "sbyte", "sealed", "short", "sizeof", "stackalloc", "static",
- "string", "struct", "switch", "this", "throw", "true", "try", "typeof", "uint", "ulong",
- "unchecked", "unsafe", "ushort", "using", "virtual", "void", "volatile", "while", "value", "partial" };
- }
-
- /// <summary>
- /// Append @ to all reserved keywords that appear on the given name
- /// </summary>
- /// <param name="name"></param>
- /// <returns></returns>
- public string Mangle(string name)
- {
- var builder = new StringBuilder();
- string[] names = name.Split(Dot);
- for (int i = 0; i < names.Length; ++i)
- {
- if (ReservedKeywords.Contains(names[i]))
- builder.Append(At);
- builder.Append(names[i]);
- builder.Append(Dot);
- }
- builder.Remove(builder.Length - 1, 1);
- return builder.ToString();
- }
-
- /// <summary>
- /// Remove all the @
- /// </summary>
- /// <param name="name"></param>
- /// <returns></returns>
- public string UnMangle(string name)
- {
- var builder = new StringBuilder(name.Length);
- for (int i = 0; i < name.Length; ++i)
- if (name[i] != At)
- builder.Append(name[i]);
- return builder.ToString();
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/Generic/DatumReader.cs b/lang/csharp/src/apache/main/Generic/DatumReader.cs
deleted file mode 100644
index 00b5fbe..0000000
--- a/lang/csharp/src/apache/main/Generic/DatumReader.cs
+++ /dev/null
@@ -1,325 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using Avro.IO;
-
-namespace Avro.Generic
-{
- public interface DatumReader<T>
- {
- Schema ReaderSchema { get; }
- Schema WriterSchema { get; }
-
- /// <summary>
- /// Read a datum. Traverse the schema, depth-first, reading all leaf values
- /// in the schema into a datum that is returned. If the provided datum is
- /// non-null it may be reused and returned.
- /// </summary>
- T Read(T reuse, Decoder decoder);
- }
-
- ///// <summary>
- ///// Deserialize Avro-encoded data into a .net data structure.
- ///// </summary>
- //public class DatumReader
- //{
- // public Schema WriterSchema { get; private set; }
- // public Schema ReaderSchema { get; private set; }
-
- // /// <summary>
- // /// As defined in the Avro specification, we call the schema encoded
- // /// in the data the "writer's schema", and the schema expected by the
- // /// reader the "reader's schema".
- // /// </summary>
- // /// <param name="writerSchema"></param>
- // /// <param name="readerSchema"></param>
- // public DatumReader(Schema writerSchema, Schema readerSchema)
- // {
- // if (null == writerSchema) throw new ArgumentNullException("writerSchema", "writerSchema cannot be null.");
- // if (null == readerSchema) throw new ArgumentNullException("readerSchema", "readerSchema cannot be null.");
-
- // this.WriterSchema = writerSchema;
- // this.ReaderSchema = readerSchema;
- // }
-
-
- // static bool checkProps(Schema a, Schema b, params string[] props)
- // {
- // foreach (string prop in props)
- // {
- // if (!string.Equals(a[prop], b[prop]))
- // return false;
- // }
-
- // return true;
- // }
- // //static bool CheckProps(Schema schema_one, Schema schema_two, IEnumerable<string> props)
- // //{
-
- // //}
-
- // static bool matchSchemas(Schema writers_schema, Schema readers_schema)
- // {
- // string w_type = writers_schema.Type, r_type = readers_schema.Type;
-
- // if (string.Equals(Schema.UNION, w_type) || string.Equals(Schema.UNION, r_type))
- // return true;
- // else if (PrimitiveSchema.PrimitiveKeyLookup.ContainsKey(w_type) && PrimitiveSchema.PrimitiveKeyLookup.ContainsKey(r_type) && w_type == r_type)
- // return true;
- // else if (w_type == Schema.RECORD && r_type == Schema.RECORD && DatumReader.checkProps(writers_schema, readers_schema, "fullname"))
- // return true;
- // else if (w_type == "error" && r_type == "error" && DatumReader.checkProps(writers_schema, readers_schema, "fullname"))
- // return true;
- // else if (w_type == "request" && r_type == "request")
- // return true;
- // else if (w_type == Schema.FIXED && r_type == Schema.FIXED && DatumReader.checkProps(writers_schema, readers_schema, "fullname", "size"))
- // return true;
- // else if (w_type == Schema.ENUM && r_type == Schema.ENUM && DatumReader.checkProps(writers_schema, readers_schema, "fullname"))
- // return true;
- // //else if (w_type == Schema.MAP && r_type == Schema.MAP && DatumReader.CheckProps(writers_schema.values, readers_schema.values, "type"))
- // // return true;
- // //else if (w_type == Schema.ARRAY && r_type == Schema.ARRAY && DatumReader.check_props(writers_schema.items, readers_schema.items, "type"))
- // // return true;
- // else if (w_type == Schema.INT && Util.checkIsValue(r_type, Schema.LONG, Schema.FLOAT, Schema.DOUBLE))
- // return true;
- // else if (w_type == Schema.LONG && Util.checkIsValue(r_type, Schema.FLOAT, Schema.DOUBLE))
- // return true;
- // else if (w_type == Schema.FLOAT && r_type == Schema.DOUBLE)
- // return true;
-
- // if (Util.checkIsValue(w_type, Schema.MAP, Schema.ARRAY))
- // throw new NotImplementedException(w_type);
-
- // return false;
- // }
-
- // public object Read(BinaryDecoder decoder)
- // {
- // if (null == this.ReaderSchema)
- // this.ReaderSchema = this.WriterSchema;
-
- // return ReadData(this.WriterSchema, this.ReaderSchema, decoder);
-
- // }
-
- // private object ReadData(Schema writers_schema, Schema readers_schema, BinaryDecoder decoder)
- // {
- // if (!matchSchemas(writers_schema, readers_schema))
- // throw new SchemaResolutionException("Schemas do not match.", writers_schema, readers_schema);
-
- // if (writers_schema.Type != Schema.UNION && readers_schema.Type == Schema.UNION)
- // {
- // foreach (Schema s in ((UnionSchema)readers_schema).Schemas)
- // {
- // if (DatumReader.matchSchemas(writers_schema, s))
- // {
- // return ReadData(writers_schema, s, decoder);
- // }
- // }
-
- // throw new SchemaResolutionException("Schemas do not match.", writers_schema, readers_schema);
- // }
-
- // if (writers_schema.Type == Schema.NULL)
- // return decoder.ReadNull();
- // else if (writers_schema.Type == Schema.BOOLEAN)
- // return decoder.ReadBool();
- // else if (writers_schema.Type == Schema.STRING)
- // return decoder.ReadUTF8();
- // else if (writers_schema.Type == Schema.INT)
- // return decoder.ReadInt();
- // else if (writers_schema.Type == Schema.LONG)
- // return decoder.ReadLong();
- // else if (writers_schema.Type == Schema.FLOAT)
- // return decoder.ReadFloat();
- // else if (writers_schema.Type == Schema.DOUBLE)
- // return decoder.ReadDouble();
- // else if (writers_schema.Type == Schema.BYTES)
- // return decoder.ReadBytes();
- // else if (writers_schema.Type == Schema.FIXED)
- // return ReadFixed(writers_schema, readers_schema, decoder);
- // else if (writers_schema.Type == Schema.ENUM)
- // return ReadEnum(writers_schema, readers_schema, decoder);
- // else if (writers_schema.Type == Schema.ARRAY)
- // return ReadArray(writers_schema, readers_schema, decoder);
- // else if (writers_schema.Type == Schema.MAP)
- // return ReadMap(writers_schema, readers_schema, decoder);
- // else if (writers_schema.Type == Schema.UNION)
- // return ReadUnion(writers_schema, readers_schema, decoder);
- // else if (Util.checkIsValue(writers_schema.Type, Schema.RECORD, "error", "request"))
- // return ReadRecord(writers_schema, readers_schema, decoder);
- // else
- // throw new AvroException("Cannot Read unknown type type) " + writers_schema.Type);
- // }
-
- // public void SkipData(Schema writers_schema, BinaryDecoder decoder)
- // {
- // if (writers_schema.Type == Schema.NULL)
- // decoder.SkipNull();
- // else if (writers_schema.Type == Schema.BOOLEAN)
- // decoder.SkipBoolean();
- // else if (writers_schema.Type == Schema.STRING)
- // decoder.SkipUTF8();
- // else if (writers_schema.Type == Schema.INT)
- // decoder.SkipInt();
- // else if (writers_schema.Type == Schema.LONG)
- // decoder.SkipLong();
- // else if (writers_schema.Type == Schema.FLOAT)
- // decoder.SkipFloat();
- // else if (writers_schema.Type == Schema.DOUBLE)
- // decoder.SkipDouble();
- // else if (writers_schema.Type == Schema.BYTES)
- // decoder.ReadBytes();
- // else if (writers_schema.Type == Schema.FIXED)
- // SkipFixed(writers_schema as FixedSchema, decoder);
- // else if (writers_schema.Type == Schema.ENUM)
- // SkipEnum(writers_schema, decoder);
- // else if (writers_schema.Type == Schema.ARRAY)
- // SkipArray(writers_schema as ArraySchema, decoder);
- // else if (writers_schema.Type == Schema.MAP)
- // SkipMap(writers_schema as MapSchema, decoder);
- // else if (writers_schema.Type == Schema.UNION)
- // SkipUnion(writers_schema as UnionSchema, decoder);
- // else if (Util.checkIsValue(writers_schema.Type, Schema.RECORD, "error", "request"))
- // SkipRecord(writers_schema as RecordSchema, decoder);
- // else
- // throw new AvroException("Unknown type type: %s" + writers_schema.Type);
-
- // }
-
- // private void SkipRecord(RecordSchema writers_schema, BinaryDecoder decoder)
- // {
- // foreach (Field field in writers_schema.Fields)
- // SkipData(field.Schema, decoder);
- // }
-
- // private void SkipUnion(UnionSchema writers_schema, BinaryDecoder decoder)
- // {
- // int index_of_schema = (int)decoder.ReadLong();
- // SkipData(writers_schema.Schemas[index_of_schema], decoder);
- // }
-
- // private void SkipMap(MapSchema writers_schema, BinaryDecoder decoder)
- // {
- // long block_count = decoder.ReadLong();
- // while (block_count != 0)
- // {
- // if (block_count < 0)
- // {
- // long block_size = decoder.ReadLong();
- // decoder.skip(block_size);
- // }
- // else
- // {
- // for (int i = 0; i < block_count; i++)
- // {
- // decoder.SkipUTF8();
- // SkipData(writers_schema.Values, decoder);
- // block_count = decoder.ReadLong();
- // }
- // }
- // }
- // }
-
- // private void SkipArray(ArraySchema writers_schema, BinaryDecoder decoder)
- // {
- // long block_count = decoder.ReadLong();
- // while (block_count != 0)
- // {
- // if (block_count < 0)
- // {
- // long block_size = decoder.ReadLong();
- // decoder.skip(block_size);
- // }
- // else
- // {
- // for (int i = 0; i < block_count; i++)
- // {
- // decoder.SkipUTF8();
- // SkipData(writers_schema.Items, decoder);
- // block_count = decoder.ReadLong();
- // }
- // }
- // }
- // }
-
- // private void SkipEnum(Schema writers_schema, BinaryDecoder decoder)
- // {
- // decoder.SkipInt();
- // }
-
- // private void SkipFixed(FixedSchema writers_schema, BinaryDecoder decoder)
- // {
- // decoder.skip(writers_schema.Size);
- // }
-
- // /// <summary>
- // /// A record is encoded by encoding the values of its fields
- // /// in the order that they are declared. In other words, a record
- // /// is encoded as just the concatenation of the encodings of its fields.
- // /// Field values are encoded per their schema.
-
- // /// Schema Resolution:
- // /// * the ordering of fields may be different: fields are matched by name.
- // /// * schemas for fields with the same name in both records are resolved
- // /// recursively.
- // /// * if the writer's record contains a field with a name not present in the
- // /// reader's record, the writer's value for that field is ignored.
- // /// * if the reader's record schema has a field that contains a default value,
- // /// and writer's schema does not have a field with the same name, then the
- // /// reader should use the default value from its field.
- // /// * if the reader's record schema has a field with no default value, and
- // /// writer's schema does not have a field with the same name, then the
- // /// field's value is unset.
- // /// </summary>
- // /// <param name="writers_schema"></param>
- // /// <param name="readers_schema"></param>
- // /// <param name="decoder"></param>
- // /// <returns></returns>
- // private object ReadRecord(Schema writers_schema, Schema readers_schema, BinaryDecoder decoder)
- // {
- // throw new NotImplementedException();
- // }
-
- // private object ReadUnion(Schema writers_schema, Schema readers_schema, BinaryDecoder decoder)
- // {
- // throw new NotImplementedException();
- // }
-
- // private object ReadMap(Schema writers_schema, Schema readers_schema, BinaryDecoder decoder)
- // {
- // throw new NotImplementedException();
- // }
-
- // private object ReadArray(Schema writers_schema, Schema readers_schema, BinaryDecoder decoder)
- // {
- // throw new NotImplementedException();
- // }
-
- // private object ReadEnum(Schema writers_schema, Schema readers_schema, BinaryDecoder decoder)
- // {
- // throw new NotImplementedException();
- // }
-
- // private object ReadFixed(Schema writers_schema, Schema readers_schema, BinaryDecoder decoder)
- // {
- // throw new NotImplementedException();
- // }
- //}
-}
diff --git a/lang/csharp/src/apache/main/Generic/DatumWriter.cs b/lang/csharp/src/apache/main/Generic/DatumWriter.cs
deleted file mode 100644
index 87095d6..0000000
--- a/lang/csharp/src/apache/main/Generic/DatumWriter.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * 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.
- */
-using System;
-using Avro.IO;
-
-namespace Avro.Generic
-{
- public interface DatumWriter<T>
- {
- Schema Schema { get; }
- void Write(T datum, Encoder encoder);
- }
-}
diff --git a/lang/csharp/src/apache/main/Generic/GenericEnum.cs b/lang/csharp/src/apache/main/Generic/GenericEnum.cs
deleted file mode 100644
index 1aa0058..0000000
--- a/lang/csharp/src/apache/main/Generic/GenericEnum.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace Avro.Generic
-{
- /// <summary>
- /// The defualt class to hold values for enum schema in GenericReader and GenericWriter.
- /// </summary>
- public class GenericEnum
- {
- public EnumSchema Schema { get; private set; }
- private string value;
- public string Value {
- get { return value; }
- set
- {
- if (! Schema.Contains(value)) throw new AvroException("Unknown value for enum: " + value + "(" + Schema + ")");
- this.value = value;
- }
- }
-
- public GenericEnum(EnumSchema schema, string value)
- {
- this.Schema = schema;
- this.Value = value;
- }
-
- public override bool Equals(object obj)
- {
- if (obj == this) return true;
- return (obj != null && obj is GenericEnum) ? Value.Equals((obj as GenericEnum).Value) : false;
- }
-
- public override int GetHashCode()
- {
- return 17 * Value.GetHashCode();
- }
-
- public override string ToString()
- {
- return "Schema: " + Schema + ", value: " + Value;
- }
-
- }
-}
diff --git a/lang/csharp/src/apache/main/Generic/GenericFixed.cs b/lang/csharp/src/apache/main/Generic/GenericFixed.cs
deleted file mode 100644
index 8b94a52..0000000
--- a/lang/csharp/src/apache/main/Generic/GenericFixed.cs
+++ /dev/null
@@ -1,109 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace Avro.Generic
-{
- /// <summary>
- /// The default type used by GenericReader and GenericWriter for objects for FixedSchema
- /// </summary>
- public class GenericFixed
- {
- protected readonly byte[] value;
- private FixedSchema schema;
-
- public FixedSchema Schema
- {
- get
- {
- return schema;
- }
-
- set
- {
- if (!(value is FixedSchema))
- throw new AvroException("Schema " + value.Name + " in set is not FixedSchema");
-
- if ((value as FixedSchema).Size != this.value.Length)
- throw new AvroException("Schema " + value.Name + " Size " + (value as FixedSchema).Size + "is not equal to bytes length " + this.value.Length);
-
- schema = value;
- }
- }
-
- public GenericFixed(FixedSchema schema)
- {
- value = new byte[schema.Size];
- this.Schema = schema;
- }
-
- public GenericFixed(FixedSchema schema, byte[] value)
- {
- this.value = new byte[schema.Size];
- this.Schema = schema;
- Value = value;
- }
-
- protected GenericFixed(uint size)
- {
- this.value = new byte[size];
- }
-
- public byte[] Value
- {
- get { return this.value; }
- set
- {
- if (value.Length == this.value.Length)
- {
- Array.Copy(value, this.value, value.Length);
- return;
- }
- throw new AvroException("Invalid length for fixed: " + value.Length + ", (" + Schema + ")");
- }
- }
-
- public override bool Equals(object obj)
- {
- if (this == obj) return true;
- if (obj != null && obj is GenericFixed)
- {
- GenericFixed that = obj as GenericFixed;
- if (that.Schema.Equals(this.Schema))
- {
- for (int i = 0; i < value.Length; i++) if (this.value[i] != that.value[i]) return false;
- return true;
- }
- }
- return false;
- }
-
- public override int GetHashCode()
- {
- int result = Schema.GetHashCode();
- foreach (byte b in value)
- {
- result += 23 * b;
- }
- return result;
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/Generic/GenericReader.cs b/lang/csharp/src/apache/main/Generic/GenericReader.cs
deleted file mode 100644
index ffd5b9a..0000000
--- a/lang/csharp/src/apache/main/Generic/GenericReader.cs
+++ /dev/null
@@ -1,632 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using Avro.IO;
-using System.IO;
-
-namespace Avro.Generic
-{
- public delegate T Reader<T>();
-
- /// <summary>
- /// A general purpose reader of data from avro streams. This can optionally resolve if the reader's and writer's
- /// schemas are different. This class is a wrapper around DefaultReader and offers a little more type safety. The default reader
- /// has the flexibility to return any type of object for each read call because the Read() method is generic. This
- /// class on the other hand can only return a single type because the type is a parameter to the class. Any
- /// user defined extension should, however, be done to DefaultReader. This class is sealed.
- /// </summary>
- /// <typeparam name="T"></typeparam>
- public sealed class GenericReader<T> : DatumReader<T>
- {
- private readonly DefaultReader reader;
-
- /// <summary>
- /// Constructs a generic reader for the given schemas using the DefaultReader. If the
- /// reader's and writer's schemas are different this class performs the resolution.
- /// </summary>
- /// <param name="writerSchema">The schema used while generating the data</param>
- /// <param name="readerSchema">The schema desired by the reader</param>
- public GenericReader(Schema writerSchema, Schema readerSchema)
- : this(new DefaultReader(writerSchema, readerSchema))
- {
- }
-
- /// <summary>
- /// Constructs a generic reader by directly using the given DefaultReader
- /// </summary>
- /// <param name="reader">The actual reader to use</param>
- public GenericReader(DefaultReader reader)
- {
- this.reader = reader;
- }
-
- public Schema WriterSchema { get { return reader.WriterSchema; } }
-
- public Schema ReaderSchema { get { return reader.ReaderSchema; } }
-
- public T Read(T reuse, Decoder d)
- {
- return reader.Read(reuse, d);
- }
- }
-
- /// <summary>
- /// The default implementation for the generic reader. It constructs new .NET objects for avro objects on the
- /// stream and returns the .NET object. Users can directly use this class or, if they want to customize the
- /// object types for differnt Avro schema types, can derive from this class. There are enough hooks in this
- /// class to allow customization.
- /// </summary>
- /// <remarks>
- /// <list type="table">
- /// <listheader><term>Avro Type</term><description>.NET Type</description></listheader>
- /// <item><term>null</term><description>null reference</description></item>
- /// </list>
- /// </remarks>
- public class DefaultReader
- {
- public Schema ReaderSchema { get; private set; }
- public Schema WriterSchema { get; private set; }
-
-
- /// <summary>
- /// Constructs the default reader for the given schemas using the DefaultReader. If the
- /// reader's and writer's schemas are different this class performs the resolution.
- /// This default implemenation maps Avro types to .NET types as follows:
- /// </summary>
- /// <param name="writerSchema">The schema used while generating the data</param>
- /// <param name="readerSchema">The schema desired by the reader</param>
- public DefaultReader(Schema writerSchema, Schema readerSchema)
- {
- this.ReaderSchema = readerSchema;
- this.WriterSchema = writerSchema;
- }
-
- /// <summary>
- /// Reads an object off the stream.
- /// </summary>
- /// <typeparam name="T">The type of object to read. A single schema typically returns an object of a single .NET class.
- /// The only exception is UnionSchema, which can return a object of different types based on the branch selected.
- /// </typeparam>
- /// <param name="reuse">If not null, the implemenation will try to use to return the object</param>
- /// <param name="decoder">The decoder for deserialization</param>
- /// <returns></returns>
- public T Read<T>(T reuse, Decoder decoder)
- {
- if (!ReaderSchema.CanRead(WriterSchema))
- throw new AvroException("Schema mismatch. Reader: " + ReaderSchema + ", writer: " + WriterSchema);
-
- return (T)Read(reuse, WriterSchema, ReaderSchema, decoder);
- }
-
- public object Read(object reuse, Schema writerSchema, Schema readerSchema, Decoder d)
- {
- if (readerSchema.Tag == Schema.Type.Union && writerSchema.Tag != Schema.Type.Union)
- {
- readerSchema = findBranch(readerSchema as UnionSchema, writerSchema);
- }
- /*
- if (!readerSchema.CanRead(writerSchema))
- {
- throw new AvroException("Schema mismatch. Reader: " + readerSchema + ", writer: " + writerSchema);
- }
- */
- switch (writerSchema.Tag)
- {
- case Schema.Type.Null:
- return ReadNull(readerSchema, d);
- case Schema.Type.Boolean:
- return Read<bool>(writerSchema.Tag, readerSchema, d.ReadBoolean);
- case Schema.Type.Int:
- {
- int i = Read<int>(writerSchema.Tag, readerSchema, d.ReadInt);
- switch (readerSchema.Tag)
- {
- case Schema.Type.Long:
- return (long)i;
- case Schema.Type.Float:
- return (float)i;
- case Schema.Type.Double:
- return (double)i;
- default:
- return i;
- }
- }
- case Schema.Type.Long:
- {
- long l = Read<long>(writerSchema.Tag, readerSchema, d.ReadLong);
- switch (readerSchema.Tag)
- {
- case Schema.Type.Float:
- return (float)l;
- case Schema.Type.Double:
- return (double)l;
- default:
- return l;
- }
- }
- case Schema.Type.Float:
- {
- float f = Read<float>(writerSchema.Tag, readerSchema, d.ReadFloat);
- switch (readerSchema.Tag)
- {
- case Schema.Type.Double:
- return (double)f;
- default:
- return f;
- }
- }
- case Schema.Type.Double:
- return Read<double>(writerSchema.Tag, readerSchema, d.ReadDouble);
- case Schema.Type.String:
- return Read<string>(writerSchema.Tag, readerSchema, d.ReadString);
- case Schema.Type.Bytes:
- return Read<byte[]>(writerSchema.Tag, readerSchema, d.ReadBytes);
- case Schema.Type.Record:
- return ReadRecord(reuse, (RecordSchema)writerSchema, readerSchema, d);
- case Schema.Type.Enumeration:
- return ReadEnum(reuse, (EnumSchema)writerSchema, readerSchema, d);
- case Schema.Type.Fixed:
- return ReadFixed(reuse, (FixedSchema)writerSchema, readerSchema, d);
- case Schema.Type.Array:
- return ReadArray(reuse, (ArraySchema)writerSchema, readerSchema, d);
- case Schema.Type.Map:
- return ReadMap(reuse, (MapSchema)writerSchema, readerSchema, d);
- case Schema.Type.Union:
- return ReadUnion(reuse, (UnionSchema)writerSchema, readerSchema, d);
- default:
- throw new AvroException("Unknown schema type: " + writerSchema);
- }
- }
-
- /// <summary>
- /// Deserializes a null from the stream.
- /// </summary>
- /// <param name="readerSchema">Reader's schema, which should be a NullSchema</param>
- /// <param name="d">The decoder for deserialization</param>
- /// <returns></returns>
- protected virtual object ReadNull(Schema readerSchema, Decoder d)
- {
- d.ReadNull();
- return null;
- }
-
- /// <summary>
- /// A generic function to read primitive types
- /// </summary>
- /// <typeparam name="S">The .NET type to read</typeparam>
- /// <param name="tag">The Avro type tag for the object on the stream</param>
- /// <param name="readerSchema">A schema compatible to the Avro type</param>
- /// <param name="reader">A function that can read the avro type from the stream</param>
- /// <returns>The primitive type just read</returns>
- protected S Read<S>(Schema.Type tag, Schema readerSchema, Reader<S> reader)
- {
- return reader();
- }
-
- /// <summary>
- /// Deserializes a record from the stream.
- /// </summary>
- /// <param name="reuse">If not null, a record object that could be reused for returning the result</param>
- /// <param name="writerSchema">The writer's RecordSchema</param>
- /// <param name="readerSchema">The reader's schema, must be RecordSchema too.</param>
- /// <param name="dec">The decoder for deserialization</param>
- /// <returns>The record object just read</returns>
- protected virtual object ReadRecord(object reuse, RecordSchema writerSchema, Schema readerSchema, Decoder dec)
- {
- RecordSchema rs = (RecordSchema)readerSchema;
-
- object rec = CreateRecord(reuse, rs);
- foreach (Field wf in writerSchema)
- {
- try
- {
- Field rf;
- if (rs.TryGetFieldAlias(wf.Name, out rf))
- {
- object obj = null;
- TryGetField(rec, wf.Name, rf.Pos, out obj);
- AddField(rec, wf.Name, rf.Pos, Read(obj, wf.Schema, rf.Schema, dec));
- }
- else
- Skip(wf.Schema, dec);
- }
- catch (Exception ex)
- {
- throw new AvroException(ex.Message + " in field " + wf.Name);
- }
- }
-
- var defaultStream = new MemoryStream();
- var defaultEncoder = new BinaryEncoder(defaultStream);
- var defaultDecoder = new BinaryDecoder(defaultStream);
- foreach (Field rf in rs)
- {
- if (writerSchema.Contains(rf.Name)) continue;
-
- defaultStream.Position = 0; // reset for writing
- Resolver.EncodeDefaultValue(defaultEncoder, rf.Schema, rf.DefaultValue);
- defaultStream.Flush();
- defaultStream.Position = 0; // reset for reading
-
- object obj = null;
- TryGetField(rec, rf.Name, rf.Pos, out obj);
- AddField(rec, rf.Name, rf.Pos, Read(obj, rf.Schema, rf.Schema, defaultDecoder));
- }
-
- return rec;
- }
-
- /// <summary>
- /// Creates a new record object. Derived classes can override this to return an object of their choice.
- /// </summary>
- /// <param name="reuse">If appropriate, will reuse this object instead of constructing a new one</param>
- /// <param name="readerSchema">The schema the reader is using</param>
- /// <returns></returns>
- protected virtual object CreateRecord(object reuse, RecordSchema readerSchema)
- {
- GenericRecord ru = (reuse == null || !(reuse is GenericRecord) || !(reuse as GenericRecord).Schema.Equals(readerSchema)) ?
- new GenericRecord(readerSchema) :
- reuse as GenericRecord;
- return ru;
- }
-
- /// <summary>
- /// Used by the default implementation of ReadRecord() to get the existing field of a record object. The derived
- /// classes can override this to make their own interpretation of the record object.
- /// </summary>
- /// <param name="record">The record object to be probed into. This is guaranteed to be one that was returned
- /// by a previous call to CreateRecord.</param>
- /// <param name="fieldName">The name of the field to probe.</param>
- /// <param name="value">The value of the field, if found. Null otherwise.</param>
- /// <returns>True if and only if a field with the given name is found.</returns>
- protected virtual bool TryGetField(object record, string fieldName, int fieldPos, out object value)
- {
- return (record as GenericRecord).TryGetValue(fieldName, out value);
- }
-
- /// <summary>
- /// Used by the default implementation of ReadRecord() to add a field to a record object. The derived
- /// classes can override this to suit their own implementation of the record object.
- /// </summary>
- /// <param name="record">The record object to be probed into. This is guaranteed to be one that was returned
- /// by a previous call to CreateRecord.</param>
- /// <param name="fieldName">The name of the field to probe.</param>
- /// <param name="fieldValue">The value to be added for the field</param>
- protected virtual void AddField(object record, string fieldName, int fieldPos, object fieldValue)
- {
- (record as GenericRecord).Add(fieldName, fieldValue);
- }
-
- /// <summary>
- /// Deserializes a enum. Uses CreateEnum to construct the new enum object.
- /// </summary>
- /// <param name="reuse">If appropirate, uses this instead of creating a new enum object.</param>
- /// <param name="writerSchema">The schema the writer used while writing the enum</param>
- /// <param name="readerSchema">The schema the reader is using</param>
- /// <param name="d">The decoder for deserialization.</param>
- /// <returns>An enum object.</returns>
- protected virtual object ReadEnum(object reuse, EnumSchema writerSchema, Schema readerSchema, Decoder d)
- {
- EnumSchema es = readerSchema as EnumSchema;
- return CreateEnum(reuse, readerSchema as EnumSchema, writerSchema[d.ReadEnum()]);
- }
-
- /// <summary>
- /// Used by the default implementation of ReadEnum to construct a new enum object.
- /// </summary>
- /// <param name="reuse">If appropriate, use this enum object instead of a new one.</param>
- /// <param name="es">The enum schema used by the reader.</param>
- /// <param name="symbol">The symbol that needs to be used.</param>
- /// <returns>The default implemenation returns a GenericEnum.</returns>
- protected virtual object CreateEnum(object reuse, EnumSchema es, string symbol)
- {
- if (reuse is GenericEnum)
- {
- GenericEnum ge = reuse as GenericEnum;
- if (ge.Schema.Equals(es))
- {
- ge.Value = symbol;
- return ge;
- }
- }
- return new GenericEnum(es, symbol);
- }
-
- /// <summary>
- /// Deserializes an array and returns an array object. It uses CreateArray() and works on it before returning it.
- /// It also uses GetArraySize(), ResizeArray(), SetArrayElement() and GetArrayElement() methods. Derived classes can
- /// override these methods to customize their behavior.
- /// </summary>
- /// <param name="reuse">If appropriate, uses this instead of creating a new array object.</param>
- /// <param name="writerSchema">The schema used by the writer.</param>
- /// <param name="readerSchema">The schema that the reader uses.</param>
- /// <param name="d">The decoder for deserialization.</param>
- /// <returns>The deserialized array object.</returns>
- protected virtual object ReadArray(object reuse, ArraySchema writerSchema, Schema readerSchema, Decoder d)
- {
-
- ArraySchema rs = (ArraySchema)readerSchema;
- object result = CreateArray(reuse, rs);
- int i = 0;
- for (int n = (int)d.ReadArrayStart(); n != 0; n = (int)d.ReadArrayNext())
- {
- if (GetArraySize(result) < (i + n)) ResizeArray(ref result, i + n);
- for (int j = 0; j < n; j++, i++)
- {
- SetArrayElement(result, i, Read(GetArrayElement(result, i), writerSchema.ItemSchema, rs.ItemSchema, d));
- }
- }
- if (GetArraySize(result) != i) ResizeArray(ref result, i);
- return result;
- }
-
- /// <summary>
- /// Creates a new array object. The initial size of the object could be anything. The users
- /// should use GetArraySize() to determine the size. The default implementation creates an <c>object[]</c>.
- /// </summary>
- /// <param name="reuse">If appropriate use this instead of creating a new one.</param>
- /// <returns>An object suitable to deserialize an avro array</returns>
- protected virtual object CreateArray(object reuse, ArraySchema rs)
- {
- return (reuse != null && reuse is object[]) ? (object[])reuse : new object[0];
- }
-
- /// <summary>
- /// Returns the size of the given array object.
- /// </summary>
- /// <param name="array">Array object whose size is required. This is guaranteed to be somthing returned by
- /// a previous call to CreateArray().</param>
- /// <returns>The size of the array</returns>
- protected virtual int GetArraySize(object array)
- {
- return (array as object[]).Length;
- }
-
- /// <summary>
- /// Resizes the array to the new value.
- /// </summary>
- /// <param name="array">Array object whose size is required. This is guaranteed to be somthing returned by
- /// a previous call to CreateArray().</param>
- /// <param name="n">The new size.</param>
- protected virtual void ResizeArray(ref object array, int n)
- {
- object[] o = array as object[];
- Array.Resize(ref o, n);
- array = o;
- }
-
- /// <summary>
- /// Assigns a new value to the object at the given index
- /// </summary>
- /// <param name="array">Array object whose size is required. This is guaranteed to be somthing returned by
- /// a previous call to CreateArray().</param>
- /// <param name="index">The index to reassign to.</param>
- /// <param name="value">The value to assign.</param>
- protected virtual void SetArrayElement(object array, int index, object value)
- {
- object[] a = array as object[];
- a[index] = value;
- }
-
- /// <summary>
- /// Returns the element at the given index.
- /// </summary>
- /// <param name="array">Array object whose size is required. This is guaranteed to be somthing returned by
- /// a previous call to CreateArray().</param>
- /// <param name="index">The index to look into.</param>
- /// <returns>The object the given index. Null if no object has been assigned to that index.</returns>
- protected virtual object GetArrayElement(object array, int index)
- {
- return (array as object[])[index];
- }
-
- /// <summary>
- /// Deserialized an avro map. The default implemenation creats a new map using CreateMap() and then
- /// adds elements to the map using AddMapEntry().
- /// </summary>
- /// <param name="reuse">If appropriate, use this instead of creating a new map object.</param>
- /// <param name="writerSchema">The schema the writer used to write the map.</param>
- /// <param name="readerSchema">The schema the reader is using.</param>
- /// <param name="d">The decoder for serialization.</param>
- /// <returns>The deserialized map object.</returns>
- protected virtual object ReadMap(object reuse, MapSchema writerSchema, Schema readerSchema, Decoder d)
- {
- MapSchema rs = (MapSchema)readerSchema;
- object result = CreateMap(reuse, rs);
- for (int n = (int)d.ReadMapStart(); n != 0; n = (int)d.ReadMapNext())
- {
- for (int j = 0; j < n; j++)
- {
- string k = d.ReadString();
- AddMapEntry(result, k, Read(null, writerSchema.ValueSchema, rs.ValueSchema, d));
- }
- }
- return result;
- }
-
- /// <summary>
- /// Used by the default implementation of ReadMap() to create a fresh map object. The default
- /// implementaion of this method returns a IDictionary<string, map>.
- /// </summary>
- /// <param name="reuse">If appropriate, use this map object instead of creating a new one.</param>
- /// <returns>An empty map object.</returns>
- protected virtual object CreateMap(object reuse, MapSchema ms)
- {
- if (reuse != null && reuse is IDictionary<string, object>)
- {
- IDictionary<string, object> result = reuse as IDictionary<string, object>;
- result.Clear();
- return result;
- }
- return new Dictionary<string, object>();
- }
-
- /// <summary>
- /// Adds an entry to the map.
- /// </summary>
- /// <param name="map">A map object, which is guaranteed to be one returned by a previous call to CreateMap().</param>
- /// <param name="key">The key to add.</param>
- /// <param name="value">The value to add.</param>
- protected virtual void AddMapEntry(object map, string key, object value)
- {
- (map as IDictionary<string, object>).Add(key, value);
- }
-
- /// <summary>
- /// Deserialized an object based on the writer's uninon schema.
- /// </summary>
- /// <param name="reuse">If appropriate, uses this object instead of creating a new one.</param>
- /// <param name="writerSchema">The UnionSchema that the writer used.</param>
- /// <param name="readerSchema">The schema the reader uses.</param>
- /// <param name="d">The decoder for serialization.</param>
- /// <returns>The deserialized object.</returns>
- protected virtual object ReadUnion(object reuse, UnionSchema writerSchema, Schema readerSchema, Decoder d)
- {
- int index = d.ReadUnionIndex();
- Schema ws = writerSchema[index];
-
- if (readerSchema is UnionSchema)
- readerSchema = findBranch(readerSchema as UnionSchema, ws);
- else
- if (!readerSchema.CanRead(ws))
- throw new AvroException("Schema mismatch. Reader: " + ReaderSchema + ", writer: " + WriterSchema);
-
- return Read(reuse, ws, readerSchema, d);
- }
-
- /// <summary>
- /// Deserializes a fixed object and returns the object. The default implementation uses CreateFixed()
- /// and GetFixedBuffer() and returns what CreateFixed() returned.
- /// </summary>
- /// <param name="reuse">If appropriate, uses this object instead of creating a new one.</param>
- /// <param name="writerSchema">The FixedSchema the writer used during serialization.</param>
- /// <param name="readerSchema">The schema that the readr uses. Must be a FixedSchema with the same
- /// size as the writerSchema.</param>
- /// <param name="d">The decoder for deserialization.</param>
- /// <returns>The deserilized object.</returns>
- protected virtual object ReadFixed(object reuse, FixedSchema writerSchema, Schema readerSchema, Decoder d)
- {
- FixedSchema rs = (FixedSchema)readerSchema;
- if (rs.Size != writerSchema.Size)
- {
- throw new AvroException("Size mismatch between reader and writer fixed schemas. Writer: " + writerSchema +
- ", reader: " + readerSchema);
- }
-
- object ru = CreateFixed(reuse, rs);
- byte[] bb = GetFixedBuffer(ru);
- d.ReadFixed(bb);
- return ru;
- }
-
- /// <summary>
- /// Returns a fixed object.
- /// </summary>
- /// <param name="reuse">If appropriate, uses this object instead of creating a new one.</param>
- /// <param name="rs">The reader's FixedSchema.</param>
- /// <returns>A fixed object with an appropriate buffer.</returns>
- protected virtual object CreateFixed(object reuse, FixedSchema rs)
- {
- return (reuse != null && reuse is GenericFixed && (reuse as GenericFixed).Schema.Equals(rs)) ?
- (GenericFixed)reuse : new GenericFixed(rs);
- }
-
- /// <summary>
- /// Returns a buffer of appropriate size to read data into.
- /// </summary>
- /// <param name="f">The fixed object. It is guaranteed that this is something that has been previously
- /// returned by CreateFixed</param>
- /// <returns>A byte buffer of fixed's size.</returns>
- protected virtual byte[] GetFixedBuffer(object f)
- {
- return (f as GenericFixed).Value;
- }
-
- protected virtual void Skip(Schema writerSchema, Decoder d)
- {
- switch (writerSchema.Tag)
- {
- case Schema.Type.Null:
- d.SkipNull();
- break;
- case Schema.Type.Boolean:
- d.SkipBoolean();
- break;
- case Schema.Type.Int:
- d.SkipInt();
- break;
- case Schema.Type.Long:
- d.SkipLong();
- break;
- case Schema.Type.Float:
- d.SkipFloat();
- break;
- case Schema.Type.Double:
- d.SkipDouble();
- break;
- case Schema.Type.String:
- d.SkipString();
- break;
- case Schema.Type.Bytes:
- d.SkipBytes();
- break;
- case Schema.Type.Record:
- foreach (Field f in writerSchema as RecordSchema) Skip(f.Schema, d);
- break;
- case Schema.Type.Enumeration:
- d.SkipEnum();
- break;
- case Schema.Type.Fixed:
- d.SkipFixed((writerSchema as FixedSchema).Size);
- break;
- case Schema.Type.Array:
- {
- Schema s = (writerSchema as ArraySchema).ItemSchema;
- for (long n = d.ReadArrayStart(); n != 0; n = d.ReadArrayNext())
- {
- for (long i = 0; i < n; i++) Skip(s, d);
- }
- }
- break;
- case Schema.Type.Map:
- {
- Schema s = (writerSchema as MapSchema).ValueSchema;
- for (long n = d.ReadMapStart(); n != 0; n = d.ReadMapNext())
- {
- for (long i = 0; i < n; i++) { d.SkipString(); Skip(s, d); }
- }
- }
- break;
- case Schema.Type.Union:
- Skip((writerSchema as UnionSchema)[d.ReadUnionIndex()], d);
- break;
- default:
- throw new AvroException("Unknown schema type: " + writerSchema);
- }
- }
-
- protected static Schema findBranch(UnionSchema us, Schema s)
- {
- int index = us.MatchingBranch(s);
- if (index >= 0) return us[index];
- throw new AvroException("No matching schema for " + s + " in " + us);
- }
-
- }
-}
diff --git a/lang/csharp/src/apache/main/Generic/GenericRecord.cs b/lang/csharp/src/apache/main/Generic/GenericRecord.cs
deleted file mode 100644
index 3804d15..0000000
--- a/lang/csharp/src/apache/main/Generic/GenericRecord.cs
+++ /dev/null
@@ -1,137 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Avro;
-
-namespace Avro.Generic
-{
- /// <summary>
- /// The default type used by GenericReader and GenericWriter for RecordSchema.
- /// </summary>
- public class GenericRecord
- {
- public RecordSchema Schema { get; private set; }
-
- private IDictionary<string, object> contents = new Dictionary<string, object>();
- public GenericRecord(RecordSchema schema)
- {
- this.Schema = schema;
- }
-
- public object this[string fieldName]
- {
- get { return contents[fieldName]; }
- }
-
- public void Add(string fieldName, object fieldValue)
- {
- if (Schema.Contains(fieldName))
- {
- // TODO: Use a matcher to verify that object has the right type for the field.
- //contents.Add(fieldName, fieldValue);
- contents[fieldName] = fieldValue;
- return;
- }
- throw new AvroException("No such field: " + fieldName);
- }
-
- public bool TryGetValue(string fieldName, out object result)
- {
- return contents.TryGetValue(fieldName, out result);
- }
-
- public override bool Equals(object obj)
- {
- if (this == obj) return true;
- if (obj != null && obj is GenericRecord)
- {
- GenericRecord other = obj as GenericRecord;
- return Schema.Equals(other.Schema) && areEqual(contents, other.contents);
- }
- return false;
- }
-
- private static bool areEqual(IDictionary<string, object> d1, IDictionary<string, object> d2)
- {
- if (d1.Count == d2.Count)
- {
- foreach (KeyValuePair<string, object> kv in d1)
- {
- object o;
- if (!d2.TryGetValue(kv.Key, out o)) return false;
- if (!areEqual(o, kv.Value)) return false;
- }
- return true;
- }
- return false;
- }
-
- private static bool areEqual(object o1, object o2)
- {
- if (o1 == null) return o2 == null;
- if (o2 == null) return false;
- if (o1 is Array)
- {
- if (!(o2 is Array)) return false;
- return areEqual(o1 as Array, o1 as Array);
- }
- else if (o1 is IDictionary<string, object>)
- {
- if (!(o2 is IDictionary<string, object>)) return false;
- return areEqual(o1 as IDictionary<string, object>, o1 as IDictionary<string, object>);
- }
- return o1.Equals(o2);
- }
-
- private static bool areEqual(Array a1, Array a2)
- {
- if (a1.Length != a2.Length) return false;
- for (int i = 0; i < a1.Length; i++)
- {
- if (!areEqual(a1.GetValue(i), a2.GetValue(i))) return false;
- }
- return true;
- }
-
- public override int GetHashCode()
- {
- return 31 * contents.GetHashCode()/* + 29 * Schema.GetHashCode()*/;
- }
-
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- sb.Append("Schema: ");
- sb.Append(Schema);
- sb.Append(", contents: ");
- sb.Append("{ ");
- foreach (KeyValuePair<string, object> kv in contents)
- {
- sb.Append(kv.Key);
- sb.Append(": ");
- sb.Append(kv.Value);
- sb.Append(", ");
- }
- sb.Append("}");
- return sb.ToString();
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/Generic/GenericWriter.cs b/lang/csharp/src/apache/main/Generic/GenericWriter.cs
deleted file mode 100644
index bfe461f..0000000
--- a/lang/csharp/src/apache/main/Generic/GenericWriter.cs
+++ /dev/null
@@ -1,445 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using Avro.IO;
-
-namespace Avro.Generic
-{
- public delegate void Writer<T>(T t);
- /// <summary>
- /// A typesafe wrapper around DefaultWriter. While a specific object of DefaultWriter
- /// allows the client to serialize a generic type, an object of this class allows
- /// only a single type of object to be serialized through it.
- /// </summary>
- /// <typeparam name="T">The type of object to be serialized.</typeparam>
- public class GenericWriter<T> : DatumWriter<T>
- {
- private readonly DefaultWriter writer;
- public GenericWriter(Schema schema) : this(new DefaultWriter(schema))
- {
-
- }
-
- public Schema Schema { get { return writer.Schema; } }
-
- public GenericWriter(DefaultWriter writer)
- {
- this.writer = writer;
- }
-
- /// <summary>
- /// Serializes the given object using this writer's schema.
- /// </summary>
- /// <param name="value">The value to be serialized</param>
- /// <param name="encoder">The encoder to use for serializing</param>
- public void Write(T value, Encoder encoder)
- {
- writer.Write(value, encoder);
- }
- }
-
- /// <summary>
- /// A General purpose writer for serializing objects into a Stream using
- /// Avro. This class implements a default way of serializing objects. But
- /// one can derive a class from this and override different methods to
- /// acheive results that are different from the default implementation.
- /// </summary>
- public class DefaultWriter
- {
- public Schema Schema { get; private set; }
-
- /// <summary>
- /// Constructs a generic writer for the given schema.
- /// </summary>
- /// <param name="schema">The schema for the object to be serialized</param>
- public DefaultWriter(Schema schema)
- {
- this.Schema = schema;
- }
-
- public void Write<T>(T value, Encoder encoder)
- {
- Write(Schema, value, encoder);
- }
- /// <summary>
- /// Examines the schema and dispatches the actual work to one
- /// of the other methods of this class. This allows the derived
- /// classes to override specific methods and get custom results.
- /// </summary>
- /// <param name="schema">The schema to use for serializing</param>
- /// <param name="value">The value to be serialized</param>
- /// <param name="encoder">The encoder to use during serialization</param>
- public virtual void Write(Schema schema, object value, Encoder encoder)
- {
- switch (schema.Tag)
- {
- case Schema.Type.Null:
- WriteNull(value, encoder);
- break;
- case Schema.Type.Boolean:
- Write<bool>(value, schema.Tag, encoder.WriteBoolean);
- break;
- case Schema.Type.Int:
- Write<int>(value, schema.Tag, encoder.WriteInt);
- break;
- case Schema.Type.Long:
- Write<long>(value, schema.Tag, encoder.WriteLong);
- break;
- case Schema.Type.Float:
- Write<float>(value, schema.Tag, encoder.WriteFloat);
- break;
- case Schema.Type.Double:
- Write<double>(value, schema.Tag, encoder.WriteDouble);
- break;
- case Schema.Type.String:
- Write<string>(value, schema.Tag, encoder.WriteString);
- break;
- case Schema.Type.Bytes:
- Write<byte[]>(value, schema.Tag, encoder.WriteBytes);
- break;
- case Schema.Type.Record:
- WriteRecord(schema as RecordSchema, value, encoder);
- break;
- case Schema.Type.Enumeration:
- WriteEnum(schema as EnumSchema, value, encoder);
- break;
- case Schema.Type.Fixed:
- WriteFixed(schema as FixedSchema, value, encoder);
- break;
- case Schema.Type.Array:
- WriteArray(schema as ArraySchema, value, encoder);
- break;
- case Schema.Type.Map:
- WriteMap(schema as MapSchema, value, encoder);
- break;
- case Schema.Type.Union:
- WriteUnion(schema as UnionSchema, value, encoder);
- break;
- default:
- error(schema, value);
- break;
- }
- }
-
- /// <summary>
- /// Serializes a "null"
- /// </summary>
- /// <param name="value">The object to be serialized using null schema</param>
- /// <param name="encoder">The encoder to use while serialization</param>
- protected virtual void WriteNull(object value, Encoder encoder)
- {
- if (value != null) throw TypeMismatch(value, "null", "null");
- }
-
- /// <summary>
- /// A generic method to serialize primitive Avro types.
- /// </summary>
- /// <typeparam name="S">Type of the C# type to be serialized</typeparam>
- /// <param name="value">The value to be serialized</param>
- /// <param name="tag">The schema type tag</param>
- /// <param name="writer">The writer which should be used to write the given type.</param>
- protected virtual void Write<S>(object value, Schema.Type tag, Writer<S> writer)
- {
- if (!(value is S)) throw TypeMismatch(value, tag.ToString(), typeof(S).ToString());
- writer((S)value);
- }
-
- /// <summary>
- /// Serialized a record using the given RecordSchema. It uses GetField method
- /// to extract the field value from the given object.
- /// </summary>
- /// <param name="schema">The RecordSchema to use for serialization</param>
- /// <param name="value">The value to be serialized</param>
- /// <param name="encoder">The Encoder for serialization</param>
-
- protected virtual void WriteRecord(RecordSchema schema, object value, Encoder encoder)
- {
- EnsureRecordObject(schema, value);
- foreach (Field field in schema)
- {
- try
- {
- object obj = GetField(value, field.Name, field.Pos);
- Write(field.Schema, obj, encoder);
- }
- catch (Exception ex)
- {
- throw new AvroException(ex.Message + " in field " + field.Name);
- }
- }
- }
-
- protected virtual void EnsureRecordObject(RecordSchema s, object value)
- {
- if (value == null || !(value is GenericRecord) || !((value as GenericRecord).Schema.Equals(s)))
- {
- throw TypeMismatch(value, "record", "GenericRecord");
- }
- }
-
- /// <summary>
- /// Extracts the field value from the given object. In this default implementation,
- /// value should be of type GenericRecord.
- /// </summary>
- /// <param name="value">The record value from which the field needs to be extracted</param>
- /// <param name="fieldName">The name of the field in the record</param>
- /// <param name="fieldPos">The position of field in the record</param>
- /// <returns></returns>
- protected virtual object GetField(object value, string fieldName, int fieldPos)
- {
- GenericRecord d = value as GenericRecord;
- return d[fieldName];
- }
-
- /// <summary>
- /// Serializes an enumeration. The default implementation expectes the value to be string whose
- /// value is the name of the enumeration.
- /// </summary>
- /// <param name="es">The EnumSchema for serialization</param>
- /// <param name="value">Value to be written</param>
- /// <param name="encoder">Encoder for serialization</param>
- protected virtual void WriteEnum(EnumSchema es, object value, Encoder encoder)
- {
- if (value == null || !(value is GenericEnum) || !((value as GenericEnum).Schema.Equals(es)))
- throw TypeMismatch(value, "enum", "GenericEnum");
- encoder.WriteEnum(es.Ordinal((value as GenericEnum).Value));
- }
-
- /// <summary>
- /// Serialized an array. The default implementation calls EnsureArrayObject() to ascertain that the
- /// given value is an array. It then calls GetArrayLength() and GetArrayElement()
- /// to access the members of the array and then serialize them.
- /// </summary>
- /// <param name="schema">The ArraySchema for serialization</param>
- /// <param name="value">The value being serialized</param>
- /// <param name="encoder">The encoder for serialization</param>
- protected virtual void WriteArray(ArraySchema schema, object value, Encoder encoder)
- {
- EnsureArrayObject(value);
- long l = GetArrayLength(value);
- encoder.WriteArrayStart();
- encoder.SetItemCount(l);
- for (long i = 0; i < l; i++)
- {
- encoder.StartItem();
- Write(schema.ItemSchema, GetArrayElement(value, i), encoder);
- }
- encoder.WriteArrayEnd();
- }
-
- /// <summary>
- /// Checks if the given object is an array. If it is a valid array, this function returns normally. Otherwise,
- /// it throws an exception. The default implementation checks if the value is an array.
- /// </summary>
- /// <param name="value"></param>
- protected virtual void EnsureArrayObject(object value)
- {
- if (value == null || !(value is Array)) throw TypeMismatch(value, "array", "Array");
- }
-
- /// <summary>
- /// Returns the length of an array. The default implementation requires the object
- /// to be an array of objects and returns its length. The defaul implementation
- /// gurantees that EnsureArrayObject() has been called on the value before this
- /// function is called.
- /// </summary>
- /// <param name="value">The object whose array length is required</param>
- /// <returns>The array length of the given object</returns>
- protected virtual long GetArrayLength(object value)
- {
- return (value as Array).Length;
- }
-
- /// <summary>
- /// Returns the element at the given index from the given array object. The default implementation
- /// requires that the value is an object array and returns the element in that array. The defaul implementation
- /// gurantees that EnsureArrayObject() has been called on the value before this
- /// function is called.
- /// </summary>
- /// <param name="value">The array object</param>
- /// <param name="index">The index to look for</param>
- /// <returns>The array element at the index</returns>
- protected virtual object GetArrayElement(object value, long index)
- {
- return (value as Array).GetValue(index);
- }
-
- /// <summary>
- /// Serialized a map. The default implementation first ensure that the value is indeed a map and then uses
- /// GetMapSize() and GetMapElements() to access the contents of the map.
- /// </summary>
- /// <param name="schema">The MapSchema for serialization</param>
- /// <param name="value">The value to be serialized</param>
- /// <param name="encoder">The encoder for serialization</param>
- protected virtual void WriteMap(MapSchema schema, object value, Encoder encoder)
- {
- EnsureMapObject(value);
- IDictionary<string, object> vv = (IDictionary<string, object>)value;
- encoder.WriteMapStart();
- encoder.SetItemCount(GetMapSize(value));
- foreach (KeyValuePair<string, object> obj in GetMapValues(vv))
- {
- encoder.StartItem();
- encoder.WriteString(obj.Key);
- Write(schema.ValueSchema, obj.Value, encoder);
- }
- encoder.WriteMapEnd();
- }
-
- /// <summary>
- /// Checks if the given object is a map. If it is a valid map, this function returns normally. Otherwise,
- /// it throws an exception. The default implementation checks if the value is an IDictionary<string, object>.
- /// </summary>
- /// <param name="value"></param>
- protected virtual void EnsureMapObject(object value)
- {
- if (value == null || !(value is IDictionary<string, object>)) throw TypeMismatch(value, "map", "IDictionary<string, object>");
- }
-
- /// <summary>
- /// Returns the size of the map object. The default implementation gurantees that EnsureMapObject has been
- /// successfully called with the given value. The default implementation requires the value
- /// to be an IDictionary<string, object> and returns the number of elements in it.
- /// </summary>
- /// <param name="value">The map object whose size is desired</param>
- /// <returns>The size of the given map object</returns>
- protected virtual long GetMapSize(object value)
- {
- return (value as IDictionary<string, object>).Count;
- }
-
- /// <summary>
- /// Returns the contents of the given map object. The default implementation guarantees that EnsureMapObject
- /// has been called with the given value. The defualt implementation of this method requires that
- /// the value is an IDictionary<string, object> and returns its contents.
- /// </summary>
- /// <param name="value">The map object whose size is desired</param>
- /// <returns>The contents of the given map object</returns>
- protected virtual IEnumerable<KeyValuePair<string, object>> GetMapValues(object value)
- {
- return value as IDictionary<string, object>;
- }
-
- /// <summary>
- /// Resolves the given value against the given UnionSchema and serializes the object against
- /// the resolved schema member. The default implementation of this method uses
- /// ResolveUnion to find the member schema within the UnionSchema.
- /// </summary>
- /// <param name="us">The UnionSchema to resolve against</param>
- /// <param name="value">The value to be serialized</param>
- /// <param name="encoder">The encoder for serialization</param>
- protected virtual void WriteUnion(UnionSchema us, object value, Encoder encoder)
- {
- int index = ResolveUnion(us, value);
- encoder.WriteUnionIndex(index);
- Write(us[index], value, encoder);
- }
-
- /// <summary>
- /// Finds the branch within the given UnionSchema that matches the given object. The default implementation
- /// calls Matches() method in the order of branches within the UnionSchema. If nothing matches, throws
- /// an exception.
- /// </summary>
- /// <param name="us">The UnionSchema to resolve against</param>
- /// <param name="obj">The object that should be used in matching</param>
- /// <returns></returns>
- protected virtual int ResolveUnion(UnionSchema us, object obj)
- {
- for (int i = 0; i < us.Count; i++)
- {
- if (Matches(us[i], obj)) return i;
- }
- throw new AvroException("Cannot find a match for " + obj.GetType() + " in " + us);
- }
-
- /// <summary>
- /// Serialized a fixed object. The default implementation requires that the value is
- /// a GenericFixed object with an identical schema as es.
- /// </summary>
- /// <param name="es">The schema for serialization</param>
- /// <param name="value">The value to be serialized</param>
- /// <param name="encoder">The encoder for serialization</param>
- protected virtual void WriteFixed(FixedSchema es, object value, Encoder encoder)
- {
- if (value == null || !(value is GenericFixed) || !(value as GenericFixed).Schema.Equals(es))
- {
- throw TypeMismatch(value, "fixed", "GenericFixed");
- }
- GenericFixed ba = (GenericFixed)value;
- encoder.WriteFixed(ba.Value);
- }
-
- protected AvroException TypeMismatch(object obj, string schemaType, string type)
- {
- return new AvroException(type + " required to write against " + schemaType + " schema but found " + (null == obj ? "null" : obj.GetType().ToString()) );
- }
-
- private void error(Schema schema, Object value)
- {
- throw new AvroTypeException("Not a " + schema + ": " + value);
- }
-
- /*
- * FIXME: This method of determining the Union branch has problems. If the data is IDictionary<string, object>
- * if there are two branches one with record schema and the other with map, it choose the first one. Similarly if
- * the data is byte[] and there are fixed and bytes schemas as branches, it choose the first one that matches.
- * Also it does not recognize the arrays of primitive types.
- */
- protected virtual bool Matches(Schema sc, object obj)
- {
- if (obj == null && sc.Tag != Avro.Schema.Type.Null) return false;
- switch (sc.Tag)
- {
- case Schema.Type.Null:
- return obj == null;
- case Schema.Type.Boolean:
- return obj is bool;
- case Schema.Type.Int:
- return obj is int;
- case Schema.Type.Long:
- return obj is long;
- case Schema.Type.Float:
- return obj is float;
- case Schema.Type.Double:
- return obj is double;
- case Schema.Type.Bytes:
- return obj is byte[];
- case Schema.Type.String:
- return obj is string;
- case Schema.Type.Record:
- //return obj is GenericRecord && (obj as GenericRecord).Schema.Equals(s);
- return obj is GenericRecord && (obj as GenericRecord).Schema.SchemaName.Equals((sc as RecordSchema).SchemaName);
- case Schema.Type.Enumeration:
- //return obj is GenericEnum && (obj as GenericEnum).Schema.Equals(s);
- return obj is GenericEnum && (obj as GenericEnum).Schema.SchemaName.Equals((sc as EnumSchema).SchemaName);
- case Schema.Type.Array:
- return obj is Array && !(obj is byte[]);
- case Schema.Type.Map:
- return obj is IDictionary<string, object>;
- case Schema.Type.Union:
- return false; // Union directly within another union not allowed!
- case Schema.Type.Fixed:
- //return obj is GenericFixed && (obj as GenericFixed).Schema.Equals(s);
- return obj is GenericFixed && (obj as GenericFixed).Schema.SchemaName.Equals((sc as FixedSchema).SchemaName);
- default:
- throw new AvroException("Unknown schema type: " + sc.Tag);
- }
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/IO/BinaryDecoder.cs b/lang/csharp/src/apache/main/IO/BinaryDecoder.cs
deleted file mode 100644
index a8afed8..0000000
--- a/lang/csharp/src/apache/main/IO/BinaryDecoder.cs
+++ /dev/null
@@ -1,299 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.IO;
-
-namespace Avro.IO
-{
- /// <summary>
- /// Decoder for Avro binary format
- /// </summary>
- public class BinaryDecoder : Decoder
- {
- private readonly Stream stream;
-
- public BinaryDecoder(Stream stream)
- {
- this.stream = stream;
- }
-
- /// <summary>
- /// null is written as zero bytes
- /// </summary>
- public void ReadNull()
- {
- }
-
- /// <summary>
- /// a boolean is written as a single byte
- /// whose value is either 0 (false) or 1 (true).
- /// </summary>
- /// <returns></returns>
- public bool ReadBoolean()
- {
- byte b = read();
- if (b == 0) return false;
- if (b == 1) return true;
- throw new AvroException("Not a boolean value in the stream: " + b);
- }
-
- /// <summary>
- /// int and long values are written using variable-length, zig-zag coding.
- /// </summary>
- /// <param name="?"></param>
- /// <returns></returns>
- public int ReadInt()
- {
- return (int)ReadLong();
- }
- /// <summary>
- /// int and long values are written using variable-length, zig-zag coding.
- /// </summary>
- /// <param name="?"></param>
- /// <returns></returns>
- public long ReadLong()
- {
- byte b = read();
- ulong n = b & 0x7FUL;
- int shift = 7;
- while ((b & 0x80) != 0)
- {
- b = read();
- n |= (b & 0x7FUL) << shift;
- shift += 7;
- }
- long value = (long)n;
- return (-(value & 0x01L)) ^ ((value >> 1) & 0x7fffffffffffffffL);
- }
-
- /// <summary>
- /// A float is written as 4 bytes.
- /// The float is converted into a 32-bit integer using a method equivalent to
- /// Java's floatToIntBits and then encoded in little-endian format.
- /// </summary>
- /// <returns></returns>
- public float ReadFloat()
- {
- byte[] buffer = read(4);
-
- if (!BitConverter.IsLittleEndian)
- Array.Reverse(buffer);
-
- return BitConverter.ToSingle(buffer, 0);
-
- //int bits = (Stream.ReadByte() & 0xff |
- //(Stream.ReadByte()) & 0xff << 8 |
- //(Stream.ReadByte()) & 0xff << 16 |
- //(Stream.ReadByte()) & 0xff << 24);
- //return intBitsToFloat(bits);
- }
-
- /// <summary>
- /// A double is written as 8 bytes.
- /// The double is converted into a 64-bit integer using a method equivalent to
- /// Java's doubleToLongBits and then encoded in little-endian format.
- /// </summary>
- /// <param name="?"></param>
- /// <returns></returns>
- public double ReadDouble()
- {
- long bits = (stream.ReadByte() & 0xffL) |
- (stream.ReadByte() & 0xffL) << 8 |
- (stream.ReadByte() & 0xffL) << 16 |
- (stream.ReadByte() & 0xffL) << 24 |
- (stream.ReadByte() & 0xffL) << 32 |
- (stream.ReadByte() & 0xffL) << 40 |
- (stream.ReadByte() & 0xffL) << 48 |
- (stream.ReadByte() & 0xffL) << 56;
- return BitConverter.Int64BitsToDouble(bits);
- }
-
- /// <summary>
- /// Bytes are encoded as a long followed by that many bytes of data.
- /// </summary>
- /// <returns></returns>
- public byte[] ReadBytes()
- {
- return read(ReadLong());
- }
-
- public string ReadString()
- {
- int length = ReadInt();
- byte[] buffer = new byte[length];
- //TODO: Fix this because it's lame;
- ReadFixed(buffer);
- return System.Text.Encoding.UTF8.GetString(buffer);
- }
-
- public int ReadEnum()
- {
- return ReadInt();
- }
-
- public long ReadArrayStart()
- {
- return doReadItemCount();
- }
-
- public long ReadArrayNext()
- {
- return doReadItemCount();
- }
-
- public long ReadMapStart()
- {
- return doReadItemCount();
- }
-
- public long ReadMapNext()
- {
- return doReadItemCount();
- }
-
- public int ReadUnionIndex()
- {
- return ReadInt();
- }
-
- public void ReadFixed(byte[] buffer)
- {
- ReadFixed(buffer, 0, buffer.Length);
- }
-
- public void ReadFixed(byte[] buffer, int start, int length)
- {
- Read(buffer, start, length);
- }
-
- public void SkipNull()
- {
- ReadNull();
- }
-
- public void SkipBoolean()
- {
- ReadBoolean();
- }
-
-
- public void SkipInt()
- {
- ReadInt();
- }
-
- public void SkipLong()
- {
- ReadLong();
- }
-
- public void SkipFloat()
- {
- Skip(4);
- }
-
- public void SkipDouble()
- {
- Skip(8);
- }
-
- public void SkipBytes()
- {
- Skip(ReadLong());
- }
-
- public void SkipString()
- {
- SkipBytes();
- }
-
- public void SkipEnum()
- {
- ReadLong();
- }
-
- public void SkipUnionIndex()
- {
- ReadLong();
- }
-
- public void SkipFixed(int len)
- {
- Skip(len);
- }
-
- // Read p bytes into a new byte buffer
- private byte[] read(long p)
- {
- byte[] buffer = new byte[p];
- Read(buffer, 0, buffer.Length);
- return buffer;
- }
-
- private static float intBitsToFloat(int value)
- {
- return BitConverter.ToSingle(BitConverter.GetBytes(value), 0);
- }
-
- private byte read()
- {
- int n = stream.ReadByte();
- if (n >= 0) return (byte)n;
- throw new AvroException("End of stream reached");
- }
-
- private void Read(byte[] buffer, int start, int len)
- {
- while (len > 0)
- {
- int n = stream.Read(buffer, start, len);
- if (n <= 0) throw new AvroException("End of stream reached");
- start += n;
- len -= n;
- }
- }
-
- private long doReadItemCount()
- {
- long result = ReadLong();
- if (result < 0)
- {
- ReadLong(); // Consume byte-count if present
- result = -result;
- }
- return result;
- }
-
- private void Skip(int p)
- {
- stream.Seek(p, SeekOrigin.Current);
- }
-
- private void Skip(long p)
- {
- stream.Seek(p, SeekOrigin.Current);
- }
-
- internal void skip(long block_size)
- {
- throw new NotImplementedException();
- }
-
- }
-}
diff --git a/lang/csharp/src/apache/main/IO/BinaryEncoder.cs b/lang/csharp/src/apache/main/IO/BinaryEncoder.cs
deleted file mode 100644
index b4dfeb9..0000000
--- a/lang/csharp/src/apache/main/IO/BinaryEncoder.cs
+++ /dev/null
@@ -1,190 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.IO;
-
-namespace Avro.IO
-{
- /// <summary>
- /// Write leaf values.
- /// </summary>
- public class BinaryEncoder : Encoder
- {
- private readonly Stream Stream;
-
- public BinaryEncoder() : this(null)
- {
- }
-
- public BinaryEncoder(Stream stream)
- {
- this.Stream = stream;
- }
-
- /// <summary>
- /// null is written as zero bytes
- /// </summary>
- public void WriteNull()
- {
- }
-
- /// <summary>
- /// true is written as 1 and false 0.
- /// </summary>
- /// <param name="b">Boolean value to write</param>
- public void WriteBoolean(bool b)
- {
- writeByte((byte)(b ? 1 : 0));
- }
-
- /// <summary>
- /// int and long values are written using variable-length, zig-zag coding.
- /// </summary>
- /// <param name="datum"></param>
- public void WriteInt(int value)
- {
- WriteLong(value);
- }
- /// <summary>
- /// int and long values are written using variable-length, zig-zag coding.
- /// </summary>
- /// <param name="datum"></param>
- public void WriteLong(long value)
- {
- ulong n = (ulong)((value << 1) ^ (value >> 63));
- while ((n & ~0x7FUL) != 0)
- {
- writeByte((byte)((n & 0x7f) | 0x80));
- n >>= 7;
- }
- writeByte((byte)n);
- }
-
- /// <summary>
- /// A float is written as 4 bytes.
- /// The float is converted into a 32-bit integer using a method equivalent to
- /// Java's floatToIntBits and then encoded in little-endian format.
- /// </summary>
- /// <param name="value"></param>
- public void WriteFloat(float value)
- {
- byte[] buffer = BitConverter.GetBytes(value);
- if (!BitConverter.IsLittleEndian) Array.Reverse(buffer);
- writeBytes(buffer);
- }
- /// <summary>
- ///A double is written as 8 bytes.
- ///The double is converted into a 64-bit integer using a method equivalent to
- ///Java's doubleToLongBits and then encoded in little-endian format.
- /// </summary>
- /// <param name="value"></param>
- public void WriteDouble(double value)
- {
- long bits = BitConverter.DoubleToInt64Bits(value);
-
- writeByte((byte)((bits) & 0xFF));
- writeByte((byte)((bits >> 8) & 0xFF));
- writeByte((byte)((bits >> 16) & 0xFF));
- writeByte((byte)((bits >> 24) & 0xFF));
- writeByte((byte)((bits >> 32) & 0xFF));
- writeByte((byte)((bits >> 40) & 0xFF));
- writeByte((byte)((bits >> 48) & 0xFF));
- writeByte((byte)((bits >> 56) & 0xFF));
-
- }
-
- /// <summary>
- /// Bytes are encoded as a long followed by that many bytes of data.
- /// </summary>
- /// <param name="value"></param>
- ///
- public void WriteBytes(byte[] value)
- {
- WriteLong(value.Length);
- writeBytes(value);
- }
-
- /// <summary>
- /// A string is encoded as a long followed by
- /// that many bytes of UTF-8 encoded character data.
- /// </summary>
- /// <param name="value"></param>
- public void WriteString(string value)
- {
- WriteBytes(System.Text.Encoding.UTF8.GetBytes(value));
- }
-
- public void WriteEnum(int value)
- {
- WriteLong(value);
- }
-
- public void StartItem()
- {
- }
-
- public void SetItemCount(long value)
- {
- if (value > 0) WriteLong(value);
- }
-
- public void WriteArrayStart()
- {
- }
-
- public void WriteArrayEnd()
- {
- WriteLong(0);
- }
-
- public void WriteMapStart()
- {
- }
-
- public void WriteMapEnd()
- {
- WriteLong(0);
- }
-
- public void WriteUnionIndex(int value)
- {
- WriteLong(value);
- }
-
- public void WriteFixed(byte[] data)
- {
- WriteFixed(data, 0, data.Length);
- }
-
- public void WriteFixed(byte[] data, int start, int len)
- {
- Stream.Write(data, start, len);
- }
-
- private void writeBytes(byte[] bytes)
- {
- Stream.Write(bytes, 0, bytes.Length);
- }
-
- private void writeByte(byte b)
- {
- Stream.WriteByte(b);
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/IO/Decoder.cs b/lang/csharp/src/apache/main/IO/Decoder.cs
deleted file mode 100644
index e3fdec6..0000000
--- a/lang/csharp/src/apache/main/IO/Decoder.cs
+++ /dev/null
@@ -1,188 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.IO;
-
-namespace Avro.IO
-{
- /// <summary>
- /// Decoder is used to decode Avro data on a stream. There are methods to read the Avro types on the stream. There are also
- /// methods to skip items, which are usually more efficient than reading, on the stream.
- /// </summary>
- public interface Decoder
- {
- /// <summary>
- /// Reads a null Avro type.
- /// </summary>
- void ReadNull();
-
- /// <summary>
- /// Read a boolean Avro type
- /// </summary>
- /// <returns>The boolean just read</returns>
- bool ReadBoolean();
-
- /// <summary>
- /// Reads an int Avro type.
- /// </summary>
- /// <returns>The int just read</returns>
- int ReadInt();
-
- /// <summary>
- /// Reads a long Avro type.
- /// </summary>
- /// <returns>The long just read</returns>
- long ReadLong();
-
- /// <summary>
- /// Reads a float Avro type
- /// </summary>
- /// <returns>The float just read</returns>
- float ReadFloat();
-
- /// <summary>
- /// Reads a double Avro type
- /// </summary>
- /// <returns>The double just read</returns>
- double ReadDouble();
-
- /// <summary>
- /// Reads the bytes Avro type
- /// </summary>
- /// <returns>The bytes just read</returns>
- byte[] ReadBytes();
-
- /// <summary>
- /// Reads a string Avro type
- /// </summary>
- /// <returns>The string just read</returns>
- string ReadString();
-
- /// <summary>
- /// Reads an enum AvroType
- /// </summary>
- /// <returns>The enum just read</returns>
- int ReadEnum();
-
- /// <summary>
- /// Starts reading the array Avro type. This, together with ReadArrayNext() is used to read the
- /// items from Avro array. This returns the number of entries in the initial chunk. After consuming
- /// the chunk, the client should call ReadArrayNext() to get the number of entries in the next
- /// chunk. The client should repeat the procedure until there are no more entries in the array.
- ///
- /// for (int n = decoder.ReadArrayStart(); n > 0; n = decoder.ReadArrayNext())
- /// {
- /// // Read one array entry.
- /// }
- /// </summary>
- /// <returns>The number of entries in the initial chunk, 0 if the array is empty.</returns>
- long ReadArrayStart();
-
- /// <summary>
- /// See ReadArrayStart().
- /// </summary>
- /// <returns>The number of array entries in the next chunk, 0 if there are no more entries.</returns>
- long ReadArrayNext();
-
- /// <summary>
- /// Starts reading the map Avro type. This, together with ReadMapNext() is used to read the
- /// entries from Avro map. This returns the number of entries in the initial chunk. After consuming
- /// the chunk, the client should call ReadMapNext() to get the number of entriess in the next
- /// chunk. The client should repeat the procedure until there are no more entries in the array.
- /// for (int n = decoder.ReadMapStart(); n > 0; n = decoder.ReadMapNext())
- /// {
- /// // Read one map entry.
- /// }
- /// </summary>
- /// <returns>The number of entries in the initial chunk, 0 if the map is empty.</returns>
- long ReadMapStart();
-
- /// <summary>
- /// See ReadMapStart().
- /// </summary>
- /// <returns>The number of map entries in the next chunk, 0 if there are no more entries.</returns>
- long ReadMapNext();
-
- /// <summary>
- /// Reads the index, which determines the type in an union Avro type.
- /// </summary>
- /// <returns>The index of the type within the union.</returns>
- int ReadUnionIndex();
-
- /// <summary>
- /// A convenience method for ReadFixed(buffer, 0, buffer.Length);
- /// </summary>
- /// <param name="buffer"> The buffer to read into.</param>
- void ReadFixed(byte[] buffer);
-
- /// <summary>
- /// Read a Fixed Avro type of length.
- /// </summary>
- /// <param name="buffer">Buffer to read into</param>
- /// <param name="start">Starting position of buffer to read into</param>
- /// <param name="length">Number of bytes to read</param>
- void ReadFixed(byte[] buffer, int start, int length);
-
- /// <summary>
- /// Skips a null Avro type on the stream.
- /// </summary>
- void SkipNull();
-
- /// <summary>
- /// Skips a boolean Avro type on the stream.
- /// </summary>
- void SkipBoolean();
-
- /// <summary>
- /// Skips a int Avro type on the stream.
- /// </summary>
- void SkipInt();
-
- /// <summary>
- /// Skips a long Avro type on the stream.
- /// </summary>
- void SkipLong();
-
- /// <summary>
- /// Skips a float Avro type on the stream.
- /// </summary>
- void SkipFloat();
-
- /// <summary>
- /// Skips a double Avro type on the stream.
- /// </summary>
- void SkipDouble();
-
- /// <summary>
- /// Skips a bytes Avro type on the stream.
- /// </summary>
- void SkipBytes();
-
- /// <summary>
- /// Skips a string Avro type on the stream.
- /// </summary>
- void SkipString();
-
- void SkipEnum();
-
- void SkipUnionIndex();
-
- void SkipFixed(int len);
- }
-
-}
diff --git a/lang/csharp/src/apache/main/IO/Encoder.cs b/lang/csharp/src/apache/main/IO/Encoder.cs
deleted file mode 100644
index 010d334..0000000
--- a/lang/csharp/src/apache/main/IO/Encoder.cs
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.IO;
-
-namespace Avro.IO
-{
- public interface Encoder
- {
- void WriteNull();
- void WriteBoolean(bool value);
- void WriteInt(int value);
- void WriteLong(long value);
- void WriteFloat(float value);
- void WriteDouble(double value);
- void WriteBytes(byte[] value);
- void WriteString(string value);
-
- void WriteEnum(int value);
-
- void SetItemCount(long value);
- void StartItem();
-
- void WriteArrayStart();
- void WriteArrayEnd();
-
- void WriteMapStart();
- void WriteMapEnd();
-
- void WriteUnionIndex(int value);
- void WriteFixed(byte[] data);
- void WriteFixed(byte[] data, int start, int len);
- }
-}
diff --git a/lang/csharp/src/apache/main/IO/Resolver.cs b/lang/csharp/src/apache/main/IO/Resolver.cs
deleted file mode 100644
index e06bea7..0000000
--- a/lang/csharp/src/apache/main/IO/Resolver.cs
+++ /dev/null
@@ -1,166 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using Newtonsoft.Json.Linq;
-using Newtonsoft.Json;
-
-namespace Avro.IO
-{
- static class Resolver
- {
- /// <summary>
- /// Reads the passed JToken default value field and writes it in the specified encoder
- /// </summary>
- /// <param name="enc">encoder to use for writing</param>
- /// <param name="schema">schema object for the current field</param>
- /// <param name="jtok">default value as JToken</param>
- public static void EncodeDefaultValue(Encoder enc, Schema schema, JToken jtok)
- {
- if (null == jtok) return;
-
- switch (schema.Tag)
- {
- case Schema.Type.Boolean:
- if (jtok.Type != JTokenType.Boolean)
- throw new AvroException("Default boolean value " + jtok.ToString() + " is invalid, expected is json boolean.");
- enc.WriteBoolean((bool)jtok);
- break;
-
- case Schema.Type.Int:
- if (jtok.Type != JTokenType.Integer)
- throw new AvroException("Default int value " + jtok.ToString() + " is invalid, expected is json integer.");
- enc.WriteInt(Convert.ToInt32((int)jtok));
- break;
-
- case Schema.Type.Long:
- if (jtok.Type != JTokenType.Integer)
- throw new AvroException("Default long value " + jtok.ToString() + " is invalid, expected is json integer.");
- enc.WriteLong(Convert.ToInt64((long)jtok));
- break;
-
- case Schema.Type.Float:
- if (jtok.Type != JTokenType.Float)
- throw new AvroException("Default float value " + jtok.ToString() + " is invalid, expected is json number.");
- enc.WriteFloat((float)jtok);
- break;
-
- case Schema.Type.Double:
- if (jtok.Type == JTokenType.Integer)
- enc.WriteDouble(Convert.ToDouble((int)jtok));
- else if (jtok.Type == JTokenType.Float)
- enc.WriteDouble(Convert.ToDouble((float)jtok));
- else
- throw new AvroException("Default double value " + jtok.ToString() + " is invalid, expected is json number.");
-
- break;
-
- case Schema.Type.Bytes:
- if (jtok.Type != JTokenType.String)
- throw new AvroException("Default bytes value " + jtok.ToString() + " is invalid, expected is json string.");
- var en = System.Text.Encoding.GetEncoding("iso-8859-1");
- enc.WriteBytes(en.GetBytes((string)jtok));
- break;
-
- case Schema.Type.Fixed:
- if (jtok.Type != JTokenType.String)
- throw new AvroException("Default fixed value " + jtok.ToString() + " is invalid, expected is json string.");
- en = System.Text.Encoding.GetEncoding("iso-8859-1");
- int len = (schema as FixedSchema).Size;
- byte[] bb = en.GetBytes((string)jtok);
- if (bb.Length != len)
- throw new AvroException("Default fixed value " + jtok.ToString() + " is not of expected length " + len);
- enc.WriteFixed(bb);
- break;
-
- case Schema.Type.String:
- if (jtok.Type != JTokenType.String)
- throw new AvroException("Default string value " + jtok.ToString() + " is invalid, expected is json string.");
- enc.WriteString((string)jtok);
- break;
-
- case Schema.Type.Enumeration:
- if (jtok.Type != JTokenType.String)
- throw new AvroException("Default enum value " + jtok.ToString() + " is invalid, expected is json string.");
- enc.WriteEnum((schema as EnumSchema).Ordinal((string)jtok));
- break;
-
- case Schema.Type.Null:
- if (jtok.Type != JTokenType.Null)
- throw new AvroException("Default null value " + jtok.ToString() + " is invalid, expected is json null.");
- enc.WriteNull();
- break;
-
- case Schema.Type.Array:
- if (jtok.Type != JTokenType.Array)
- throw new AvroException("Default array value " + jtok.ToString() + " is invalid, expected is json array.");
- JArray jarr = jtok as JArray;
- enc.WriteArrayStart();
- enc.SetItemCount(jarr.Count);
- foreach (JToken jitem in jarr)
- {
- enc.StartItem();
- EncodeDefaultValue(enc, (schema as ArraySchema).ItemSchema, jitem);
- }
- enc.WriteArrayEnd();
- break;
-
- case Schema.Type.Record:
- case Schema.Type.Error:
- if (jtok.Type != JTokenType.Object)
- throw new AvroException("Default record value " + jtok.ToString() + " is invalid, expected is json object.");
- RecordSchema rcs = schema as RecordSchema;
- JObject jo = jtok as JObject;
- foreach (Field field in rcs)
- {
- JToken val = jo[field.Name];
- if (null == val)
- val = field.DefaultValue;
- if (null == val)
- throw new AvroException("No default value for field " + field.Name);
-
- EncodeDefaultValue(enc, field.Schema, val);
- }
- break;
-
- case Schema.Type.Map:
- if (jtok.Type != JTokenType.Object)
- throw new AvroException("Default map value " + jtok.ToString() + " is invalid, expected is json object.");
- jo = jtok as JObject;
- enc.WriteMapStart();
- enc.SetItemCount(jo.Count);
- foreach (KeyValuePair<string, JToken> jp in jo)
- {
- enc.StartItem();
- enc.WriteString(jp.Key);
- EncodeDefaultValue(enc, (schema as MapSchema).ValueSchema, jp.Value);
- }
- enc.WriteMapEnd();
- break;
-
- case Schema.Type.Union:
- enc.WriteUnionIndex(0);
- EncodeDefaultValue(enc, (schema as UnionSchema).Schemas[0], jtok);
- break;
-
- default:
- throw new AvroException("Unsupported schema type " + schema.Tag);
- }
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/Properties/AssemblyInfo.cs b/lang/csharp/src/apache/main/Properties/AssemblyInfo.cs
deleted file mode 100644
index 413706b..0000000
--- a/lang/csharp/src/apache/main/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * 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.
- */
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("Avro")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("Apache")]
-[assembly: AssemblyProduct("Avro")]
-[assembly: AssemblyCopyright("Copyright © Apache 2010")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("6984e56e-b67f-44c1-9aaf-0483c7589642")]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("0.9.0.0")]
-[assembly: AssemblyFileVersion("0.9.0.0")]
diff --git a/lang/csharp/src/apache/main/Properties/Settings.Designer.cs b/lang/csharp/src/apache/main/Properties/Settings.Designer.cs
deleted file mode 100644
index 2e7908b..0000000
--- a/lang/csharp/src/apache/main/Properties/Settings.Designer.cs
+++ /dev/null
@@ -1,44 +0,0 @@
-//------------------------------------------------------------------------------
-// <auto-generated>
-// This code was generated by a tool.
-// Runtime Version:4.0.30319.1
-//
-// Changes to this file may cause incorrect behavior and will be lost if
-// the code is regenerated.
-// </auto-generated>
-//------------------------------------------------------------------------------
-
-/**
- * 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.
- */
-
-namespace Avro.Properties {
-
-
- [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
- internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
-
- private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
-
- public static Settings Default {
- get {
- return defaultInstance;
- }
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/Protocol/Message.cs b/lang/csharp/src/apache/main/Protocol/Message.cs
deleted file mode 100644
index 3f6715c..0000000
--- a/lang/csharp/src/apache/main/Protocol/Message.cs
+++ /dev/null
@@ -1,185 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Text;
-using Newtonsoft.Json.Linq;
-using Newtonsoft.Json;
-
-namespace Avro
-{
- public class Message
- {
- /// <summary>
- /// Name of the message
- /// </summary>
- public string Name { get; set; }
-
- /// <summary>
- /// Documentation for the message
- /// </summary>
- public string Doc { get; set; }
-
- /// <summary>
- /// Anonymous record for the list of parameters for the request fields
- /// </summary>
- public RecordSchema Request { get; set; }
-
- /// <summary>
- /// Schema object for the 'response' attribute
- /// </summary>
- public Schema Response { get; set; }
-
- /// <summary>
- /// Union schema object for the 'error' attribute
- /// </summary>
- public UnionSchema Error { get; set; }
-
- /// <summary>
- /// Optional one-way attribute
- /// </summary>
- public bool? Oneway { get; set; }
-
- /// <summary>
- /// Constructor for Message class
- /// </summary>
- /// <param name="name">name property</param>
- /// <param name="doc">doc property</param>
- /// <param name="request">list of parameters</param>
- /// <param name="response">response property</param>
- /// <param name="error">error union schema</param>
- public Message(string name, string doc, RecordSchema request, Schema response, UnionSchema error, bool? oneway)
- {
- if (string.IsNullOrEmpty(name)) throw new ArgumentNullException("name", "name cannot be null.");
- this.Request = request;
- this.Response = response;
- this.Error = error;
- this.Name = name;
- this.Doc = doc;
- this.Oneway = oneway;
- }
-
- /// <summary>
- /// Parses the messages section of a protocol definition
- /// </summary>
- /// <param name="jmessage">messages JSON object</param>
- /// <param name="names">list of parsed names</param>
- /// <param name="encspace">enclosing namespace</param>
- /// <returns></returns>
- internal static Message Parse(JProperty jmessage, SchemaNames names, string encspace)
- {
- string name = jmessage.Name;
- string doc = JsonHelper.GetOptionalString(jmessage.Value, "doc");
- bool? oneway = JsonHelper.GetOptionalBoolean(jmessage.Value, "one-way");
-
- PropertyMap props = Schema.GetProperties(jmessage.Value);
- RecordSchema schema = RecordSchema.NewInstance(Schema.Type.Record, jmessage.Value as JObject, props, names, encspace);
-
- JToken jresponse = jmessage.Value["response"];
- var response = Schema.ParseJson(jresponse, names, encspace);
-
- JToken jerrors = jmessage.Value["errors"];
- UnionSchema uerrorSchema = null;
- if (null != jerrors)
- {
- Schema errorSchema = Schema.ParseJson(jerrors, names, encspace);
- if (!(errorSchema is UnionSchema))
- throw new AvroException("");
-
- uerrorSchema = errorSchema as UnionSchema;
- }
-
- return new Message(name, doc, schema, response, uerrorSchema, oneway);
- }
-
- /// <summary>
- /// Writes the messages section of a protocol definition
- /// </summary>
- /// <param name="writer">writer</param>
- /// <param name="names">list of names written</param>
- /// <param name="encspace">enclosing namespace</param>
- internal void writeJson(Newtonsoft.Json.JsonTextWriter writer, SchemaNames names, string encspace)
- {
- writer.WriteStartObject();
- JsonHelper.writeIfNotNullOrEmpty(writer, "doc", this.Doc);
-
- if (null != this.Request)
- this.Request.WriteJsonFields(writer, names, null);
-
- if (null != this.Response)
- {
- writer.WritePropertyName("response");
- writer.WriteValue(Response.Name);
- }
-
- if (null != this.Error)
- {
- writer.WritePropertyName("errors");
- this.Error.WriteJson(writer, names, encspace);
- }
-
- if (null != Oneway)
- {
- writer.WritePropertyName("one-way");
- writer.WriteValue(Oneway);
- }
-
- writer.WriteEndObject();
- }
-
- /// <summary>
- /// Tests equality of this Message object with the passed object
- /// </summary>
- /// <param name="obj"></param>
- /// <returns></returns>
- public override bool Equals(Object obj)
- {
- if (obj == this) return true;
- if (!(obj is Message)) return false;
-
- Message that = obj as Message;
- return this.Name.Equals(that.Name) &&
- this.Request.Equals(that.Request) &&
- areEqual(this.Response, that.Response) &&
- areEqual(this.Error, that.Error);
- }
-
- /// <summary>
- /// Returns the hash code of this Message object
- /// </summary>
- /// <returns></returns>
- public override int GetHashCode()
- {
- return Name.GetHashCode() +
- Request.GetHashCode() +
- (Response == null ? 0 : Response.GetHashCode()) +
- (Error == null ? 0 : Error.GetHashCode());
- }
-
- /// <summary>
- /// Tests equality of two objects taking null values into account
- /// </summary>
- /// <param name="o1"></param>
- /// <param name="o2"></param>
- /// <returns></returns>
- protected static bool areEqual(object o1, object o2)
- {
- return o1 == null ? o2 == null : o1.Equals(o2);
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/Protocol/Protocol.cs b/lang/csharp/src/apache/main/Protocol/Protocol.cs
deleted file mode 100644
index e9645a5..0000000
--- a/lang/csharp/src/apache/main/Protocol/Protocol.cs
+++ /dev/null
@@ -1,294 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
-
-namespace Avro
-{
- public class Protocol
- {
- /// <summary>
- /// Name of the protocol
- /// </summary>
- public string Name { get; set; }
-
- /// <summary>
- /// Namespace of the protocol
- /// </summary>
- public string Namespace { get; set; }
-
- /// <summary>
- /// Documentation for the protocol
- /// </summary>
- public string Doc { get; set; }
-
- /// <summary>
- /// List of schemas objects representing the different schemas defined under the 'types' attribute
- /// </summary>
- public IList<Schema> Types { get; set; }
-
- /// <summary>
- /// List of message objects representing the different schemas defined under the 'messages' attribute
- /// </summary>
- public IDictionary<string,Message> Messages { get; set; }
-
- private byte[] md5;
- public byte[] MD5
- {
- get
- {
- try
- {
- if (md5 == null)
- md5 = System.Security.Cryptography.MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(ToString()));
- }
- catch (Exception ex)
- {
- throw new AvroRuntimeException("MD5 get exception", ex);
- }
- return md5;
- }
- }
-
- /// <summary>
- /// Constructor for Protocol class
- /// </summary>
- /// <param name="name">required name of protocol</param>
- /// <param name="space">optional namespace</param>
- /// <param name="doc">optional documentation</param>
- /// <param name="types">required list of types</param>
- /// <param name="messages">required list of messages</param>
- public Protocol(string name, string space,
- string doc, IEnumerable<Schema> types,
- IDictionary<string,Message> messages)
- {
- if (string.IsNullOrEmpty(name)) throw new ArgumentNullException("name", "name cannot be null.");
- if (null == types) throw new ArgumentNullException("types", "types cannot be null.");
- if (null == messages) throw new ArgumentNullException("messages", "messages cannot be null.");
-
- this.Name = name;
- this.Namespace = space;
- this.Doc = doc;
- this.Types = new List<Schema>(types);
- this.Messages = new Dictionary<string, Message>(messages);
- }
-
- /// <summary>
- /// Parses the given JSON string to create a Protocol object
- /// </summary>
- /// <param name="jstring">JSON string</param>
- /// <returns>Protocol object</returns>
- public static Protocol Parse(string jstring)
- {
- if (string.IsNullOrEmpty(jstring)) throw new ArgumentNullException("json", "json cannot be null.");
-
- JToken jtok = null;
- try
- {
- jtok = JObject.Parse(jstring);
- }
- catch (Exception ex)
- {
- throw new ProtocolParseException("Invalid JSON format: " + jstring, ex);
- }
- return Parse(jtok);
- }
-
- /// <summary>
- /// Parses the given JSON object to create a Protocol object
- /// </summary>
- /// <param name="jtok">JSON object</param>
- /// <returns>Protocol object</returns>
- private static Protocol Parse(JToken jtok)
- {
- string name = JsonHelper.GetRequiredString(jtok, "protocol");
- string space = JsonHelper.GetOptionalString(jtok, "namespace");
- string doc = JsonHelper.GetOptionalString(jtok, "doc");
-
- var names = new SchemaNames();
-
- JToken jtypes = jtok["types"];
- var types = new List<Schema>();
- if (jtypes is JArray)
- {
- foreach (JToken jtype in jtypes)
- {
- var schema = Schema.ParseJson(jtype, names, space);
- types.Add(schema);
- }
- }
-
- var messages = new Dictionary<string,Message>();
- JToken jmessages = jtok["messages"];
- if (null != jmessages)
- {
- foreach (JProperty jmessage in jmessages)
- {
- var message = Message.Parse(jmessage, names, space);
- messages.Add(message.Name, message);
- }
- }
-
- return new Protocol(name, space, doc, types, messages);
- }
-
- /// <summary>
- /// Writes Protocol in JSON format
- /// </summary>
- /// <returns>JSON string</returns>
- public override string ToString()
- {
- using (System.IO.StringWriter sw = new System.IO.StringWriter())
- {
- using (Newtonsoft.Json.JsonTextWriter writer = new Newtonsoft.Json.JsonTextWriter(sw))
- {
- #if(DEBUG)
- writer.Formatting = Newtonsoft.Json.Formatting.Indented;
- #endif
-
- WriteJson(writer, new SchemaNames());
- writer.Flush();
- return sw.ToString();
- }
- }
- }
-
- /// <summary>
- /// Writes Protocol in JSON format
- /// </summary>
- /// <param name="writer">JSON writer</param>
- /// <param name="names">list of named schemas already written</param>
- internal void WriteJson(Newtonsoft.Json.JsonTextWriter writer, SchemaNames names)
- {
- writer.WriteStartObject();
-
- JsonHelper.writeIfNotNullOrEmpty(writer, "protocol", this.Name);
- JsonHelper.writeIfNotNullOrEmpty(writer, "namespace", this.Namespace);
- JsonHelper.writeIfNotNullOrEmpty(writer, "doc", this.Doc);
-
- writer.WritePropertyName("types");
- writer.WriteStartArray();
-
- foreach (Schema type in this.Types)
- type.WriteJson(writer, names, this.Namespace);
-
- writer.WriteEndArray();
-
- writer.WritePropertyName("messages");
- writer.WriteStartObject();
-
- foreach (KeyValuePair<string,Message> message in this.Messages)
- {
- writer.WritePropertyName(message.Key);
- message.Value.writeJson(writer, names, this.Namespace);
- }
-
- writer.WriteEndObject();
- writer.WriteEndObject();
- }
-
- /// <summary>
- /// Tests equality of this protocol object with the passed object
- /// </summary>
- /// <param name="obj"></param>
- /// <returns></returns>
- public override bool Equals(object obj)
- {
- if (obj == this) return true;
- if (!(obj is Protocol)) return false;
-
- Protocol that = obj as Protocol;
-
- return this.Name.Equals(that.Name) && this.Namespace.Equals(that.Namespace) &&
- TypesEquals(that.Types) && MessagesEquals(that.Messages);
- }
-
- /// <summary>
- /// Test equality of this protocols Types list with the passed Types list.
- /// Order of schemas does not matter, as long as all types in this protocol
- /// are also defined in the passed protocol
- /// </summary>
- /// <param name="that"></param>
- /// <returns></returns>
- private bool TypesEquals(IList<Schema> that)
- {
- if (Types.Count != that.Count) return false;
- foreach (Schema schema in Types)
- if (!that.Contains(schema)) return false;
- return true;
- }
-
- /// <summary>
- /// Test equality of this protocols Message map with the passed Message map
- /// Order of messages does not matter, as long as all messages in this protocol
- /// are also defined in the passed protocol
- /// </summary>
- /// <param name="that"></param>
- /// <returns></returns>
- private bool MessagesEquals(IDictionary<string, Message> that)
- {
- if (Messages.Count != that.Count) return false;
- foreach (KeyValuePair<string, Message> pair in Messages)
- {
- if (!that.ContainsKey(pair.Key))
- return false;
- if (!pair.Value.Equals(that[pair.Key]))
- return false;
- }
- return true;
- }
-
- /// <summary>
- /// Returns the hash code of this protocol object
- /// </summary>
- /// <returns></returns>
- public override int GetHashCode()
- {
- return Name.GetHashCode() + Namespace.GetHashCode() +
- GetTypesHashCode() + GetMessagesHashCode();
- }
-
- /// <summary>
- /// Returns the hash code of the Types list
- /// </summary>
- /// <returns></returns>
- private int GetTypesHashCode()
- {
- int hash = Types.Count;
- foreach (Schema schema in Types)
- hash += schema.GetHashCode();
- return hash;
- }
-
- /// <summary>
- /// Returns the hash code of the Messages map
- /// </summary>
- /// <returns></returns>
- private int GetMessagesHashCode()
- {
- int hash = Messages.Count;
- foreach (KeyValuePair<string, Message> pair in Messages)
- hash += (pair.Key.GetHashCode() + pair.Value.GetHashCode());
- return hash;
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/Protocol/ProtocolParseException.cs b/lang/csharp/src/apache/main/Protocol/ProtocolParseException.cs
deleted file mode 100644
index 4e67013..0000000
--- a/lang/csharp/src/apache/main/Protocol/ProtocolParseException.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace Avro
-{
- public class ProtocolParseException:AvroException
- {
- public ProtocolParseException(string s)
- : base(s)
- {
- }
-
- public ProtocolParseException(string s, Exception inner)
- : base(s, inner)
- {
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/Schema/ArraySchema.cs b/lang/csharp/src/apache/main/Schema/ArraySchema.cs
deleted file mode 100644
index c5e4203..0000000
--- a/lang/csharp/src/apache/main/Schema/ArraySchema.cs
+++ /dev/null
@@ -1,111 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using Newtonsoft.Json.Linq;
-
-namespace Avro
-{
- /// <summary>
- /// Class for array type schemas
- /// </summary>
- public class ArraySchema : UnnamedSchema
- {
- /// <summary>
- /// Schema for the array 'type' attribute
- /// </summary>
- public Schema ItemSchema { get; set; }
-
- /// <summary>
- /// Static class to return a new instance of ArraySchema
- /// </summary>
- /// <param name="jtok">JSON object for the array schema</param>
- /// <param name="names">list of named schemas already parsed</param>
- /// <param name="encspace">enclosing namespace for the array schema</param>
- /// <returns></returns>
- internal static ArraySchema NewInstance(JToken jtok, PropertyMap props, SchemaNames names, string encspace)
- {
- JToken jitem = jtok["items"];
- if (null == jitem) throw new AvroTypeException("Array does not have 'items'");
-
- return new ArraySchema(Schema.ParseJson(jitem, names, encspace), props);
- }
-
- /// <summary>
- /// Constructor
- /// </summary>
- /// <param name="items">schema for the array items type</param>
- private ArraySchema(Schema items, PropertyMap props) : base(Type.Array, props)
- {
- if (null == items) throw new ArgumentNullException("items");
- this.ItemSchema = items;
- }
-
- /// <summary>
- /// Writes the array schema in JSON format
- /// </summary>
- /// <param name="writer">JSON writer</param>
- /// <param name="names">list of named schemas already written</param>
- /// <param name="encspace">enclosing namespace</param>
- protected internal override void WriteJsonFields(Newtonsoft.Json.JsonTextWriter writer, SchemaNames names, string encspace)
- {
- writer.WritePropertyName("items");
- ItemSchema.WriteJson(writer, names, encspace);
- }
-
- /// <summary>
- /// Checks if this schema can read data written by the given schema. Used for decoding data.
- /// </summary>
- /// <param name="writerSchema">writer schema</param>
- /// <returns>true if this and writer schema are compatible based on the AVRO specification, false otherwise</returns>
- public override bool CanRead(Schema writerSchema)
- {
- if (writerSchema.Tag != Tag) return false;
-
- ArraySchema that = writerSchema as ArraySchema;
- return ItemSchema.CanRead(that.ItemSchema);
- }
-
- /// <summary>
- /// Function to compare equality of two array schemas
- /// </summary>
- /// <param name="obj">other array schema</param>
- /// <returns>true two schemas are equal, false otherwise</returns>
- public override bool Equals(object obj)
- {
- if (this == obj) return true;
-
- if (obj != null && obj is ArraySchema)
- {
- ArraySchema that = obj as ArraySchema;
- if (ItemSchema.Equals(that.ItemSchema))
- return areEqual(that.Props, this.Props);
- }
- return false;
- }
-
- /// <summary>
- /// Hashcode function
- /// </summary>
- /// <returns></returns>
- public override int GetHashCode()
- {
- return 29 * ItemSchema.GetHashCode() + getHashCode(Props);
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/Schema/AvroException.cs b/lang/csharp/src/apache/main/Schema/AvroException.cs
deleted file mode 100644
index 688fd59..0000000
--- a/lang/csharp/src/apache/main/Schema/AvroException.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace Avro
-{
- public class AvroException : Exception
- {
- public AvroException(string s)
- : base(s)
- {
- }
-
- public AvroException(string s, Exception inner)
- : base(s, inner)
- {
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/Schema/AvroTypeException.cs b/lang/csharp/src/apache/main/Schema/AvroTypeException.cs
deleted file mode 100644
index 6c8b052..0000000
--- a/lang/csharp/src/apache/main/Schema/AvroTypeException.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace Avro
-{
- public class AvroTypeException : AvroException
- {
- public AvroTypeException(string s)
- : base(s)
- {
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/Schema/EnumSchema.cs b/lang/csharp/src/apache/main/Schema/EnumSchema.cs
deleted file mode 100644
index d346ecf..0000000
--- a/lang/csharp/src/apache/main/Schema/EnumSchema.cs
+++ /dev/null
@@ -1,206 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Text;
-using Newtonsoft.Json.Linq;
-
-namespace Avro
-{
- /// <summary>
- /// Class for enum type schemas
- /// </summary>
- public class EnumSchema : NamedSchema
- {
- /// <summary>
- /// List of strings representing the enum symbols
- /// </summary>
- public IList<string> Symbols { get; private set; }
-
- /// <summary>
- /// Map of enum symbols and it's corresponding ordinal number
- /// </summary>
- private readonly IDictionary<string, int> symbolMap;
-
- /// <summary>
- /// Count of enum symbols
- /// </summary>
- public int Count { get { return Symbols.Count; } }
-
- /// <summary>
- /// Static function to return new instance of EnumSchema
- /// </summary>
- /// <param name="jtok">JSON object for enum schema</param>
- /// <param name="names">list of named schema already parsed in</param>
- /// <param name="encspace">enclosing namespace for the enum schema</param>
- /// <returns>new instance of enum schema</returns>
- internal static EnumSchema NewInstance(JToken jtok, PropertyMap props, SchemaNames names, string encspace)
- {
- SchemaName name = NamedSchema.GetName(jtok, encspace);
- var aliases = NamedSchema.GetAliases(jtok, name.Space, name.EncSpace);
-
- JArray jsymbols = jtok["symbols"] as JArray;
- if (null == jsymbols)
- throw new SchemaParseException("Enum has no symbols: " + name);
-
- List<string> symbols = new List<string>();
- IDictionary<string, int> symbolMap = new Dictionary<string, int>();
- int i = 0;
- foreach (JValue jsymbol in jsymbols)
- {
- string s = (string)jsymbol.Value;
- if (symbolMap.ContainsKey(s))
- throw new SchemaParseException("Duplicate symbol: " + s);
-
- symbolMap[s] = i++;
- symbols.Add(s);
- }
- return new EnumSchema(name, aliases, symbols, symbolMap, props, names);
- }
-
- /// <summary>
- /// Constructor for enum schema
- /// </summary>
- /// <param name="name">name of enum</param>
- /// <param name="aliases">list of aliases for the name</param>
- /// <param name="symbols">list of enum symbols</param>
- /// <param name="symbolMap">map of enum symbols and value</param>
- /// <param name="names">list of named schema already read</param>
- private EnumSchema(SchemaName name, IList<SchemaName> aliases, List<string> symbols,
- IDictionary<String, int> symbolMap, PropertyMap props, SchemaNames names)
- : base(Type.Enumeration, name, aliases, props, names)
- {
- if (null == name.Name) throw new SchemaParseException("name cannot be null for enum schema.");
- this.Symbols = symbols;
- this.symbolMap = symbolMap;
- }
-
- /// <summary>
- /// Writes enum schema in JSON format
- /// </summary>
- /// <param name="writer">JSON writer</param>
- /// <param name="names">list of named schema already written</param>
- /// <param name="encspace">enclosing namespace of the enum schema</param>
- protected internal override void WriteJsonFields(Newtonsoft.Json.JsonTextWriter writer,
- SchemaNames names, string encspace)
- {
- base.WriteJsonFields(writer, names, encspace);
- writer.WritePropertyName("symbols");
- writer.WriteStartArray();
- foreach (string s in this.Symbols)
- writer.WriteValue(s);
- writer.WriteEndArray();
- }
-
- /// <summary>
- /// Returns the position of the given symbol within this enum.
- /// Throws AvroException if the symbol is not found in this enum.
- /// </summary>
- /// <param name="symbol">name of the symbol to find</param>
- /// <returns>position of the given symbol in this enum schema</returns>
- public int Ordinal(string symbol)
- {
- int result;
- if (symbolMap.TryGetValue(symbol, out result)) return result;
- throw new AvroException("No such symbol: " + symbol);
- }
-
- /// <summary>
- /// Returns the enum symbol of the given index to the list
- /// </summary>
- /// <param name="index">symbol index</param>
- /// <returns>symbol name</returns>
- public string this[int index]
- {
- get
- {
- if (index < Symbols.Count) return Symbols[index];
- throw new AvroException("Enumeration out of range. Must be less than " + Symbols.Count + ", but is " + index);
- }
- }
-
- /// <summary>
- /// Checks if given symbol is in the list of enum symbols
- /// </summary>
- /// <param name="symbol">symbol to check</param>
- /// <returns>true if symbol exist, false otherwise</returns>
- public bool Contains(string symbol)
- {
- return symbolMap.ContainsKey(symbol);
- }
-
- /// <summary>
- /// Returns an enumerator that enumerates the symbols in this enum schema in the order of their definition.
- /// </summary>
- /// <returns>Enumeration over the symbols of this enum schema</returns>
- public IEnumerator<string> GetEnumerator()
- {
- return Symbols.GetEnumerator();
- }
-
- /// <summary>
- /// Checks equality of two enum schema
- /// </summary>
- /// <param name="obj"></param>
- /// <returns></returns>
- public override bool Equals(object obj)
- {
- if (obj == this) return true;
- if (obj != null && obj is EnumSchema)
- {
- EnumSchema that = obj as EnumSchema;
- if (SchemaName.Equals(that.SchemaName) && Count == that.Count)
- {
- for (int i = 0; i < Count; i++) if (!Symbols[i].Equals(that.Symbols[i])) return false;
- return areEqual(that.Props, this.Props);
- }
- }
- return false;
- }
-
- /// <summary>
- /// Hashcode function
- /// </summary>
- /// <returns></returns>
- public override int GetHashCode()
- {
- int result = SchemaName.GetHashCode() + getHashCode(Props);
- foreach (string s in Symbols) result += 23 * s.GetHashCode();
- return result;
- }
-
- /// <summary>
- /// Checks if this schema can read data written by the given schema. Used for decoding data.
- /// </summary>
- /// <param name="writerSchema">writer schema</param>
- /// <returns>true if this and writer schema are compatible based on the AVRO specification, false otherwise</returns>
- public override bool CanRead(Schema writerSchema)
- {
- if (writerSchema.Tag != Tag) return false;
-
- EnumSchema that = writerSchema as EnumSchema;
- if (!that.SchemaName.Equals(SchemaName))
- if (!InAliases(that.SchemaName)) return false;
-
- // we defer checking of symbols. Writer may have a symbol missing from the reader,
- // but if writer never used the missing symbol, then reader should still be able to read the data
-
- return true;
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/Schema/Field.cs b/lang/csharp/src/apache/main/Schema/Field.cs
deleted file mode 100644
index 740c44d..0000000
--- a/lang/csharp/src/apache/main/Schema/Field.cs
+++ /dev/null
@@ -1,245 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Text;
-using Newtonsoft.Json.Linq;
-using Newtonsoft.Json;
-
-namespace Avro
-{
-
- /// <summary>
- /// Class for fields defined in a record
- /// </summary>
- public class Field
- {
- /// <summary>
- /// Enum for the sorting order of record fields
- /// </summary>
- public enum SortOrder
- {
- ascending,
- descending,
- ignore
- }
-
- /// <summary>
- /// Name of the field.
- /// </summary>
- public readonly string Name;
-
- /// <summary>
- /// List of aliases for the field name
- /// </summary>
- public readonly IList<string> aliases;
-
- /// <summary>
- /// Position of the field within its record.
- /// </summary>
- public int Pos { get; private set; }
-
- /// <summary>
- /// Documentation for the field, if any. Null if there is no documentation.
- /// </summary>
- public string Documentation { get; private set; }
-
- /// <summary>
- /// The default value for the field stored as JSON object, if defined. Otherwise, null.
- /// </summary>
- public JToken DefaultValue { get; private set; }
-
- /// <summary>
- /// Order of the field
- /// </summary>
- public SortOrder? Ordering { get; private set; }
-
- /// <summary>
- /// Field type's schema
- /// </summary>
- public Schema Schema { get; private set; }
-
- /// <summary>
- /// Custom properties for the field. We don't store the fields custom properties in
- /// the field type's schema because if the field type is only a reference to the schema
- /// instead of an actual schema definition, then the schema could already have it's own set
- /// of custom properties when it was previously defined.
- /// </summary>
- private readonly PropertyMap Props;
-
- /// <summary>
- /// Static comparer object for JSON objects such as the fields default value
- /// </summary>
- internal static JTokenEqualityComparer JtokenEqual = new JTokenEqualityComparer();
-
- /// <summary>
- /// A flag to indicate if reader schema has a field that is missing from writer schema and has a default value
- /// This is set in CanRead() which is always be called before deserializing data
- /// </summary>
-
- /// <summary>
- /// Constructor for the field class
- /// </summary>
- /// <param name="schema">schema for the field type</param>
- /// <param name="name">name of the field</param>
- /// <param name="aliases">list of aliases for the name of the field</param>
- /// <param name="pos">position of the field</param>
- /// <param name="doc">documentation for the field</param>
- /// <param name="defaultValue">field's default value if it exists</param>
- /// <param name="sortorder">sort order of the field</param>
- internal Field(Schema schema, string name, IList<string> aliases, int pos, string doc,
- JToken defaultValue, SortOrder sortorder, PropertyMap props)
- {
- if (string.IsNullOrEmpty(name)) throw new ArgumentNullException("name", "name cannot be null.");
- if (null == schema) throw new ArgumentNullException("type", "type cannot be null.");
- this.Schema = schema;
- this.Name = name;
- this.aliases = aliases;
- this.Pos = pos;
- this.Documentation = doc;
- this.DefaultValue = defaultValue;
- this.Ordering = sortorder;
- this.Props = props;
- }
-
- /// <summary>
- /// Writes the Field class in JSON format
- /// </summary>
- /// <param name="writer">JSON writer</param>
- /// <param name="names">list of named schemas already written</param>
- /// <param name="encspace">enclosing namespace for the field</param>
- protected internal void writeJson(JsonTextWriter writer, SchemaNames names, string encspace)
- {
- writer.WriteStartObject();
- JsonHelper.writeIfNotNullOrEmpty(writer, "name", this.Name);
- JsonHelper.writeIfNotNullOrEmpty(writer, "doc", this.Documentation);
-
- if (null != this.DefaultValue)
- {
- writer.WritePropertyName("default");
- this.DefaultValue.WriteTo(writer, null);
- }
- if (null != this.Schema)
- {
- writer.WritePropertyName("type");
- Schema.WriteJson(writer, names, encspace);
- }
-
- if (null != this.Props)
- this.Props.WriteJson(writer);
-
- if (null != aliases)
- {
- writer.WritePropertyName("aliases");
- writer.WriteStartArray();
- foreach (string name in aliases)
- writer.WriteValue(name);
- writer.WriteEndArray();
- }
-
- writer.WriteEndObject();
- }
-
- /// <summary>
- /// Parses the 'aliases' property from the given JSON token
- /// </summary>
- /// <param name="jtok">JSON object to read</param>
- /// <returns>List of string that represents the list of alias. If no 'aliases' specified, then it returns null.</returns>
- internal static IList<string> GetAliases(JToken jtok)
- {
- JToken jaliases = jtok["aliases"];
- if (null == jaliases)
- return null;
-
- if (jaliases.Type != JTokenType.Array)
- throw new SchemaParseException("Aliases must be of format JSON array of strings");
-
- var aliases = new List<string>();
- foreach (JToken jalias in jaliases)
- {
- if (jalias.Type != JTokenType.String)
- throw new SchemaParseException("Aliases must be of format JSON array of strings");
-
- aliases.Add((string)jalias);
- }
- return aliases;
- }
-
- /// <summary>
- /// Returns the field's custom property value given the property name
- /// </summary>
- /// <param name="key">custom property name</param>
- /// <returns>custom property value</returns>
- public string GetProperty(string key)
- {
- if (null == this.Props) return null;
- string v;
- return (this.Props.TryGetValue(key, out v)) ? v : null;
- }
-
- /// <summary>
- /// Compares two field objects
- /// </summary>
- /// <param name="obj">field to compare with this field</param>
- /// <returns>true if two fields are equal, false otherwise</returns>
- public override bool Equals(object obj)
- {
- if (obj == this) return true;
- if (obj != null && obj is Field)
- {
- Field that = obj as Field;
- return areEqual(that.Name, Name) && that.Pos == Pos && areEqual(that.Documentation, Documentation)
- && areEqual(that.Ordering, Ordering) && JtokenEqual.Equals(that.DefaultValue, DefaultValue)
- && that.Schema.Equals(Schema) && areEqual(that.Props, this.Props);
- }
- return false;
- }
-
- /// <summary>
- /// Compares two objects
- /// </summary>
- /// <param name="o1">first object</param>
- /// <param name="o2">second object</param>
- /// <returns>true if two objects are equal, false otherwise</returns>
- private static bool areEqual(object o1, object o2)
- {
- return o1 == null ? o2 == null : o1.Equals(o2);
- }
-
- /// <summary>
- /// Hash code function
- /// </summary>
- /// <returns></returns>
- public override int GetHashCode()
- {
- return 17 * Name.GetHashCode() + Pos + 19 * getHashCode(Documentation) +
- 23 * getHashCode(Ordering) + 29 * getHashCode(DefaultValue) + 31 * Schema.GetHashCode() +
- 37 * getHashCode(Props);
- }
-
- /// <summary>
- /// Hash code helper function
- /// </summary>
- /// <param name="obj"></param>
- /// <returns></returns>
- private static int getHashCode(object obj)
- {
- return obj == null ? 0 : obj.GetHashCode();
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/Schema/FixedSchema.cs b/lang/csharp/src/apache/main/Schema/FixedSchema.cs
deleted file mode 100644
index 67c843d..0000000
--- a/lang/csharp/src/apache/main/Schema/FixedSchema.cs
+++ /dev/null
@@ -1,120 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Text;
-using Newtonsoft.Json.Linq;
-
-namespace Avro
-{
- /// <summary>
- /// Class for fixed schemas
- /// </summary>
- public class FixedSchema : NamedSchema
- {
- /// <summary>
- /// Fixed size for the bytes
- /// </summary>
- public int Size { get; set; }
-
- /// <summary>
- /// Static function to return new instance of the fixed schema class
- /// </summary>
- /// <param name="jtok">JSON object for the fixed schema</param>
- /// <param name="names">list of named schema already parsed in</param>
- /// <param name="encspace">enclosing namespace of the fixed schema</param>
- /// <returns></returns>
- internal static FixedSchema NewInstance(JToken jtok, PropertyMap props, SchemaNames names, string encspace)
- {
- SchemaName name = NamedSchema.GetName(jtok, encspace);
- var aliases = NamedSchema.GetAliases(jtok, name.Space, name.EncSpace);
-
- return new FixedSchema(name, aliases, JsonHelper.GetRequiredInteger(jtok, "size"), props, names);
- }
-
- /// <summary>
- /// Constructor
- /// </summary>
- /// <param name="name">name of the fixed schema</param>
- /// <param name="aliases">list of aliases for the name</param>
- /// <param name="size">fixed size</param>
- /// <param name="names">list of named schema already parsed in</param>
- private FixedSchema(SchemaName name, IList<SchemaName> aliases, int size, PropertyMap props, SchemaNames names)
- : base(Type.Fixed, name, aliases, props, names)
- {
- if (null == name.Name) throw new SchemaParseException("name cannot be null for fixed schema.");
- if (size <= 0) throw new ArgumentOutOfRangeException("size", "size must be greater than zero.");
- this.Size = size;
- }
-
- /// <summary>
- /// Writes the fixed schema class in JSON format
- /// </summary>
- /// <param name="writer">JSON writer</param>
- /// <param name="names">list of named schema already written</param>
- /// <param name="encspace">enclosing namespace for the fixed schema</param>
- protected internal override void WriteJsonFields(Newtonsoft.Json.JsonTextWriter writer, SchemaNames names, string encspace)
- {
- base.WriteJsonFields(writer, names, encspace);
- writer.WritePropertyName("size");
- writer.WriteValue(this.Size);
- }
-
- /// <summary>
- /// Compares two fixed schemas
- /// </summary>
- /// <param name="obj">fixed schema to compare against this schema</param>
- /// <returns>true if two schemas are the same, false otherwise</returns>
- public override bool Equals(object obj)
- {
- if (obj == this) return true;
-
- if (obj != null && obj is FixedSchema)
- {
- FixedSchema that = obj as FixedSchema;
- return SchemaName.Equals(that.SchemaName) && Size == that.Size && areEqual(that.Props, this.Props);
- }
- return false;
- }
-
- /// <summary>
- /// Hash code function
- /// </summary>
- /// <returns></returns>
- public override int GetHashCode()
- {
- return 53 * SchemaName.GetHashCode() + 47 * Size + getHashCode(Props);
- }
-
- /// <summary>
- /// Checks if this schema can read data written by the given schema. Used for decoding data.
- /// </summary>
- /// <param name="writerSchema">writer schema</param>
- /// <returns>true if this and writer schema are compatible based on the AVRO specification, false otherwise</returns>
- public override bool CanRead(Schema writerSchema)
- {
- if (writerSchema.Tag != Tag) return false;
- FixedSchema that = writerSchema as FixedSchema;
- if (that.Size != Size) return false;
- if (that.SchemaName.Equals(SchemaName))
- return true;
- else
- return InAliases(that.SchemaName);
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/Schema/JsonHelper.cs b/lang/csharp/src/apache/main/Schema/JsonHelper.cs
deleted file mode 100644
index 13db058..0000000
--- a/lang/csharp/src/apache/main/Schema/JsonHelper.cs
+++ /dev/null
@@ -1,122 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Text;
-using Newtonsoft.Json.Linq;
-using Newtonsoft.Json;
-
-namespace Avro
-{
- class JsonHelper
- {
- /// <summary>
- /// Retrieves the optional string property value for the given property name from the given JSON object.
- /// This throws an exception if property exists but it is not a string.
- /// </summary>
- /// <param name="jtok">JSON object to read</param>
- /// <param name="field">property name</param>
- /// <returns>property value if property exists, null if property doesn't exist in the JSON object</returns>
- public static string GetOptionalString(JToken jtok, string field)
- {
- if (null == jtok) throw new ArgumentNullException("jtok", "jtok cannot be null.");
- if (string.IsNullOrEmpty(field)) throw new ArgumentNullException("field", "field cannot be null.");
-
- JToken child = jtok[field];
- if (null == child) return null;
-
- if (child.Type == JTokenType.String)
- {
- string value = child.ToString();
- return value.Trim('\"');
- }
- throw new SchemaParseException("Field " + field + " is not a string");
- }
-
- /// <summary>
- /// Retrieves the required string property value for the given property name from the given JSON object.
- /// </summary>
- /// <param name="jtok">JSON object to read</param>
- /// <param name="field">property name</param>
- /// <returns>property value</returns>
- public static string GetRequiredString(JToken jtok, string field)
- {
- string value = GetOptionalString(jtok, field);
- if (string.IsNullOrEmpty(value)) throw new SchemaParseException(string.Format("No \"{0}\" JSON field: {1}", field, jtok));
- return value;
- }
-
- /// <summary>
- /// Retrieves the required int property value for the given property name from the given JSON object.
- /// </summary>
- /// <param name="jtok">JSON object to read</param>
- /// <param name="field">property name</param>
- /// <returns>property value</returns>
- public static int GetRequiredInteger(JToken jtok, string field)
- {
- ensureValidFieldName(field);
- JToken child = jtok[field];
- if (null == child) throw new SchemaParseException(string.Format("No \"{0}\" JSON field: {1}", field, jtok));
-
- if (child.Type == JTokenType.Integer) return (int) child;
- throw new SchemaParseException("Field " + field + " is not an integer");
- }
-
- /// <summary>
- /// Retrieves the optional boolean property value for the given property name from the given JSON object.
- /// </summary>
- /// <param name="jtok">JSON object to read</param>
- /// <param name="field">property name</param>
- /// <returns>null if property doesn't exist, otherise returns property boolean value</returns>
- public static bool? GetOptionalBoolean(JToken jtok, string field)
- {
- if (null == jtok) throw new ArgumentNullException("jtok", "jtok cannot be null.");
- if (string.IsNullOrEmpty(field)) throw new ArgumentNullException("field", "field cannot be null.");
-
- JToken child = jtok[field];
- if (null == child) return null;
-
- if (child.Type == JTokenType.Boolean)
- return (bool)child;
-
- throw new SchemaParseException("Field " + field + " is not a boolean");
- }
-
- /// <summary>
- /// Writes JSON property name and value if value is not null
- /// </summary>
- /// <param name="writer">JSON writer</param>
- /// <param name="key">property name</param>
- /// <param name="value">property value</param>
- internal static void writeIfNotNullOrEmpty(JsonTextWriter writer, string key, string value)
- {
- if (string.IsNullOrEmpty(value)) return;
- writer.WritePropertyName(key);
- writer.WriteValue(value);
- }
-
- /// <summary>
- /// Checks if given name is not null or empty
- /// </summary>
- /// <param name="name"></param>
- private static void ensureValidFieldName(string name)
- {
- if (string.IsNullOrEmpty(name)) throw new ArgumentNullException("name");
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/Schema/MapSchema.cs b/lang/csharp/src/apache/main/Schema/MapSchema.cs
deleted file mode 100644
index 7f68f5f..0000000
--- a/lang/csharp/src/apache/main/Schema/MapSchema.cs
+++ /dev/null
@@ -1,112 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Text;
-using Newtonsoft.Json.Linq;
-
-namespace Avro
-{
- /// <summary>
- /// Class for map schemas
- /// </summary>
- public class MapSchema : UnnamedSchema
- {
- /// <summary>
- /// Schema for map values type
- /// </summary>
- public Schema ValueSchema { get; set; }
-
- /// <summary>
- /// Static function to return new instance of map schema
- /// </summary>
- /// <param name="jtok">JSON object for the map schema</param>
- /// <param name="names">list of named schemas already read</param>
- /// <param name="encspace">enclosing namespace of the map schema</param>
- /// <returns></returns>
- internal static MapSchema NewInstance(JToken jtok, PropertyMap props, SchemaNames names, string encspace)
- {
- JToken jvalue = jtok["values"];
- if (null == jvalue) throw new AvroTypeException("Map does not have 'values'");
-
- return new MapSchema(Schema.ParseJson(jvalue, names, encspace), props);
- }
-
- /// <summary>
- /// Constructor for map schema class
- /// </summary>
- /// <param name="valueSchema">schema for map values type</param>
- private MapSchema(Schema valueSchema, PropertyMap props) : base(Type.Map, props)
- {
- if (null == valueSchema) throw new ArgumentNullException("valueSchema", "valueSchema cannot be null.");
- this.ValueSchema = valueSchema;
- }
-
- /// <summary>
- /// Writes map schema in JSON format
- /// </summary>
- /// <param name="writer">JSON writer</param>
- /// <param name="names">list of named schemas already written</param>
- /// <param name="encspace">enclosing namespace of the map schema</param>
- protected internal override void WriteJsonFields(Newtonsoft.Json.JsonTextWriter writer, SchemaNames names, string encspace)
- {
- writer.WritePropertyName("values");
- ValueSchema.WriteJson(writer, names, encspace);
- }
-
- /// <summary>
- /// Checks if this schema can read data written by the given schema. Used for decoding data.
- /// </summary>
- /// <param name="writerSchema">writer schema</param>
- /// <returns>true if this and writer schema are compatible based on the AVRO specification, false otherwise</returns>
- public override bool CanRead(Schema writerSchema)
- {
- if (writerSchema.Tag != Tag) return false;
-
- MapSchema that = writerSchema as MapSchema;
- return ValueSchema.CanRead(that.ValueSchema);
- }
-
- /// <summary>
- /// Compares equality of two map schemas
- /// </summary>
- /// <param name="obj">map schema to compare against this schema</param>
- /// <returns>true if two schemas are equal, false otherwise</returns>
- public override bool Equals(object obj)
- {
- if (this == obj) return true;
-
- if (obj != null && obj is MapSchema)
- {
- MapSchema that = obj as MapSchema;
- if (ValueSchema.Equals(that.ValueSchema))
- return areEqual(that.Props, this.Props);
- }
- return false;
- }
-
- /// <summary>
- /// Hashcode function
- /// </summary>
- /// <returns></returns>
- public override int GetHashCode()
- {
- return 29 * ValueSchema.GetHashCode() + getHashCode(Props);
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/Schema/NamedSchema.cs b/lang/csharp/src/apache/main/Schema/NamedSchema.cs
deleted file mode 100644
index be4b00b..0000000
--- a/lang/csharp/src/apache/main/Schema/NamedSchema.cs
+++ /dev/null
@@ -1,206 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Text;
-using Newtonsoft.Json.Linq;
-
-
-namespace Avro
-{
- /// <summary>
- /// Base class for all named schemas: fixed, enum, record
- /// </summary>
- public abstract class NamedSchema : Schema
- {
- /// <summary>
- /// Name of the schema, contains name, namespace and enclosing namespace
- /// </summary>
- public SchemaName SchemaName { get; private set; }
-
- /// <summary>
- /// Name of the schema
- /// </summary>
- public override string Name
- {
- get { return SchemaName.Name; }
- }
-
- /// <summary>
- /// Namespace of the schema
- /// </summary>
- public string Namespace
- {
- get { return SchemaName.Namespace; }
- }
-
- /// <summary>
- /// Namespace.Name of the schema
- /// </summary>
- public string Fullname
- {
- get { return SchemaName.Fullname; }
- }
-
- /// <summary>
- /// List of aliases for this named schema
- /// </summary>
- private readonly IList<SchemaName> aliases;
-
- /// <summary>
- /// Static function to return a new instance of the named schema
- /// </summary>
- /// <param name="jo">JSON object of the named schema</param>
- /// <param name="names">list of named schemas already read</param>
- /// <param name="encspace">enclosing namespace of the named schema</param>
- /// <returns></returns>
- internal static NamedSchema NewInstance(JObject jo, PropertyMap props, SchemaNames names, string encspace)
- {
- string type = JsonHelper.GetRequiredString(jo, "type");
- switch (type)
- {
- case "fixed":
- return FixedSchema.NewInstance(jo, props, names, encspace);
- case "enum":
- return EnumSchema.NewInstance(jo, props, names, encspace);
- case "record":
- return RecordSchema.NewInstance(Type.Record, jo, props, names, encspace);
- case "error":
- return RecordSchema.NewInstance(Type.Error, jo, props, names, encspace);
- default:
- NamedSchema result;
- if (names.TryGetValue(type, null, encspace, out result))
- return result;
- return null;
- }
- }
-
- /// <summary>
- /// Constructor for named schema class
- /// </summary>
- /// <param name="type">schema type</param>
- /// <param name="name">name</param>
- /// <param name="names">list of named schemas already read</param>
- protected NamedSchema(Type type, SchemaName name, IList<SchemaName> aliases, PropertyMap props, SchemaNames names)
- : base(type, props)
- {
- this.SchemaName = name;
- this.aliases = aliases;
- if (!names.Add(name, this))
- throw new AvroException("Duplicate schema name " + name.Fullname);
- }
-
- /// <summary>
- /// Parses the name and namespace from the given JSON schema object then creates
- /// SchemaName object including the given enclosing namespace
- /// </summary>
- /// <param name="jtok">JSON object to read</param>
- /// <param name="encspace">enclosing namespace</param>
- /// <returns>new SchemaName object</returns>
- protected static SchemaName GetName(JToken jtok, string encspace)
- {
- String n = JsonHelper.GetOptionalString(jtok, "name"); // Changed this to optional string for anonymous records in messages
- String ns = JsonHelper.GetOptionalString(jtok, "namespace");
- return new SchemaName(n, ns, encspace);
- }
-
- /// <summary>
- /// Parses the 'aliases' property from the given JSON token
- /// </summary>
- /// <param name="jtok">JSON object to read</param>
- /// <param name="space">namespace of the name this alias is for</param>
- /// <param name="encspace">enclosing namespace of the name this alias is for</param>
- /// <returns>List of SchemaName that represents the list of alias. If no 'aliases' specified, then it returns null.</returns>
- protected static IList<SchemaName> GetAliases(JToken jtok, string space, string encspace)
- {
- JToken jaliases = jtok["aliases"];
- if (null == jaliases)
- return null;
-
- if (jaliases.Type != JTokenType.Array)
- throw new SchemaParseException("Aliases must be of format JSON array of strings");
-
- var aliases = new List<SchemaName>();
- foreach (JToken jalias in jaliases)
- {
- if (jalias.Type != JTokenType.String)
- throw new SchemaParseException("Aliases must be of format JSON array of strings");
-
- aliases.Add(new SchemaName((string)jalias, space, encspace));
- }
- return aliases;
- }
-
- protected bool InAliases(SchemaName name)
- {
- if (null != aliases)
- {
- foreach (SchemaName alias in aliases)
- if (name.Equals(alias)) return true;
- }
- return false;
- }
-
- /// <summary>
- /// Writes named schema in JSON format
- /// </summary>
- /// <param name="writer">JSON writer</param>
- /// <param name="names">list of named schemas already written</param>
- /// <param name="encspace">enclosing namespace of the named schema</param>
- protected internal override void WriteJson(Newtonsoft.Json.JsonTextWriter writer, SchemaNames names, string encspace)
- {
- if (!names.Add(this))
- {
- // schema is already in the list, write name only
- SchemaName schemaName = this.SchemaName;
- string name;
- if (schemaName.Namespace != encspace)
- name = schemaName.Namespace + "." + schemaName.Name; // we need to add the qualifying namespace of the target schema if it's not the same as current namespace
- else
- name = schemaName.Name;
- writer.WriteValue(name);
- }
- else
- // schema is not in the list, write full schema definition
- base.WriteJson(writer, names, encspace);
- }
-
- /// <summary>
- /// Writes named schema in JSON format
- /// </summary>
- /// <param name="writer">JSON writer</param>
- /// <param name="names">list of named schemas already written</param>
- /// <param name="encspace">enclosing namespace of the named schema</param>
- protected internal override void WriteJsonFields(Newtonsoft.Json.JsonTextWriter writer, SchemaNames names, string encspace)
- {
- this.SchemaName.WriteJson(writer, names, encspace);
-
- if (null != aliases)
- {
- writer.WritePropertyName("aliases");
- writer.WriteStartArray();
- foreach (SchemaName name in aliases)
- {
- string fullname = (null != name.Space) ? name.Space + "." + name.Name : name.Name;
- writer.WriteValue(fullname);
- }
- writer.WriteEndArray();
- }
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/Schema/PrimitiveSchema.cs b/lang/csharp/src/apache/main/Schema/PrimitiveSchema.cs
deleted file mode 100644
index fa33bc6..0000000
--- a/lang/csharp/src/apache/main/Schema/PrimitiveSchema.cs
+++ /dev/null
@@ -1,130 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Text;
-using Newtonsoft.Json;
-
-namespace Avro
-{
- /// <summary>
- /// Class for schemas of primitive types
- /// </summary>
- public sealed class PrimitiveSchema : UnnamedSchema
- {
- /// <summary>
- /// Constructor for primitive schema
- /// </summary>
- /// <param name="type"></param>
- private PrimitiveSchema(Type type, PropertyMap props) : base(type, props)
- {
- }
-
- /// <summary>
- /// Static function to return new instance of primitive schema
- /// </summary>
- /// <param name="type">primitive type</param>
- /// <returns></returns>
- public static PrimitiveSchema NewInstance(string type, PropertyMap props = null)
- {
- const string q = "\"";
- if (type.StartsWith(q) && type.EndsWith(q)) type = type.Substring(1, type.Length - 2);
- switch (type)
- {
- case "null":
- return new PrimitiveSchema(Schema.Type.Null, props);
- case "boolean":
- return new PrimitiveSchema(Schema.Type.Boolean, props);
- case "int":
- return new PrimitiveSchema(Schema.Type.Int, props);
- case "long":
- return new PrimitiveSchema(Schema.Type.Long, props);
- case "float":
- return new PrimitiveSchema(Schema.Type.Float, props);
- case "double":
- return new PrimitiveSchema(Schema.Type.Double, props);
- case "bytes":
- return new PrimitiveSchema(Schema.Type.Bytes, props);
- case "string":
- return new PrimitiveSchema(Schema.Type.String, props);
- default:
- return null;
- }
- }
-
- /// <summary>
- /// Writes primitive schema in JSON format
- /// </summary>
- /// <param name="w"></param>
- /// <param name="names"></param>
- /// <param name="encspace"></param>
- protected internal override void WriteJson(JsonTextWriter w, SchemaNames names, string encspace)
- {
- w.WriteValue(Name);
- }
-
- /// <summary>
- /// Checks if this schema can read data written by the given schema. Used for decoding data.
- /// </summary>
- /// <param name="writerSchema">writer schema</param>
- /// <returns>true if this and writer schema are compatible based on the AVRO specification, false otherwise</returns>
- public override bool CanRead(Schema writerSchema)
- {
- if (writerSchema is UnionSchema || Tag == writerSchema.Tag) return true;
- Type t = writerSchema.Tag;
- switch (Tag)
- {
- case Type.Double:
- return t == Type.Int || t == Type.Long || t == Type.Float;
- case Type.Float:
- return t == Type.Int || t == Type.Long;
- case Type.Long:
- return t == Type.Int;
- default:
- return false;
- }
- }
-
- /// <summary>
- /// Function to compare equality of two primitive schemas
- /// </summary>
- /// <param name="obj">other primitive schema</param>
- /// <returns>true two schemas are equal, false otherwise</returns>
- public override bool Equals(object obj)
- {
- if (this == obj) return true;
-
- if (obj != null && obj is PrimitiveSchema)
- {
- var that = obj as PrimitiveSchema;
- if (this.Tag == that.Tag)
- return areEqual(that.Props, this.Props);
- }
- return false;
- }
-
- /// <summary>
- /// Hashcode function
- /// </summary>
- /// <returns></returns>
- public override int GetHashCode()
- {
- return 13 * Tag.GetHashCode() + getHashCode(Props);
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/Schema/Property.cs b/lang/csharp/src/apache/main/Schema/Property.cs
deleted file mode 100644
index 3901623..0000000
--- a/lang/csharp/src/apache/main/Schema/Property.cs
+++ /dev/null
@@ -1,124 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Newtonsoft.Json.Linq;
-using Newtonsoft.Json;
-
-namespace Avro
-{
- public class PropertyMap : Dictionary<string, string>
- {
- /// <summary>
- /// Set of reserved schema property names, any other properties not defined in this set are custom properties and can be added to this map
- /// </summary>
- private static readonly HashSet<string> ReservedProps = new HashSet<string>() { "type", "name", "namespace", "fields", "items", "size", "symbols", "values", "aliases", "order", "doc", "default" };
-
- /// <summary>
- /// Parses the custom properties from the given JSON object and stores them
- /// into the schema's list of custom properties
- /// </summary>
- /// <param name="jtok">JSON object to prase</param>
- public void Parse(JToken jtok)
- {
- JObject jo = jtok as JObject;
- foreach (JProperty prop in jo.Properties())
- {
- if (ReservedProps.Contains(prop.Name))
- continue;
- if (!ContainsKey(prop.Name))
- Add(prop.Name, prop.Value.ToString());
- }
- }
-
- /// <summary>
- /// Adds a custom property to the schema
- /// </summary>
- /// <param name="key">custom property name</param>
- /// <param name="value">custom property value</param>
- public void Set(string key, string value)
- {
- if (ReservedProps.Contains(key))
- throw new AvroException("Can't set reserved property: " + key);
-
- string oldValue;
- if (TryGetValue(key, out oldValue))
- {
- if (!oldValue.Equals(value)) throw new AvroException("Property cannot be overwritten: " + key);
- }
- else
- Add(key, value);
- }
-
- /// <summary>
- /// Writes the schema's custom properties in JSON format
- /// </summary>
- /// <param name="writer">JSON writer</param>
- public void WriteJson(JsonTextWriter writer)
- {
- foreach (KeyValuePair<string, string> kp in this)
- {
- if (ReservedProps.Contains(kp.Key)) continue;
-
- writer.WritePropertyName(kp.Key);
- writer.WriteRawValue(kp.Value);
- }
- }
-
- /// <summary>
- /// Function to compare equality of two PropertyMaps
- /// </summary>
- /// <param name="obj">other PropertyMap</param>
- /// <returns>true if contents of the two maps are the same, false otherwise</returns>
- public override bool Equals(object obj)
- {
- if (this == obj) return true;
-
- if (obj != null && obj is PropertyMap)
- {
- var that = obj as PropertyMap;
- if (this.Count != that.Count)
- return false;
- foreach (KeyValuePair<string, string> pair in this)
- {
- if (!that.ContainsKey(pair.Key))
- return false;
- if (!pair.Value.Equals(that[pair.Key]))
- return false;
- }
- return true;
- }
- return false;
- }
-
- /// <summary>
- /// Hashcode function
- /// </summary>
- /// <returns></returns>
- public override int GetHashCode()
- {
- int hash = this.Count;
- int index = 1;
- foreach (KeyValuePair<string, string> pair in this)
- hash += (pair.Key.GetHashCode() + pair.Value.GetHashCode()) * index++;
- return hash;
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/Schema/RecordSchema.cs b/lang/csharp/src/apache/main/Schema/RecordSchema.cs
deleted file mode 100644
index 642c3ab..0000000
--- a/lang/csharp/src/apache/main/Schema/RecordSchema.cs
+++ /dev/null
@@ -1,338 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Text;
-using Newtonsoft.Json.Linq;
-using Newtonsoft.Json;
-
-namespace Avro
-{
- internal delegate T Function<T>();
-
- /// <summary>
- /// Class for record schemas
- /// </summary>
- public class RecordSchema : NamedSchema
- {
- /// <summary>
- /// List of fields in the record
- /// </summary>
- public List<Field> Fields { get; private set; }
-
- /// <summary>
- /// Number of fields in the record
- /// </summary>
- public int Count { get { return Fields.Count; } }
-
- /// <summary>
- /// Map of field name and Field object for faster field lookups
- /// </summary>
- private readonly IDictionary<string, Field> fieldLookup;
-
- private readonly IDictionary<string, Field> fieldAliasLookup;
- private bool request;
-
- /// <summary>
- /// Static function to return new instance of the record schema
- /// </summary>
- /// <param name="type">type of record schema, either record or error</param>
- /// <param name="jtok">JSON object for the record schema</param>
- /// <param name="names">list of named schema already read</param>
- /// <param name="encspace">enclosing namespace of the records schema</param>
- /// <returns>new RecordSchema object</returns>
- internal static RecordSchema NewInstance(Type type, JToken jtok, PropertyMap props, SchemaNames names, string encspace)
- {
- bool request = false;
- JToken jfields = jtok["fields"]; // normal record
- if (null == jfields)
- {
- jfields = jtok["request"]; // anonymous record from messages
- if (null != jfields) request = true;
- }
- if (null == jfields)
- throw new SchemaParseException("'fields' cannot be null for record");
- if (jfields.Type != JTokenType.Array)
- throw new SchemaParseException("'fields' not an array for record");
-
- var name = GetName(jtok, encspace);
- var aliases = NamedSchema.GetAliases(jtok, name.Space, name.EncSpace);
- var fields = new List<Field>();
- var fieldMap = new Dictionary<string, Field>();
- var fieldAliasMap = new Dictionary<string, Field>();
- var result = new RecordSchema(type, name, aliases, props, fields, request, fieldMap, fieldAliasMap, names);
-
- int fieldPos = 0;
- foreach (JObject jfield in jfields)
- {
- string fieldName = JsonHelper.GetRequiredString(jfield, "name");
- Field field = createField(jfield, fieldPos++, names, name.Namespace); // add record namespace for field look up
- fields.Add(field);
- addToFieldMap(fieldMap, fieldName, field);
- addToFieldMap(fieldAliasMap, fieldName, field);
-
- if (null != field.aliases) // add aliases to field lookup map so reader function will find it when writer field name appears only as an alias on the reader field
- foreach (string alias in field.aliases)
- addToFieldMap(fieldAliasMap, alias, field);
- }
- return result;
- }
-
- /// <summary>
- /// Constructor for the record schema
- /// </summary>
- /// <param name="type">type of record schema, either record or error</param>
- /// <param name="name">name of the record schema</param>
- /// <param name="aliases">list of aliases for the record name</param>
- /// <param name="fields">list of fields for the record</param>
- /// <param name="request">true if this is an anonymous record with 'request' instead of 'fields'</param>
- /// <param name="fieldMap">map of field names and field objects</param>
- /// <param name="names">list of named schema already read</param>
- private RecordSchema(Type type, SchemaName name, IList<SchemaName> aliases, PropertyMap props,
- List<Field> fields, bool request, IDictionary<string, Field> fieldMap,
- IDictionary<string, Field> fieldAliasMap, SchemaNames names)
- : base(type, name, aliases, props, names)
- {
- this.Fields = fields;
- this.request = request;
- this.fieldLookup = fieldMap;
- this.fieldAliasLookup = fieldAliasMap;
- }
-
- /// <summary>
- /// Creates a new field for the record
- /// </summary>
- /// <param name="jfield">JSON object for the field</param>
- /// <param name="pos">position number of the field</param>
- /// <param name="names">list of named schemas already read</param>
- /// <param name="encspace">enclosing namespace of the records schema</param>
- /// <returns>new Field object</returns>
- private static Field createField(JToken jfield, int pos, SchemaNames names, string encspace)
- {
- var name = JsonHelper.GetRequiredString(jfield, "name");
- var doc = JsonHelper.GetOptionalString(jfield, "doc");
-
- var jorder = JsonHelper.GetOptionalString(jfield, "order");
- Field.SortOrder sortorder = Field.SortOrder.ignore;
- if (null != jorder)
- sortorder = (Field.SortOrder) Enum.Parse(typeof(Field.SortOrder), jorder);
-
- var aliases = Field.GetAliases(jfield);
- var props = Schema.GetProperties(jfield);
- var defaultValue = jfield["default"];
-
- JToken jtype = jfield["type"];
- if (null == jtype)
- throw new SchemaParseException("'type' was not found for field: " + name);
- var schema = Schema.ParseJson(jtype, names, encspace);
-
- return new Field(schema, name, aliases, pos, doc, defaultValue, sortorder, props);
- }
-
- private static void addToFieldMap(Dictionary<string, Field> map, string name, Field field)
- {
- if (map.ContainsKey(name))
- throw new SchemaParseException("field or alias " + name + " is a duplicate name");
- map.Add(name, field);
- }
-
- /// <summary>
- /// Returns the field with the given name.
- /// </summary>
- /// <param name="name">field name</param>
- /// <returns>Field object</returns>
- public Field this[string name]
- {
- get
- {
- if (string.IsNullOrEmpty(name)) throw new ArgumentNullException("name");
- Field field;
- return (fieldLookup.TryGetValue(name, out field)) ? field : null;
- }
- }
-
- /// <summary>
- /// Returns true if and only if the record contains a field by the given name.
- /// </summary>
- /// <param name="fieldName">The name of the field</param>
- /// <returns>true if the field exists, false otherwise</returns>
- public bool Contains(string fieldName)
- {
- return fieldLookup.ContainsKey(fieldName);
- }
-
- public bool TryGetField(string fieldName, out Field field)
- {
- return fieldLookup.TryGetValue(fieldName, out field);
- }
- public bool TryGetFieldAlias(string fieldName, out Field field)
- {
- return fieldAliasLookup.TryGetValue(fieldName, out field);
- }
-
- /// <summary>
- /// Returns an enumerator which enumerates over the fields of this record schema
- /// </summary>
- /// <returns>Enumerator over the field in the order of their definition</returns>
- public IEnumerator<Field> GetEnumerator()
- {
- return Fields.GetEnumerator();
- }
-
- /// <summary>
- /// Writes the records schema in JSON format
- /// </summary>
- /// <param name="writer">JSON writer</param>
- /// <param name="names">list of named schemas already written</param>
- /// <param name="encspace">enclosing namespace of the record schema</param>
- protected internal override void WriteJsonFields(Newtonsoft.Json.JsonTextWriter writer, SchemaNames names, string encspace)
- {
- base.WriteJsonFields(writer, names, encspace);
-
- // we allow reading for empty fields, so writing of records with empty fields are allowed as well
- if (request)
- writer.WritePropertyName("request");
- else
- writer.WritePropertyName("fields");
- writer.WriteStartArray();
-
- if (null != this.Fields && this.Fields.Count > 0)
- {
- foreach (Field field in this)
- field.writeJson(writer, names, this.Namespace); // use the namespace of the record for the fields
- }
- writer.WriteEndArray();
- }
-
- /// <summary>
- /// Compares equality of two record schemas
- /// </summary>
- /// <param name="obj">record schema to compare against this schema</param>
- /// <returns>true if the two schemas are equal, false otherwise</returns>
- public override bool Equals(object obj)
- {
- if (obj == this) return true;
- if (obj != null && obj is RecordSchema)
- {
- RecordSchema that = obj as RecordSchema;
- return protect(() => true, () =>
- {
- if (this.SchemaName.Equals(that.SchemaName) && this.Count == that.Count)
- {
- for (int i = 0; i < Fields.Count; i++) if (!Fields[i].Equals(that.Fields[i])) return false;
- return areEqual(that.Props, this.Props);
- }
- return false;
- }, that);
- }
- return false;
- }
-
- /// <summary>
- /// Hash code function
- /// </summary>
- /// <returns></returns>
- public override int GetHashCode()
- {
- return protect(() => 0, () =>
- {
- int result = SchemaName.GetHashCode();
- foreach (Field f in Fields) result += 29 * f.GetHashCode();
- result += getHashCode(Props);
- return result;
- }, this);
- }
-
- /// <summary>
- /// Checks if this schema can read data written by the given schema. Used for decoding data.
- /// </summary>
- /// <param name="writerSchema">writer schema</param>
- /// <returns>true if this and writer schema are compatible based on the AVRO specification, false otherwise</returns>
- public override bool CanRead(Schema writerSchema)
- {
- if (writerSchema.Tag != Type.Record) return false;
- RecordSchema that = writerSchema as RecordSchema;
- return protect(() => true, () =>
- {
- if (!that.SchemaName.Equals(SchemaName))
- if (!InAliases(that.SchemaName))
- return false;
-
- foreach (Field f in this)
- {
- Field f2 = that[f.Name];
- if (null == f2) // reader field not in writer field, check aliases of reader field if any match with a writer field
- if (null != f.aliases)
- foreach (string alias in f.aliases)
- {
- f2 = that[alias];
- if (null != f2) break;
- }
-
- if (f2 == null && f.DefaultValue != null)
- continue; // Writer field missing, reader has default.
-
- if (f2 != null && f.Schema.CanRead(f2.Schema)) continue; // Both fields exist and are compatible.
- return false;
- }
- return true;
- }, that);
- }
-
- private class RecordSchemaPair
- {
- public readonly RecordSchema first;
- public readonly RecordSchema second;
-
- public RecordSchemaPair(RecordSchema first, RecordSchema second)
- {
- this.first = first;
- this.second = second;
- }
- }
-
- [ThreadStatic]
- private static List<RecordSchemaPair> seen;
-
- /**
- * We want to protect against infinite recursion when the schema is recursive. We look into a thread local
- * to see if we have been into this if so, we execute the bypass function otherwise we execute the main function.
- * Before executing the main function, we ensure that we create a marker so that if we come back here recursively
- * we can detect it.
- *
- * The infinite loop happens in ToString(), Equals() and GetHashCode() methods.
- * Though it does not happen for CanRead() because of the current implemenation of UnionSchema's can read,
- * it could potenitally happen.
- * We do a linear seach for the marker as we don't expect the list to be very long.
- */
- private T protect<T>(Function<T> bypass, Function<T> main, RecordSchema that)
- {
- if (seen == null)
- seen = new List<RecordSchemaPair>();
-
- else if (seen.Find((RecordSchemaPair rs) => rs.first == this && rs.second == that) != null)
- return bypass();
-
- RecordSchemaPair p = new RecordSchemaPair(this, that);
- seen.Add(p);
- try { return main(); }
- finally { seen.Remove(p); }
- }
-
- }
-}
diff --git a/lang/csharp/src/apache/main/Schema/Schema.cs b/lang/csharp/src/apache/main/Schema/Schema.cs
deleted file mode 100644
index 41f5b00..0000000
--- a/lang/csharp/src/apache/main/Schema/Schema.cs
+++ /dev/null
@@ -1,306 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Text;
-using Newtonsoft.Json.Linq;
-using Newtonsoft.Json;
-
-namespace Avro
-{
- /// <summary>
- /// Base class for all schema types
- /// </summary>
- public abstract class Schema
- {
- /// <summary>
- /// Enum for schema types
- /// </summary>
- public enum Type
- {
- Null,
- Boolean,
- Int,
- Long,
- Float,
- Double,
- Bytes,
- String,
- Record,
- Enumeration,
- Array,
- Map,
- Union,
- Fixed,
- Error
- }
-
- /// <summary>
- /// Schema type property
- /// </summary>
- public Type Tag { get; private set; }
-
- /// <summary>
- /// Additional JSON attributes apart from those defined in the AVRO spec
- /// </summary>
- internal PropertyMap Props { get; private set; }
-
- /// <summary>
- /// Constructor for schema class
- /// </summary>
- /// <param name="type"></param>
- protected Schema(Type type, PropertyMap props)
- {
- this.Tag = type;
- this.Props = props;
- }
-
- /// <summary>
- /// The name of this schema. If this is a named schema such as an enum, it returns the fully qualified
- /// name for the schema. For other schemas, it returns the type of the schema.
- /// </summary>
- public abstract string Name { get; }
-
- /// <summary>
- /// Static class to return new instance of schema object
- /// </summary>
- /// <param name="jtok">JSON object</param>
- /// <param name="names">list of named schemas already read</param>
- /// <param name="encspace">enclosing namespace of the schema</param>
- /// <returns>new Schema object</returns>
- internal static Schema ParseJson(JToken jtok, SchemaNames names, string encspace)
- {
- if (null == jtok) throw new ArgumentNullException("j", "j cannot be null.");
-
- if (jtok.Type == JTokenType.String) // primitive schema with no 'type' property or primitive or named type of a record field
- {
- string value = (string)jtok;
-
- PrimitiveSchema ps = PrimitiveSchema.NewInstance(value);
- if (null != ps) return ps;
-
- NamedSchema schema = null;
- if (names.TryGetValue(value, null, encspace, out schema)) return schema;
-
- throw new SchemaParseException("Undefined name: " + value);
- }
-
- if (jtok is JArray) // union schema with no 'type' property or union type for a record field
- return UnionSchema.NewInstance(jtok as JArray, null, names, encspace);
-
- if (jtok is JObject) // JSON object with open/close parenthesis, it must have a 'type' property
- {
- JObject jo = jtok as JObject;
-
- JToken jtype = jo["type"];
- if (null == jtype)
- throw new SchemaParseException("Property type is required");
-
- var props = Schema.GetProperties(jtok);
-
- if (jtype.Type == JTokenType.String)
- {
- string type = (string)jtype;
-
- if (type.Equals("array"))
- return ArraySchema.NewInstance(jtok, props, names, encspace);
- if (type.Equals("map"))
- return MapSchema.NewInstance(jtok, props, names, encspace);
-
- Schema schema = PrimitiveSchema.NewInstance((string)type, props);
- if (null != schema) return schema;
-
- return NamedSchema.NewInstance(jo, props, names, encspace);
- }
- else if (jtype.Type == JTokenType.Array)
- return UnionSchema.NewInstance(jtype as JArray, props, names, encspace);
- }
- throw new AvroTypeException("Invalid JSON for schema: " + jtok);
- }
-
- /// <summary>
- /// Parses a given JSON string to create a new schema object
- /// </summary>
- /// <param name="json">JSON string</param>
- /// <returns>new Schema object</returns>
- public static Schema Parse(string json)
- {
- if (string.IsNullOrEmpty(json)) throw new ArgumentNullException("json", "json cannot be null.");
- return Parse(json.Trim(), new SchemaNames(), null); // standalone schema, so no enclosing namespace
- }
-
- /// <summary>
- /// Parses a JSON string to create a new schema object
- /// </summary>
- /// <param name="json">JSON string</param>
- /// <param name="names">list of named schemas already read</param>
- /// <param name="encspace">enclosing namespace of the schema</param>
- /// <returns>new Schema object</returns>
- internal static Schema Parse(string json, SchemaNames names, string encspace)
- {
- Schema sc = PrimitiveSchema.NewInstance(json);
- if (null != sc) return sc;
-
- try
- {
- bool IsArray = json.StartsWith("[") && json.EndsWith("]");
- JContainer j = IsArray ? (JContainer)JArray.Parse(json) : (JContainer)JObject.Parse(json);
-
- return ParseJson(j, names, encspace);
- }
- catch (Newtonsoft.Json.JsonSerializationException ex)
- {
- throw new SchemaParseException("Could not parse. " + ex.Message + Environment.NewLine + json);
- }
- }
-
- /// <summary>
- /// Static function to parse custom properties (not defined in the Avro spec) from the given JSON object
- /// </summary>
- /// <param name="jtok">JSON object to parse</param>
- /// <returns>Property map if custom properties were found, null if no custom properties found</returns>
- internal static PropertyMap GetProperties(JToken jtok)
- {
- var props = new PropertyMap();
- props.Parse(jtok);
- if (props.Count > 0)
- return props;
- else
- return null;
- }
-
- /// <summary>
- /// Returns the canonical JSON representation of this schema.
- /// </summary>
- /// <returns>The canonical JSON representation of this schema.</returns>
- public override string ToString()
- {
- System.IO.StringWriter sw = new System.IO.StringWriter();
- Newtonsoft.Json.JsonTextWriter writer = new Newtonsoft.Json.JsonTextWriter(sw);
-
- if (this is PrimitiveSchema || this is UnionSchema)
- {
- writer.WriteStartObject();
- writer.WritePropertyName("type");
- }
-
- WriteJson(writer, new SchemaNames(), null); // stand alone schema, so no enclosing name space
-
- if (this is PrimitiveSchema || this is UnionSchema)
- writer.WriteEndObject();
-
- return sw.ToString();
- }
-
- /// <summary>
- /// Writes opening { and 'type' property
- /// </summary>
- /// <param name="writer">JSON writer</param>
- private void writeStartObject(JsonTextWriter writer)
- {
- writer.WriteStartObject();
- writer.WritePropertyName("type");
- writer.WriteValue(getTypeString(this.Tag));
- }
-
- /// <summary>
- /// Returns symbol name for the given schema type
- /// </summary>
- /// <param name="type">schema type</param>
- /// <returns>symbol name</returns>
- protected static string getTypeString(Type type)
- {
- if (type != Type.Enumeration) return type.ToString().ToLower();
- return "enum";
- }
-
- /// <summary>
- /// Default implementation for writing schema properties in JSON format
- /// </summary>
- /// <param name="writer">JSON writer</param>
- /// <param name="names">list of named schemas already written</param>
- /// <param name="encspace">enclosing namespace of the schema</param>
- protected internal virtual void WriteJsonFields(JsonTextWriter writer, SchemaNames names, string encspace)
- {
- }
-
- /// <summary>
- /// Writes schema object in JSON format
- /// </summary>
- /// <param name="writer">JSON writer</param>
- /// <param name="names">list of named schemas already written</param>
- /// <param name="encspace">enclosing namespace of the schema</param>
- protected internal virtual void WriteJson(JsonTextWriter writer, SchemaNames names, string encspace)
- {
- writeStartObject(writer);
- WriteJsonFields(writer, names, encspace);
- if (null != this.Props) Props.WriteJson(writer);
- writer.WriteEndObject();
- }
-
- /// <summary>
- /// Returns the schema's custom property value given the property name
- /// </summary>
- /// <param name="key">custom property name</param>
- /// <returns>custom property value</returns>
- public string GetProperty(string key)
- {
- if (null == this.Props) return null;
- string v;
- return (this.Props.TryGetValue(key, out v)) ? v : null;
- }
-
- /// <summary>
- /// Hash code function
- /// </summary>
- /// <returns></returns>
- public override int GetHashCode()
- {
- return Tag.GetHashCode() + getHashCode(Props);
- }
-
- /// <summary>
- /// Returns true if and only if data written using writerSchema can be read using the current schema
- /// according to the Avro resolution rules.
- /// </summary>
- /// <param name="writerSchema">The writer's schema to match against.</param>
- /// <returns>True if and only if the current schema matches the writer's.</returns>
- public virtual bool CanRead(Schema writerSchema) { return Tag == writerSchema.Tag; }
-
- /// <summary>
- /// Compares two objects, null is equal to null
- /// </summary>
- /// <param name="o1">first object</param>
- /// <param name="o2">second object</param>
- /// <returns>true if two objects are equal, false otherwise</returns>
- protected static bool areEqual(object o1, object o2)
- {
- return o1 == null ? o2 == null : o1.Equals(o2);
- }
-
- /// <summary>
- /// Hash code helper function
- /// </summary>
- /// <param name="obj"></param>
- /// <returns></returns>
- protected static int getHashCode(object obj)
- {
- return obj == null ? 0 : obj.GetHashCode();
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/Schema/SchemaName.cs b/lang/csharp/src/apache/main/Schema/SchemaName.cs
deleted file mode 100644
index dda77e6..0000000
--- a/lang/csharp/src/apache/main/Schema/SchemaName.cs
+++ /dev/null
@@ -1,222 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace Avro
-{
- /// <summary>
- /// Class to store schema name, namespace and enclosing namespace
- /// </summary>
- public class SchemaName
- {
- /// <summary>
- /// Name of the schema
- /// </summary>
- public String Name { get; private set; }
-
- /// <summary>
- /// Namespace specified within the schema
- /// </summary>
- public String Space { get; private set; }
-
- /// <summary>
- /// Namespace from the most tightly enclosing schema
- /// </summary>
- public String EncSpace { get; private set; }
-
- /// <summary>
- /// Namespace.Name of the schema
- /// </summary>
- public String Fullname { get { return string.IsNullOrEmpty(Namespace) ? this.Name : Namespace + "." + this.Name; } }
-
- /// <summary>
- /// Namespace of the schema
- /// </summary>
- public String Namespace { get { return string.IsNullOrEmpty(this.Space) ? this.EncSpace : this.Space; } }
-
- /// <summary>
- /// Constructor for SchemaName
- /// </summary>
- /// <param name="name">name of the schema</param>
- /// <param name="space">namespace of the schema</param>
- /// <param name="encspace">enclosing namespace of the schema</param>
- public SchemaName(String name, String space, String encspace)
- {
- if (name == null)
- { // anonymous
- this.Name = this.Space = null;
- this.EncSpace = encspace; // need to save enclosing namespace for anonymous types, so named types within the anonymous type can be resolved
- }
- else if (!name.Contains("."))
- { // unqualified name
- this.Space = space; // use default space
- this.Name = name;
- this.EncSpace = encspace;
- }
- else
- {
- string[] parts = name.Split('.');
- this.Space = string.Join(".", parts, 0, parts.Length - 1);
- this.Name = parts[parts.Length - 1];
- this.EncSpace = encspace;
- }
- }
-
- /// <summary>
- /// Returns the full name of the schema
- /// </summary>
- /// <returns></returns>
- public override string ToString()
- {
- return Fullname;
- }
-
- /// <summary>
- /// Writes the schema name in JSON format
- /// </summary>
- /// <param name="writer">JSON writer</param>
- /// <param name="names">list of named schemas already written</param>
- /// <param name="encspace">enclosing namespace of the schema</param>
- internal void WriteJson(Newtonsoft.Json.JsonTextWriter writer, SchemaNames names, string encspace)
- {
- if (null != this.Name) // write only if not anonymous
- {
- JsonHelper.writeIfNotNullOrEmpty(writer, "name", this.Name);
- if (!String.IsNullOrEmpty(this.Space))
- JsonHelper.writeIfNotNullOrEmpty(writer, "namespace", this.Space);
- else if (!String.IsNullOrEmpty(this.EncSpace)) // need to put enclosing name space for code generated classes
- JsonHelper.writeIfNotNullOrEmpty(writer, "namespace", this.EncSpace);
- }
- }
-
- /// <summary>
- /// Compares two schema names
- /// </summary>
- /// <param name="obj">SchameName object to compare against this object</param>
- /// <returns>true or false</returns>
- public override bool Equals(Object obj)
- {
- if (obj == this) return true;
- if (obj != null && obj is SchemaName)
- {
- SchemaName that = (SchemaName)obj;
- return areEqual(that.Name, Name) && areEqual(that.Namespace, Namespace);
- }
- return false;
- }
-
- /// <summary>
- /// Compares two objects
- /// </summary>
- /// <param name="obj1">first object</param>
- /// <param name="obj2">second object</param>
- /// <returns>true or false</returns>
- private static bool areEqual(object obj1, object obj2)
- {
- return obj1 == null ? obj2 == null : obj1.Equals(obj2);
- }
-
- public override int GetHashCode()
- {
- return string.IsNullOrEmpty(Fullname) ? 0 : 29 * Fullname.GetHashCode();
- }
- }
-
- /// <summary>
- /// A class that contains a list of named schemas. This is used when reading or writing a schema/protocol.
- /// This prevents reading and writing of duplicate schema definitions within a protocol or schema file
- /// </summary>
- public class SchemaNames
- {
- /// <summary>
- /// Map of schema name and named schema objects
- /// </summary>
- public IDictionary<SchemaName, NamedSchema> Names { get; private set; }
-
- /// <summary>
- /// Constructor
- /// </summary>
- public SchemaNames()
- {
- Names = new Dictionary<SchemaName, NamedSchema>();
- }
-
- /// <summary>
- /// Checks if given name is in the map
- /// </summary>
- /// <param name="name">schema name</param>
- /// <returns>true or false</returns>
- public bool Contains(SchemaName name)
- {
- if (Names.ContainsKey(name))
- return true;
- return false;
- }
-
- /// <summary>
- /// Adds a schema name to the map if it doesn't exist yet
- /// </summary>
- /// <param name="name">schema name</param>
- /// <param name="schema">schema object</param>
- /// <returns>true if schema was added to the list, false if schema is already in the list</returns>
- public bool Add(SchemaName name, NamedSchema schema)
- {
- if (Names.ContainsKey(name))
- return false;
-
- Names.Add(name, schema);
- return true;
- }
-
- /// <summary>
- /// Adds a named schema to the list
- /// </summary>
- /// <param name="schema">schema object</param>
- /// <returns>true if schema was added to the list, false if schema is already in the list</returns>
- public bool Add(NamedSchema schema)
- {
- SchemaName name = schema.SchemaName;
- return Add(name, schema);
- }
-
- /// <summary>
- /// Tries to get the value for the given name fields
- /// </summary>
- /// <param name="name">name of the schema</param>
- /// <param name="space">namespace of the schema</param>
- /// <param name="encspace">enclosing namespace of the schema</param>
- /// <param name="schema">schema object found</param>
- /// <returns>true if name is found in the map, false otherwise</returns>
- public bool TryGetValue(string name, string space, string encspace, out NamedSchema schema)
- {
- SchemaName schemaname = new SchemaName(name, space, encspace);
- return Names.TryGetValue(schemaname, out schema);
- }
-
- /// <summary>
- /// Returns the enumerator for the map
- /// </summary>
- /// <returns></returns>
- public IEnumerator<KeyValuePair<SchemaName, NamedSchema>> GetEnumerator()
- {
- return Names.GetEnumerator();
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/Schema/SchemaParseException.cs b/lang/csharp/src/apache/main/Schema/SchemaParseException.cs
deleted file mode 100644
index 73859af..0000000
--- a/lang/csharp/src/apache/main/Schema/SchemaParseException.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace Avro
-{
- public class SchemaParseException:AvroException
- {
- public SchemaParseException(string s)
- : base(s)
- {
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/Schema/UnionSchema.cs b/lang/csharp/src/apache/main/Schema/UnionSchema.cs
deleted file mode 100644
index aaf100e..0000000
--- a/lang/csharp/src/apache/main/Schema/UnionSchema.cs
+++ /dev/null
@@ -1,164 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Text;
-using Newtonsoft.Json.Linq;
-using Newtonsoft.Json;
-
-namespace Avro
-{
- /// <summary>
- /// Class for union schemas
- /// </summary>
- public class UnionSchema : UnnamedSchema
- {
- /// <summary>
- /// List of schemas in the union
- /// </summary>
- public IList<Schema> Schemas { get; private set; }
-
- /// <summary>
- /// Count of schemas in the union
- /// </summary>
- public int Count { get { return Schemas.Count; } }
-
- /// <summary>
- /// Static function to return instance of the union schema
- /// </summary>
- /// <param name="jarr">JSON object for the union schema</param>
- /// <param name="names">list of named schemas already read</param>
- /// <param name="encspace">enclosing namespace of the schema</param>
- /// <returns>new UnionSchema object</returns>
- internal static UnionSchema NewInstance(JArray jarr, PropertyMap props, SchemaNames names, string encspace)
- {
- List<Schema> schemas = new List<Schema>();
- IDictionary<string, string> uniqueSchemas = new Dictionary<string, string>();
-
- foreach (JToken jvalue in jarr)
- {
- Schema unionType = Schema.ParseJson(jvalue, names, encspace);
- if (null == unionType)
- throw new SchemaParseException("Invalid JSON in union" + jvalue.ToString());
-
- string name = unionType.Name;
- if (uniqueSchemas.ContainsKey(name))
- throw new SchemaParseException("Duplicate type in union: " + name);
-
- uniqueSchemas.Add(name, name);
- schemas.Add(unionType);
- }
-
- return new UnionSchema(schemas, props);
- }
-
- /// <summary>
- /// Contructor for union schema
- /// </summary>
- /// <param name="schemas"></param>
- private UnionSchema(List<Schema> schemas, PropertyMap props) : base(Type.Union, props)
- {
- if (schemas.Count == 0)
- throw new ArgumentNullException("schemas");
- this.Schemas = schemas;
- }
-
- /// <summary>
- /// Returns the schema at the given branch.
- /// </summary>
- /// <param name="index">Index to the branch, starting with 0.</param>
- /// <returns>The branch corresponding to the given index.</returns>
- public Schema this[int index]
- {
- get
- {
- return Schemas[index];
- }
- }
-
- /// <summary>
- /// Writes union schema in JSON format
- /// </summary>
- /// <param name="writer">JSON writer</param>
- /// <param name="names">list of named schemas already written</param>
- /// <param name="encspace">enclosing namespace of the schema</param>
- protected internal override void WriteJson(Newtonsoft.Json.JsonTextWriter writer, SchemaNames names, string encspace)
- {
- writer.WriteStartArray();
- foreach (Schema schema in this.Schemas)
- schema.WriteJson(writer, names, encspace);
- writer.WriteEndArray();
- }
-
- /// <summary>
- /// Returns the index of a branch that can read the data written by the given schema s.
- /// </summary>
- /// <param name="s">The schema to match the branches against.</param>
- /// <returns>The index of the matching branch. If non matches a -1 is returned.</returns>
- public int MatchingBranch(Schema s)
- {
- if (s is UnionSchema) throw new AvroException("Cannot find a match against union schema");
- // Try exact match.
- //for (int i = 0; i < Count; i++) if (Schemas[i].Equals(s)) return i; // removed this for performance's sake
- for (int i = 0; i < Count; i++) if (Schemas[i].CanRead(s)) return i;
- return -1;
- }
-
- /// <summary>
- /// Checks if this schema can read data written by the given schema. Used for decoding data.
- /// </summary>
- /// <param name="writerSchema">writer schema</param>
- /// <returns>true if this and writer schema are compatible based on the AVRO specification, false otherwise</returns>
- public override bool CanRead(Schema writerSchema)
- {
- return writerSchema.Tag == Schema.Type.Union || MatchingBranch(writerSchema) >= 0;
- }
-
- /// <summary>
- /// Compares two union schema objects
- /// </summary>
- /// <param name="obj">union schema object to compare against this schema</param>
- /// <returns>true if objects are equal, false otherwise</returns>
- public override bool Equals(object obj)
- {
- if (obj == this) return true;
- if (obj != null && obj is UnionSchema)
- {
- UnionSchema that = obj as UnionSchema;
- if (that.Count == Count)
- {
- for (int i = 0; i < Count; i++) if (!that[i].Equals(this[i])) return false;
- return areEqual(that.Props, this.Props);
- }
- }
- return false;
- }
-
- /// <summary>
- /// Hash code function
- /// </summary>
- /// <returns></returns>
- public override int GetHashCode()
- {
- int result = 53;
- foreach (Schema schema in Schemas) result += 89 * schema.GetHashCode();
- result += getHashCode(Props);
- return result;
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/Schema/UnnamedSchema.cs b/lang/csharp/src/apache/main/Schema/UnnamedSchema.cs
deleted file mode 100644
index aebbb10..0000000
--- a/lang/csharp/src/apache/main/Schema/UnnamedSchema.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace Avro
-{
- /// <summary>
- /// Base class for all unnamed schemas
- /// </summary>
- public abstract class UnnamedSchema : Schema
- {
- protected UnnamedSchema(Type type, PropertyMap props) : base(type, props)
- {
- }
-
- public override string Name
- {
- get { return Tag.ToString().ToLower(); }
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/Specific/ObjectCreator.cs b/lang/csharp/src/apache/main/Specific/ObjectCreator.cs
deleted file mode 100644
index 3288aa3..0000000
--- a/lang/csharp/src/apache/main/Specific/ObjectCreator.cs
+++ /dev/null
@@ -1,195 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Reflection;
-using System.Reflection.Emit;
-
-namespace Avro.Specific
-{
-
- public sealed class ObjectCreator
- {
- private static readonly ObjectCreator instance = new ObjectCreator();
- public static ObjectCreator Instance { get { return instance; } }
-
- /// <summary>
- /// Static generic dictionary type used for creating new dictionary instances
- /// </summary>
- private Type GenericMapType = typeof(Dictionary<,>);
-
- /// <summary>
- /// Static generic list type used for creating new array instances
- /// </summary>
- private Type GenericListType = typeof(List<>);
-
- private readonly Assembly execAssembly;
- private readonly Assembly entryAssembly;
- private readonly bool diffAssembly;
- private readonly Type[] margs;
- private readonly Type[] largs;
-
- public delegate object CtorDelegate();
- private Type ctorType = typeof(CtorDelegate);
- Dictionary<NameCtorKey, CtorDelegate> ctors;
-
- private ObjectCreator()
- {
- execAssembly = System.Reflection.Assembly.GetExecutingAssembly();
- entryAssembly = System.Reflection.Assembly.GetEntryAssembly();
- if (entryAssembly != null && execAssembly != entryAssembly) // entryAssembly returns null when running from NUnit
- diffAssembly = true;
-
- GenericMapType = typeof(Dictionary<,>);
- GenericListType = typeof(List<>);
- margs = new Type[2] { typeof(string), null };
- largs = new Type[1] { null };
-
- ctors = new Dictionary<NameCtorKey, CtorDelegate>();
- }
-
- public struct NameCtorKey : IEquatable<NameCtorKey>
- {
- public string name { get; private set; }
- public Schema.Type type { get; private set; }
- public NameCtorKey(string value1, Schema.Type value2)
- : this()
- {
- name = value1;
- type = value2;
- }
- public bool Equals(NameCtorKey other)
- {
- return Equals(other.name, name) && other.type == type;
- }
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(null, obj))
- return false;
- if (obj.GetType() != typeof(NameCtorKey))
- return false;
- return Equals((NameCtorKey)obj);
- }
- public override int GetHashCode()
- {
- unchecked
- {
- return ((name != null ? name.GetHashCode() : 0) * 397) ^ type.GetHashCode();
- }
- }
- public static bool operator ==(NameCtorKey left, NameCtorKey right)
- {
- return left.Equals(right);
- }
- public static bool operator !=(NameCtorKey left, NameCtorKey right)
- {
- return !left.Equals(right);
- }
- }
-
- /// <summary>
- /// Gets the type of the specified type name
- /// </summary>
- /// <param name="name">name of the object to get type of</param>
- /// <param name="schemaType">schema type for the object</param>
- /// <returns>Type</returns>
- public Type GetType(string name, Schema.Type schemaType)
- {
- Type type;
- if (diffAssembly)
- {
- // entry assembly different from current assembly, try entry assembly first
- type = entryAssembly.GetType(name);
- if (type == null) // now try current assembly and mscorlib
- type = Type.GetType(name);
- }
- else
- type = Type.GetType(name);
-
- if (type == null) // type is still not found, need to loop through all loaded assemblies
- {
- Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
- foreach (Assembly assembly in assemblies)
- {
- type = assembly.GetType(name);
- if (type != null)
- break;
- }
- }
- if (type == null)
- throw new AvroException("Unable to find type " + name + " in all loaded assemblies");
-
- if (schemaType == Schema.Type.Map)
- {
- margs[1] = type;
- type = GenericMapType.MakeGenericType(margs);
- }
- else if (schemaType == Schema.Type.Array)
- {
- largs[0] = type;
- type = GenericListType.MakeGenericType(largs);
- }
-
- return type;
- }
-
- /// <summary>
- /// Gets the default constructor for the specified type
- /// </summary>
- /// <param name="name">name of object for the type</param>
- /// <param name="schemaType">schema type for the object</param>
- /// <param name="type">type of the object</param>
- /// <returns>Default constructor for the type</returns>
- public CtorDelegate GetConstructor(string name, Schema.Type schemaType, Type type)
- {
- ConstructorInfo ctorInfo = type.GetConstructor(Type.EmptyTypes);
- if (ctorInfo == null)
- throw new AvroException("Class " + name + " has no default constructor");
-
- DynamicMethod dynMethod = new DynamicMethod("DM$OBJ_FACTORY_" + name, typeof(object), null, type, true);
- ILGenerator ilGen = dynMethod.GetILGenerator();
- ilGen.Emit(OpCodes.Nop);
- ilGen.Emit(OpCodes.Newobj, ctorInfo);
- ilGen.Emit(OpCodes.Ret);
-
- return (CtorDelegate)dynMethod.CreateDelegate(ctorType);
- }
-
- /// <summary>
- /// Creates new instance of the given type
- /// </summary>
- /// <param name="name">fully qualified name of the type</param>
- /// <param name="schemaType">type of schema</param>
- /// <returns>new object of the given type</returns>
- public object New(string name, Schema.Type schemaType)
- {
- NameCtorKey key = new NameCtorKey(name, schemaType);
-
- CtorDelegate ctor;
- if (!ctors.TryGetValue(key, out ctor))
- {
- Type type = GetType(name, schemaType);
- ctor = GetConstructor(name, schemaType, type);
-
- ctors.Add(key, ctor);
- }
- return ctor();
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/Specific/SpecificFixed.cs b/lang/csharp/src/apache/main/Specific/SpecificFixed.cs
deleted file mode 100644
index 7a50c7d..0000000
--- a/lang/csharp/src/apache/main/Specific/SpecificFixed.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Avro.Generic;
-
-namespace Avro.Specific
-{
- /// <summary>
- /// Base class for all generated classes
- /// </summary>
- public abstract class SpecificFixed : GenericFixed
- {
- public SpecificFixed(uint size) : base(size) { }
- public abstract new Schema Schema { get; }
- }
-}
diff --git a/lang/csharp/src/apache/main/Specific/SpecificReader.cs b/lang/csharp/src/apache/main/Specific/SpecificReader.cs
deleted file mode 100644
index cae9e98..0000000
--- a/lang/csharp/src/apache/main/Specific/SpecificReader.cs
+++ /dev/null
@@ -1,277 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using System.IO;
-using Avro;
-using Avro.IO;
-using Avro.Generic;
-
-namespace Avro.Specific
-{
- /// <summary>
- /// Reader wrapper class for reading data and storing into specific classes
- /// </summary>
- /// <typeparam name="T">Specific class type</typeparam>
- public class SpecificReader<T> : DatumReader<T>
- {
- /// <summary>
- /// Reader class for reading data and storing into specific classes
- /// </summary>
- private readonly SpecificDefaultReader reader;
-
- /// <summary>
- /// Schema for the writer class
- /// </summary>
- public Schema WriterSchema { get { return reader.WriterSchema; } }
-
- /// <summary>
- /// Schema for the reader class
- /// </summary>
- public Schema ReaderSchema { get { return reader.ReaderSchema; } }
-
- /// <summary>
- /// Constructs a generic reader for the given schemas using the DefaultReader. If the
- /// reader's and writer's schemas are different this class performs the resolution.
- /// </summary>
- /// <param name="writerSchema">The schema used while generating the data</param>
- /// <param name="readerSchema">The schema desired by the reader</param>
- public SpecificReader(Schema writerSchema, Schema readerSchema)
- {
- reader = new SpecificDefaultReader(writerSchema, readerSchema);
- }
-
- public SpecificReader(SpecificDefaultReader reader)
- {
- this.reader = reader;
- }
-
- /// <summary>
- /// Generic read function
- /// </summary>
- /// <param name="reuse">object to store data read</param>
- /// <param name="dec">decorder to use for reading data</param>
- /// <returns></returns>
- public T Read(T reuse, Decoder dec)
- {
- return reader.Read(reuse, dec);
- }
- }
-
- /// <summary>
- /// Reader class for reading data and storing into specific classes
- /// </summary>
- public class SpecificDefaultReader : DefaultReader
- {
- /// <summary>
- /// Static dictionary of type names and its corresponding assembly type.
- /// This is used to prevent multiple reflection for the same type name.
- /// </summary>
- private static IDictionary<string, Type> TypeName = new Dictionary<string, Type>();
-
- /// <summary>
- /// Constructor
- /// </summary>
- /// <param name="writerSchema">schema of the object that wrote the data</param>
- /// <param name="readerSchema">schema of the object that will store the data</param>
- public SpecificDefaultReader(Schema writerSchema, Schema readerSchema) : base(writerSchema,readerSchema)
- {
- }
-
- /// <summary>
- /// Deserializes a record from the stream.
- /// </summary>
- /// <param name="reuse">If not null, a record object that could be reused for returning the result</param>
- /// <param name="writerSchema">The writer's RecordSchema</param>
- /// <param name="readerSchema">The reader's schema, must be RecordSchema too.</param>
- /// <param name="dec">The decoder for deserialization</param>
- /// <returns>The record object just read</returns>
- protected override object ReadRecord(object reuse, RecordSchema writerSchema, Schema readerSchema, Decoder dec)
- {
- RecordSchema rs = (RecordSchema)readerSchema;
-
- ISpecificRecord rec = (reuse != null ? reuse : ObjectCreator.Instance.New(rs.Fullname, Schema.Type.Record)) as ISpecificRecord;
- object obj;
- foreach (Field wf in writerSchema)
- {
- try
- {
- Field rf;
- if (rs.TryGetField(wf.Name, out rf))
- {
- obj = rec.Get(rf.Pos);
- rec.Put(rf.Pos, Read(obj, wf.Schema, rf.Schema, dec));
- }
- else
- Skip(wf.Schema, dec);
- }
- catch (Exception ex)
- {
- throw new AvroException(ex.Message + " in field " + wf.Name);
- }
- }
-
- var defaultStream = new MemoryStream();
- var defaultEncoder = new BinaryEncoder(defaultStream);
- var defaultDecoder = new BinaryDecoder(defaultStream);
- foreach (Field rf in rs)
- {
- if (writerSchema.Contains(rf.Name)) continue;
-
- defaultStream.Position = 0; // reset for writing
- Resolver.EncodeDefaultValue(defaultEncoder, rf.Schema, rf.DefaultValue);
- defaultStream.Flush();
- defaultStream.Position = 0; // reset for reading
-
- obj = rec.Get(rf.Pos);
- rec.Put(rf.Pos, Read(obj, rf.Schema, rf.Schema, defaultDecoder));
- }
-
- return rec;
- }
-
- /// <summary>
- /// Deserializes a fixed object and returns the object. The default implementation uses CreateFixed()
- /// and GetFixedBuffer() and returns what CreateFixed() returned.
- /// </summary>
- /// <param name="reuse">If appropriate, uses this object instead of creating a new one.</param>
- /// <param name="writerSchema">The FixedSchema the writer used during serialization.</param>
- /// <param name="readerSchema">The schema that the readr uses. Must be a FixedSchema with the same
- /// size as the writerSchema.</param>
- /// <param name="d">The decoder for deserialization.</param>
- /// <returns>The deserilized object.</returns>
- protected override object ReadFixed(object reuse, FixedSchema writerSchema, Schema readerSchema, Decoder d)
- {
- FixedSchema rs = readerSchema as FixedSchema;
- if (rs.Size != writerSchema.Size)
- {
- throw new AvroException("Size mismatch between reader and writer fixed schemas. Writer: " + writerSchema +
- ", reader: " + readerSchema);
- }
-
- SpecificFixed fixedrec = (reuse != null ? reuse : ObjectCreator.Instance.New(rs.Fullname, Schema.Type.Fixed)) as SpecificFixed;
- d.ReadFixed(fixedrec.Value);
- return fixedrec;
- }
-
- /// <summary>
- /// Reads an enum from the given decoder
- /// </summary>
- /// <param name="reuse">object to store data read</param>
- /// <param name="writerSchema">schema of the object that wrote the data</param>
- /// <param name="readerSchema">schema of the object that will store the data</param>
- /// <param name="dec">decoder object that contains the data to be read</param>
- /// <returns>enum value</returns>
- protected override object ReadEnum(object reuse, EnumSchema writerSchema, Schema readerSchema, Decoder dec)
- {
- return dec.ReadEnum();
- }
-
- /// <summary>
- /// Reads an array from the given decoder
- /// </summary>
- /// <param name="reuse">object to store data read</param>
- /// <param name="writerSchema">schema of the object that wrote the data</param>
- /// <param name="readerSchema">schema of the object that will store the data</param>
- /// <param name="dec">decoder object that contains the data to be read</param>
- /// <returns>array</returns>
- protected override object ReadArray(object reuse, ArraySchema writerSchema, Schema readerSchema, Decoder dec)
- {
- ArraySchema rs = readerSchema as ArraySchema;
- System.Collections.IList array;
- if (reuse != null)
- {
- array = reuse as System.Collections.IList;
- if (array == null)
- throw new AvroException("array object does not implement non-generic IList");
-
- array.Clear();
- }
- else
- array = ObjectCreator.Instance.New(getTargetType(readerSchema), Schema.Type.Array) as System.Collections.IList;
-
- int i = 0;
- for (int n = (int)dec.ReadArrayStart(); n != 0; n = (int)dec.ReadArrayNext())
- {
- for (int j = 0; j < n; j++, i++)
- array.Add(Read(null, writerSchema.ItemSchema, rs.ItemSchema, dec));
- }
- return array;
- }
-
- /// <summary>
- /// Deserialized an avro map. The default implemenation creats a new map using CreateMap() and then
- /// adds elements to the map using AddMapEntry().
- /// </summary>
- /// <param name="reuse">If appropriate, use this instead of creating a new map object.</param>
- /// <param name="writerSchema">The schema the writer used to write the map.</param>
- /// <param name="readerSchema">The schema the reader is using.</param>
- /// <param name="d">The decoder for serialization.</param>
- /// <returns>The deserialized map object.</returns>
- protected override object ReadMap(object reuse, MapSchema writerSchema, Schema readerSchema, Decoder d)
- {
- MapSchema rs = readerSchema as MapSchema;
- System.Collections.IDictionary map;
- if (reuse != null)
- {
- map = reuse as System.Collections.IDictionary;
- if (map == null)
- throw new AvroException("map object does not implement non-generic IList");
-
- map.Clear();
- }
- else
- map = ObjectCreator.Instance.New(getTargetType(readerSchema), Schema.Type.Map) as System.Collections.IDictionary;
-
- for (int n = (int)d.ReadMapStart(); n != 0; n = (int)d.ReadMapNext())
- {
- for (int j = 0; j < n; j++)
- {
- string k = d.ReadString();
- map[k] = Read(null, writerSchema.ValueSchema, rs.ValueSchema, d); // always create new map item
- }
- }
- return map;
- }
-
- /// <summary>
- /// Gets the target type name in the given schema
- /// </summary>
- /// <param name="schema">schema containing the type to be determined</param>
- /// <param name="nullible">used for union schema</param>
- /// <returns></returns>
- protected virtual string getTargetType(Schema schema)
- {
- bool nEnum = false;
- string type = Avro.CodeGen.getType(schema, false, ref nEnum);
- if (schema.Tag == Schema.Type.Array)
- {
- type = type.Remove(0, 6); // remove IList<
- type = type.Remove(type.Length - 1); // remove >
- }
- else if (schema.Tag == Schema.Type.Map)
- {
- type = type.Remove(0, 19); // remove IDictionary<string,
- type = type.Remove(type.Length - 1); // remove >
- }
- return type;
- }
- }
-}
diff --git a/lang/csharp/src/apache/main/Specific/SpecificRecord.cs b/lang/csharp/src/apache/main/Specific/SpecificRecord.cs
deleted file mode 100644
index eab5f96..0000000
--- a/lang/csharp/src/apache/main/Specific/SpecificRecord.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace Avro.Specific
-{
- /// <summary>
- /// Interface class for generated classes
- /// </summary>
- public interface ISpecificRecord
- {
- Schema Schema { get; }
- object Get(int fieldPos);
- void Put(int fieldPos, object fieldValue);
- }
-}
diff --git a/lang/csharp/src/apache/main/Specific/SpecificWriter.cs b/lang/csharp/src/apache/main/Specific/SpecificWriter.cs
deleted file mode 100644
index 0328cb8..0000000
--- a/lang/csharp/src/apache/main/Specific/SpecificWriter.cs
+++ /dev/null
@@ -1,215 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Avro;
-using Avro.IO;
-using Avro.Generic;
-
-namespace Avro.Specific
-{
- /// <summary>
- /// Generic wrapper class for writing data from specific objects
- /// </summary>
- /// <typeparam name="T">type name of specific object</typeparam>
- public class SpecificWriter<T> : GenericWriter<T>
- {
- public SpecificWriter(Schema schema) : base(new SpecificDefaultWriter(schema)) { }
- public SpecificWriter(SpecificDefaultWriter writer) : base(writer) { }
- }
-
- /// <summary>
- /// Class for writing data from any specific objects
- /// </summary>
- public class SpecificDefaultWriter : DefaultWriter
- {
- /// <summary>
- /// Constructor
- /// </summary>
- /// <param name="schema">schema of the object to be written</param>
- public SpecificDefaultWriter(Schema schema) : base(schema) { }
-
- /// <summary>
- /// Serialized a record using the given RecordSchema. It uses GetField method
- /// to extract the field value from the given object.
- /// </summary>
- /// <param name="schema">The RecordSchema to use for serialization</param>
- /// <param name="value">The value to be serialized</param>
- /// <param name="encoder">The Encoder for serialization</param>
-
- protected override void WriteRecord(RecordSchema schema, object value, Encoder encoder)
- {
- var rec = value as ISpecificRecord;
- if (rec == null)
- throw new AvroTypeException("Record object is not derived from ISpecificRecord");
-
- foreach (Field field in schema)
- {
- try
- {
- Write(field.Schema, rec.Get(field.Pos), encoder);
- }
- catch (Exception ex)
- {
- throw new AvroException(ex.Message + " in field " + field.Name);
- }
- }
- }
-
- /// <summary>
- /// Validates that the record is a fixed record object and that the schema in the object is the
- /// same as the given writer schema. Writes the given fixed record into the given encoder
- /// </summary>
- /// <param name="schema">writer schema</param>
- /// <param name="value">fixed object to write</param>
- /// <param name="encoder">encoder to write to</param>
- protected override void WriteFixed(FixedSchema schema, object value, Encoder encoder)
- {
- var fixedrec = value as SpecificFixed;
- if (fixedrec == null)
- throw new AvroTypeException("Fixed object is not derived from SpecificFixed");
-
- encoder.WriteFixed(fixedrec.Value);
- }
-
- /// <summary>
- /// Writes the given enum value into the given encoder.
- /// </summary>
- /// <param name="schema">writer schema</param>
- /// <param name="value">enum value</param>
- /// <param name="encoder">encoder to write to</param>
- protected override void WriteEnum(EnumSchema schema, object value, Encoder encoder)
- {
- if (value == null)
- throw new AvroTypeException("value is null in SpecificDefaultWriter.WriteEnum");
-
- encoder.WriteEnum(schema.Ordinal(value.ToString()));
- }
-
- /// <summary>
- /// Serialized an array. The default implementation calls EnsureArrayObject() to ascertain that the
- /// given value is an array. It then calls GetArrayLength() and GetArrayElement()
- /// to access the members of the array and then serialize them.
- /// </summary>
- /// <param name="schema">The ArraySchema for serialization</param>
- /// <param name="value">The value being serialized</param>
- /// <param name="encoder">The encoder for serialization</param>
- protected override void WriteArray(ArraySchema schema, object value, Encoder encoder)
- {
- var arr = value as System.Collections.IList;
- if (arr == null)
- throw new AvroTypeException("Array does not implement non-generic IList");
-
- long l = arr.Count;
- encoder.WriteArrayStart();
- encoder.SetItemCount(l);
- for (int i = 0; i < l; i++)
- {
- encoder.StartItem();
- Write(schema.ItemSchema, arr[i], encoder);
- }
- encoder.WriteArrayEnd();
- }
-
- /// <summary>
- /// Writes the given map into the given encoder.
- /// </summary>
- /// <param name="schema">writer schema</param>
- /// <param name="value">map to write</param>
- /// <param name="encoder">encoder to write to</param>
- protected override void WriteMap(MapSchema schema, object value, Encoder encoder)
- {
- var map = value as System.Collections.IDictionary;
- if (map == null)
- throw new AvroTypeException("Map does not implement non-generic IDictionary");
-
- encoder.WriteArrayStart();
- encoder.SetItemCount(map.Count);
- foreach (System.Collections.DictionaryEntry de in map)
- {
- encoder.StartItem();
- encoder.WriteString(de.Key as string);
- Write(schema.ValueSchema, de.Value, encoder);
- }
- encoder.WriteMapEnd();
- }
-
- /// <summary>
- /// Resolves the given value against the given UnionSchema and serializes the object against
- /// the resolved schema member. The default implementation of this method uses
- /// ResolveUnion to find the member schema within the UnionSchema.
- /// </summary>
- /// <param name="us">The UnionSchema to resolve against</param>
- /// <param name="value">The value to be serialized</param>
- /// <param name="encoder">The encoder for serialization</param>
- protected override void WriteUnion(UnionSchema us, object value, Encoder encoder)
- {
- for (int i = 0; i < us.Count; i++)
- {
- if (Matches(us[i], value))
- {
- encoder.WriteUnionIndex(i);
- Write(us[i], value, encoder);
- return;
- }
- }
- throw new AvroException("Cannot find a match for " + value.GetType() + " in " + us);
- }
-
- protected override bool Matches(Schema sc, object obj)
- {
- if (obj == null && sc.Tag != Avro.Schema.Type.Null) return false;
- switch (sc.Tag)
- {
- case Schema.Type.Null:
- return obj == null;
- case Schema.Type.Boolean:
- return obj is bool;
- case Schema.Type.Int:
- return obj is int;
- case Schema.Type.Long:
- return obj is long;
- case Schema.Type.Float:
- return obj is float;
- case Schema.Type.Double:
- return obj is double;
- case Schema.Type.Bytes:
- return obj is byte[];
- case Schema.Type.String:
- return obj is string;
- case Schema.Type.Record:
- return obj is ISpecificRecord &&
- (((obj as ISpecificRecord).Schema) as RecordSchema).SchemaName.Equals((sc as RecordSchema).SchemaName);
- case Schema.Type.Enumeration:
- return obj.GetType().IsEnum && (sc as EnumSchema).Symbols.Contains(obj.ToString());
- case Schema.Type.Array:
- return obj is System.Collections.IList;
- case Schema.Type.Map:
- return obj is System.Collections.IDictionary;
- case Schema.Type.Union:
- return false; // Union directly within another union not allowed!
- case Schema.Type.Fixed:
- return obj is SpecificFixed &&
- (((obj as SpecificFixed).Schema) as FixedSchema).SchemaName.Equals((sc as FixedSchema).SchemaName);
- default:
- throw new AvroException("Unknown schema type: " + sc.Tag);
- }
- }
- }
-}
diff --git a/lang/csharp/src/apache/test/Avro.test.csproj b/lang/csharp/src/apache/test/Avro.test.csproj
deleted file mode 100644
index dc71767..0000000
--- a/lang/csharp/src/apache/test/Avro.test.csproj
+++ /dev/null
@@ -1,131 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- 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.
--->
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>8.0.30703</ProductVersion>
- <SchemaVersion>2.0</SchemaVersion>
- <ProjectGuid>{911D56AB-587B-4E5F-B5EA-D47D8A46F1FA}</ProjectGuid>
- <OutputType>Library</OutputType>
- <AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>Avro.test</RootNamespace>
- <AssemblyName>Avro.test</AssemblyName>
- <TargetFrameworkVersion Condition=" '$(TargetFrameworkVersion)' == '' ">v4.0</TargetFrameworkVersion>
- <FileAlignment>512</FileAlignment>
- <TargetFrameworkProfile>Client</TargetFrameworkProfile>
- <FileUpgradeFlags>
- </FileUpgradeFlags>
- <OldToolsVersion>3.5</OldToolsVersion>
- <UpgradeBackupLocation />
- <PublishUrl>publish\</PublishUrl>
- <Install>true</Install>
- <InstallFrom>Disk</InstallFrom>
- <UpdateEnabled>false</UpdateEnabled>
- <UpdateMode>Foreground</UpdateMode>
- <UpdateInterval>7</UpdateInterval>
- <UpdateIntervalUnits>Days</UpdateIntervalUnits>
- <UpdatePeriodically>false</UpdatePeriodically>
- <UpdateRequired>false</UpdateRequired>
- <MapFileExtensions>true</MapFileExtensions>
- <ApplicationRevision>0</ApplicationRevision>
- <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
- <IsWebBootstrapper>false</IsWebBootstrapper>
- <UseApplicationTrust>false</UseApplicationTrust>
- <BootstrapperEnabled>true</BootstrapperEnabled>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>..\..\..\build\test\Debug\</OutputPath>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugType>none</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>..\..\..\build\test\Release\</OutputPath>
- <DefineConstants>
- </DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
- </PropertyGroup>
- <ItemGroup>
- <Reference Include="nunit.framework, Version=2.5.7.10213, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\..\lib\test\nunit.framework.dll</HintPath>
- </Reference>
- <Reference Include="System" />
- <Reference Include="System.Core" />
- <Reference Include="System.Xml.Linq" />
- <Reference Include="System.Data.DataSetExtensions" />
- <Reference Include="Microsoft.CSharp" />
- <Reference Include="System.Data" />
- <Reference Include="System.Xml" />
- </ItemGroup>
- <ItemGroup>
- <Compile Include="CodGen\CodeGenTest.cs" />
- <Compile Include="Generic\GenericTests.cs" />
- <Compile Include="IO\BinaryCodecTests.cs" />
- <Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="Protocol\ProtocolTest.cs" />
- <Compile Include="Schema\AliasTest.cs" />
- <Compile Include="Schema\SchemaTests.cs" />
- <Compile Include="Specific\SpecificTests.cs" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\main\Avro.main.csproj">
- <Project>{A0A5CA3C-F58C-4D07-98B0-2C7B62AB20F0}</Project>
- <Name>Avro.main</Name>
- </ProjectReference>
- </ItemGroup>
- <ItemGroup>
- <BootstrapperPackage Include=".NETFramework,Version=v3.5">
- <Visible>False</Visible>
- <ProductName>Microsoft .NET Framework 4 %28x86 and x64%29</ProductName>
- <Install>true</Install>
- </BootstrapperPackage>
- <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
- <Visible>False</Visible>
- <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
- <Install>false</Install>
- </BootstrapperPackage>
- <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
- <Visible>False</Visible>
- <ProductName>.NET Framework 3.5 SP1</ProductName>
- <Install>false</Install>
- </BootstrapperPackage>
- <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
- <Visible>False</Visible>
- <ProductName>Windows Installer 3.1</ProductName>
- <Install>true</Install>
- </BootstrapperPackage>
- </ItemGroup>
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
- <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
- Other similar extension points exist, see Microsoft.Common.targets.
- <Target Name="BeforeBuild">
- </Target>
- <Target Name="AfterBuild">
- </Target>
- -->
-</Project>
diff --git a/lang/csharp/src/apache/test/CodGen/CodeGenTest.cs b/lang/csharp/src/apache/test/CodGen/CodeGenTest.cs
deleted file mode 100644
index 39490a2..0000000
--- a/lang/csharp/src/apache/test/CodGen/CodeGenTest.cs
+++ /dev/null
@@ -1,122 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.CodeDom;
-using System.CodeDom.Compiler;
-using Microsoft.CSharp;
-using NUnit.Framework;
-using Avro;
-using Avro.Specific;
-using System.Reflection;
-
-namespace Avro.Test
-{
- [TestFixture]
-
- class CodeGenTest
- {
- [TestCase(@"{
-""type"" : ""record"",
-""name"" : ""ClassKeywords"",
-""namespace"" : ""com.base"",
-""fields"" :
- [
- { ""name"" : ""int"", ""type"" : ""int"" },
- { ""name"" : ""base"", ""type"" : ""long"" },
- { ""name"" : ""event"", ""type"" : ""boolean"" },
- { ""name"" : ""foreach"", ""type"" : ""double"" },
- { ""name"" : ""bool"", ""type"" : ""float"" },
- { ""name"" : ""internal"", ""type"" : ""bytes"" },
- { ""name"" : ""while"", ""type"" : ""string"" },
- { ""name"" : ""return"", ""type"" : ""null"" },
- { ""name"" : ""enum"", ""type"" : { ""type"" : ""enum"", ""name"" : ""class"", ""symbols"" : [ ""A"", ""B"" ] } },
- { ""name"" : ""string"", ""type"" : { ""type"": ""fixed"", ""size"": 16, ""name"": ""static"" } }
- ]
-}
-", new object[] {"com.base.ClassKeywords", typeof(int), typeof(long), typeof(bool), typeof(double), typeof(float), typeof(byte[]), typeof(string),typeof(object),"com.base.class", "com.base.static"})]
- [TestCase(@"{
-""type"" : ""record"",
-""name"" : ""SchemaObject"",
-""namespace"" : ""schematest"",
-""fields"" :
- [
- { ""name"" : ""myobject"", ""type"" :
- [
- ""null"",
- {""type"" : ""array"", ""items"" : [ ""null"",
- { ""type"" : ""enum"", ""name"" : ""MyEnum"", ""symbols"" : [ ""A"", ""B"" ] },
- { ""type"": ""fixed"", ""size"": 16, ""name"": ""MyFixed"" }
- ]
- }
- ]
- }
- ]
-}
-", new object[] { "schematest.SchemaObject", typeof(IList<object>) })]
- public static void TestCodeGen(string str, object[] result)
- {
- Schema schema = Schema.Parse(str);
-
- var codegen = new CodeGen();
- codegen.AddSchema(schema);
- var compileUnit = codegen.GenerateCode();
-
- var comparam = new CompilerParameters(new string[] {"mscorlib.dll"});
- comparam.ReferencedAssemblies.Add("System.dll");
- comparam.ReferencedAssemblies.Add("System.Core.dll");
- comparam.ReferencedAssemblies.Add(Type.GetType("Mono.Runtime") != null ? "Mono.CSharp.dll" : "Microsoft.CSharp.dll");
- comparam.ReferencedAssemblies.Add("Avro.dll");
- comparam.GenerateInMemory = true;
- var ccp = new Microsoft.CSharp.CSharpCodeProvider();
- var units = new CodeCompileUnit[] { compileUnit };
- var compres = ccp.CompileAssemblyFromDom(comparam, units);
- if (compres == null || compres.Errors.Count>0)
- {
- for (int i=0; i<compres.Errors.Count;i++)
- Console.WriteLine(compres.Errors[i]);
- }
- if (null != compres)
- Assert.AreEqual(0, compres.Errors.Count);
-
- // instantiate object
- ISpecificRecord rec = compres.CompiledAssembly.CreateInstance((string)result[0]) as ISpecificRecord;
- Assert.IsNotNull(rec);
-
- // test type of each fields
- for (int i = 1; i < result.Length; ++i)
- {
- object field = rec.Get(i - 1);
- Type stype;
- if (result[i].GetType() == typeof(string))
- {
- object obj = compres.CompiledAssembly.CreateInstance((string)result[i]);
- Assert.IsNotNull(obj);
- stype = obj.GetType();
- }
- else
- stype = (Type)result[i];
- if (!stype.IsValueType)
- Assert.IsNull(field); // can't test reference type, it will be null
- else
- Assert.AreEqual(stype, field.GetType());
- }
- }
- }
-}
diff --git a/lang/csharp/src/apache/test/Generic/GenericTests.cs b/lang/csharp/src/apache/test/Generic/GenericTests.cs
deleted file mode 100644
index bc9879d..0000000
--- a/lang/csharp/src/apache/test/Generic/GenericTests.cs
+++ /dev/null
@@ -1,455 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.IO;
-using Avro.IO;
-using System.Collections.Generic;
-using Avro.Generic;
-using NUnit.Framework;
-
-namespace Avro.Test.Generic
-{
- class GenericTests
- {
- private static void test<T>(string s, T value)
- {
- Stream ms;
- Schema ws;
- serialize(s, value, out ms, out ws);
- Schema rs = Schema.Parse(s);
- T output = deserialize<T>(ms, ws, rs);
- Assert.AreEqual(value, output);
- }
-
- [TestCase("{\"type\": \"boolean\"}", true)]
- [TestCase("{\"type\": \"boolean\"}", false)]
-
- // Union
- [TestCase("[\"boolean\", \"null\"]", null)]
- [TestCase("[\"boolean\", \"null\"]", true)]
- [TestCase("[\"int\", \"long\"]", 100)]
- [TestCase("[\"int\", \"long\"]", 100L)]
- [TestCase("[\"float\", \"double\"]", 100.75)]
- [TestCase("[\"float\", \"double\"]", 23.67f)]
- [TestCase("[{\"type\": \"array\", \"items\": \"float\"}, \"double\"]", new float[] { 23.67f, 22.78f })]
- [TestCase("[{\"type\": \"array\", \"items\": \"float\"}, \"double\"]", 100.89)]
- [TestCase("[{\"type\": \"array\", \"items\": \"string\"}, \"string\"]", "a")]
- [TestCase("[{\"type\": \"array\", \"items\": \"string\"}, \"string\"]", new string[] { "a", "b" })]
- [TestCase("[{\"type\": \"array\", \"items\": \"bytes\"}, \"bytes\"]", new byte[] { 1, 2, 3 })]
- [TestCase("[{\"type\": \"array\", \"items\": \"bytes\"}, \"bytes\"]",
- new object[] { new byte[] { 1, 2 }, new byte[] { 3, 4 } })]
- [TestCase("[{\"type\": \"enum\", \"symbols\": [\"s1\", \"s2\"], \"name\": \"e\"}, \"string\"]", "h1")]
- public void TestPrimitive(string schema, object value)
- {
- test(schema, value);
- }
-
- [TestCase("{\"type\":\"record\", \"name\":\"n\", \"fields\":[{\"name\":\"f1\", \"type\":\"null\"}]}",
- new object[] { "f1", null })]
- [TestCase("{\"type\":\"record\", \"name\":\"n\", \"fields\":[{\"name\":\"f1\", \"type\":\"boolean\"}]}",
- new object[] { "f1", true })]
- [TestCase("{\"type\":\"record\", \"name\":\"n\", \"fields\":[{\"name\":\"f1\", \"type\":\"boolean\"}]}",
- new object[] { "f1", false })]
- [TestCase("{\"type\":\"record\", \"name\":\"n\", \"fields\":[{\"name\":\"f1\", \"type\":\"int\"}]}",
- new object[] { "f1", 101 })]
- [TestCase("{\"type\":\"record\", \"name\":\"n\", \"fields\":[{\"name\":\"f1\", \"type\":\"long\"}]}",
- new object[] { "f1", 101L })]
- [TestCase("{\"type\":\"record\", \"name\":\"n\", \"fields\":[{\"name\":\"f1\", \"type\":\"float\"}]}",
- new object[] { "f1", 101.78f })]
- [TestCase("{\"type\":\"record\", \"name\":\"n\", \"fields\":[{\"name\":\"f1\", \"type\":\"double\"}]}",
- new object[] { "f1", 101.78 })]
- [TestCase("{\"type\":\"record\", \"name\":\"n\", \"fields\":[{\"name\":\"f1\", \"type\":\"string\"}]}",
- new object[] { "f1", "A" })]
- [TestCase("{\"type\":\"record\", \"name\":\"n\", \"fields\":[{\"name\":\"f1\", \"type\":\"bytes\"}]}",
- new object[] { "f1", new byte[] { 0, 1 } })]
- [TestCase("{\"type\":\"record\", \"name\":\"n\", \"fields\":" +
- "[{\"name\":\"f1\", \"type\":{\"type\": \"enum\", \"name\": \"e\", \"symbols\":[\"s1\", \"s2\"]}}]}",
- new object[] { "f1", "s2" })]
- [TestCase("{\"type\":\"record\", \"name\":\"n\", \"fields\":" +
- "[{\"name\":\"f1\", \"type\":{\"type\": \"array\", \"items\": \"int\"}}]}",
- new object[] { "f1", new object[] { 0, 1, 101 } })]
- [TestCase("{\"type\":\"record\", \"name\":\"n\", \"fields\":" +
- "[{\"name\":\"f1\", \"type\":{\"type\": \"array\", \"items\": \"int\"}}]}",
- new object[] { "f1", new int[] { 0, 1, 101 } })]
- [TestCase("{\"type\":\"record\", \"name\":\"n\", \"fields\":" +
- "[{\"name\":\"f1\", \"type\":[\"int\", \"long\"]}]}",
- new object[] { "f1", 100 })]
- [TestCase("{\"type\":\"record\", \"name\":\"n\", \"fields\":" +
- "[{\"name\":\"f1\", \"type\":[\"int\", \"long\"]}]}",
- new object[] { "f1", 100L })]
- [TestCase("{\"type\":\"record\", \"name\":\"n\", \"fields\":" +
- "[{\"name\":\"f1\", \"type\":{\"type\": \"fixed\", \"name\": \"f\", \"size\": 2}}]}",
- new object[] { "f1", new byte[] { 1, 2 } })]
- public void TestRecord(string schema, object[] kv)
- {
- test(schema, mkRecord(kv, Schema.Parse(schema) as RecordSchema));
- }
-
- [TestCase("{\"type\": \"map\", \"values\": \"string\"}",
- new object[] { "a", "0", "b", "1", "c", "101" })]
- public void TestMap(string schema, object[] values)
- {
- test(schema, mkMap(values));
- }
-
- [TestCase("[{\"type\":\"record\", \"name\":\"n\", \"fields\":[{\"name\":\"f1\", \"type\":\"string\"}]}, \"string\"]",
- "{\"type\":\"record\", \"name\":\"n\", \"fields\":[{\"name\":\"f1\", \"type\":\"string\"}]}",
- new object[] { "f1", "v1" })]
- public void TestUnion_record(string unionSchema, string recordSchema, object[] value)
- {
- test(unionSchema, mkRecord(value, Schema.Parse(recordSchema) as RecordSchema));
- }
-
- [TestCase("[{\"type\": \"enum\", \"symbols\": [\"s1\", \"s2\"], \"name\": \"e\"}, \"string\"]",
- "{\"type\": \"enum\", \"symbols\": [\"s1\", \"s2\"], \"name\": \"e\"}", "s1")]
- [TestCase("[{\"type\": \"enum\", \"symbols\": [\"s1\", \"s2\"], \"name\": \"e\"}, \"string\"]",
- "{\"type\": \"enum\", \"symbols\": [\"s1\", \"s2\"], \"name\": \"e\"}", "s2")]
- [TestCase("[{\"type\": \"enum\", \"symbols\": [\"s1\", \"s2\"], \"name\": \"e\"}, \"string\"]",
- "{\"type\": \"enum\", \"symbols\": [\"s1\", \"s2\"], \"name\": \"e\"}", "s3",
- ExpectedException = typeof(AvroException))]
- public void TestUnion_enum(string unionSchema, string enumSchema, string value)
- {
- test(unionSchema, mkEnum(enumSchema, value));
- }
-
-
- [TestCase("[{\"type\": \"map\", \"values\": \"int\"}, \"string\"]",
- "{\"type\": \"map\", \"values\": \"int\"}", new object[] { "a", 1, "b", 2 })]
- public void TestUnion_map(string unionSchema, string mapSchema, object[] value)
- {
- test(unionSchema, mkMap(value));
- }
-
- [TestCase("[{\"type\": \"fixed\", \"size\": 2, \"name\": \"f\"}, \"string\"]",
- "{\"type\": \"fixed\", \"size\": 2, \"name\": \"f\"}", new byte[] { 1, 2 })]
- [TestCase("[{\"type\": \"fixed\", \"size\": 2, \"name\": \"f\"}, \"string\"]",
- "{\"type\": \"fixed\", \"size\": 2, \"name\": \"f\"}", new byte[] { 1, 2, 3 },
- ExpectedException = typeof(AvroException))]
- [TestCase("[{\"type\": \"fixed\", \"size\": 2, \"name\": \"f\"}, \"string\"]",
- "{\"type\": \"fixed\", \"size\": 3, \"name\": \"f\"}", new byte[] { 1, 2, 3 },
- ExpectedException = typeof(AvroException))]
- public void TestUnion_fixed(string unionSchema, string fixedSchema, byte[] value)
- {
- test(unionSchema, mkFixed(fixedSchema, value));
- }
-
- public void TestResolution<T, S>(string writerSchema, T actual, string readerSchema, S expected)
- {
- Stream ms;
- Schema ws;
- serialize<T>(writerSchema, actual, out ms, out ws);
- Schema rs = Schema.Parse(readerSchema);
- S output = deserialize<S>(ms, ws, rs);
- Assert.AreEqual(expected, output);
- }
-
- [TestCase("int", 10, "long", 10L)]
- [TestCase("int", 10, "float", 10.0f)]
- [TestCase("int", 10, "double", 10.0)]
- [TestCase("long", 10L, "float", 10.0f)]
- [TestCase("long", 10L, "double", 10.0)]
- [TestCase("float", 10.0f, "double", 10.0)]
- [TestCase("{\"type\":\"array\", \"items\":\"int\"}", new int[] { 10, 20 },
- "{\"type\":\"array\", \"items\":\"long\"}", new object[] { 10L, 20L })]
- [TestCase("[\"int\", \"boolean\"]", true, "[\"boolean\", \"double\"]", true)]
- [TestCase("[\"int\", \"boolean\"]", 10, "[\"boolean\", \"double\"]", 10.0)]
- [TestCase("[\"int\", \"boolean\"]", 10, "\"int\"", 10)]
- [TestCase("[\"int\", \"boolean\"]", 10, "\"double\"", 10.0)]
- [TestCase("\"int\"", 10, "[\"int\", \"boolean\"]", 10)]
- [TestCase("\"int\"", 10, "[\"long\", \"boolean\"]", 10L)]
- public void TestResolution_simple(string writerSchema, object actual, string readerSchema, object expected)
- {
- TestResolution(writerSchema, actual, readerSchema, expected);
- }
-
- [Test]
- public void TestResolution_intMapToLongMap()
- {
- TestResolution("{\"type\":\"map\", \"values\":\"int\"}", mkMap(new object[] { "a", 10, "b", 20 }),
- "{\"type\":\"map\", \"values\":\"long\"}", mkMap(new object[] { "a", 10L, "b", 20L }));
- }
-
- [Test]
- public void TestResolution_enum()
- {
- string ws = "{\"type\":\"enum\", \"symbols\":[\"a\", \"b\"], \"name\":\"e\"}";
- string rs = "{\"type\":\"enum\", \"symbols\":[\"a\", \"b\"], \"name\":\"e\"}";
- TestResolution(ws, mkEnum(ws, "a"), rs, mkEnum(rs, "a"));
- }
-
- [TestCase("{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f1\",\"type\":\"boolean\"},{\"name\":\"f2\",\"type\":\"int\"}]}",
- new object[] { "f1", true, "f2", 100 },
- "{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f2\",\"type\":\"int\"},{\"name\":\"f1\",\"type\":\"boolean\"}]}",
- new object[] { "f1", true, "f2", 100 }, Description = "Out of order fields")]
- [TestCase("{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f1\",\"type\":\"boolean\"},{\"name\":\"f2\",\"type\":\"int\"}]}",
- new object[] { "f1", true, "f2", 100 },
- "{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f1\",\"type\":\"boolean\"},{\"name\":\"f2\",\"type\":\"long\"}]}",
- new object[] { "f1", true, "f2", 100L }, Description = "Field promotion")]
- [TestCase("{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f1\",\"type\":\"boolean\"},{\"name\":\"f2\",\"type\":\"int\"}]}",
- new object[] { "f1", true, "f2", 100 },
- "{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f1\",\"type\":\"boolean\"}]}",
- new object[] { "f1", true }, Description = "Missing fields - 1")]
- [TestCase("{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f1\",\"type\":\"null\"},{\"name\":\"f2\",\"type\":\"int\"}]}",
- new object[] { "f1", null, "f2", 100 },
- "{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f2\",\"type\":\"int\"}]}",
- new object[] { "f2", 100 }, Description = "Missing fields - null")]
- [TestCase("{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f1\",\"type\":\"boolean\"},{\"name\":\"f2\",\"type\":\"int\"}]}",
- new object[] { "f1", true, "f2", 100 },
- "{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f2\",\"type\":\"int\"}]}",
- new object[] { "f2", 100 }, Description = "Missing fields - boolean")]
- [TestCase("{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f1\",\"type\":\"int\"},{\"name\":\"f2\",\"type\":\"int\"}]}",
- new object[] { "f1", 1, "f2", 100 },
- "{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f2\",\"type\":\"int\"}]}",
- new object[] { "f2", 100 }, Description = "Missing fields - int")]
- [TestCase("{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f1\",\"type\":\"long\"},{\"name\":\"f2\",\"type\":\"int\"}]}",
- new object[] { "f1", 1L, "f2", 100 },
- "{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f2\",\"type\":\"int\"}]}",
- new object[] { "f2", 100 }, Description = "Missing fields - long")]
- [TestCase("{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f1\",\"type\":\"float\"},{\"name\":\"f2\",\"type\":\"int\"}]}",
- new object[] { "f1", 1.0f, "f2", 100 },
- "{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f2\",\"type\":\"int\"}]}",
- new object[] { "f2", 100 }, Description = "Missing fields - float")]
- [TestCase("{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f1\",\"type\":\"double\"},{\"name\":\"f2\",\"type\":\"int\"}]}",
- new object[] { "f1", 1.0, "f2", 100 },
- "{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f2\",\"type\":\"int\"}]}",
- new object[] { "f2", 100 }, Description = "Missing fields - double")]
- [TestCase("{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f1\",\"type\":\"bytes\"},{\"name\":\"f2\",\"type\":\"int\"}]}",
- new object[] { "f1", new byte[] { 1 , 0 }, "f2", 100 },
- "{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f2\",\"type\":\"int\"}]}",
- new object[] { "f2", 100 }, Description = "Missing fields - bytes")]
- [TestCase("{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f1\",\"type\":\"string\"},{\"name\":\"f2\",\"type\":\"int\"}]}",
- new object[] { "f1", "h", "f2", 100 },
- "{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f2\",\"type\":\"int\"}]}",
- new object[] { "f2", 100 }, Description = "Missing fields - string")]
- [TestCase("{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f1\",\"type\":{\"type\":\"array\",\"items\":\"int\"}},{\"name\":\"f2\",\"type\":\"int\"}]}",
- new object[] { "f1", new int[] { 100, 101 }, "f2", 100 },
- "{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f2\",\"type\":\"int\"}]}",
- new object[] { "f2", 100 }, Description = "Missing fields - array")]
- [TestCase("{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f1\",\"type\":[\"int\", \"null\"]},{\"name\":\"f2\",\"type\":\"int\"}]}",
- new object[] { "f1", 101, "f2", 100 },
- "{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f2\",\"type\":\"int\"}]}",
- new object[] { "f2", 100 }, Description = "Missing fields - union")]
- // TODO: Missing fields - record, enum, map, fixed
- /* FIXME: Resolution using defaults don't work yet.
- [TestCase("{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f1\",\"type\":\"boolean\"}]}",
- new object[] { "f1", true },
- "{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f1\",\"type\":\"boolean\"},{\"name\":\"f2\",\"type\":\"string\",\"default\":\"d\"}]}",
- new object[] { "f1", true, "f2", "d" }, Description = "Default field")]
- */
- public void TestResolution_record(string ws, object[] actual, string rs, object[] expected)
- {
- TestResolution(ws, mkRecord(actual, Schema.Parse(ws) as RecordSchema), rs,
- mkRecord(expected, Schema.Parse(rs) as RecordSchema));
- }
-
- [TestCase("{\"type\":\"map\",\"values\":\"int\"}", new object[] { "a", 100, "b", -202 },
- "{\"type\":\"map\",\"values\":\"long\"}", new object[] { "a", 100L, "b", -202L })]
- public void TestResolution_intMapToLongMap(string ws, object[] value, string rs, object[] expected)
- {
- TestResolution(ws, mkMap(value), rs, mkMap(expected));
- }
-
-
- private static void testResolutionMismatch<T>(string writerSchema, T value, string readerSchema)
- {
- Stream ms;
- Schema ws;
- serialize(writerSchema, value, out ms, out ws);
- deserialize<object>(ms, ws, Schema.Parse(readerSchema));
- }
-
- [TestCase("boolean", true, "null", ExpectedException = typeof(AvroException))]
- [TestCase("int", 10, "boolean", ExpectedException = typeof(AvroException))]
- [TestCase("int", 10, "string", ExpectedException = typeof(AvroException))]
- [TestCase("int", 10, "bytes", ExpectedException = typeof(AvroException))]
- [TestCase("int", 10, "{\"type\":\"record\",\"name\":\"r\",\"fields\":[{\"name\":\"f\", \"type\":\"int\"}]}",
- ExpectedException = typeof(AvroException))]
- [TestCase("int", 10, "{\"type\":\"enum\",\"name\":\"e\",\"symbols\":[\"s\", \"t\"]}", ExpectedException = typeof(AvroException))]
- [TestCase("int", 10, "{\"type\":\"array\",\"items\":\"int\"}", ExpectedException = typeof(AvroException))]
- [TestCase("int", 10, "{\"type\":\"map\",\"values\":\"int\"}", ExpectedException = typeof(AvroException))]
- [TestCase("int", 10, "[\"string\", \"bytes\"]", ExpectedException = typeof(AvroException))]
- [TestCase("int", 10, "{\"type\":\"fixed\",\"name\":\"f\",\"size\":2}", ExpectedException = typeof(AvroException))]
- [TestCase("{\"type\":\"array\",\"items\":\"int\"}", new int[] { 10 },
- "\"boolean\"", ExpectedException = typeof(AvroException))]
- [TestCase("{\"type\":\"array\",\"items\":\"int\"}", new int[] { 10 },
- "{\"type\":\"array\",\"items\":\"string\"}", ExpectedException = typeof(AvroException))]
- [TestCase("[\"int\", \"boolean\"]", 10, "[\"string\", \"bytes\"]", ExpectedException = typeof(AvroException))]
- [TestCase("[\"int\", \"boolean\"]", 10, "\"string\"", ExpectedException = typeof(AvroException))]
- public void TestResolutionMismatch_simple(string writerSchema, object value, string readerSchema)
- {
- testResolutionMismatch(writerSchema, value, readerSchema);
- }
-
- [TestCase("{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f1\",\"type\":[\"int\", \"null\"]},{\"name\":\"f2\",\"type\":\"int\"}]}",
- new object[] { "f1", 101, "f2", 100 }, "int",
- ExpectedException = typeof(AvroException), Description = "Non-record schema")]
- [TestCase("{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f1\",\"type\":[\"int\", \"null\"]},{\"name\":\"f2\",\"type\":\"int\"}]}",
- new object[] { "f1", 101, "f2", 100 },
- "{\"type\":\"record\",\"name\":\"s\",\"fields\":" +
- "[{\"name\":\"f2\",\"type\":\"int\"}]}",
- ExpectedException = typeof(AvroException), Description = "Name mismatch")]
- [TestCase("{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f1\",\"type\":[\"int\", \"null\"]},{\"name\":\"f2\",\"type\":\"int\"}]}",
- new object[] { "f1", 101, "f2", 100 },
- "{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f2\",\"type\":\"string\"}]}",
- ExpectedException = typeof(AvroException), Description = "incompatible field")]
- [TestCase("{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f1\",\"type\":[\"int\", \"null\"]},{\"name\":\"f2\",\"type\":\"int\"}]}",
- new object[] { "f1", 101, "f2", 100 },
- "{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
- "[{\"name\":\"f3\",\"type\":\"string\"}]}",
- ExpectedException = typeof(AvroException), Description = "new field without default")]
- public void TestResolutionMismatch_record(string ws, object[] actual, string rs)
- {
- testResolutionMismatch(ws, mkRecord(actual, Schema.Parse(ws) as RecordSchema), rs);
- }
-
- [TestCase("{\"type\":\"enum\",\"name\":\"e\",\"symbols\":[\"s\", \"t\"]}", "s", "int",
- ExpectedException = typeof(AvroException), Description = "Non-enum schema")]
- [TestCase("{\"type\":\"enum\",\"name\":\"e\",\"symbols\":[\"s\", \"t\"]}",
- "s", "{\"type\":\"enum\",\"name\":\"f\",\"symbols\":[\"s\", \"t\"]}",
- ExpectedException = typeof(AvroException), Description = "Name mismatch")]
- [TestCase("{\"type\":\"enum\",\"name\":\"e\",\"symbols\":[\"s\", \"t\"]}",
- "s", "{\"type\":\"enum\",\"name\":\"f\",\"symbols\":[\"t\", \"u\"]}",
- ExpectedException = typeof(AvroException), Description = "Incompatible symbols")]
- public void TestResolutionMismatch_enum(string ws, string value, string rs)
- {
- testResolutionMismatch(ws, mkEnum(ws, value), rs);
- }
-
- [TestCase("{\"type\":\"map\",\"values\":\"int\"}", new object[] { "a", 0 }, "int",
- ExpectedException = typeof(AvroException), Description = "Non-map schema")]
- [TestCase("{\"type\":\"map\",\"values\":\"int\"}",
- new object[] { "a", 0 }, "{\"type\":\"map\",\"values\":\"string\"}",
- ExpectedException = typeof(AvroException), Description = "Name mismatch")]
- public void TestResolutionMismatch_map(string ws, object[] value, string rs)
- {
- testResolutionMismatch(ws, mkMap(value), rs);
- }
-
- [TestCase("{\"type\":\"fixed\",\"name\":\"f\",\"size\":2}", new byte[] { 1, 1 }, "int",
- ExpectedException = typeof(AvroException), Description = "Non-fixed schema")]
- [TestCase("{\"type\":\"fixed\",\"name\":\"f\",\"size\":2}",
- new byte[] { 1, 1 }, "{\"type\":\"fixed\",\"name\":\"g\",\"size\":2}",
- ExpectedException = typeof(AvroException), Description = "Name mismatch")]
- [TestCase("{\"type\":\"fixed\",\"name\":\"f\",\"size\":2}",
- new byte[] { 1, 1 }, "{\"type\":\"fixed\",\"name\":\"f\",\"size\":1}",
- ExpectedException = typeof(AvroException), Description = "Size mismatch")]
- public void TestResolutionMismatch_fixed(string ws, byte[] value, string rs)
- {
- testResolutionMismatch(ws, mkFixed(ws, value), rs);
- }
-
- private static GenericRecord mkRecord(object[] kv, RecordSchema s)
- {
- GenericRecord input = new GenericRecord(s);
- for (int i = 0; i < kv.Length; i += 2)
- {
- string fieldName = (string)kv[i];
- object fieldValue = kv[i + 1];
- Schema inner = s[fieldName].Schema;
- if (inner is EnumSchema)
- {
- GenericEnum ge = new GenericEnum(inner as EnumSchema, (string)fieldValue);
- fieldValue = ge;
- }
- else if (inner is FixedSchema)
- {
- GenericFixed gf = new GenericFixed(inner as FixedSchema);
- gf.Value = (byte[])fieldValue;
- fieldValue = gf;
- }
- input.Add(fieldName, fieldValue);
- }
- return input;
- }
-
- private static IDictionary<string, object> mkMap(object[] vv)
- {
- IDictionary<string, object> d = new Dictionary<string, object>();
- for (int j = 0; j < vv.Length; j += 2)
- {
- d[(string)vv[j]] = vv[j + 1];
- }
- return d;
- }
-
- private static object mkEnum(string enumSchema, string value)
- {
- return new GenericEnum(Schema.Parse(enumSchema) as EnumSchema, value);
- }
-
- private static object mkFixed(string fixedSchema, byte[] value)
- {
- return new GenericFixed(Schema.Parse(fixedSchema) as FixedSchema, value);
- }
-
- private static S deserialize<S>(Stream ms, Schema ws, Schema rs)
- {
- GenericReader<S> r = new GenericReader<S>(ws, rs);
- Decoder d = new BinaryDecoder(ms);
- S n = default(S);
- S output = r.Read(n, d);
- Assert.AreEqual(ms.Length, ms.Position); // Ensure we have read everything.
- return output;
- }
-
- private static void serialize<T>(string writerSchema, T actual, out Stream ms, out Schema ws)
- {
- ms = new MemoryStream();
- Encoder e = new BinaryEncoder(ms);
- ws = Schema.Parse(writerSchema);
- GenericWriter<T> w = new GenericWriter<T>(ws);
- w.Write(actual, e);
- ms.Flush();
- ms.Position = 0;
- }
-
- }
-}
diff --git a/lang/csharp/src/apache/test/IO/BinaryCodecTests.cs b/lang/csharp/src/apache/test/IO/BinaryCodecTests.cs
deleted file mode 100644
index b6d2e89..0000000
--- a/lang/csharp/src/apache/test/IO/BinaryCodecTests.cs
+++ /dev/null
@@ -1,334 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Text;
-using NUnit.Framework;
-using System.IO;
-
-using Avro.IO;
-
-namespace Avro.Test
-{
- using Decoder = Avro.IO.Decoder;
- using Encoder = Avro.IO.Encoder;
- delegate T Decode<T>(Decoder d);
- delegate void Skip<T>(Decoder d);
- delegate void Encode<T>(Encoder e, T t);
-
- /// <summary>
- /// Tests the BinaryEncoder and BinaryDecoder. This is pertty general set of test cases and hence
- /// can be used for any encoder and its corresponding decoder.
- /// </summary>
- [TestFixture]
- public class BinaryCodecTests
- {
-
- /// <summary>
- /// Writes an avro type T with value t into a stream using the encode method e
- /// and reads it back using the decode method d and verifies that
- /// the value read back is the same as the one written in.
- /// </summary>
- /// <typeparam name="T">Avro type to test</typeparam>
- /// <param name="t">Value for the Avro type to test.</param>
- /// <param name="r">The decode method</param>
- /// <param name="w">The encode method</param>
- private void TestRead<T>(T t, Decode<T> r, Encode<T> w, int size)
- {
- MemoryStream iostr = new MemoryStream();
- Encoder e = new BinaryEncoder(iostr);
- w(e, t);
- iostr.Flush();
- Assert.AreEqual(size, iostr.Length);
- iostr.Position = 0;
- Decoder d = new BinaryDecoder(iostr);
- T actual = r(d);
- Assert.AreEqual(t, actual);
- Assert.AreEqual(-1, iostr.ReadByte());
- iostr.Close();
- }
-
- /// <summary>
- /// Writes an avro type T with value t into a stream using the encode method e
- /// and reads it back using the decode method d and verifies that
- /// the value read back is the same as the one written in.
- /// </summary>
- /// <typeparam name="T">Avro type to test</typeparam>
- /// <param name="t">Value for the Avro type to test.</param>
- /// <param name="r">The skip method</param>
- /// <param name="w">The encode method</param>
- private void TestSkip<T>(T t, Skip<T> s, Encode<T> w, int size)
- {
- MemoryStream iostr = new MemoryStream();
- Encoder e = new BinaryEncoder(iostr);
- w(e, t);
- iostr.Flush();
- Assert.AreEqual(size, iostr.Length);
- iostr.Position = 0;
- Decoder d = new BinaryDecoder(iostr);
- s(d);
- Assert.AreEqual(-1, iostr.ReadByte());
- iostr.Close();
- }
-
-
- [TestCase(true)]
- [TestCase(false)]
- public void TestBoolean(bool b)
- {
- TestRead(b, (Decoder d) => d.ReadBoolean(), (Encoder e, bool t) => e.WriteBoolean(t), 1);
- TestSkip(b, (Decoder d) => d.SkipBoolean(), (Encoder e, bool t) => e.WriteBoolean(t), 1);
- }
-
- [TestCase(0, 1)]
- [TestCase(1, 1)]
- [TestCase(63, 1)]
- [TestCase(64, 2)]
- [TestCase(8191, 2)]
- [TestCase(8192, 3)]
- [TestCase(1048575, 3)]
- [TestCase(1048576, 4)]
- [TestCase(134217727, 4)]
- [TestCase(134217728, 5)]
- [TestCase(2147483647, 5)]
- [TestCase(-1, 1)]
- [TestCase(-64, 1)]
- [TestCase(-65, 2)]
- [TestCase(-8192, 2)]
- [TestCase(-8193, 3)]
- [TestCase(-1048576, 3)]
- [TestCase(-1048577, 4)]
- [TestCase(-134217728, 4)]
- [TestCase(-134217729, 5)]
- [TestCase(-2147483648, 5)]
- public void TestInt(int n, int size)
- {
- TestRead(n, (Decoder d) => d.ReadInt(), (Encoder e, int t) => e.WriteInt(t), size);
- TestSkip(n, (Decoder d) => d.SkipInt(), (Encoder e, int t) => e.WriteInt(t), size);
- }
-
- [TestCase(0, 1)]
- [TestCase(1, 1)]
- [TestCase(63, 1)]
- [TestCase(64, 2)]
- [TestCase(8191, 2)]
- [TestCase(8192, 3)]
- [TestCase(1048575, 3)]
- [TestCase(1048576, 4)]
- [TestCase(134217727, 4)]
- [TestCase(134217728, 5)]
- [TestCase(17179869183L, 5)]
- [TestCase(17179869184L, 6)]
- [TestCase(2199023255551L, 6)]
- [TestCase(2199023255552L, 7)]
- [TestCase(281474976710655L, 7)]
- [TestCase(281474976710656L, 8)]
- [TestCase(36028797018963967L, 8)]
- [TestCase(36028797018963968L, 9)]
- [TestCase(4611686018427387903L, 9)]
- [TestCase(4611686018427387904L, 10)]
- [TestCase(9223372036854775807L, 10)]
- [TestCase(-1, 1)]
- [TestCase(-64, 1)]
- [TestCase(-65, 2)]
- [TestCase(-8192, 2)]
- [TestCase(-8193, 3)]
- [TestCase(-1048576, 3)]
- [TestCase(-1048577, 4)]
- [TestCase(-134217728, 4)]
- [TestCase(-134217729, 5)]
- [TestCase(-17179869184L, 5)]
- [TestCase(-17179869185L, 6)]
- [TestCase(-2199023255552L, 6)]
- [TestCase(-2199023255553L, 7)]
- [TestCase(-281474976710656L, 7)]
- [TestCase(-281474976710657L, 8)]
- [TestCase(-36028797018963968L, 8)]
- [TestCase(-36028797018963969L, 9)]
- [TestCase(-4611686018427387904L, 9)]
- [TestCase(-4611686018427387905L, 10)]
- [TestCase(-9223372036854775808L, 10)]
- public void TestLong(long n, int size)
- {
- TestRead(n, (Decoder d) => d.ReadLong(), (Encoder e, long t) => e.WriteLong(t), size);
- TestSkip(n, (Decoder d) => d.SkipLong(), (Encoder e, long t) => e.WriteLong(t), size);
- }
-
- [TestCase(0.0f)]
- [TestCase(Single.MaxValue, Description = "Max value")]
- [TestCase(1.17549435E-38f, Description = "Min 'normal' value")]
- [TestCase(1.4e-45f, Description = "Min value")]
- public void TestFloat(float n)
- {
- TestRead(n, (Decoder d) => d.ReadFloat(), (Encoder e, float t) => e.WriteFloat(t), 4);
- TestSkip(n, (Decoder d) => d.SkipFloat(), (Encoder e, float t) => e.WriteFloat(t), 4);
- }
-
- [TestCase(0.0)]
- [TestCase(1.7976931348623157e+308, Description = "Max value")]
- [TestCase(2.2250738585072014E-308, Description = "Min 'normal' value")]
- [TestCase(4.9e-324, Description = "Min value")]
- public void TestDouble(double n)
- {
- TestRead(n, (Decoder d) => d.ReadDouble(), (Encoder e, double t) => e.WriteDouble(t), 8);
- TestSkip(n, (Decoder d) => d.SkipDouble(), (Encoder e, double t) => e.WriteDouble(t), 8);
- }
-
-
- [TestCase(0, 1)]
- [TestCase(5, 1)]
- [TestCase(63, 1)]
- [TestCase(64, 2)]
- [TestCase(8191, 2)]
- [TestCase(8192, 3)]
- public void TestBytes(int length, int overhead)
- {
- Random r = new Random();
- byte[] b = new byte[length];
- r.NextBytes(b);
- TestRead(b, (Decoder d) => d.ReadBytes(), (Encoder e, byte[] t) => e.WriteBytes(t), overhead + b.Length);
- TestSkip(b, (Decoder d) => d.SkipBytes(), (Encoder e, byte[] t) => e.WriteBytes(t), overhead + b.Length);
- }
-
- [TestCase("", 1)]
- [TestCase("hello", 1)]
- [TestCase("1234567890123456789012345678901234567890123456789012345678901234", 2)]
- public void TestString(string n, int overhead)
- {
- TestRead(n, (Decoder d) => d.ReadString(), (Encoder e, string t) => e.WriteString(t), overhead + n.Length);
- TestSkip(n, (Decoder d) => d.SkipString(), (Encoder e, string t) => e.WriteString(t), overhead + n.Length);
- }
-
- [TestCase(0, 1)]
- [TestCase(1, 1)]
- [TestCase(64, 2)]
- public void TestEnum(int n, int size)
- {
- TestRead(n, (Decoder d) => d.ReadEnum(), (Encoder e, int t) => e.WriteEnum(t), size);
- TestSkip(n, (Decoder d) => d.SkipEnum(), (Encoder e, int t) => e.WriteEnum(t), size);
- }
-
- [TestCase(1, new int[] { })]
- [TestCase(3, new int[] { 0 })]
- [TestCase(4, new int[] { 64 })]
- public void TestArray(int size, int[] entries)
- {
- TestRead(entries, (Decoder d) =>
- {
- int[] t = new int[entries.Length];
- int j = 0;
- for (long n = d.ReadArrayStart(); n != 0; n = d.ReadArrayNext())
- {
- for (int i = 0; i < n; i++) { t[j++] = d.ReadInt(); }
-
- }
- return t;
- },
- (Encoder e, int[] t) =>
- {
- e.WriteArrayStart();
- e.SetItemCount(t.Length);
- foreach (int i in t) { e.StartItem(); e.WriteInt(i); } e.WriteArrayEnd();
- }, size);
-
- TestSkip(entries, (Decoder d) =>
- {
- for (long n = d.ReadArrayStart(); n != 0; n = d.ReadArrayNext())
- {
- for (int i = 0; i < n; i++) { d.SkipInt(); }
-
- }
- },
- (Encoder e, int[] t) =>
- {
- e.WriteArrayStart();
- e.SetItemCount(t.Length);
- foreach (int i in t) { e.StartItem(); e.WriteInt(i); } e.WriteArrayEnd();
- }, size);
- }
-
- [TestCase(1, new string[] { })]
- [TestCase(6, new string[] { "a", "b" })]
- [TestCase(9, new string[] { "a", "b", "c", "" })]
- public void TestMap(int size, string[] entries)
- {
- TestRead(entries, (Decoder d) =>
- {
- string[] t = new string[entries.Length];
- int j = 0;
- for (long n = d.ReadArrayStart(); n != 0; n = d.ReadArrayNext())
- {
- for (int i = 0; i < n; i++) { t[j++] = d.ReadString(); t[j++] = d.ReadString(); }
-
- }
- return t;
- },
- (Encoder e, string[] t) =>
- {
- e.WriteArrayStart();
- e.SetItemCount(t.Length / 2);
- for (int i = 0; i < t.Length; i += 2)
- {
- e.StartItem(); e.WriteString(t[i]); e.WriteString(t[i + 1]);
- }
- e.WriteArrayEnd();
- }, size);
-
- TestSkip(entries, (Decoder d) =>
- {
- for (long n = d.ReadArrayStart(); n != 0; n = d.ReadArrayNext())
- {
- for (int i = 0; i < n; i++) { d.SkipString(); d.SkipString(); }
-
- }
- },
- (Encoder e, string[] t) =>
- {
- e.WriteArrayStart();
- e.SetItemCount(t.Length / 2);
- for (int i = 0; i < t.Length; i += 2)
- {
- e.StartItem(); e.WriteString(t[i]); e.WriteString(t[i + 1]);
- }
- e.WriteArrayEnd();
- }, size);
- }
-
- [TestCase(0, 1)]
- [TestCase(1, 1)]
- [TestCase(64, 2)]
- public void TestUnionIndex(int n, int size)
- {
- TestRead(n, (Decoder d) => d.ReadUnionIndex(), (Encoder e, int t) => e.WriteUnionIndex(t), size);
- TestSkip(n, (Decoder d) => d.SkipUnionIndex(), (Encoder e, int t) => e.WriteUnionIndex(t), size);
- }
-
- [TestCase(0)]
- [TestCase(1)]
- [TestCase(64)]
- public void TestFixed(int size)
- {
- byte[] b = new byte[size];
- new Random().NextBytes(b);
- TestRead(b, (Decoder d) => { byte[] t = new byte[size]; d.ReadFixed(t); return t; },
- (Encoder e, byte[] t) => e.WriteFixed(t), size);
- TestSkip(b, (Decoder d) => d.SkipFixed(size),
- (Encoder e, byte[] t) => e.WriteFixed(t), size);
- }
- }
-}
diff --git a/lang/csharp/src/apache/test/Properties/AssemblyInfo.cs b/lang/csharp/src/apache/test/Properties/AssemblyInfo.cs
deleted file mode 100644
index 0741dbc..0000000
--- a/lang/csharp/src/apache/test/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * 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.
- */
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("Avro.test")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("Apache.org")]
-[assembly: AssemblyProduct("Avro.test")]
-[assembly: AssemblyCopyright("Copyright © Apache 2010")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("9c47069f-9d58-4815-bfea-f7dac9a48b05")]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("0.9.0.0")]
-[assembly: AssemblyFileVersion("0.9.0.0")]
diff --git a/lang/csharp/src/apache/test/Protocol/ProtocolTest.cs b/lang/csharp/src/apache/test/Protocol/ProtocolTest.cs
deleted file mode 100644
index 3c6c00b..0000000
--- a/lang/csharp/src/apache/test/Protocol/ProtocolTest.cs
+++ /dev/null
@@ -1,445 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.IO;
-using NUnit.Framework;
-using Avro;
-
-namespace Avro.Test
-{
- [TestFixture]
- public class ProtocolTest
- {
- [TestCase(@"{
- ""protocol"": ""TestProtocol"",
- ""namespace"": ""com.acme"",
- ""doc"": ""HelloWorld"",
-
- ""types"": [
- {""name"": ""Greeting"", ""type"": ""record"", ""fields"": [
- {""name"": ""message"", ""type"": ""string""}]},
- {""name"": ""Curse"", ""type"": ""error"", ""fields"": [
- {""name"": ""message"", ""type"": ""string""}]},
- {""name"": ""CurseMore"", ""type"": ""error"", ""fields"": [
- {""name"": ""message"", ""type"": ""string""}]}
- ],
-
- ""messages"": {
- ""hello"": {
- ""request"": [{""name"": ""greeting"", ""type"": ""Greeting"" }],
- ""response"": ""Greeting"",
- ""errors"": [""Curse"", ""CurseMore""]
- }
- }
-}", true)]
- [TestCase(@"{
- ""protocol"" : ""MyProtocol"",
- ""namespace"" : ""com.foo"",
- ""types"" : [
- {
- ""type"" : ""record"",
- ""name"" : ""A"",
- ""fields"" : [ { ""name"" : ""f1"", ""type"" : ""long"" } ]
- },
- {
- ""type"" : ""enum"",
- ""name"" : ""MyEnum"",
- ""symbols"" : [ ""A"", ""B"", ""C"" ]
- },
- {
- ""type"": ""fixed"",
- ""size"": 16,
- ""name"": ""MyFixed""
- },
- {
- ""type"" : ""record"",
- ""name"" : ""Z"",
- ""fields"" :
- [
- { ""name"" : ""myUInt"", ""type"" : [ ""int"", ""null"" ] },
- { ""name"" : ""myULong"", ""type"" : [ ""long"", ""null"" ] },
- { ""name"" : ""myUBool"", ""type"" : [ ""boolean"", ""null"" ] },
- { ""name"" : ""myUDouble"", ""type"" : [ ""double"", ""null"" ] },
- { ""name"" : ""myUFloat"", ""type"" : [ ""float"", ""null"" ] },
- { ""name"" : ""myUBytes"", ""type"" : [ ""bytes"", ""null"" ] },
- { ""name"" : ""myUString"", ""type"" : [ ""string"", ""null"" ] },
-
- { ""name"" : ""myInt"", ""type"" : ""int"" },
- { ""name"" : ""myLong"", ""type"" : ""long"" },
- { ""name"" : ""myBool"", ""type"" : ""boolean"" },
- { ""name"" : ""myDouble"", ""type"" : ""double"" },
- { ""name"" : ""myFloat"", ""type"" : ""float"" },
- { ""name"" : ""myBytes"", ""type"" : ""bytes"" },
- { ""name"" : ""myString"", ""type"" : ""string"" },
- { ""name"" : ""myNull"", ""type"" : ""null"" },
-
- { ""name"" : ""myFixed"", ""type"" : ""MyFixed"" },
- { ""name"" : ""myFixed2"", ""type"" : ""MyFixed"" },
- { ""name"" : ""myA"", ""type"" : ""A"" },
- { ""name"" : ""myE"", ""type"" : ""MyEnum"" },
- { ""name"" : ""myArray"", ""type"" : { ""type"" : ""array"", ""items"" : ""bytes"" } },
- { ""name"" : ""myArray2"", ""type"" : { ""type"" : ""array"", ""items"" : { ""type"" : ""record"", ""name"" : ""newRec"", ""fields"" : [ { ""name"" : ""f1"", ""type"" : ""long""} ] } } },
- { ""name"" : ""myMap"", ""type"" : { ""type"" : ""map"", ""values"" : ""string"" } },
- { ""name"" : ""myMap2"", ""type"" : { ""type"" : ""map"", ""values"" : ""newRec"" } },
- { ""name"" : ""myObject"", ""type"" : [ ""MyEnum"", ""A"", ""null"" ] },
- { ""name"" : ""next"", ""type"" : [ ""A"", ""null"" ] }
- ]
- } ,
- {
- ""type"" : ""int""
- }
- ]
-}", true)]
- [TestCase(@"{
- ""protocol"" : ""MyProtocol"",
- ""namespace"" : ""com.bar"",
- ""types"" : [
- {
- ""type"" : ""record"",
- ""name"" : ""A"",
- ""fields"" :
- [
- { ""name"" : ""f1"", ""type"" : ""long"" }
- ]
- },
- {
- ""type"" : ""enum"",
- ""name"" : ""MyEnum"",
- ""symbols"" : [ ""A"", ""B"", ""C"" ]
- },
- {
- ""type"": ""fixed"",
- ""size"": 16,
- ""name"": ""MyFixed""
- },
- {
- ""type"" : ""record"",
- ""name"" : ""Z"",
- ""fields"" :
- [
- { ""name"" : ""myUInt"", ""type"" : [ ""int"", ""null"" ], ""default"" : 1 },
- { ""name"" : ""myULong"", ""type"" : [ ""long"", ""null"" ], ""default"" : 2 },
- { ""name"" : ""myUBool"", ""type"" : [ ""boolean"", ""null"" ], ""default"" : true },
- { ""name"" : ""myUDouble"", ""type"" : [ ""double"", ""null"" ], ""default"" : 3 },
- { ""name"" : ""myUFloat"", ""type"" : [ ""float"", ""null"" ], ""default"" : 4.5 },
- { ""name"" : ""myUBytes"", ""type"" : [ ""bytes"", ""null"" ], ""default"" : ""\u00ff"" },
- { ""name"" : ""myUString"", ""type"" : [ ""string"", ""null"" ], ""default"" : ""foo"" },
-
- { ""name"" : ""myInt"", ""type"" : ""int"", ""default"" : 10 },
- { ""name"" : ""myLong"", ""type"" : ""long"", ""default"" : 11 },
- { ""name"" : ""myBool"", ""type"" : ""boolean"", ""default"" : false },
- { ""name"" : ""myDouble"", ""type"" : ""double"", ""default"" : 12 },
- { ""name"" : ""myFloat"", ""type"" : ""float"", ""default"" : 13.14 },
- { ""name"" : ""myBytes"", ""type"" : ""bytes"", ""default"" : ""\u00ff"" },
- { ""name"" : ""myString"", ""type"" : ""string"", ""default"" : ""bar"" },
- { ""name"" : ""myNull"", ""type"" : ""null"", ""default"" : null },
-
- { ""name"" : ""myFixed"", ""type"" : ""MyFixed"", ""default"" : ""\u00FFFFFFFFFFFFFFFFA"" },
- { ""name"" : ""myFixed2"", ""type"" : ""MyFixed"", ""default"" : ""\u00FFFFFFFFFFFFFFFFA"" },
- { ""name"" : ""myA"", ""type"" : ""A"", ""default"" : {""f1"":5} },
- { ""name"" : ""myE"", ""type"" : ""MyEnum"", ""default"" : ""C"" },
- { ""name"" : ""myArray"", ""type"" : { ""type"" : ""array"", ""items"" : ""bytes"" }, ""default"" : [ ""a12b"", ""cc50"" ] },
- { ""name"" : ""myArray2"", ""type"" : { ""type"" : ""array"", ""items"" : { ""type"" : ""record"", ""name"" : ""newRec"", ""fields"" : [ { ""name"" : ""f2"", ""type"" : ""long""} ], ""default"" : {""f2"":5} } }, ""default"" : [ {""f2"":6}, {""f2"":7} ] },
- { ""name"" : ""myMap"", ""type"" : { ""type"" : ""map"", ""values"" : ""string"" }, ""default"" : {""a"":""A"", ""b"":""B""} },
- { ""name"" : ""myMap2"", ""type"" : { ""type"" : ""map"", ""values"" : ""newRec"" }, ""default"" : { ""key1"":{""f2"":6}, ""key2"":{""f2"":7} } },
- { ""name"" : ""myObject"", ""type"" : [ ""MyEnum"", ""A"", ""null"" ], ""default"" : ""A"" },
- { ""name"" : ""next"", ""type"" : [ ""null"" , ""A"" ], ""default"" : null }
- ]
- } ,
- {
- ""type"" : ""int""
- }
- ]
-}", true)]
- public static void TestProtocol(string str, bool valid)
- {
- Protocol protocol = Protocol.Parse(str);
- Assert.IsTrue(valid);
- string json = protocol.ToString();
-
- Protocol protocol2 = Protocol.Parse(json);
- string json2 = protocol2.ToString();
-
- Assert.AreEqual(json,json2);
- }
-
- // Protocols match
- [TestCase(
-@"{
- ""protocol"": ""TestProtocol"",
- ""namespace"": ""com.acme"",
-
- ""types"": [
- {""name"": ""Greeting"", ""type"": ""record"", ""fields"": [
- {""name"": ""message"", ""type"": ""string""}]},
- {""name"": ""Curse"", ""type"": ""error"", ""fields"": [
- {""name"": ""message"", ""type"": ""string""}]}
- ],
-
- ""messages"": {
- ""hello"": {
- ""request"": [{""name"": ""greeting"", ""type"": ""Greeting"" }],
- ""response"": ""Greeting"",
- ""errors"": [""Curse""]
- }
- }
-}",
-@"{
- ""protocol"": ""TestProtocol"",
- ""namespace"": ""com.acme"",
-
- ""types"": [
- {""name"": ""Greeting"", ""type"": ""record"", ""fields"": [
- {""name"": ""message"", ""type"": ""string""}]},
- {""name"": ""Curse"", ""type"": ""error"", ""fields"": [
- {""name"": ""message"", ""type"": ""string""}]}
- ],
-
- ""messages"": {
- ""hello"": {
- ""request"": [{""name"": ""greeting"", ""type"": ""Greeting"" }],
- ""response"": ""Greeting"",
- ""errors"": [""Curse""]
- }
- }
-}",
- true,true)]
- // Protocols match, order of schemas in 'types' are different
- [TestCase(
-@"{
- ""protocol"": ""TestProtocol"",
- ""namespace"": ""com.acme"",
-
- ""types"": [
- {""name"": ""Curse"", ""type"": ""error"", ""fields"": [
- {""name"": ""message"", ""type"": ""string""}]},
- {""name"": ""Greeting"", ""type"": ""record"", ""fields"": [
- {""name"": ""message"", ""type"": ""string""}]}
- ],
-
- ""messages"": {
- ""hello"": {
- ""request"": [{""name"": ""greeting"", ""type"": ""Greeting"" }],
- ""response"": ""Greeting"",
- ""errors"": [""Curse""]
- }
- }
-}",
-@"{
- ""protocol"": ""TestProtocol"",
- ""namespace"": ""com.acme"",
-
- ""types"": [
- {""name"": ""Greeting"", ""type"": ""record"", ""fields"": [
- {""name"": ""message"", ""type"": ""string""}]},
- {""name"": ""Curse"", ""type"": ""error"", ""fields"": [
- {""name"": ""message"", ""type"": ""string""}]}
- ],
-
- ""messages"": {
- ""hello"": {
- ""request"": [{""name"": ""greeting"", ""type"": ""Greeting"" }],
- ""response"": ""Greeting"",
- ""errors"": [""Curse""]
- }
- }
-}",
- false,true)]
- // Name of protocol is different
- [TestCase(
-@"{
- ""protocol"": ""TestProtocol1"",
- ""namespace"": ""com.acme"",
-
- ""types"": [
- {""name"": ""Greeting"", ""type"": ""record"", ""fields"": [
- {""name"": ""message"", ""type"": ""string""}]},
- {""name"": ""Curse"", ""type"": ""error"", ""fields"": [
- {""name"": ""message"", ""type"": ""string""}]}
- ],
-
- ""messages"": {
- ""hello"": {
- ""request"": [{""name"": ""greeting"", ""type"": ""Greeting"" }],
- ""response"": ""Greeting"",
- ""errors"": [""Curse""]
- }
- }
-}",
-@"{
- ""protocol"": ""TestProtocol"",
- ""namespace"": ""com.acme"",
-
- ""types"": [
- {""name"": ""Greeting"", ""type"": ""record"", ""fields"": [
- {""name"": ""message"", ""type"": ""string""}]},
- {""name"": ""Curse"", ""type"": ""error"", ""fields"": [
- {""name"": ""message"", ""type"": ""string""}]}
- ],
-
- ""messages"": {
- ""hello"": {
- ""request"": [{""name"": ""greeting"", ""type"": ""Greeting"" }],
- ""response"": ""Greeting"",
- ""errors"": [""Curse""]
- }
- }
-}",
- false,false)]
- // Name of a message request is different: 'hi'
- [TestCase(
-@"{
- ""protocol"": ""TestProtocol"",
- ""namespace"": ""com.acme"",
-
- ""types"": [
- {""name"": ""Greeting"", ""type"": ""record"", ""fields"": [
- {""name"": ""message"", ""type"": ""string""}]},
- {""name"": ""Curse"", ""type"": ""error"", ""fields"": [
- {""name"": ""message"", ""type"": ""string""}]}
- ],
-
- ""messages"": {
- ""hello"": {
- ""request"": [{""name"": ""greeting"", ""type"": ""Greeting"" }],
- ""response"": ""Greeting"",
- ""errors"": [""Curse""]
- }
- }
-}",
-@"{
- ""protocol"": ""TestProtocol"",
- ""namespace"": ""com.acme"",
-
- ""types"": [
- {""name"": ""Greeting"", ""type"": ""record"", ""fields"": [
- {""name"": ""message"", ""type"": ""string""}]},
- {""name"": ""Curse"", ""type"": ""error"", ""fields"": [
- {""name"": ""message"", ""type"": ""string""}]}
- ],
-
- ""messages"": {
- ""hi"": {
- ""request"": [{""name"": ""greeting"", ""type"": ""Greeting"" }],
- ""response"": ""Greeting"",
- ""errors"": [""Curse""]
- }
- }
-}",
- false,false)]
- // Name of a type is different : Curse1
- [TestCase(
-@"{
- ""protocol"": ""TestProtocol"",
- ""namespace"": ""com.acme"",
-
- ""types"": [
- {""name"": ""Greeting"", ""type"": ""record"", ""fields"": [
- {""name"": ""message"", ""type"": ""string""}]},
- {""name"": ""Curse1"", ""type"": ""error"", ""fields"": [
- {""name"": ""message"", ""type"": ""string""}]}
- ],
-
- ""messages"": {
- ""hello"": {
- ""request"": [{""name"": ""greeting"", ""type"": ""Greeting"" }],
- ""response"": ""Greeting"",
- ""errors"": [""Curse1""]
- }
- }
-}",
-@"{
- ""protocol"": ""TestProtocol"",
- ""namespace"": ""com.acme"",
-
- ""types"": [
- {""name"": ""Greeting"", ""type"": ""record"", ""fields"": [
- {""name"": ""message"", ""type"": ""string""}]},
- {""name"": ""Curse"", ""type"": ""error"", ""fields"": [
- {""name"": ""message"", ""type"": ""string""}]}
- ],
-
- ""messages"": {
- ""hi"": {
- ""request"": [{""name"": ""greeting"", ""type"": ""Greeting"" }],
- ""response"": ""Greeting"",
- ""errors"": [""Curse""]
- }
- }
-}",
- false,false)]
- // Name of a record field is different: 'mymessage'
- [TestCase(
-@"{
- ""protocol"": ""TestProtocol"",
- ""namespace"": ""com.acme"",
-
- ""types"": [
- {""name"": ""Greeting"", ""type"": ""record"", ""fields"": [
- {""name"": ""message"", ""type"": ""string""}]},
- {""name"": ""Curse"", ""type"": ""error"", ""fields"": [
- {""name"": ""message"", ""type"": ""string""}]}
- ],
-
- ""messages"": {
- ""hello"": {
- ""request"": [{""name"": ""greeting"", ""type"": ""Greeting"" }],
- ""response"": ""Greeting"",
- ""errors"": [""Curse""]
- }
- }
-}",
-@"{
- ""protocol"": ""TestProtocol"",
- ""namespace"": ""com.acme"",
-
- ""types"": [
- {""name"": ""Greeting"", ""type"": ""record"", ""fields"": [
- {""name"": ""message"", ""type"": ""string""}]},
- {""name"": ""Curse"", ""type"": ""error"", ""fields"": [
- {""name"": ""mymessage"", ""type"": ""string""}]}
- ],
-
- ""messages"": {
- ""hi"": {
- ""request"": [{""name"": ""greeting"", ""type"": ""Greeting"" }],
- ""response"": ""Greeting"",
- ""errors"": [""Curse""]
- }
- }
-}",
- false,false)]
- public static void TestProtocolHash(string str1, string str2, bool md5_equal, bool hash_equal)
- {
- Protocol protocol1 = Protocol.Parse(str1);
- Protocol protocol2 = Protocol.Parse(str2);
-
- byte[] md51 = protocol1.MD5;
- byte[] md52 = protocol2.MD5;
-
- int hash1 = protocol1.GetHashCode();
- int hash2 = protocol2.GetHashCode();
-
- Assert.AreEqual(md5_equal, md51.SequenceEqual(md52));
- Assert.AreEqual(hash_equal, hash1 == hash2);
- }
- }
-}
diff --git a/lang/csharp/src/apache/test/Schema/AliasTest.cs b/lang/csharp/src/apache/test/Schema/AliasTest.cs
deleted file mode 100644
index e8aeed7..0000000
--- a/lang/csharp/src/apache/test/Schema/AliasTest.cs
+++ /dev/null
@@ -1,239 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using NUnit.Framework;
-using Avro;
-
-namespace Avro.Test
-{
- [TestFixture]
- public class AliasTest
- {
- [TestCase(@"{""type"":""record"",""name"":""LongList"", ""namespace"":""com"", ""aliases"":[""c"",""foo.y""],
- ""fields"":
- [{""name"":""f1"",""type"":""long"", ""extraprop"":""important"", ""id"":""1029"", ""aliases"":[""a"",""b"",""c""] },
- {""name"":""f2"",""type"": ""int""}]}",
- true)]
- [TestCase(@"{""type"":""record"",""name"":""LongList"", ""aliases"":[""Alias1""],
- ""fields"":[{""name"":""f1"",""type"":""long"", ""order"":""junk"" },
- {""name"":""f2"",""type"": ""int""}]}",
- false)]
- [TestCase(@"{""type"":""record"",""name"":""LongList"", ""aliases"":[""Alias1""], ""customprop"":""123456"",
- ""fields"":[{""name"":""f1"",""type"":""long"", ""order"":""ascending"", ""fprop"":""faaa"" },
- {""name"":""f2"",""type"": ""int""}]}",
- true)]
- [TestCase(@"{""type"":""record"",""name"":""LongList"", ""aliases"":[""Alias1""],
- ""fields"":[{""name"":""f1"",""type"":""long""},
- {""name"":""f2"",""type"": ""int""}]}",
- true)]
- [TestCase(@"{""type"":""record"",""name"":""LongList"", ""aliases"":[""Alias1"",""Alias2""],
- ""fields"":[{""name"":""f1"",""type"":""long""},
- {""name"":""f2"",""type"": ""int""}]}",
- true)]
- [TestCase(@"{""type"":""record"",""name"":""LongList"", ""aliases"":[""Alias1"",9],
- ""fields"":[{""name"":""f1"",""type"":""long""},
- {""name"":""f2"",""type"": ""int""}]}",
- false)]
- [TestCase(@"{""type"":""record"",""name"":""LongList"", ""aliases"":[1, 2],
- ""fields"":[{""name"":""f1"",""type"":""long"", ""default"": ""100""},
- {""name"":""f2"",""type"": ""int""}]}",
- false)]
- [TestCase(@"{""type"":""record"",""name"":""LongList"", ""aliases"": ""wrong alias format"",
- ""fields"":[{""name"":""value"",""type"":""long"", ""default"": ""100""},
- {""name"":""next"",""type"":[""LongList"",""null""]}]}",
- false)]
- public void TestAliases(string s, bool valid) // also tests properties, default, order
- {
- try
- {
- Schema sc = Schema.Parse(s);
- Assert.IsTrue(valid);
-
- string json = sc.ToString();
- Schema sc2 = Schema.Parse(json);
- string json2 = sc2.ToString();
-
- Assert.IsTrue(json == json2);
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- Assert.IsFalse(valid);
- }
- }
-
- // Enum
- [TestCase(@"{""type"":""enum"",""name"":""Symbols"", ""symbols"" : [ ""A"", ""B"", ""C"" ] }",
- @"{""type"":""enum"",""name"":""Symbols"", ""symbols"" : [ ""A"", ""B"", ""C"" ] }",
- true)]
- [TestCase(@"{""type"":""enum"",""name"":""Symbols"", ""symbols"" : [ ""A"", ""B"", ""C"" ] }",
- @"{""type"":""enum"",""name"":""NewSymbols"", ""symbols"" : [ ""A"", ""B"", ""C"" ] }",
- false)]
- [TestCase(@"{""type"":""enum"",""name"":""Symbols"", ""aliases"" : [""NewSymbols""], ""symbols"" : [ ""A"", ""B"", ""C"" ] }",
- @"{""type"":""enum"",""name"":""NewSymbols"", ""symbols"" : [ ""A"", ""B"", ""C"" ] }",
- true)]
- [TestCase(@"{""type"":""enum"",""name"":""Symbols"", ""aliases"" : [""DiffSymbols"", ""OtherSymbols""], ""symbols"" : [ ""A"", ""B"", ""C"" ] }",
- @"{""type"":""enum"",""name"":""NewSymbols"", ""symbols"" : [ ""A"", ""B"", ""C"" ] }",
- false)]
- public void TestEnumAliasesResolution(string reader, string writer, bool canread)
- {
- try
- {
- Schema rs = Schema.Parse(reader);
- Schema ws = Schema.Parse(writer);
- Assert.IsTrue(rs.CanRead(ws) == canread);
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- Assert.IsTrue(false);
- }
- }
-
- // Fixed
- [TestCase(@"{""type"": ""fixed"", ""name"": ""Fixed"", ""size"": 1}",
- @"{""type"": ""fixed"", ""name"": ""Fixed"", ""size"": 1}",
- true)]
- [TestCase(@"{""type"": ""fixed"", ""name"": ""Fixed"", ""size"": 1}",
- @"{""type"": ""fixed"", ""name"": ""NewFixed"", ""size"": 1}",
- false)]
- [TestCase(@"{""type"": ""fixed"", ""name"": ""Fixed"", ""aliases"" : [""NewFixed""], ""size"": 1}",
- @"{""type"": ""fixed"", ""name"": ""NewFixed"", ""size"": 1}",
- true)]
- [TestCase(@"{""type"": ""fixed"", ""name"": ""Fixed"", ""aliases"" : [""DiffFixed"", ""OtherFixed""], ""size"": 1}",
- @"{""type"": ""fixed"", ""name"": ""NewFixed"", ""size"": 1}",
- false)]
- public void TestFixedAliasesResolution(string reader, string writer, bool canread)
- {
- try
- {
- Schema rs = Schema.Parse(reader);
- Schema ws = Schema.Parse(writer);
- Assert.IsTrue(rs.CanRead(ws) == canread);
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- Assert.IsTrue(false);
- }
- }
-
- // Records
- [TestCase(1,@"{""type"":""record"",""name"":""Rec"",
- ""fields"":[{""name"":""f1"",""type"":""long"" },
- {""name"":""f2"",""type"": ""int""}]}",
- @"{""type"":""record"",""name"":""Rec"",
- ""fields"":[{""name"":""f1"",""type"":""long"" },
- {""name"":""f2"",""type"": ""int""}]}",
- true)]
- [TestCase(2,@"{""type"":""record"",""name"":""Rec"",
- ""fields"":[{""name"":""f1"",""type"":""long"" },
- {""name"":""f2"",""type"": ""int""}]}",
- @"{""type"":""record"",""name"":""NewRec"",
- ""fields"":[{""name"":""f1"",""type"":""long"" },
- {""name"":""f2"",""type"": ""int""}]}",
- false)]
- [TestCase(3,@"{""type"":""record"",""name"":""Rec"", ""aliases"":[""NewRec""],
- ""fields"":[{""name"":""f1"",""type"":""long"" },
- {""name"":""f2"",""type"": ""int""}]}",
- @"{""type"":""record"",""name"":""NewRec"",
- ""fields"":[{""name"":""f1"",""type"":""long"" },
- {""name"":""f2"",""type"": ""int""}]}",
- true)]
- [TestCase(4,@"{""type"":""record"",""name"":""Rec"", ""aliases"":[""OtherRec"",""DiffRec""],
- ""fields"":[{""name"":""f1"",""type"":""long"" },
- {""name"":""f2"",""type"": ""int""}]}",
- @"{""type"":""record"",""name"":""NewRec"",
- ""fields"":[{""name"":""f1"",""type"":""long"" },
- {""name"":""f2"",""type"": ""int""}]}",
- false)]
- [TestCase(5,@"{""type"":""record"",""name"":""Rec"",
- ""fields"":[{""name"":""f1"",""type"":""long"" },
- {""name"":""f3"",""type"": ""int""}]}",
- @"{""type"":""record"",""name"":""Rec"",
- ""fields"":[{""name"":""f1"",""type"":""long"" },
- {""name"":""f2"",""type"": ""int""}]}",
- false)]
- [TestCase(6,@"{""type"":""record"",""name"":""Rec"",
- ""fields"":[{""name"":""f1"",""type"":""long"" },
- {""name"":""f3"",""type"": ""int"", ""aliases"":[""f2""]}]}",
- @"{""type"":""record"",""name"":""Rec"",
- ""fields"":[{""name"":""f1"",""type"":""long"" },
- {""name"":""f2"",""type"": ""int""}]}",
- true)]
- [TestCase(7,@"{""type"":""record"",""name"":""Rec"",
- ""fields"":[{""name"":""f1"",""type"":""long"" },
- {""name"":""f3"",""type"": ""int"", ""aliases"":[""f4"",""f5""]}]}",
- @"{""type"":""record"",""name"":""Rec"",
- ""fields"":[{""name"":""f1"",""type"":""long"" },
- {""name"":""f2"",""type"": ""int""}]}",
- false)]
- [TestCase(8,@"{""type"":""record"",""name"":""Rec"",
- ""fields"":[{""name"":""f1"",""type"": {""type"":""enum"", ""name"":""Symbol"", ""symbols"":[""A""] }}]}",
- @"{""type"":""record"",""name"":""Rec"",
- ""fields"":[{""name"":""f1"",""type"": {""type"":""enum"", ""name"":""NewSymbol"", ""symbols"":[""A""] }}]}",
- false)]
- [TestCase(9,@"{""type"":""record"",""name"":""Rec"",
- ""fields"":[{""name"":""f1"",""type"": {""type"":""enum"", ""name"":""Symbol"", ""aliases"":[""NewSymbol""], ""symbols"":[""A""] }}]}",
- @"{""type"":""record"",""name"":""Rec"",
- ""fields"":[{""name"":""f1"",""type"": {""type"":""enum"", ""name"":""NewSymbol"", ""symbols"":[""A""] }}]}",
- true)]
- [TestCase(10,@"{""type"":""record"",""name"":""Rec"",
- ""fields"":[{""name"":""f1"",""type"": {""type"":""enum"", ""name"":""Symbol"", ""aliases"":[""DiffSymbol""], ""symbols"":[""A""] }}]}",
- @"{""type"":""record"",""name"":""Rec"",
- ""fields"":[{""name"":""f1"",""type"": {""type"":""enum"", ""name"":""NewSymbol"", ""symbols"":[""A""] }}]}",
- false)]
- [TestCase(11,@"{""type"":""record"",""name"":""Rec"",""aliases"":[""NewRec""],
- ""fields"":[{""name"":""f2"",""aliases"":[""f1""],""type"": {""type"":""enum"", ""name"":""Symbol"", ""aliases"":[""NewSymbol""], ""symbols"":[""A""] }},
- {""name"":""f3"",""aliases"":[""f4""],""type"": {""type"":""fixed"", ""name"":""Fixed"", ""aliases"":[""NewFixed""], ""size"": 1 }}
- ]}",
- @"{""type"":""record"",""name"":""NewRec"",
- ""fields"":[{""name"":""f1"",""type"": {""type"":""enum"", ""name"":""NewSymbol"", ""symbols"":[""A""] }},
- {""name"":""f4"",""type"": {""type"":""fixed"", ""name"":""NewFixed"", ""size"": 1 }}
- ]}",
- true)]
- [TestCase(12,@"{""type"":""record"",""name"":""Rec"",""aliases"":[""NewRec""],
- ""fields"":[{""name"":""f2"",""aliases"":[""f1""],""type"": {""type"":""enum"", ""name"":""Symbol"", ""aliases"":[""NewSymbol""], ""symbols"":[""A""] }},
- {""name"":""f3"",""aliases"":[""f4""],""type"": {""type"":""fixed"", ""name"":""Fixed"", ""aliases"":[""NewFixed""], ""size"":1 }}
- ]}",
- @"{""type"":""record"",""name"":""NewRec"",
- ""fields"":[{""name"":""f1"",""type"": {""type"":""enum"", ""name"":""NewSymbol"", ""symbols"":[""A"",""B""] }},
- {""name"":""f4"",""type"": {""type"":""fixed"", ""name"":""NewFixed"", ""size"":1 }}
- ]}",
- true)]
-
- public void TestRecordAliasesResolution(int testid, string reader, string writer, bool canread)
- {
- try
- {
- Schema rs = Schema.Parse(reader);
- Schema ws = Schema.Parse(writer);
- Assert.IsTrue(rs.CanRead(ws) == canread);
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- Assert.IsTrue(false);
- }
- }
-
- }
-}
diff --git a/lang/csharp/src/apache/test/Schema/SchemaTests.cs b/lang/csharp/src/apache/test/Schema/SchemaTests.cs
deleted file mode 100644
index b124831..0000000
--- a/lang/csharp/src/apache/test/Schema/SchemaTests.cs
+++ /dev/null
@@ -1,276 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.Collections.Generic;
-using System.Text;
-using NUnit.Framework;
-using Avro;
-
-namespace Avro.Test
-{
- [TestFixture]
- public class SchemaTests
- {
- // Primitive types - shorthand
- [TestCase("null")]
- [TestCase("boolean")]
- [TestCase("int")]
- [TestCase("long")]
- [TestCase("float")]
- [TestCase("double")]
- [TestCase("bytes")]
- [TestCase("string")]
-
- [TestCase("\"null\"")]
- [TestCase("\"boolean\"")]
- [TestCase("\"int\"")]
- [TestCase("\"long\"")]
- [TestCase("\"float\"")]
- [TestCase("\"double\"")]
- [TestCase("\"bytes\"")]
- [TestCase("\"string\"")]
-
- // Primitive types - longer
- [TestCase("{ \"type\": \"null\" }")]
- [TestCase("{ \"type\": \"boolean\" }")]
- [TestCase("{ \"type\": \"int\" }")]
- [TestCase("{ \"type\": \"long\" }")]
- [TestCase("{ \"type\": \"float\" }")]
- [TestCase("{ \"type\": \"double\" }")]
- [TestCase("{ \"type\": \"bytes\" }")]
- [TestCase("{ \"type\": \"string\" }")]
- // Record
- [TestCase("{\"type\": \"record\",\"name\": \"Test\",\"fields\": [{\"name\": \"f\",\"type\": \"long\"}]}")]
- [TestCase("{\"type\": \"record\",\"name\": \"Test\",\"fields\": " +
- "[{\"name\": \"f1\",\"type\": \"long\"},{\"name\": \"f2\", \"type\": \"int\"}]}")]
- [TestCase("{\"type\": \"error\",\"name\": \"Test\",\"fields\": " +
- "[{\"name\": \"f1\",\"type\": \"long\"},{\"name\": \"f2\", \"type\": \"int\"}]}")]
- [TestCase("{\"type\":\"record\",\"name\":\"LongList\"," +
- "\"fields\":[{\"name\":\"value\",\"type\":\"long\"},{\"name\":\"next\",\"type\":[\"LongList\",\"null\"]}]}")] // Recursive.
- [TestCase("{\"type\":\"record\",\"name\":\"LongList\"," +
- "\"fields\":[{\"name\":\"value\",\"type\":\"long\"},{\"name\":\"next\",\"type\":[\"LongListA\",\"null\"]}]}",
- Description = "Unknown name", ExpectedException = typeof(SchemaParseException))]
- [TestCase("{\"type\":\"record\",\"name\":\"LongList\"}",
- Description = "No fields", ExpectedException = typeof(SchemaParseException))]
- [TestCase("{\"type\":\"record\",\"name\":\"LongList\", \"fields\": \"hi\"}",
- Description = "Fields not an array", ExpectedException = typeof(SchemaParseException))]
-
- // Enum
- [TestCase("{\"type\": \"enum\", \"name\": \"Test\", \"symbols\": [\"A\", \"B\"]}")]
- [TestCase("{\"type\": \"enum\", \"name\": \"Status\", \"symbols\": \"Normal Caution Critical\"}",
- Description = "Symbols not an array", ExpectedException = typeof(SchemaParseException))]
- [TestCase("{\"type\": \"enum\", \"name\": [ 0, 1, 1, 2, 3, 5, 8 ], \"symbols\": [\"Golden\", \"Mean\"]}",
- Description = "Name not a string", ExpectedException = typeof(SchemaParseException))]
- [TestCase("{\"type\": \"enum\", \"symbols\" : [\"I\", \"will\", \"fail\", \"no\", \"name\"]}",
- Description = "No name", ExpectedException = typeof(SchemaParseException))]
- [TestCase("{\"type\": \"enum\", \"name\": \"Test\", \"symbols\" : [\"AA\", \"AA\"]}",
- Description = "Duplicate symbol", ExpectedException = typeof(SchemaParseException))]
-
- // Array
- [TestCase("{\"type\": \"array\", \"items\": \"long\"}")]
- [TestCase("{\"type\": \"array\",\"items\": {\"type\": \"enum\", \"name\": \"Test\", \"symbols\": [\"A\", \"B\"]}}")]
-
- // Map
- [TestCase("{\"type\": \"map\", \"values\": \"long\"}")]
- [TestCase("{\"type\": \"map\",\"values\": {\"type\": \"enum\", \"name\": \"Test\", \"symbols\": [\"A\", \"B\"]}}")]
-
- // Union
- [TestCase("[\"string\", \"null\", \"long\"]")]
- [TestCase("[\"string\", \"long\", \"long\"]",
- Description = "Duplicate type", ExpectedException = typeof(SchemaParseException))]
- [TestCase("[{\"type\": \"array\", \"items\": \"long\"}, {\"type\": \"array\", \"items\": \"string\"}]",
- Description = "Duplicate type", ExpectedException = typeof(SchemaParseException))]
- [TestCase("{\"type\":[\"string\", \"null\", \"long\"]}")]
-
- // Fixed
- [TestCase("{ \"type\": \"fixed\", \"name\": \"Test\", \"size\": 1}")]
- [TestCase("{\"type\": \"fixed\", \"name\": \"MyFixed\", \"namespace\": \"org.apache.hadoop.avro\", \"size\": 1}")]
- [TestCase("{ \"type\": \"fixed\", \"name\": \"Test\", \"size\": 1}")]
- [TestCase("{ \"type\": \"fixed\", \"name\": \"Test\", \"size\": 1}")]
- [TestCase("{\"type\": \"fixed\", \"name\": \"Missing size\"}", ExpectedException = typeof(SchemaParseException))]
- [TestCase("{\"type\": \"fixed\", \"size\": 314}",
- Description = "No name", ExpectedException = typeof(SchemaParseException))]
- public void TestBasic(string s)
- {
- Schema.Parse(s);
- }
-
- [TestCase("null", Schema.Type.Null)]
- [TestCase("boolean", Schema.Type.Boolean)]
- [TestCase("int", Schema.Type.Int)]
- [TestCase("long", Schema.Type.Long)]
- [TestCase("float", Schema.Type.Float)]
- [TestCase("double", Schema.Type.Double)]
- [TestCase("bytes", Schema.Type.Bytes)]
- [TestCase("string", Schema.Type.String)]
-
- [TestCase("{ \"type\": \"null\" }", Schema.Type.Null)]
- [TestCase("{ \"type\": \"boolean\" }", Schema.Type.Boolean)]
- [TestCase("{ \"type\": \"int\" }", Schema.Type.Int)]
- [TestCase("{ \"type\": \"long\" }", Schema.Type.Long)]
- [TestCase("{ \"type\": \"float\" }", Schema.Type.Float)]
- [TestCase("{ \"type\": \"double\" }", Schema.Type.Double)]
- [TestCase("{ \"type\": \"bytes\" }", Schema.Type.Bytes)]
- [TestCase("{ \"type\": \"string\" }", Schema.Type.String)]
- public void TestPrimitive(string s, Schema.Type type)
- {
- Schema sc = Schema.Parse(s);
- Assert.IsTrue(sc is PrimitiveSchema);
- Assert.AreEqual(type, sc.Tag);
-
- testEquality(s, sc);
- testToString(sc);
- }
-
- private static void testEquality(string s, Schema sc)
- {
- Assert.IsTrue(sc.Equals(sc));
- Schema sc2 = Schema.Parse(s);
- Assert.IsTrue(sc.Equals(sc2));
- Assert.AreEqual(sc.GetHashCode(), sc2.GetHashCode());
- }
-
- private static void testToString(Schema sc)
- {
- try
- {
- Assert.AreEqual(sc, Schema.Parse(sc.ToString()));
- }
- catch (Exception e)
- {
- throw new AvroException(e.ToString() + ": " + sc.ToString());
- }
- }
-
- [TestCase("{\"type\":\"record\",\"name\":\"LongList\"," +
- "\"fields\":[{\"name\":\"f1\",\"type\":\"long\"}," +
- "{\"name\":\"f2\",\"type\": \"int\"}]}",
- new string[] { "f1", "long", "100", "f2", "int", "10" })]
- [TestCase("{\"type\":\"record\",\"name\":\"LongList\"," +
- "\"fields\":[{\"name\":\"f1\",\"type\":\"long\", \"default\": \"100\"}," +
- "{\"name\":\"f2\",\"type\": \"int\"}]}",
- new string[] { "f1", "long", "100", "f2", "int", "10" })]
- [TestCase("{\"type\":\"record\",\"name\":\"LongList\"," +
- "\"fields\":[{\"name\":\"value\",\"type\":\"long\", \"default\": \"100\"}," +
- "{\"name\":\"next\",\"type\":[\"LongList\",\"null\"]}]}",
- new string[] { "value", "long", "100", "next", "union", null })]
- public void TestRecord(string s, string[] kv)
- {
- Schema sc = Schema.Parse(s);
- Assert.AreEqual(Schema.Type.Record, sc.Tag);
- RecordSchema rs = sc as RecordSchema;
- Assert.AreEqual(kv.Length / 3, rs.Count);
- for (int i = 0; i < kv.Length; i += 3)
- {
- Field f = rs[kv[i]];
- Assert.AreEqual(kv[i + 1], f.Schema.Name);
- /*
- if (kv[i + 2] != null)
- {
- Assert.IsNotNull(f.DefaultValue);
- Assert.AreEqual(kv[i + 2], f.DefaultValue);
- }
- else
- {
- Assert.IsNull(f.DefaultValue);
- }
- */
- }
- testEquality(s, sc);
- testToString(sc);
- }
-
- [TestCase("{\"type\": \"enum\", \"name\": \"Test\", \"symbols\": [\"A\", \"B\"]}",
- new string[] { "A", "B" })]
- public void TestEnum(string s, string[] symbols)
- {
- Schema sc = Schema.Parse(s);
- Assert.AreEqual(Schema.Type.Enumeration, sc.Tag);
- EnumSchema es = sc as EnumSchema;
- Assert.AreEqual(symbols.Length, es.Count);
-
- int i = 0;
- foreach (String str in es)
- {
- Assert.AreEqual(symbols[i++], str);
- }
-
- testEquality(s, sc);
- testToString(sc);
- }
-
- [TestCase("{\"type\": \"array\", \"items\": \"long\"}", "long")]
- public void TestArray(string s, string item)
- {
- Schema sc = Schema.Parse(s);
- Assert.AreEqual(Schema.Type.Array, sc.Tag);
- ArraySchema ars = sc as ArraySchema;
- Assert.AreEqual(item, ars.ItemSchema.Name);
-
- testEquality(s, sc);
- testToString(sc);
- }
-
- [TestCase("{\"type\": \"map\", \"values\": \"long\"}", "long")]
- public void TestMap(string s, string value)
- {
- Schema sc = Schema.Parse(s);
- Assert.AreEqual(Schema.Type.Map, sc.Tag);
- MapSchema ms = sc as MapSchema;
- Assert.AreEqual(value, ms.ValueSchema.Name);
-
- testEquality(s, sc);
- testToString(sc);
- }
-
- [TestCase("[\"string\", \"null\", \"long\"]", new string[] { "string", "null", "long" })]
- public void TestUnion(string s, string[] types)
- {
- Schema sc = Schema.Parse(s);
- Assert.AreEqual(Schema.Type.Union, sc.Tag);
- UnionSchema us = sc as UnionSchema;
- Assert.AreEqual(types.Length, us.Count);
-
- for (int i = 0; i < us.Count; i++)
- {
- Assert.AreEqual(types[i], us[i].Name);
- }
- testEquality(s, sc);
- testToString(sc);
- }
-
- [TestCase("{ \"type\": \"fixed\", \"name\": \"Test\", \"size\": 1}", 1)]
- public void TestFixed(string s, int size)
- {
- Schema sc = Schema.Parse(s);
- Assert.AreEqual(Schema.Type.Fixed, sc.Tag);
- FixedSchema fs = sc as FixedSchema;
- Assert.AreEqual(size, fs.Size);
- testEquality(s, sc);
- testToString(sc);
- }
-
- [TestCase("a", "o.a.h", Result = "o.a.h.a")]
- public string testFullname(string s1, string s2)
- {
- var name = new SchemaName(s1, s2, null);
- return name.Fullname;
- }
-
- }
-}
diff --git a/lang/csharp/src/apache/test/Specific/SpecificTests.cs b/lang/csharp/src/apache/test/Specific/SpecificTests.cs
deleted file mode 100644
index 4e5d03e..0000000
--- a/lang/csharp/src/apache/test/Specific/SpecificTests.cs
+++ /dev/null
@@ -1,186 +0,0 @@
-/**
- * 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.
- */
-using System;
-using System.IO;
-using System.Collections.Generic;
-using NUnit.Framework;
-using Avro;
-using Avro.Generic;
-using Avro.IO;
-using System.CodeDom;
-using System.CodeDom.Compiler;
-using Microsoft.CSharp;
-using Avro.Specific;
-using System.Reflection;
-
-namespace Avro.Test
-{
- [TestFixture]
- class SpecificTests
- {
- [TestCase(@"{
- ""protocol"" : ""MyProtocol"",
- ""namespace"" : ""com.foo"",
- ""types"" : [
- {
- ""type"" : ""record"",
- ""name"" : ""A"",
- ""fields"" : [ { ""name"" : ""f1"", ""type"" : ""long"" } ]
- },
- {
- ""type"" : ""enum"",
- ""name"" : ""MyEnum"",
- ""symbols"" : [ ""A"", ""B"", ""C"" ]
- },
- {
- ""type"": ""fixed"",
- ""size"": 16,
- ""name"": ""MyFixed""
- },
- {
- ""type"" : ""record"",
- ""name"" : ""Z"",
- ""fields"" :
- [
- { ""name"" : ""myUInt"", ""type"" : [ ""int"", ""null"" ] },
- { ""name"" : ""myULong"", ""type"" : [ ""long"", ""null"" ] },
- { ""name"" : ""myUBool"", ""type"" : [ ""boolean"", ""null"" ] },
- { ""name"" : ""myUDouble"", ""type"" : [ ""double"", ""null"" ] },
- { ""name"" : ""myUFloat"", ""type"" : [ ""float"", ""null"" ] },
- { ""name"" : ""myUBytes"", ""type"" : [ ""bytes"", ""null"" ] },
- { ""name"" : ""myUString"", ""type"" : [ ""string"", ""null"" ] },
-
- { ""name"" : ""myInt"", ""type"" : ""int"" },
- { ""name"" : ""myLong"", ""type"" : ""long"" },
- { ""name"" : ""myBool"", ""type"" : ""boolean"" },
- { ""name"" : ""myDouble"", ""type"" : ""double"" },
- { ""name"" : ""myFloat"", ""type"" : ""float"" },
- { ""name"" : ""myBytes"", ""type"" : ""bytes"" },
- { ""name"" : ""myString"", ""type"" : ""string"" },
- { ""name"" : ""myNull"", ""type"" : ""null"" },
-
- { ""name"" : ""myFixed"", ""type"" : ""MyFixed"" },
- { ""name"" : ""myA"", ""type"" : ""A"" },
- { ""name"" : ""myE"", ""type"" : ""MyEnum"" },
- { ""name"" : ""myArray"", ""type"" : { ""type"" : ""array"", ""items"" : ""bytes"" } },
- { ""name"" : ""myArray2"", ""type"" : { ""type"" : ""array"", ""items"" : { ""type"" : ""record"", ""name"" : ""newRec"", ""fields"" : [ { ""name"" : ""f1"", ""type"" : ""long""} ] } } },
- { ""name"" : ""myMap"", ""type"" : { ""type"" : ""map"", ""values"" : ""string"" } },
- { ""name"" : ""myMap2"", ""type"" : { ""type"" : ""map"", ""values"" : ""newRec"" } },
- { ""name"" : ""myObject"", ""type"" : [ ""MyEnum"", ""A"", ""null"" ] }
- ]
- }
- ]
-}"
-, new object[] {3, // index of the schema to serialize
- "com.foo.Z", // name of the schema to serialize
-@"
- Console.WriteLine(""Constructing com.foo.Z..."");
- string bytes = ""bytes sample text"";
- System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
-
- myUInt=1;
- myULong=2;
- myUBool=true;
- myUDouble=(double)3;
- myUFloat=(float)4.5;
- myUBytes = encoding.GetBytes(bytes);
- myUString=""Hello"";
-
- myInt=1;
- myLong=2;
- myBool=true;
- myDouble=(double)3;
- myFloat=(float)4.5;
- myBytes=encoding.GetBytes(bytes);
- myString=""Hello"";
- myNull=null;
-
- string fixedstr = ""My fixed record0"";
- myFixed=new MyFixed(); myFixed.Value = encoding.GetBytes(fixedstr);
- myA=new A(); myA.f1 = 10;
- myE=com.foo.MyEnum.C;
-
- myArray=new List<byte[]>();
- myArray.Add(encoding.GetBytes(""a""));
-
- myArray2 = new List<com.foo.newRec>();
- com.foo.newRec rec = new com.foo.newRec();
- rec.f1 = 50;
- myArray2.Add(rec);
-
- myMap = new Dictionary<string, string>();
- myMap.Add(""key"", ""value"");
- myMap2 = new Dictionary<string, com.foo.newRec>();
- com.foo.newRec newrec = new com.foo.newRec();
- newrec.f1 = 1200;
- myMap2.Add(""A"", newrec);
- myObject = com.foo.MyEnum.B;
-"}
-)]
- public static void TestSpecific(string str, object[] result)
- {
- Protocol protocol = Protocol.Parse(str);
- var codegen = new CodeGen();
- codegen.AddProtocol(protocol);
- var compileUnit = codegen.GenerateCode();
-
- // add a constructor to the main class using the passed assignment statements
- CodeTypeDeclaration ctd = compileUnit.Namespaces[0].Types[(int)result[0]];
- CodeConstructor constructor = new CodeConstructor();
- constructor.Attributes = MemberAttributes.Public;
- CodeSnippetExpression snippet = new CodeSnippetExpression((string)result[2]);
- constructor.Statements.Add(snippet);
- ctd.Members.Add(constructor);
-
- // compile
- var comparam = new CompilerParameters(new string[] { "mscorlib.dll" });
- comparam.ReferencedAssemblies.Add("System.dll");
- comparam.ReferencedAssemblies.Add("System.Core.dll");
- comparam.ReferencedAssemblies.Add(Type.GetType("Mono.Runtime") != null ? "Mono.CSharp.dll" : "Microsoft.CSharp.dll");
- comparam.ReferencedAssemblies.Add("Avro.dll");
- comparam.GenerateInMemory = true;
- var ccp = new Microsoft.CSharp.CSharpCodeProvider();
- var units = new CodeCompileUnit[] { compileUnit };
- var compres = ccp.CompileAssemblyFromDom(comparam, units);
- if (compres == null || compres.Errors.Count > 0)
- {
- for (int i = 0; i < compres.Errors.Count; i++)
- Console.WriteLine(compres.Errors[i]);
- }
- if (null != compres)
- Assert.IsTrue(compres.Errors.Count == 0);
-
- // create record
- ISpecificRecord rec = compres.CompiledAssembly.CreateInstance((string)result[1]) as ISpecificRecord;
- Assert.IsFalse(rec == null);
-
- // serialize
- var stream = new MemoryStream();
- var binEncoder = new BinaryEncoder(stream);
- var writer = new SpecificDefaultWriter(rec.Schema);
- writer.Write(rec.Schema, rec, binEncoder);
-
- // deserialize
- stream.Position = 0;
- var decoder = new BinaryDecoder(stream);
- var reader = new SpecificDefaultReader(rec.Schema, rec.Schema);
- var rec2 = (ISpecificRecord)reader.Read(null, rec.Schema, rec.Schema, decoder);
- Assert.IsFalse(rec2 == null);
- }
- }
-}
diff --git a/lang/java/avro/pom.xml b/lang/java/avro/pom.xml
index ea2d6d6..d405a8d 100644
--- a/lang/java/avro/pom.xml
+++ b/lang/java/avro/pom.xml
@@ -22,7 +22,7 @@
<parent>
<artifactId>avro-parent</artifactId>
<groupId>org.apache.avro</groupId>
- <version>1.5.2</version>
+ <version>1.5.0</version>
<relativePath>../</relativePath>
</parent>
<artifactId>avro</artifactId>
@@ -39,10 +39,6 @@
<groupId>com.thoughtworks.paranamer</groupId>
<artifactId>paranamer</artifactId>
</dependency>
- <dependency>
- <groupId>org.xerial.snappy</groupId>
- <artifactId>snappy-java</artifactId>
- </dependency>
</dependencies>
<build>
diff --git a/lang/java/avro/src/main/java/org/apache/avro/Schema.java b/lang/java/avro/src/main/java/org/apache/avro/Schema.java
index 899f116..66c2b68 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/Schema.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/Schema.java
@@ -618,8 +618,6 @@
gen.writeStringField("type", isError?"error":"record");
writeName(names, gen);
names.space = name.space; // set default namespace
- if (getDoc() != null)
- gen.writeStringField("doc", getDoc());
gen.writeFieldName("fields");
fieldsToJson(names, gen);
props.write(gen);
@@ -688,8 +686,6 @@
gen.writeStartObject();
gen.writeStringField("type", "enum");
writeName(names, gen);
- if (getDoc() != null)
- gen.writeStringField("doc", getDoc());
gen.writeArrayFieldStart("symbols");
for (String symbol : symbols)
gen.writeString(symbol);
@@ -829,8 +825,6 @@
gen.writeStartObject();
gen.writeStringField("type", "fixed");
writeName(names, gen);
- if (getDoc() != null)
- gen.writeStringField("doc", getDoc());
gen.writeNumberField("size", size);
props.write(gen);
aliasesToJson(gen);
@@ -909,19 +903,6 @@
return parse(parseJson(jsonSchema), new Names());
}
- /** Construct a schema from <a href="http://json.org/">JSON</a> text.
- * @param validate true if names should be validated, false if not.
- */
- public static Schema parse(String jsonSchema, boolean validate) {
- boolean saved = validateNames.get();
- try {
- validateNames.set(validate);
- return parse(jsonSchema);
- } finally {
- validateNames.set(saved);
- }
- }
-
static final Map<String,Type> PRIMITIVES = new HashMap<String,Type>();
static {
PRIMITIVES.put("string", Type.STRING);
@@ -969,15 +950,7 @@
}
}
- private static ThreadLocal<Boolean> validateNames
- = new ThreadLocal<Boolean>() {
- @Override protected Boolean initialValue() {
- return true;
- }
- };
-
private static String validateName(String name) {
- if (!validateNames.get()) return name; // not validating names
int length = name.length();
if (length == 0)
throw new SchemaParseException("Empty name");
diff --git a/lang/java/avro/src/main/java/org/apache/avro/file/CodecFactory.java b/lang/java/avro/src/main/java/org/apache/avro/file/CodecFactory.java
index 8bdebb2..be1c942 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/file/CodecFactory.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/file/CodecFactory.java
@@ -36,11 +36,6 @@
return new DeflateCodec.Option(compressionLevel);
};
- /** Snappy codec.*/
- public static CodecFactory snappyCodec() {
- return new SnappyCodec.Option();
- };
-
/** Creates internal Codec. */
protected abstract Codec createInstance();
@@ -55,7 +50,6 @@
static {
addCodec("null", nullCodec());
addCodec("deflate", deflateCodec(DEFAULT_DEFLATE_LEVEL));
- addCodec("snappy", snappyCodec());
}
/** Maps a codec name into a CodecOption. */
diff --git a/lang/java/avro/src/main/java/org/apache/avro/file/DataFileConstants.java b/lang/java/avro/src/main/java/org/apache/avro/file/DataFileConstants.java
index e3dd0f4..920f88d 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/file/DataFileConstants.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/file/DataFileConstants.java
@@ -36,6 +36,5 @@
public static final String CODEC = "avro.codec";
public static final String NULL_CODEC = "null";
public static final String DEFLATE_CODEC = "deflate";
- public static final String SNAPPY_CODEC = "snappy";
}
diff --git a/lang/java/avro/src/main/java/org/apache/avro/file/DataFileStream.java b/lang/java/avro/src/main/java/org/apache/avro/file/DataFileStream.java
index bde4f2a..1ca6934 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/file/DataFileStream.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/file/DataFileStream.java
@@ -121,7 +121,7 @@
// finalize the header
header.metaKeyList = Collections.unmodifiableList(header.metaKeyList);
- header.schema = Schema.parse(getMetaString(DataFileConstants.SCHEMA),false);
+ header.schema = Schema.parse(getMetaString(DataFileConstants.SCHEMA));
this.codec = resolveCodec();
reader.setSchema(header.schema);
}
diff --git a/lang/java/avro/src/main/java/org/apache/avro/file/DataFileWriter.java b/lang/java/avro/src/main/java/org/apache/avro/file/DataFileWriter.java
index 256ccbe..8d64e11 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/file/DataFileWriter.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/file/DataFileWriter.java
@@ -238,41 +238,13 @@
return setMeta(key, Long.toString(value));
}
- /** Thrown by {@link #append(Object)} when an exception occurs while writing a
- * datum to the buffer. When this is thrown, the file is unaltered and may
- * continue to be appended to. */
- public static class AppendWriteException extends RuntimeException {
- public AppendWriteException(Exception e) { super(e); }
- }
-
- /** Append a datum to the file.
- * @see AppendWriteException
- */
+ /** Append a datum to the file. */
public void append(D datum) throws IOException {
assertOpen();
- int usedBuffer = bufferInUse();
- try {
- dout.write(datum, bufOut);
- } catch (IOException e) {
- resetBufferTo(usedBuffer);
- throw new AppendWriteException(e);
- } catch (RuntimeException re) {
- resetBufferTo(usedBuffer);
- throw new AppendWriteException(re);
- }
+ dout.write(datum, bufOut);
blockCount++;
writeIfBlockFull();
}
-
- // if there is an error encoding, flush the encoder and then
- // reset the buffer position to contain size bytes, discarding the rest.
- // Otherwise the file will be corrupt with a partial record.
- private void resetBufferTo(int size) throws IOException {
- bufOut.flush();
- byte[] data = buffer.toByteArray();
- buffer.reset();
- buffer.write(data, 0, size);
- }
/** Expert: Append a pre-encoded datum to the file. No validation is
* performed to check that the encoding conforms to the file's schema.
@@ -284,13 +256,9 @@
blockCount++;
writeIfBlockFull();
}
-
- private int bufferInUse() {
- return (buffer.size() + bufOut.bytesBuffered());
- }
private void writeIfBlockFull() throws IOException {
- if (bufferInUse() >= syncInterval)
+ if ((buffer.size() + bufOut.bytesBuffered()) >= syncInterval)
writeBlock();
}
diff --git a/lang/java/avro/src/main/java/org/apache/avro/file/SnappyCodec.java b/lang/java/avro/src/main/java/org/apache/avro/file/SnappyCodec.java
deleted file mode 100644
index 032e6a6..0000000
--- a/lang/java/avro/src/main/java/org/apache/avro/file/SnappyCodec.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/**
- * 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.
- */
-package org.apache.avro.file;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.util.zip.CRC32;
-
-import org.xerial.snappy.Snappy;
-import org.xerial.snappy.SnappyException;
-
-/** * Implements Snappy compression and decompression. */
-class SnappyCodec extends Codec {
- private CRC32 crc32 = new CRC32();
-
- static class Option extends CodecFactory {
- @Override
- protected Codec createInstance() {
- return new SnappyCodec();
- }
- }
-
- private SnappyCodec() {}
-
- @Override String getName() { return DataFileConstants.SNAPPY_CODEC; }
-
- @Override
- ByteBuffer compress(ByteBuffer in) throws IOException {
- try {
- ByteBuffer out =
- ByteBuffer.allocate(Snappy.maxCompressedLength(in.remaining())+4);
- int size = Snappy.compress(in.array(), in.position(), in.remaining(),
- out.array(), 0);
- crc32.reset();
- crc32.update(in.array(), in.position(), in.remaining());
- out.putInt(size, (int)crc32.getValue());
-
- out.limit(size+4);
-
- return out;
- } catch (SnappyException e) {
- throw new IOException(e);
- }
- }
-
- @Override
- ByteBuffer decompress(ByteBuffer in) throws IOException {
- try {
- ByteBuffer out = ByteBuffer.allocate
- (Snappy.uncompressedLength(in.array(),in.position(),in.remaining()-4));
- int size = Snappy.uncompress(in.array(),in.position(),in.remaining()-4,
- out.array(), 0);
- out.limit(size);
-
- crc32.reset();
- crc32.update(out.array(), 0, size);
- if (in.getInt(in.limit()-4) != (int)crc32.getValue())
- throw new IOException("Checksum failure");
-
- return out;
- } catch (SnappyException e) {
- throw new IOException(e);
- }
- }
-
- @Override public int hashCode() { return getName().hashCode(); }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (getClass() != obj.getClass())
- return false;
- return true;
- }
-
-}
diff --git a/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java b/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java
index b07fd4f..9b889e8 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java
@@ -70,7 +70,7 @@
Record that = (Record)o;
if (!schema.getFullName().equals(that.schema.getFullName()))
return false; // not the same schema
- return GenericData.get().compare(this, that, schema, true) == 0;
+ return this.compareTo(that) == 0;
}
@Override public int hashCode() {
return GenericData.get().hashCode(this, schema);
@@ -609,14 +609,8 @@
* greater-than, return 1, if less than return -1. Order is consistent with
* that of {@link BinaryData#compare(byte[], int, byte[], int, Schema)}.
*/
- public int compare(Object o1, Object o2, Schema s) {
- return compare(o1, o2, s, false);
- }
-
- /** Comparison implementation. When equals is true, only checks for equality,
- * not for order. */
@SuppressWarnings(value="unchecked")
- protected int compare(Object o1, Object o2, Schema s, boolean equals) {
+ public int compare(Object o1, Object o2, Schema s) {
if (o1 == o2) return 0;
switch (s.getType()) {
case RECORD:
@@ -626,8 +620,7 @@
int pos = f.pos();
String name = f.name();
int compare =
- compare(getField(o1, name, pos), getField(o2, name, pos),
- f.schema(), equals);
+ compare(getField(o1, name, pos), getField(o2, name, pos), f.schema());
if (compare != 0) // not equal
return f.order() == Field.Order.DESCENDING ? -compare : compare;
}
@@ -641,19 +634,17 @@
Iterator e2 = a2.iterator();
Schema elementType = s.getElementType();
while(e1.hasNext() && e2.hasNext()) {
- int compare = compare(e1.next(), e2.next(), elementType, equals);
+ int compare = compare(e1.next(), e2.next(), elementType);
if (compare != 0) return compare;
}
return e1.hasNext() ? 1 : (e2.hasNext() ? -1 : 0);
case MAP:
- if (equals)
- return ((Map)o1).equals(o2) ? 0 : 1;
throw new AvroRuntimeException("Can't compare maps!");
case UNION:
int i1 = resolveUnion(s, o1);
int i2 = resolveUnion(s, o2);
return (i1 == i2)
- ? compare(o1, o2, s.getTypes().get(i1), equals)
+ ? compare(o1, o2, s.getTypes().get(i1))
: i1 - i2;
case NULL:
return 0;
diff --git a/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java b/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java
index 68dad5f..5c5fd51 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java
@@ -330,7 +330,7 @@
* byte array representation. By default, this calls {@link
* Decoder#readBytes(ByteBuffer)}.*/
protected Object readBytes(Object old, Decoder in) throws IOException {
- return in.readBytes(old instanceof ByteBuffer ? (ByteBuffer) old : null);
+ return in.readBytes((ByteBuffer)old);
}
/** Called to read integers. Subclasses may override to use a different
diff --git a/lang/java/avro/src/main/java/org/apache/avro/io/parsing/Symbol.java b/lang/java/avro/src/main/java/org/apache/avro/io/parsing/Symbol.java
index e58b3f4..7c346b6 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/io/parsing/Symbol.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/io/parsing/Symbol.java
@@ -440,7 +440,6 @@
public static class SkipAction extends ImplicitAction {
public final Symbol symToSkip;
public SkipAction(Symbol symToSkip) {
- super(true);
this.symToSkip = symToSkip;
}
diff --git a/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java b/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
index 8a6585e..2ada3fb 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
@@ -106,7 +106,6 @@
@Override
protected boolean isArray(Object datum) {
- if (datum == null) return false;
return (datum instanceof Collection) || datum.getClass().isArray();
}
@@ -450,7 +449,7 @@
}
@Override
- protected int compare(Object o1, Object o2, Schema s, boolean equals) {
+ public int compare(Object o1, Object o2, Schema s) {
switch (s.getType()) {
case ARRAY:
if (!o1.getClass().isArray())
@@ -462,7 +461,7 @@
for (int i = 0; i < l; i++) {
int compare = compare(java.lang.reflect.Array.get(o1, i),
java.lang.reflect.Array.get(o2, i),
- elementType, equals);
+ elementType);
if (compare != 0) return compare;
}
return l1 - l2;
@@ -473,7 +472,7 @@
byte[] b2 = (byte[])o2;
return BinaryData.compareBytes(b1, 0, b1.length, b2, 0, b2.length);
}
- return super.compare(o1, o2, s, equals);
+ return super.compare(o1, o2, s);
}
}
diff --git a/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectDatumWriter.java b/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectDatumWriter.java
index 17248ac..80e9b85 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectDatumWriter.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectDatumWriter.java
@@ -103,7 +103,7 @@
} catch (NullPointerException e) { // improve error message
NullPointerException result =
new NullPointerException("in "+schema.getFullName()+" "+e.getMessage());
- result.initCause(e.getCause() == null ? e : e.getCause());
+ result.initCause(e);
throw result;
}
}
diff --git a/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java b/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java
index 0932243..ff293e3 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java
@@ -101,7 +101,7 @@
public String getClassName(Schema schema) {
String namespace = schema.getNamespace();
String name = schema.getName();
- if (namespace == null || "".equals(namespace))
+ if (namespace == null)
return name;
String dot = namespace.endsWith("$") ? "" : ".";
return namespace + dot + name;
@@ -189,13 +189,13 @@
}
@Override
- protected int compare(Object o1, Object o2, Schema s, boolean eq) {
+ public int compare(Object o1, Object o2, Schema s) {
switch (s.getType()) {
case ENUM:
if (o1 instanceof Enum)
return ((Enum)o1).ordinal() - ((Enum)o2).ordinal();
default:
- return super.compare(o1, o2, s, eq);
+ return super.compare(o1, o2, s);
}
}
diff --git a/lang/java/avro/src/test/java/org/apache/avro/TestDataFile.java b/lang/java/avro/src/test/java/org/apache/avro/TestDataFile.java
index ce50a34..a588abd 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/TestDataFile.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/TestDataFile.java
@@ -26,15 +26,12 @@
import java.util.List;
import java.util.Random;
-import junit.framework.Assert;
-
import org.apache.avro.file.CodecFactory;
import org.apache.avro.file.FileReader;
import org.apache.avro.file.DataFileReader;
import org.apache.avro.file.DataFileStream;
import org.apache.avro.file.DataFileWriter;
import org.apache.avro.file.SeekableFileInput;
-import org.apache.avro.generic.GenericData;
import org.apache.avro.generic.GenericDatumReader;
import org.apache.avro.generic.GenericDatumWriter;
import org.apache.avro.io.DatumReader;
@@ -64,7 +61,6 @@
r.add(new Object[] { CodecFactory.deflateCodec(1) });
r.add(new Object[] { CodecFactory.deflateCodec(9) });
r.add(new Object[] { CodecFactory.nullCodec() });
- r.add(new Object[] { CodecFactory.snappyCodec() });
return r;
}
@@ -100,20 +96,6 @@
writer.append(datum);
if (++count%(COUNT/3) == 0)
writer.sync(); // force some syncs mid-file
- if (count == 5) {
- // force a write of an invalid record
- boolean threwProperly = false;
- try {
- GenericData.Record record = (GenericData.Record) datum;
- record.put(1, null);
- threwProperly = true;
- writer.append(record);
- threwProperly = false;
- } catch (DataFileWriter.AppendWriteException e) {
- System.out.println("Ignoring: "+e);
- }
- Assert.assertTrue("failed to throw when expected", threwProperly);
- }
}
} finally {
writer.close();
diff --git a/lang/java/avro/src/test/java/org/apache/avro/TestReflect.java b/lang/java/avro/src/test/java/org/apache/avro/TestReflect.java
index 9a12989..36aefb8 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/TestReflect.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/TestReflect.java
@@ -352,12 +352,6 @@
assertEquals(e1, response.getTypes().get(1));
}
- @Test public void testNoPackage() throws Exception {
- Class noPackage = Class.forName("NoPackage");
- Schema s = ReflectData.get().getSchema(noPackage);
- assertEquals(noPackage.getName(), ReflectData.get().getClassName(s));
- }
-
void checkReadWrite(Object object) throws Exception {
checkReadWrite(object, ReflectData.get().getSchema(object.getClass()));
}
@@ -556,14 +550,6 @@
checkBinary(schema, record);
}
- /** Test union of null and an array. */
- @Test
- public void testNullArray() throws Exception {
- String json = "[{\"type\":\"array\", \"items\": \"long\"}, \"null\"]";
- Schema schema = Schema.parse(json);
- checkBinary(schema, null);
- }
-
public static void checkBinary(Schema schema, Object datum)
throws IOException {
ReflectDatumWriter<Object> writer = new ReflectDatumWriter<Object>(schema);
diff --git a/lang/java/avro/src/test/java/org/apache/avro/io/TestResolvingIOResolving.java b/lang/java/avro/src/test/java/org/apache/avro/io/TestResolvingIOResolving.java
index f6b682e..8b92c9f 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/io/TestResolvingIOResolving.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/io/TestResolvingIOResolving.java
@@ -188,18 +188,6 @@
+ "{\"name\":\"f1\", \"type\":\"long\"},"
+ "{\"name\":\"f3\", \"type\":\"double\"}]}", "BLD",
new Object[] { true, 100L, 10.75d } },
- // Array of record with arrays.
- { "{ \"type\": \"array\", \"items\":" +
- "{\"type\":\"record\",\"name\":\"r\",\"fields\":["
- + "{\"name\":\"f0\", \"type\":\"boolean\"},"
- + "{\"name\":\"f1\", \"type\": {\"type\":\"array\", \"items\": \"boolean\" }}"
- + "]}}", "[c2sB[c2sBsB]sB[c3sBsBsB]]",
- new Object[] { true, false, false, false, true, true, true },
- "{ \"type\": \"array\", \"items\":" +
- "{\"type\":\"record\",\"name\":\"r\",\"fields\":["
- + "{\"name\":\"f0\", \"type\":\"boolean\"}"
- + "]}}", "[c2sBsB]",
- new Object[] { true, false } },
};
}
}
diff --git a/lang/java/compiler/pom.xml b/lang/java/compiler/pom.xml
index d0f3006..1d73f02 100644
--- a/lang/java/compiler/pom.xml
+++ b/lang/java/compiler/pom.xml
@@ -22,7 +22,7 @@
<parent>
<artifactId>avro-parent</artifactId>
<groupId>org.apache.avro</groupId>
- <version>1.5.2</version>
+ <version>1.5.0</version>
<relativePath>../</relativePath>
</parent>
<artifactId>avro-compiler</artifactId>
diff --git a/lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj b/lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj
index f362d0e..1dba9bf 100644
--- a/lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj
+++ b/lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj
@@ -91,14 +91,6 @@
String namespace;
Map<String,Schema> names = new LinkedHashMap<String,Schema>();
- private static final ThreadLocal<String> DOC = new ThreadLocal<String>();
- static void setDoc(String doc) { DOC.set(doc.trim()); }
- static String getDoc() {
- String doc = DOC.get();
- DOC.set(null);
- return doc;
- }
-
public Idl(File inputFile) throws IOException {
this(new FileInputStream(inputFile), "UTF-8");
this.inputDir = inputFile.getParentFile();
@@ -148,36 +140,36 @@
/* COMMENTS */
-SKIP :
+MORE :
+{
+ <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
+|
+ "/*" : IN_MULTI_LINE_COMMENT
+}
+
+SPECIAL_TOKEN :
{
<SINGLE_LINE_COMMENT: "//" (~["\n", "\r"])* ("\n" | "\r" | "\r\n")?>
}
-SKIP :
+<IN_FORMAL_COMMENT>
+SPECIAL_TOKEN :
{
- <"/**" ~["/"]> { input_stream.backup(1); } : DOC_COMMENT
-|
- "/*" : MULTI_LINE_COMMENT
+ <FORMAL_COMMENT: "*/" > : DEFAULT
}
-<DOC_COMMENT,MULTI_LINE_COMMENT>
+<IN_MULTI_LINE_COMMENT>
+SPECIAL_TOKEN :
+{
+ <MULTI_LINE_COMMENT: "*/" > : DEFAULT
+}
+
+<IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
MORE :
{
< ~[] >
}
-<DOC_COMMENT>
-SPECIAL_TOKEN :
-{
- <"*/" > {Idl.setDoc(image.substring(0, image.length()-2));} : DEFAULT
-}
-
-<MULTI_LINE_COMMENT>
-SKIP :
-{
- <"*/" > : DEFAULT
-}
-
/* RESERVED WORDS AND LITERALS */
TOKEN :
@@ -1046,7 +1038,6 @@
"protocol"
name = Identifier()
{
- getDoc(); // consume doc
p = new Protocol(name, namespace);
}
ProtocolBody(p)
@@ -1066,7 +1057,7 @@
name = Identifier()
symbols = EnumBody()
{
- Schema s = Schema.createEnum(name, getDoc(), this.namespace, symbols);
+ Schema s = Schema.createEnum(name, null, this.namespace, symbols);
names.put(s.getFullName(), s);
return s;
}
@@ -1178,7 +1169,7 @@
"fixed" name = Identifier() "(" sizeTok = <INTEGER_LITERAL> ")"
";"
{
- Schema s = Schema.createFixed(name, getDoc(), this.namespace,
+ Schema s = Schema.createFixed(name, null, this.namespace,
Integer.parseInt(sizeTok.image));
names.put(s.getFullName(), s);
return s;
@@ -1199,7 +1190,7 @@
name = Identifier()
{
Schema result = Schema.createRecord(
- name, getDoc(), this.namespace, isError);
+ name, null, this.namespace, isError);
names.put(result.getFullName(), result);
}
"{"
@@ -1263,7 +1254,7 @@
for (String key : props.keySet())
if ("order".equals(key))
order = Field.Order.valueOf(getTextProp(key,props,token).toUpperCase());
- Field field = new Field(name, type, getDoc(), defaultValue, order);
+ Field field = new Field(name, type, null, defaultValue, order);
for (String key : props.keySet())
if ("order".equals(key)) { // already handled: ignore
} else if ("aliases".equals(key)) { // aliases
diff --git a/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/protocol.vm b/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/protocol.vm
index d715b5a..3938562 100644
--- a/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/protocol.vm
+++ b/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/protocol.vm
@@ -21,7 +21,7 @@
@SuppressWarnings("all")
#if ($protocol.getDoc())
-/** $protocol.getDoc() */
+ /** $protocol.getDoc() */
#end
public interface $this.mangle($protocol.getName()) {
public static final org.apache.avro.Protocol PROTOCOL = org.apache.avro.Protocol.parse("${this.javaEscape($protocol.toString())}");
@@ -46,31 +46,4 @@
#end## (one way)
;
#end## (requests)
-
-## Generate nested callback API
- @SuppressWarnings("all")
-#if ($protocol.getDoc())
- /** $protocol.getDoc() */
-#end
- public interface Callback extends $this.mangle($protocol.getName()) {
- public static final org.apache.avro.Protocol PROTOCOL = #if ($protocol.getNamespace())$protocol.getNamespace().#end${this.mangle($protocol.getName())}.PROTOCOL;
-#foreach ($e in $protocol.getMessages().entrySet())
-#set ($name = $e.getKey())
-#set ($message = $e.getValue())
-#set ($response = $message.getResponse())
-## Generate callback method if the message is not one-way:
-#if (! $message.isOneWay())
-#if ($message.getDoc())
- /** $this.escapeForJavadoc($message.getDoc()) */
-#end
- void ${this.mangle($name)}(##
-#foreach ($p in $message.getRequest().getFields())##
-#* *#${this.javaUnbox($p.schema())} ${this.mangle($p.name())}#if ($velocityHasNext), #end
-#end
-#if ($message.getRequest().getFields().size() > 0), #end
-org.apache.avro.ipc.Callback<${this.javaType($response)}> callback) throws java.io.IOException;
-#end## (generate callback method)
-#end## (requests)
- }## End of Callback interface
-
-}## End of protocol interface
+}
diff --git a/lang/java/compiler/src/test/idl/input/simple.avdl b/lang/java/compiler/src/test/idl/input/simple.avdl
index 24136e3..888bdce 100644
--- a/lang/java/compiler/src/test/idl/input/simple.avdl
+++ b/lang/java/compiler/src/test/idl/input/simple.avdl
@@ -21,7 +21,6 @@
*/
@namespace("org.apache.avro.test")
protocol Simple {
- /** A kind of record. */
@aliases(["org.foo.KindOf"])
enum Kind {
FOO,
@@ -29,14 +28,11 @@
BAZ
}
- /** An MD5 hash. */
fixed MD5(16);
- /** A TestRecord. */
record TestRecord {
string @order("ignore") name = "foo";
- /** The kind of record. */
Kind @order("descending") kind;
@foo("bar") MD5 hash;
diff --git a/lang/java/compiler/src/test/idl/output/simple.avpr b/lang/java/compiler/src/test/idl/output/simple.avpr
index 2deb0b8..60d2e73 100644
--- a/lang/java/compiler/src/test/idl/output/simple.avpr
+++ b/lang/java/compiler/src/test/idl/output/simple.avpr
@@ -4,19 +4,16 @@
"types" : [ {
"type" : "enum",
"name" : "Kind",
- "doc" : "A kind of record.",
"symbols" : [ "FOO", "BAR", "BAZ" ],
"aliases" : [ "org.foo.KindOf" ]
}, {
"type" : "fixed",
"name" : "MD5",
- "doc" : "An MD5 hash.",
"size" : 16,
"foo" : "bar"
}, {
"type" : "record",
"name" : "TestRecord",
- "doc" : "A TestRecord.",
"fields" : [ {
"name" : "name",
"type" : "string",
@@ -25,7 +22,6 @@
}, {
"name" : "kind",
"type" : "Kind",
- "doc" : "The kind of record.",
"order" : "descending"
}, {
"name" : "hash",
diff --git a/lang/java/ipc/pom.xml b/lang/java/ipc/pom.xml
index 3a3e260..28fee01 100644
--- a/lang/java/ipc/pom.xml
+++ b/lang/java/ipc/pom.xml
@@ -22,7 +22,7 @@
<parent>
<artifactId>avro-parent</artifactId>
<groupId>org.apache.avro</groupId>
- <version>1.5.2</version>
+ <version>1.5.0</version>
<relativePath>../</relativePath>
</parent>
<artifactId>avro-ipc</artifactId>
diff --git a/lang/java/ipc/src/main/java/org/apache/avro/ipc/CallFuture.java b/lang/java/ipc/src/main/java/org/apache/avro/ipc/CallFuture.java
deleted file mode 100644
index 77561d3..0000000
--- a/lang/java/ipc/src/main/java/org/apache/avro/ipc/CallFuture.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/**
- * 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.
- */
-
-package org.apache.avro.ipc;
-
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
-/**
- * A Future implementation for RPCs.
- */
-public class CallFuture<T> implements Future<T>, Callback<T> {
- private final CountDownLatch latch = new CountDownLatch(1);
- private final Callback<T> chainedCallback;
- private T result = null;
- private Throwable error = null;
-
- /**
- * Creates a CallFuture.
- */
- public CallFuture() {
- this(null);
- }
-
- /**
- * Creates a CallFuture with a chained Callback which will be invoked
- * when this CallFuture's Callback methods are invoked.
- * @param chainedCallback the chained Callback to set.
- */
- public CallFuture(Callback<T> chainedCallback) {
- this.chainedCallback = chainedCallback;
- }
-
- /**
- * Sets the RPC response, and unblocks all threads waiting on {@link #get()}
- * or {@link #get(long, TimeUnit)}.
- * @param result the RPC result to set.
- */
- @Override
- public void handleResult(T result) {
- this.result = result;
- latch.countDown();
- if (chainedCallback != null) {
- chainedCallback.handleResult(result);
- }
- }
-
- /**
- * Sets an error thrown during RPC execution, and unblocks all threads waiting
- * on {@link #get()} or {@link #get(long, TimeUnit)}.
- * @param error the RPC error to set.
- */
- @Override
- public void handleError(Throwable error) {
- this.error = error;
- latch.countDown();
- if (chainedCallback != null) {
- chainedCallback.handleError(error);
- }
- }
-
- /**
- * Gets the value of the RPC result without blocking.
- * Using {@link #get()} or {@link #get(long, TimeUnit)} is usually
- * preferred because these methods block until the result is available or
- * an error occurs.
- * @return the value of the response, or null if no result was returned or
- * the RPC has not yet completed.
- */
- public T getResult() {
- return result;
- }
-
- /**
- * Gets the error that was thrown during RPC execution. Does not block.
- * Either {@link #get()} or {@link #get(long, TimeUnit)} should be called
- * first because these methods block until the RPC has completed.
- * @return the RPC error that was thrown, or null if no error has occurred or
- * if the RPC has not yet completed.
- */
- public Throwable getError() {
- return error;
- }
-
- @Override
- public boolean cancel(boolean mayInterruptIfRunning) {
- return false;
- }
-
- @Override
- public boolean isCancelled() {
- return false;
- }
-
- @Override
- public T get() throws InterruptedException,
- ExecutionException {
- latch.await();
- if (error != null) {
- throw new ExecutionException(error);
- }
- return result;
- }
-
- @Override
- public T get(long timeout, TimeUnit unit)
- throws InterruptedException, ExecutionException, TimeoutException {
- if (latch.await(timeout, unit)) {
- if (error != null) {
- throw new ExecutionException(error);
- }
- return result;
- } else {
- throw new TimeoutException();
- }
- }
-
- /**
- * Waits for the CallFuture to complete without returning the result.
- * @throws InterruptedException if interrupted.
- */
- public void await() throws InterruptedException {
- latch.await();
- }
-
- /**
- * Waits for the CallFuture to complete without returning the result.
- * @param timeout the maximum time to wait.
- * @param unit the time unit of the timeout argument.
- * @throws InterruptedException if interrupted.
- * @throws TimeoutException if the wait timed out.
- */
- public void await(long timeout, TimeUnit unit)
- throws InterruptedException, TimeoutException {
- if (!latch.await(timeout, unit)) {
- throw new TimeoutException();
- }
- }
-
- @Override
- public boolean isDone() {
- return latch.getCount() <= 0;
- }
-}
diff --git a/lang/java/ipc/src/main/java/org/apache/avro/ipc/Callback.java b/lang/java/ipc/src/main/java/org/apache/avro/ipc/Callback.java
deleted file mode 100644
index 594cf6b..0000000
--- a/lang/java/ipc/src/main/java/org/apache/avro/ipc/Callback.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * 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.
- */
-
-package org.apache.avro.ipc;
-
-/**
- * Interface for receiving asynchronous callbacks.
- * For each request with an asynchronous callback,
- * either {@link #handleResult(Object)} or {@link #handleError(Exception)}
- * will be invoked.
- */
-public interface Callback<T> {
- /**
- * Receives a callback result.
- * @param result the result returned in the callback.
- */
- void handleResult(T result);
-
- /**
- * Receives an error.
- * @param error the error returned in the callback.
- */
- void handleError(Throwable error);
-}
diff --git a/lang/java/ipc/src/main/java/org/apache/avro/ipc/NettyServer.java b/lang/java/ipc/src/main/java/org/apache/avro/ipc/NettyServer.java
index a0a34f8..c74932e 100644
--- a/lang/java/ipc/src/main/java/org/apache/avro/ipc/NettyServer.java
+++ b/lang/java/ipc/src/main/java/org/apache/avro/ipc/NettyServer.java
@@ -54,13 +54,13 @@
private static final Logger LOG = LoggerFactory.getLogger(NettyServer.class
.getName());
- private final Responder responder;
+ private Responder responder;
- private final Channel serverChannel;
- private final ChannelGroup allChannels = new DefaultChannelGroup(
+ private Channel serverChannel;
+ private ChannelGroup allChannels = new DefaultChannelGroup(
"avro-netty-server");
- private final ChannelFactory channelFactory;
- private final CountDownLatch closed = new CountDownLatch(1);
+ private ChannelFactory channelFactory;
+ private CountDownLatch closed = new CountDownLatch(1);
public NettyServer(Responder responder, InetSocketAddress addr) {
this.responder = responder;
@@ -133,13 +133,14 @@
NettyDataPack dataPack = (NettyDataPack) e.getMessage();
List<ByteBuffer> req = dataPack.getDatas();
List<ByteBuffer> res = responder.respond(req, connectionMetadata);
- // response will be null for oneway messages.
- if(res != null) {
- dataPack.setDatas(res);
- e.getChannel().write(dataPack);
- }
+ dataPack.setDatas(res);
+ e.getChannel().write(dataPack);
} catch (IOException ex) {
LOG.warn("unexpect error");
+ } finally {
+ if(!connectionMetadata.isConnected()){
+ e.getChannel().close();
+ }
}
}
diff --git a/lang/java/ipc/src/main/java/org/apache/avro/ipc/NettyTransceiver.java b/lang/java/ipc/src/main/java/org/apache/avro/ipc/NettyTransceiver.java
index 72c0383..ac4feba 100644
--- a/lang/java/ipc/src/main/java/org/apache/avro/ipc/NettyTransceiver.java
+++ b/lang/java/ipc/src/main/java/org/apache/avro/ipc/NettyTransceiver.java
@@ -27,8 +27,10 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.concurrent.Future;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.avro.Protocol;
@@ -43,7 +45,6 @@
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
-import org.jboss.netty.channel.ChannelState;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.channel.ExceptionEvent;
@@ -60,53 +61,26 @@
private static final Logger LOG = LoggerFactory.getLogger(NettyTransceiver.class
.getName());
- private final AtomicInteger serialGenerator = new AtomicInteger(0);
- private final Map<Integer, Callback<List<ByteBuffer>>> requests =
- new ConcurrentHashMap<Integer, Callback<List<ByteBuffer>>>();
+ private ChannelFactory channelFactory;
+ private Channel channel;
- private final ChannelFactory channelFactory;
- private final ClientBootstrap bootstrap;
- private final InetSocketAddress remoteAddr;
+ private AtomicInteger serialGenerator = new AtomicInteger(0);
+ private Map<Integer, CallFuture> requests =
+ new ConcurrentHashMap<Integer, CallFuture>();
- /**
- * Read lock must be acquired whenever using non-final state.
- * Write lock must be acquired whenever modifying state.
- */
- private final ReadWriteLock stateLock = new ReentrantReadWriteLock();
- private Channel channel; // Synchronized on stateLock
- private Protocol remote; // Synchronized on stateLock
+ private Protocol remote;
- NettyTransceiver() {
- channelFactory = null;
- bootstrap = null;
- remoteAddr = null;
+ NettyTransceiver() {}
+
+ public NettyTransceiver(InetSocketAddress addr) {
+ this(addr, new NioClientSocketChannelFactory(Executors.
+ newCachedThreadPool(), Executors.newCachedThreadPool()));
}
- /**
- * Creates a NettyTransceiver, and attempts to connect to the given address.
- * @param addr the address to connect to.
- * @throws IOException if an error occurs connecting to the given address.
- */
- public NettyTransceiver(InetSocketAddress addr) throws IOException {
- this(addr, new NioClientSocketChannelFactory(Executors.newCachedThreadPool(),
- Executors.newCachedThreadPool()));
- }
-
- /**
- * Creates a NettyTransceiver, and attempts to connect to the given address.
- * @param addr the address to connect to.
- * @param channelFactory the factory to use to create a new Netty Channel.
- * @throws IOException if an error occurs connecting to the given address.
- */
- public NettyTransceiver(InetSocketAddress addr, ChannelFactory channelFactory) throws IOException {
- if (channelFactory == null) {
- throw new NullPointerException("channelFactory is null");
- }
-
+ public NettyTransceiver(InetSocketAddress addr, ChannelFactory channelFactory) {
// Set up.
this.channelFactory = channelFactory;
- bootstrap = new ClientBootstrap(channelFactory);
- remoteAddr = addr;
+ ClientBootstrap bootstrap = new ClientBootstrap(channelFactory);
// Configure the event pipeline factory.
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@@ -123,190 +97,54 @@
bootstrap.setOption("tcpNoDelay", true);
// Make a new connection.
- stateLock.readLock().lock();
- try {
- getChannel();
- } finally {
- stateLock.readLock().unlock();
+ ChannelFuture channelFuture = bootstrap.connect(addr);
+ channelFuture.awaitUninterruptibly();
+ if (!channelFuture.isSuccess()) {
+ channelFuture.getCause().printStackTrace();
+ throw new RuntimeException(channelFuture.getCause());
}
- }
-
- /**
- * Tests whether the given channel is ready for writing.
- * @return true if the channel is open and ready; false otherwise.
- */
- private static boolean isChannelReady(Channel channel) {
- return (channel != null) &&
- channel.isOpen() && channel.isBound() && channel.isConnected();
- }
-
- /**
- * Gets the Netty channel. If the channel is not connected, first attempts
- * to connect.
- * NOTE: The stateLock read lock *must* be acquired before calling this
- * method.
- * @return the Netty channel
- * @throws IOException if an error occurs connecting the channel.
- */
- private Channel getChannel() throws IOException {
- if (!isChannelReady(channel)) {
- // Need to reconnect
- // Upgrade to write lock
- stateLock.readLock().unlock();
- stateLock.writeLock().lock();
- try {
- LOG.info("Connecting to " + remoteAddr);
- ChannelFuture channelFuture = bootstrap.connect(remoteAddr);
- channelFuture.awaitUninterruptibly();
- if (!channelFuture.isSuccess()) {
- channelFuture.getCause().printStackTrace();
- throw new IOException("Error connecting to " + remoteAddr,
- channelFuture.getCause());
- }
- channel = channelFuture.getChannel();
- } finally {
- // Downgrade to read lock:
- stateLock.readLock().lock();
- stateLock.writeLock().unlock();
- }
- }
- return channel;
- }
-
- /**
- * Closes the connection to the remote peer if connected.
- */
- private void disconnect() {
- disconnect(false, false);
- }
-
- /**
- * Closes the connection to the remote peer if connected.
- * @param awaitCompletion if true, will block until the close has completed.
- * @param cancelPendingRequests if true, will drain the requests map and
- * send an IOException to all Callbacks.
- */
- private void disconnect(boolean awaitCompletion, boolean cancelPendingRequests) {
- Map<Integer, Callback<List<ByteBuffer>>> requestsToCancel = null;
- stateLock.writeLock().lock();
- try {
- if (channel != null) {
- LOG.info("Disconnecting from " + remoteAddr);
- ChannelFuture closeFuture = channel.close();
- if (awaitCompletion) {
- closeFuture.awaitUninterruptibly();
- }
- channel = null;
- remote = null;
- if (cancelPendingRequests) {
- // Remove all pending requests (will be canceled after relinquishing
- // write lock).
- requestsToCancel =
- new ConcurrentHashMap<Integer, Callback<List<ByteBuffer>>>(requests);
- requests.clear();
- }
- }
- } finally {
- stateLock.writeLock().unlock();
- }
-
- if ((requestsToCancel != null) && !requestsToCancel.isEmpty()) {
- LOG.warn("Removing " + requestsToCancel.size() + " pending request(s).");
- for (Callback<List<ByteBuffer>> request : requestsToCancel.values()) {
- request.handleError(
- new IOException(getClass().getSimpleName() + " closed"));
- }
- }
- }
-
- /**
- * Netty channels are thread-safe, so there is no need to acquire locks.
- * This method is a no-op.
- */
- @Override
- public void lockChannel() {
-
- }
-
- /**
- * Netty channels are thread-safe, so there is no need to acquire locks.
- * This method is a no-op.
- */
- @Override
- public void unlockChannel() {
-
+ channel = channelFuture.getChannel();
}
public void close() {
- try {
- // Close the connection:
- disconnect(true, true);
- } finally {
- // Shut down all thread pools to exit.
- channelFactory.releaseExternalResources();
- }
+ // Close the connection.
+ channel.close().awaitUninterruptibly();
+ // Shut down all thread pools to exit.
+ channelFactory.releaseExternalResources();
}
@Override
- public String getRemoteName() throws IOException {
- stateLock.readLock().lock();
- try {
- return getChannel().getRemoteAddress().toString();
- } finally {
- stateLock.readLock().unlock();
- }
+ public String getRemoteName() {
+ return channel.getRemoteAddress().toString();
}
/**
* Override as non-synchronized method because the method is thread safe.
*/
@Override
- public List<ByteBuffer> transceive(List<ByteBuffer> request)
- throws IOException {
+ public List<ByteBuffer> transceive(List<ByteBuffer> request)
+ throws IOException {
+ int serial = serialGenerator.incrementAndGet();
+ NettyDataPack dataPack = new NettyDataPack(serial, request);
+ CallFuture callFuture = new CallFuture();
+ requests.put(serial, callFuture);
+ channel.write(dataPack);
try {
- CallFuture<List<ByteBuffer>> transceiverFuture = new CallFuture<List<ByteBuffer>>();
- transceive(request, transceiverFuture);
- return transceiverFuture.get();
+ return callFuture.get();
} catch (InterruptedException e) {
LOG.warn("failed to get the response", e);
return null;
} catch (ExecutionException e) {
LOG.warn("failed to get the response", e);
return null;
- }
- }
-
- @Override
- public void transceive(List<ByteBuffer> request,
- Callback<List<ByteBuffer>> callback) throws IOException {
- stateLock.readLock().lock();
- try {
- int serial = serialGenerator.incrementAndGet();
- NettyDataPack dataPack = new NettyDataPack(serial, request);
- requests.put(serial, callback);
- writeDataPack(dataPack);
} finally {
- stateLock.readLock().unlock();
+ requests.remove(serial);
}
}
-
+
@Override
public void writeBuffers(List<ByteBuffer> buffers) throws IOException {
- writeDataPack(new NettyDataPack(serialGenerator.incrementAndGet(), buffers));
- }
-
- /**
- * Writes a NettyDataPack, reconnecting to the remote peer if necessary.
- * @param dataPack the data pack to write.
- * @throws IOException if an error occurs connecting to the remote peer.
- */
- private void writeDataPack(NettyDataPack dataPack) throws IOException {
- stateLock.readLock().lock();
- try {
- getChannel().write(dataPack);
- } finally {
- stateLock.readLock().unlock();
- }
+ throw new UnsupportedOperationException();
}
@Override
@@ -316,32 +154,71 @@
@Override
public Protocol getRemote() {
- stateLock.readLock().lock();
- try {
- return remote;
- } finally {
- stateLock.readLock().unlock();
- }
+ return remote;
}
@Override
public boolean isConnected() {
- stateLock.readLock().lock();
- try {
- return remote!=null;
- } finally {
- stateLock.readLock().unlock();
- }
+ return remote!=null;
}
@Override
public void setRemote(Protocol protocol) {
- stateLock.writeLock().lock();
- try {
- this.remote = protocol;
- } finally {
- stateLock.writeLock().unlock();
+ this.remote = protocol;
+ }
+
+ /**
+ * Future class for a RPC call
+ */
+ class CallFuture implements Future<List<ByteBuffer>>{
+ private Semaphore sem = new Semaphore(0);
+ private List<ByteBuffer> response = null;
+
+ public void setResponse(List<ByteBuffer> response) {
+ this.response = response;
+ sem.release();
}
+
+ public void releaseSemphore() {
+ sem.release();
+ }
+
+ public List<ByteBuffer> getResponse() {
+ return response;
+ }
+
+ @Override
+ public boolean cancel(boolean mayInterruptIfRunning) {
+ return false;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return false;
+ }
+
+ @Override
+ public List<ByteBuffer> get() throws InterruptedException,
+ ExecutionException {
+ sem.acquire();
+ return response;
+ }
+
+ @Override
+ public List<ByteBuffer> get(long timeout, TimeUnit unit)
+ throws InterruptedException, ExecutionException, TimeoutException {
+ if (sem.tryAcquire(timeout, unit)) {
+ return response;
+ } else {
+ throw new TimeoutException();
+ }
+ }
+
+ @Override
+ public boolean isDone() {
+ return sem.availablePermits()>0;
+ }
+
}
/**
@@ -354,12 +231,6 @@
throws Exception {
if (e instanceof ChannelStateEvent) {
LOG.info(e.toString());
- ChannelStateEvent cse = (ChannelStateEvent)e;
- if ((cse.getState() == ChannelState.OPEN) && (Boolean.FALSE.equals(cse.getValue()))) {
- // Server closed connection; disconnect client side
- LOG.info("Remote peer " + remoteAddr + " closed connection.");
- disconnect();
- }
}
super.handleUpstream(ctx, e);
}
@@ -374,15 +245,11 @@
@Override
public void messageReceived(ChannelHandlerContext ctx, final MessageEvent e) {
NettyDataPack dataPack = (NettyDataPack)e.getMessage();
- Callback<List<ByteBuffer>> callback = requests.get(dataPack.getSerial());
- if (callback==null) {
+ CallFuture callFuture = requests.get(dataPack.getSerial());
+ if (callFuture==null) {
throw new RuntimeException("Missing previous call info");
}
- try {
- callback.handleResult(dataPack.getDatas());
- } finally {
- requests.remove(dataPack.getSerial());
- }
+ callFuture.setResponse(dataPack.getDatas());
}
@Override
@@ -390,9 +257,9 @@
LOG.warn("Unexpected exception from downstream.", e.getCause());
e.getChannel().close();
// let the blocking waiting exit
- Iterator<Callback<List<ByteBuffer>>> it = requests.values().iterator();
+ Iterator<CallFuture> it = requests.values().iterator();
while(it.hasNext()) {
- it.next().handleError(e.getCause());
+ it.next().releaseSemphore();
it.remove();
}
diff --git a/lang/java/ipc/src/main/java/org/apache/avro/ipc/Requestor.java b/lang/java/ipc/src/main/java/org/apache/avro/ipc/Requestor.java
index c600545..0a44b13 100644
--- a/lang/java/ipc/src/main/java/org/apache/avro/ipc/Requestor.java
+++ b/lang/java/ipc/src/main/java/org/apache/avro/ipc/Requestor.java
@@ -20,15 +20,12 @@
import java.io.IOException;
import java.nio.ByteBuffer;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.locks.ReentrantLock;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.avro.AvroRemoteException;
import org.apache.avro.AvroRuntimeException;
import org.apache.avro.Protocol;
import org.apache.avro.Schema;
@@ -60,13 +57,12 @@
private static final GenericDatumWriter<Map<CharSequence,ByteBuffer>>
META_WRITER = new GenericDatumWriter<Map<CharSequence,ByteBuffer>>(META);
- private final Protocol local;
- private volatile Protocol remote;
- private volatile boolean sendLocalText;
- private final Transceiver transceiver;
- private final ReentrantLock handshakeLock = new ReentrantLock();
+ private Protocol local;
+ private Protocol remote;
+ private boolean sendLocalText;
+ private Transceiver transceiver;
- protected final List<RPCPlugin> rpcMetaPlugins;
+ protected List<RPCPlugin> rpcMetaPlugins;
public Protocol getLocal() { return local; }
public Transceiver getTransceiver() { return transceiver; }
@@ -76,7 +72,7 @@
this.local = local;
this.transceiver = transceiver;
this.rpcMetaPlugins =
- new CopyOnWriteArrayList<RPCPlugin>();
+ Collections.synchronizedList(new ArrayList<RPCPlugin>());
}
/**
@@ -89,96 +85,93 @@
}
private static final EncoderFactory ENCODER_FACTORY = new EncoderFactory();
+ private BinaryEncoder encoder =
+ ENCODER_FACTORY.binaryEncoder(new ByteBufferOutputStream(), null);
/** Writes a request message and reads a response or error message. */
- public Object request(String messageName, Object request)
- throws Exception {
- // Initialize request
- Request rpcRequest = new Request(messageName, request, new RPCContext());
- CallFuture<Object> future = /* only need a Future for two-way messages */
- rpcRequest.getMessage().isOneWay() ? null : new CallFuture<Object>();
-
- // Send request
- request(rpcRequest, future);
-
- if (future == null) // the message is one-way, so return immediately
- return null;
- try { // the message is two-way, wait for the result
- return future.get();
- } catch (ExecutionException e) {
- if (e.getCause() instanceof Exception) {
- throw (Exception)e.getCause();
- } else {
- throw new AvroRemoteException(e.getCause());
- }
- }
- }
-
- /**
- * Writes a request message and returns the result through a Callback.
- * Clients can also use a Future interface by creating a new CallFuture<T>,
- * passing it in as the Callback parameter, and then waiting on that Future.
- * @param <T> the return type of the message.
- * @param messageName the name of the message to invoke.
- * @param request the request data to send.
- * @param callback the callback which will be invoked when the response is returned
- * or an error occurs.
- * @throws Exception if an error occurs sending the message.
- */
- public <T> void request(String messageName, Object request, Callback<T> callback)
- throws Exception {
- request(new Request(messageName, request, new RPCContext()), callback);
- }
-
- /** Writes a request message and returns the result through a Callback. */
- <T> void request(Request request, Callback<T> callback)
+ public synchronized Object request(String messageName, Object request)
throws Exception {
Transceiver t = getTransceiver();
- if (!t.isConnected()) {
- // Acquire handshake lock so that only one thread is performing the
- // handshake and other threads block until the handshake is completed
- handshakeLock.lock();
- try {
- if (t.isConnected()) {
- // Another thread already completed the handshake; no need to hold
- // the write lock
- handshakeLock.unlock();
- } else {
- CallFuture<T> callFuture = new CallFuture<T>(callback);
- t.transceive(request.getBytes(),
- new TransceiverCallback<T>(request, callFuture));
- // Block until handshake complete
- callFuture.await();
- return;
- }
- } finally{
- if (handshakeLock.isHeldByCurrentThread()) {
- handshakeLock.unlock();
- }
- }
- }
+ BinaryDecoder in = null;
+ Message m;
+ RPCContext context = new RPCContext();
+ do {
+ ByteBufferOutputStream bbo = new ByteBufferOutputStream();
+ //safe to use encoder because this is synchronized
+ BinaryEncoder out = ENCODER_FACTORY.binaryEncoder(bbo, encoder);
+
+ // use local protocol to write request
+ m = getLocal().getMessages().get(messageName);
+ if (m == null)
+ throw new AvroRuntimeException("Not a local message: "+messageName);
+ context.setMessage(m);
- if (request.getMessage().isOneWay()) {
- t.lockChannel();
- try {
- t.writeBuffers(request.getBytes());
- if (callback != null) {
- callback.handleResult(null);
- }
- } finally {
- t.unlockChannel();
+ writeRequest(m.getRequest(), request, out); // write request payload
+
+ out.flush();
+ List<ByteBuffer> payload = bbo.getBufferList();
+
+ writeHandshake(out); // prepend handshake if needed
+
+ context.setRequestPayload(payload);
+ for (RPCPlugin plugin : rpcMetaPlugins) {
+ plugin.clientSendRequest(context); // get meta-data from plugins
}
+ META_WRITER.write(context.requestCallMeta(), out);
+
+ out.writeString(m.getName()); // write message name
+
+ out.flush();
+ bbo.append(payload);
+
+ List<ByteBuffer> requestBytes = bbo.getBufferList();
+
+ if (m.isOneWay() && t.isConnected()) { // send one-way message
+ t.writeBuffers(requestBytes);
+
+ return null;
+ } else { // two-way message
+ List<ByteBuffer> response = t.transceive(requestBytes);
+ ByteBufferInputStream bbi = new ByteBufferInputStream(response);
+ in = DecoderFactory.get().binaryDecoder(bbi, in);
+ }
+ } while (!readHandshake(in));
+
+ // use remote protocol to read response
+ Message rm = remote.getMessages().get(messageName);
+ if (rm == null)
+ throw new AvroRuntimeException("Not a remote message: "+messageName);
+
+ if ((m.isOneWay() != rm.isOneWay()) && t.isConnected())
+ throw new AvroRuntimeException("Not both one-way messages: "+messageName);
+
+ if (m.isOneWay() && t.isConnected()) return null; // one-way w/ handshake
+
+ context.setResponseCallMeta(META_READER.read(null, in));
+
+ if (!in.readBoolean()) { // no error
+ Object response = readResponse(rm.getResponse(), in);
+ context.setResponse(response);
+ for (RPCPlugin plugin : rpcMetaPlugins) {
+ plugin.clientReceiveResponse(context);
+ }
+ return response;
+
} else {
- t.transceive(request.getBytes(),
- new TransceiverCallback<T>(request, callback));
+ Exception error = readError(rm.getErrors(), in);
+ context.setError(error);
+ for (RPCPlugin plugin : rpcMetaPlugins) {
+ plugin.clientReceiveResponse(context);
+ }
+ throw error;
}
}
- private static final ConcurrentMap<String,MD5> REMOTE_HASHES =
- new ConcurrentHashMap<String,MD5>();
- private static final ConcurrentMap<MD5,Protocol> REMOTE_PROTOCOLS =
- new ConcurrentHashMap<MD5,Protocol>();
+ private static final Map<String,MD5> REMOTE_HASHES =
+ Collections.synchronizedMap(new HashMap<String,MD5>());
+ private static final Map<MD5,Protocol> REMOTE_PROTOCOLS =
+ Collections.synchronizedMap(new HashMap<MD5,Protocol>());
private static final SpecificDatumWriter<HandshakeRequest> HANDSHAKE_WRITER =
new SpecificDatumWriter<HandshakeRequest>(HandshakeRequest.class);
@@ -192,11 +185,10 @@
localHash.bytes(local.getMD5());
String remoteName = transceiver.getRemoteName();
MD5 remoteHash = REMOTE_HASHES.get(remoteName);
+ remote = REMOTE_PROTOCOLS.get(remoteHash);
if (remoteHash == null) { // guess remote is local
remoteHash = localHash;
remote = local;
- } else {
- remote = REMOTE_PROTOCOLS.get(remoteHash);
}
HandshakeRequest handshake = new HandshakeRequest();
handshake.clientHash = localHash;
@@ -248,40 +240,34 @@
return established;
}
- private void setRemote(HandshakeResponse handshake) throws IOException {
+ private void setRemote(HandshakeResponse handshake) {
remote = Protocol.parse(handshake.serverProtocol.toString());
MD5 remoteHash = (MD5)handshake.serverHash;
REMOTE_HASHES.put(transceiver.getRemoteName(), remoteHash);
- REMOTE_PROTOCOLS.putIfAbsent(remoteHash, remote);
+ if (!REMOTE_PROTOCOLS.containsKey(remoteHash))
+ REMOTE_PROTOCOLS.put(remoteHash, remote);
}
/** Return the remote protocol. Force a handshake if required. */
- public Protocol getRemote() throws IOException {
+ public synchronized Protocol getRemote() throws IOException {
if (remote != null) return remote; // already have it
MD5 remoteHash = REMOTE_HASHES.get(transceiver.getRemoteName());
- if (remoteHash != null) {
- remote = REMOTE_PROTOCOLS.get(remoteHash);
- if (remote != null) return remote; // already cached
- }
- handshakeLock.lock();
- try {
- // force handshake
- ByteBufferOutputStream bbo = new ByteBufferOutputStream();
- // direct because the payload is tiny.
- Encoder out = ENCODER_FACTORY.directBinaryEncoder(bbo, null);
- writeHandshake(out);
- out.writeInt(0); // empty metadata
- out.writeString(""); // bogus message name
- List<ByteBuffer> response =
- getTransceiver().transceive(bbo.getBufferList());
- ByteBufferInputStream bbi = new ByteBufferInputStream(response);
- BinaryDecoder in =
- DecoderFactory.get().binaryDecoder(bbi, null);
- readHandshake(in);
- return this.remote;
- } finally {
- handshakeLock.unlock();
- }
+ remote = REMOTE_PROTOCOLS.get(remoteHash);
+ if (remote != null) return remote; // already cached
+ // force handshake
+ ByteBufferOutputStream bbo = new ByteBufferOutputStream();
+ // direct because the payload is tiny.
+ Encoder out = ENCODER_FACTORY.directBinaryEncoder(bbo, null);
+ writeHandshake(out);
+ out.writeInt(0); // empty metadata
+ out.writeString(""); // bogus message name
+ List<ByteBuffer> response =
+ getTransceiver().transceive(bbo.getBufferList());
+ ByteBufferInputStream bbi = new ByteBufferInputStream(response);
+ BinaryDecoder in =
+ DecoderFactory.get().binaryDecoder(bbi, null);
+ readHandshake(in);
+ return this.remote;
}
@@ -289,266 +275,12 @@
public abstract void writeRequest(Schema schema, Object request,
Encoder out) throws IOException;
- @Deprecated // for compatibility in 1.5
- public Object readResponse(Schema schema, Decoder in) throws IOException {
- return readResponse(schema, schema, in);
- }
-
/** Reads a response message. */
- public abstract Object readResponse(Schema writer, Schema reader, Decoder in)
+ public abstract Object readResponse(Schema schema, Decoder in)
throws IOException;
- @Deprecated // for compatibility in 1.5
- public Object readError(Schema schema, Decoder in) throws IOException {
- return readError(schema, schema, in);
- }
-
/** Reads an error message. */
- public abstract Exception readError(Schema writer, Schema reader, Decoder in)
+ public abstract Exception readError(Schema schema, Decoder in)
throws IOException;
-
- /**
- * Handles callbacks from transceiver invocations.
- */
- protected class TransceiverCallback<T> implements Callback<List<ByteBuffer>> {
- private final Request request;
- private final Callback<T> callback;
-
- /**
- * Creates a TransceiverCallback.
- * @param request the request to set.
- * @param callback the callback to set.
- */
- public TransceiverCallback(Request request, Callback<T> callback) {
- this.request = request;
- this.callback = callback;
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public void handleResult(List<ByteBuffer> responseBytes) {
- ByteBufferInputStream bbi = new ByteBufferInputStream(responseBytes);
- BinaryDecoder in = DecoderFactory.get().binaryDecoder(bbi, null);
- try {
- if (!readHandshake(in)) {
- // Resend the handshake and return
- Request handshake = new Request(request);
- getTransceiver().transceive
- (handshake.getBytes(),
- new TransceiverCallback<T>(handshake, callback));
- return;
- }
- } catch (Exception e) {
- LOG.error("Error handling transceiver callback: " + e, e);
- }
-
- // Read response; invoke callback
- Response response = new Response(request, in);
- Object responseObject;
- try {
- try {
- responseObject = response.getResponse();
- } catch (Exception e) {
- if (callback != null) {
- callback.handleError(e);
- }
- return;
- }
- if (callback != null) {
- callback.handleResult((T)responseObject);
- }
- } catch (Throwable t) {
- LOG.error("Error in callback handler: " + t, t);
- }
- }
-
- @Override
- public void handleError(Throwable error) {
- callback.handleError(error);
- }
- }
-
- /**
- * Encapsulates/generates a request.
- */
- class Request {
- private final String messageName;
- private final Object request;
- private final RPCContext context;
- private final BinaryEncoder encoder;
- private Message message;
- private List<ByteBuffer> requestBytes;
-
- /**
- * Creates a Request.
- * @param messageName the name of the message to invoke.
- * @param request the request data to send.
- * @param context the RPC context to use.
- */
- public Request(String messageName, Object request, RPCContext context) {
- this(messageName, request, context, null);
- }
-
- /**
- * Creates a Request.
- * @param messageName the name of the message to invoke.
- * @param request the request data to send.
- * @param context the RPC context to use.
- * @param encoder the BinaryEncoder to use to serialize the request.
- */
- public Request(String messageName, Object request, RPCContext context,
- BinaryEncoder encoder) {
- this.messageName = messageName;
- this.request = request;
- this.context = context;
- this.encoder =
- ENCODER_FACTORY.binaryEncoder(new ByteBufferOutputStream(), encoder);
- }
-
- /**
- * Copy constructor.
- * @param other Request from which to copy fields.
- */
- public Request(Request other) {
- this.messageName = other.messageName;
- this.request = other.request;
- this.context = other.context;
- this.encoder = other.encoder;
- }
-
- /**
- * Gets the message name.
- * @return the message name.
- */
- public String getMessageName() {
- return messageName;
- }
-
- /**
- * Gets the RPC context.
- * @return the RPC context.
- */
- public RPCContext getContext() {
- return context;
- }
-
- /**
- * Gets the Message associated with this request.
- * @return this request's message.
- */
- public Message getMessage() {
- if (message == null) {
- message = getLocal().getMessages().get(messageName);
- if (message == null) {
- throw new AvroRuntimeException("Not a local message: "+messageName);
- }
- }
- return message;
- }
-
- /**
- * Gets the request data, generating it first if necessary.
- * @return the request data.
- * @throws Exception if an error occurs generating the request data.
- */
- public List<ByteBuffer> getBytes()
- throws Exception {
- if (requestBytes == null) {
- ByteBufferOutputStream bbo = new ByteBufferOutputStream();
- BinaryEncoder out = ENCODER_FACTORY.binaryEncoder(bbo, encoder);
-
- // use local protocol to write request
- Message m = getMessage();
- context.setMessage(m);
-
- writeRequest(m.getRequest(), request, out); // write request payload
-
- out.flush();
- List<ByteBuffer> payload = bbo.getBufferList();
-
- writeHandshake(out); // prepend handshake if needed
-
- context.setRequestPayload(payload);
- for (RPCPlugin plugin : rpcMetaPlugins) {
- plugin.clientSendRequest(context); // get meta-data from plugins
- }
- META_WRITER.write(context.requestCallMeta(), out);
-
- out.writeString(m.getName()); // write message name
-
- out.flush();
- bbo.append(payload);
-
- requestBytes = bbo.getBufferList();
- }
- return requestBytes;
- }
- }
-
- /**
- * Encapsulates/parses a response.
- */
- class Response {
- private final Request request;
- private final BinaryDecoder in;
-
- /**
- * Creates a Response.
- * @param request the Request associated with this response.
- */
- public Response(Request request) {
- this(request, null);
- }
-
- /**
- * Creates a Creates a Response.
- * @param request the Request associated with this response.
- * @param in the BinaryDecoder to use to deserialize the response.
- */
- public Response(Request request, BinaryDecoder in) {
- this.request = request;
- this.in = in;
- }
-
- /**
- * Gets the RPC response, reading/deserializing it first if necessary.
- * @return the RPC response.
- * @throws Exception if an error occurs reading/deserializing the response.
- */
- public Object getResponse()
- throws Exception {
- Message lm = request.getMessage();
- Message rm = remote.getMessages().get(request.getMessageName());
- if (rm == null)
- throw new AvroRuntimeException
- ("Not a remote message: "+request.getMessageName());
-
- Transceiver t = getTransceiver();
- if ((lm.isOneWay() != rm.isOneWay()) && t.isConnected())
- throw new AvroRuntimeException
- ("Not both one-way messages: "+request.getMessageName());
-
- if (lm.isOneWay() && t.isConnected()) return null; // one-way w/ handshake
-
- RPCContext context = request.getContext();
- context.setResponseCallMeta(META_READER.read(null, in));
-
- if (!in.readBoolean()) { // no error
- Object response = readResponse(rm.getResponse(), lm.getResponse(), in);
- context.setResponse(response);
- for (RPCPlugin plugin : rpcMetaPlugins) {
- plugin.clientReceiveResponse(context);
- }
- return response;
-
- } else {
- Exception error = readError(rm.getErrors(), lm.getErrors(), in);
- context.setError(error);
- for (RPCPlugin plugin : rpcMetaPlugins) {
- plugin.clientReceiveResponse(context);
- }
- throw error;
- }
- }
- }
}
+
diff --git a/lang/java/ipc/src/main/java/org/apache/avro/ipc/Responder.java b/lang/java/ipc/src/main/java/org/apache/avro/ipc/Responder.java
index 455bc17..428756e 100644
--- a/lang/java/ipc/src/main/java/org/apache/avro/ipc/Responder.java
+++ b/lang/java/ipc/src/main/java/org/apache/avro/ipc/Responder.java
@@ -21,8 +21,9 @@
import java.io.IOException;
import java.nio.ByteBuffer;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -61,12 +62,12 @@
private static final ThreadLocal<Protocol> REMOTE =
new ThreadLocal<Protocol>();
- private final Map<MD5,Protocol> protocols
- = new ConcurrentHashMap<MD5,Protocol>();
+ private Map<MD5,Protocol> protocols
+ = Collections.synchronizedMap(new HashMap<MD5,Protocol>());
- private final Protocol local;
- private final MD5 localHash;
- protected final List<RPCPlugin> rpcMetaPlugins;
+ private Protocol local;
+ private MD5 localHash;
+ protected List<RPCPlugin> rpcMetaPlugins;
protected Responder(Protocol local) {
this.local = local;
@@ -74,7 +75,7 @@
localHash.bytes(local.getMD5());
protocols.put(localHash, local);
this.rpcMetaPlugins =
- new CopyOnWriteArrayList<RPCPlugin>();
+ Collections.synchronizedList(new ArrayList<RPCPlugin>());
}
/** Return the remote protocol. Accesses a {@link ThreadLocal} that's set
diff --git a/lang/java/ipc/src/main/java/org/apache/avro/ipc/SaslSocketTransceiver.java b/lang/java/ipc/src/main/java/org/apache/avro/ipc/SaslSocketTransceiver.java
index 880c7a5..5a88899 100644
--- a/lang/java/ipc/src/main/java/org/apache/avro/ipc/SaslSocketTransceiver.java
+++ b/lang/java/ipc/src/main/java/org/apache/avro/ipc/SaslSocketTransceiver.java
@@ -256,7 +256,7 @@
zeroHeader.flip(); // zero-terminate
writes.add(zeroHeader);
- writeFully(writes.toArray(new ByteBuffer[writes.size()]));
+ channel.write(writes.toArray(new ByteBuffer[writes.size()]));
}
private void write(Status status, String prefix, ByteBuffer response)
@@ -275,7 +275,7 @@
ByteBuffer statusBuffer = ByteBuffer.allocate(1);
statusBuffer.clear();
statusBuffer.put((byte)(status.ordinal())).flip();
- writeFully(statusBuffer);
+ channel.write(statusBuffer);
write(response);
}
@@ -283,20 +283,7 @@
LOG.debug("writing: {}", response.remaining());
writeHeader.clear();
writeHeader.putInt(response.remaining()).flip();
- writeFully(writeHeader, response);
- }
-
- private void writeFully(ByteBuffer... buffers) throws IOException {
- int length = buffers.length;
- int start = 0;
- do {
- channel.write(buffers, start, length-start);
- while (buffers[start].remaining() == 0) {
- start++;
- if (start == length)
- return;
- }
- } while (true);
+ channel.write(new ByteBuffer[] { writeHeader, response });
}
@Override public void close() throws IOException {
diff --git a/lang/java/ipc/src/main/java/org/apache/avro/ipc/SocketServer.java b/lang/java/ipc/src/main/java/org/apache/avro/ipc/SocketServer.java
index 8db5d66..1ade0dc 100644
--- a/lang/java/ipc/src/main/java/org/apache/avro/ipc/SocketServer.java
+++ b/lang/java/ipc/src/main/java/org/apache/avro/ipc/SocketServer.java
@@ -83,7 +83,6 @@
}
public void close() {
- this.interrupt();
group.interrupt();
}
diff --git a/lang/java/ipc/src/main/java/org/apache/avro/ipc/Transceiver.java b/lang/java/ipc/src/main/java/org/apache/avro/ipc/Transceiver.java
index 898fd77..c566c60 100644
--- a/lang/java/ipc/src/main/java/org/apache/avro/ipc/Transceiver.java
+++ b/lang/java/ipc/src/main/java/org/apache/avro/ipc/Transceiver.java
@@ -22,58 +22,21 @@
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.List;
-import java.util.concurrent.locks.ReentrantLock;
import org.apache.avro.Protocol;
/** Base transport class used by {@link Requestor}. */
public abstract class Transceiver implements Closeable {
- private final ReentrantLock channelLock = new ReentrantLock();
- public abstract String getRemoteName() throws IOException;
-
- /**
- * Acquires an exclusive lock on the transceiver's channel.
- */
- public void lockChannel() {
- channelLock.lock();
- }
-
- /**
- * Releases the lock on the transceiver's channel if held by the calling thread.
- */
- public void unlockChannel() {
- if (channelLock.isHeldByCurrentThread()) {
- channelLock.unlock();
- }
- }
+ public abstract String getRemoteName();
/** Called by {@link Requestor#request(String,Object)} for two-way messages.
* By default calls {@link #writeBuffers(List)} followed by
* {@link #readBuffers()}. */
- public List<ByteBuffer> transceive(List<ByteBuffer> request)
+ public synchronized List<ByteBuffer> transceive(List<ByteBuffer> request)
throws IOException {
- lockChannel();
- try {
- writeBuffers(request);
- return readBuffers();
- } finally {
- unlockChannel();
- }
- }
-
- /**
- * Called by {@link Requestor#request(String,Object,Callback)} for two-way messages using callbacks.
- */
- public void transceive(List<ByteBuffer> request, Callback<List<ByteBuffer>> callback)
- throws IOException {
- // The default implementation works synchronously
- try {
- List<ByteBuffer> response = transceive(request);
- callback.handleResult(response);
- } catch (IOException e) {
- callback.handleError(e);
- }
+ writeBuffers(request);
+ return readBuffers();
}
/** Called by the default definition of {@link #transceive(List)}.*/
diff --git a/lang/java/ipc/src/main/java/org/apache/avro/ipc/generic/GenericRequestor.java b/lang/java/ipc/src/main/java/org/apache/avro/ipc/generic/GenericRequestor.java
index 30ddac0..5b5424c 100644
--- a/lang/java/ipc/src/main/java/org/apache/avro/ipc/generic/GenericRequestor.java
+++ b/lang/java/ipc/src/main/java/org/apache/avro/ipc/generic/GenericRequestor.java
@@ -28,7 +28,6 @@
import org.apache.avro.generic.GenericDatumWriter;
import org.apache.avro.io.Decoder;
import org.apache.avro.io.Encoder;
-import org.apache.avro.ipc.Callback;
import org.apache.avro.ipc.Requestor;
import org.apache.avro.ipc.Transceiver;
@@ -54,35 +53,20 @@
}
@Override
- public <T> void request(String messageName, Object request, Callback<T> callback)
- throws IOException {
- try {
- super.request(messageName, request, callback);
- } catch (Exception e) {
- if (e instanceof RuntimeException)
- throw (RuntimeException)e;
- if (e instanceof IOException)
- throw (IOException)e;
- throw new AvroRemoteException(e);
- }
- }
-
- @Override
public void writeRequest(Schema schema, Object request, Encoder out)
throws IOException {
new GenericDatumWriter<Object>(schema).write(request, out);
}
@Override
- public Object readResponse(Schema writer, Schema reader, Decoder in)
- throws IOException {
- return new GenericDatumReader<Object>(writer, reader).read(null, in);
+ public Object readResponse(Schema schema, Decoder in) throws IOException {
+ return new GenericDatumReader<Object>(schema).read(null, in);
}
@Override
- public Exception readError(Schema writer, Schema reader, Decoder in)
+ public Exception readError(Schema schema, Decoder in)
throws IOException {
- Object error = new GenericDatumReader<Object>(writer, reader).read(null,in);
+ Object error = new GenericDatumReader<Object>(schema).read(null,in);
if (error instanceof CharSequence)
return new AvroRuntimeException(error.toString()); // system error
return new AvroRemoteException(error);
diff --git a/lang/java/ipc/src/main/java/org/apache/avro/ipc/reflect/ReflectRequestor.java b/lang/java/ipc/src/main/java/org/apache/avro/ipc/reflect/ReflectRequestor.java
index 0560d7e..b91d52f 100644
--- a/lang/java/ipc/src/main/java/org/apache/avro/ipc/reflect/ReflectRequestor.java
+++ b/lang/java/ipc/src/main/java/org/apache/avro/ipc/reflect/ReflectRequestor.java
@@ -50,8 +50,8 @@
}
@Override
- protected DatumReader<Object> getDatumReader(Schema writer, Schema reader) {
- return new ReflectDatumReader<Object>(writer, reader);
+ protected DatumReader<Object> getDatumReader(Schema schema) {
+ return new ReflectDatumReader<Object>(schema);
}
/** Create a proxy instance whose methods invoke RPCs. */
diff --git a/lang/java/ipc/src/main/java/org/apache/avro/ipc/specific/SpecificRequestor.java b/lang/java/ipc/src/main/java/org/apache/avro/ipc/specific/SpecificRequestor.java
index 7ad6f43..c4c8712 100644
--- a/lang/java/ipc/src/main/java/org/apache/avro/ipc/specific/SpecificRequestor.java
+++ b/lang/java/ipc/src/main/java/org/apache/avro/ipc/specific/SpecificRequestor.java
@@ -22,10 +22,7 @@
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Type;
-import java.util.Arrays;
-import org.apache.avro.AvroRemoteException;
import org.apache.avro.Protocol;
import org.apache.avro.Schema;
import org.apache.avro.AvroRuntimeException;
@@ -35,7 +32,6 @@
import org.apache.avro.io.Encoder;
import org.apache.avro.ipc.Transceiver;
import org.apache.avro.ipc.Requestor;
-import org.apache.avro.ipc.Callback;
import org.apache.avro.specific.SpecificData;
import org.apache.avro.specific.SpecificDatumReader;
import org.apache.avro.specific.SpecificDatumWriter;
@@ -56,50 +52,15 @@
@Override
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
- try {
- // Check if this is a callback-based RPC:
- Type[] parameterTypes = method.getParameterTypes();
- if ((parameterTypes.length > 0) &&
- (parameterTypes[parameterTypes.length - 1] instanceof Class) &&
- Callback.class.isAssignableFrom(((Class<?>)parameterTypes[parameterTypes.length - 1]))) {
- // Extract the Callback from the end of of the argument list
- Object[] finalArgs = Arrays.copyOf(args, args.length - 1);
- Callback<?> callback = (Callback<?>)args[args.length - 1];
- request(method.getName(), finalArgs, callback);
- return null;
- }
- else {
- return request(method.getName(), args);
- }
- } catch (Exception e) {
- // Check if this is a declared Exception:
- for (Class<?> exceptionClass : method.getExceptionTypes()) {
- if (exceptionClass.isAssignableFrom(e.getClass())) {
- throw e;
- }
- }
-
- // Next, check for RuntimeExceptions:
- if (e instanceof RuntimeException) {
- throw e;
- }
-
- // Not an expected Exception, so wrap it in AvroRemoteException:
- throw new AvroRemoteException(e);
- }
+ return request(method.getName(), args);
}
protected DatumWriter<Object> getDatumWriter(Schema schema) {
return new SpecificDatumWriter<Object>(schema);
}
- @Deprecated // for compatibility in 1.5
protected DatumReader<Object> getDatumReader(Schema schema) {
- return getDatumReader(schema, schema);
- }
-
- protected DatumReader<Object> getDatumReader(Schema writer, Schema reader) {
- return new SpecificDatumReader<Object>(writer, reader);
+ return new SpecificDatumReader<Object>(schema);
}
@Override
@@ -112,15 +73,14 @@
}
@Override
- public Object readResponse(Schema writer, Schema reader, Decoder in)
- throws IOException {
- return getDatumReader(writer, reader).read(null, in);
+ public Object readResponse(Schema schema, Decoder in) throws IOException {
+ return getDatumReader(schema).read(null, in);
}
@Override
- public Exception readError(Schema writer, Schema reader, Decoder in)
+ public Exception readError(Schema schema, Decoder in)
throws IOException {
- Object value = getDatumReader(writer, reader).read(null, in);
+ Object value = getDatumReader(schema).read(null, in);
if (value instanceof Exception)
return (Exception)value;
return new AvroRuntimeException(value.toString());
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolGeneric.java b/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolGeneric.java
index 30eb4ca..8b000fc 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolGeneric.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolGeneric.java
@@ -44,8 +44,6 @@
import java.util.List;
import java.util.Random;
-import org.codehaus.jackson.node.BooleanNode;
-
public class TestProtocolGeneric {
private static final Logger LOG
= LoggerFactory.getLogger(TestProtocolGeneric.class);
@@ -213,50 +211,6 @@
}
}
- @Test
- /** Construct and use a different protocol whose "echo" response has an extra
- field to check that correct schema is used to parse response. */
- public void testResponseChange() throws IOException {
-
- List<Field> fields = new ArrayList<Field>();
- for (Field f : PROTOCOL.getType("TestRecord").getFields())
- fields.add(new Field(f.name(), f.schema(), null, null));
- fields.add(new Field("extra", Schema.create(Schema.Type.BOOLEAN),
- null, BooleanNode.TRUE));
- Schema record =
- Schema.createRecord("TestRecord", null, "org.apache.avro.test", false);
- record.setFields(fields);
-
- Protocol protocol = new Protocol("Simple", "org.apache.avro.test");
- List<Field> params = new ArrayList<Field>();
- params.add(new Field("record", record, null, null));
-
- Protocol.Message message =
- protocol.createMessage("echo", null, Schema.createRecord(params),
- record,
- Schema.createUnion(new ArrayList<Schema>()));
- protocol.getMessages().put("echo", message);
- Transceiver t
- = new SocketTransceiver(new InetSocketAddress(server.getPort()));
- try {
- GenericRequestor r = new GenericRequestor(protocol, t);
- GenericRecord args = new GenericData.Record(message.getRequest());
- GenericRecord rec = new GenericData.Record(record);
- rec.put("name", new Utf8("foo"));
- rec.put("kind", new GenericData.EnumSymbol
- (PROTOCOL.getType("Kind"), "BAR"));
- rec.put("hash", new GenericData.Fixed
- (PROTOCOL.getType("MD5"),
- new byte[]{0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5}));
- rec.put("extra", Boolean.TRUE);
- args.put("record", rec);
- GenericRecord response = (GenericRecord)r.request("echo", args);
- assertEquals(rec, response);
- } finally {
- t.close();
- }
- }
-
@AfterClass
public static void testStopServer() throws IOException {
client.close();
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolHttp.java b/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolHttp.java
index dc460c5..c187334 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolHttp.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolHttp.java
@@ -34,6 +34,7 @@
import java.net.URL;
import java.net.ServerSocket;
import java.net.SocketTimeoutException;
+import java.lang.reflect.UndeclaredThrowableException;
import java.util.ArrayList;
public class TestProtocolHttp extends TestProtocolSpecific {
@@ -61,7 +62,7 @@
Simple proxy = SpecificRequestor.getClient(Simple.class, client);
try {
proxy.hello("foo");
- } catch (AvroRemoteException e) {
+ } catch (UndeclaredThrowableException e) {
throw e.getCause();
} finally {
s.close();
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolNetty.java b/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolNetty.java
deleted file mode 100644
index 9fefa04..0000000
--- a/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolNetty.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * 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.
- */
-
-package org.apache.avro;
-
-import java.net.InetSocketAddress;
-
-import org.apache.avro.ipc.NettyServer;
-import org.apache.avro.ipc.NettyTransceiver;
-import org.apache.avro.ipc.Responder;
-import org.apache.avro.ipc.Server;
-import org.apache.avro.ipc.Transceiver;
-
-/**
- * Protocol test with Netty server and transceiver
- */
-public class TestProtocolNetty extends TestProtocolSpecific {
- @Override
- public Server createServer(Responder testResponder) throws Exception {
- return new NettyServer(responder, new InetSocketAddress(0));
- }
-
- @Override
- public Transceiver createTransceiver() throws Exception{
- return new NettyTransceiver(new InetSocketAddress(server.getPort()));
- }
-
- @Override
- protected int getExpectedHandshakeCount() {
- return REPEATING;
- }
-}
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java b/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java
index 94f9136..fde018b 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java
@@ -45,6 +45,7 @@
import org.apache.avro.io.Decoder;
import org.apache.avro.io.Encoder;
import org.apache.avro.io.EncoderFactory;
+import org.apache.avro.io.JsonDecoder;
import org.apache.avro.compiler.specific.TestSpecificCompiler;
import org.apache.avro.util.Utf8;
@@ -78,7 +79,7 @@
+ " \"name\": \"inner_union\" }\n" + " ]\n" + "}\n";
private static final int COUNT =
- Integer.parseInt(System.getProperty("test.count", "30"));
+ Integer.parseInt(System.getProperty("test.count", "10"));
@Test
public void testNull() throws Exception {
@@ -162,18 +163,6 @@
check("{\"type\":\"map\", \"values\":\"long\"}", "{\"a\":1}", map);
checkParseError("{\"type\":\"map\"}"); // values required
}
-
- @Test
- public void testUnionMap() throws Exception {
- String unionMapSchema = "{\"name\":\"foo\", \"type\":\"record\"," +
- " \"fields\":[ {\"name\":\"mymap\", \"type\":" +
- " [{\"type\":\"map\", \"values\":" +
- " [\"int\",\"long\",\"float\",\"string\"]}," +
- " \"null\"]" +
- " }]" +
- " }";
- check(unionMapSchema, true);
- }
@Test
public void testRecord() throws Exception {
@@ -210,26 +199,6 @@
+"{\"name\":\"f.g\",\"type\":\"int\"}]}");
}
- @Test public void testInvalidNameTolerance() {
- Schema.parse("{\"type\":\"record\",\"name\":\"1X\",\"fields\":[]}", false);
- Schema.parse("{\"type\":\"record\",\"name\":\"X-\",\"fields\":[]}", false);
- Schema.parse("{\"type\":\"record\",\"name\":\"X$\",\"fields\":[]}", false);
- }
-
- @Test
- public void testMapInRecord() throws Exception {
- String json = "{\"type\":\"record\", \"name\":\"Test\", \"fields\":"
- +"[{\"name\":\"f\", \"type\": {\"type\":\"map\", \"values\":\"long\"}}]}";
- Schema schema = Schema.parse(json);
-
- HashMap<Utf8,Long> map = new HashMap<Utf8,Long>();
- map.put(new Utf8("a"), 1L);
- GenericData.Record record = new GenericData.Record(schema);
- record.put("f", map);
- check(json, "{\"f\":{\"a\":1}}", record, false);
- }
-
-
@Test
public void testEnum() throws Exception {
check(BASIC_ENUM_SCHEMA, "\"B\"",
@@ -575,7 +544,6 @@
throws Exception {
Schema schema = Schema.parse(jsonSchema);
checkProp(schema);
- Object reuse = null;
for (Object datum : new RandomData(schema, COUNT)) {
if (induce) {
@@ -588,10 +556,7 @@
checkBinary(schema, datum,
new GenericDatumWriter<Object>(),
- new GenericDatumReader<Object>(), null);
- reuse = checkBinary(schema, datum,
- new GenericDatumWriter<Object>(),
- new GenericDatumReader<Object>(), reuse);
+ new GenericDatumReader<Object>());
checkDirectBinary(schema, datum,
new GenericDatumWriter<Object>(),
new GenericDatumReader<Object>());
@@ -624,14 +589,6 @@
DatumWriter<Object> writer,
DatumReader<Object> reader)
throws IOException {
- checkBinary(schema, datum, writer, reader, null);
- }
-
- public static Object checkBinary(Schema schema, Object datum,
- DatumWriter<Object> writer,
- DatumReader<Object> reader,
- Object reuse)
- throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
writer.setSchema(schema);
Encoder encoder = EncoderFactory.get().binaryEncoder(out, null);
@@ -642,11 +599,10 @@
reader.setSchema(schema);
Object decoded =
- reader.read(reuse, DecoderFactory.get().binaryDecoder(
+ reader.read(null, DecoderFactory.get().binaryDecoder(
data, null));
assertEquals("Decoded data does not match.", datum, decoded);
- return decoded;
}
public static void checkDirectBinary(Schema schema, Object datum,
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestNettyServer.java b/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestNettyServer.java
index 46c6a75..4fa3eda 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestNettyServer.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestNettyServer.java
@@ -18,11 +18,7 @@
package org.apache.avro.ipc;
-import static org.junit.Assert.assertEquals;
-
import java.net.InetSocketAddress;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
import junit.framework.Assert;
@@ -31,109 +27,52 @@
import org.apache.avro.test.Mail;
import org.apache.avro.test.Message;
import org.apache.avro.util.Utf8;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
import org.junit.Test;
public class TestNettyServer {
- private static Server server;
- private static Transceiver transceiver;
- private static Mail proxy;
- private static MailImpl mailService;
-
public static class MailImpl implements Mail {
-
- private CountDownLatch allMessages = new CountDownLatch(5);
-
// in this simple example just return details of the message
public CharSequence send(Message message) {
return new Utf8("Sent message to [" + message.to.toString() + "] from ["
+ message.from.toString() + "] with body [" + message.body.toString()
+ "]");
}
-
- public void fireandforget(Message message) {
- allMessages.countDown();
- }
-
- private void awaitMessages() throws InterruptedException {
- allMessages.await(2, TimeUnit.SECONDS);
- }
-
- private void assertAllMessagesReceived() {
- assertEquals(0, allMessages.getCount());
- }
-
- public void reset() {
- allMessages = new CountDownLatch(5);
- }
}
-
- @BeforeClass
- public static void initializeConnections()throws Exception {
+
+ @Test
+ public void test() throws Exception {
// start server
System.out.println("starting server...");
- mailService = new MailImpl();
- Responder responder = new SpecificResponder(Mail.class, mailService);
- server = new NettyServer(responder, new InetSocketAddress(0));
+ Responder responder = new SpecificResponder(Mail.class, new MailImpl());
+ Server server = new NettyServer(responder, new InetSocketAddress(0));
server.start();
-
+
int serverPort = server.getPort();
System.out.println("server port : " + serverPort);
- transceiver = new NettyTransceiver(new InetSocketAddress(
+ // client
+ Transceiver transceiver = new NettyTransceiver(new InetSocketAddress(
serverPort));
- proxy = SpecificRequestor.getClient(Mail.class, transceiver);
- }
-
- @AfterClass
- public static void tearDownConnections() throws Exception{
- transceiver.close();
- server.close();
- }
+ Mail proxy = SpecificRequestor.getClient(Mail.class, transceiver);
- @Test
- public void testRequestResponse() throws Exception {
- for(int x = 0; x < 5; x++) {
- verifyResponse(proxy.send(createMessage()));
- }
- }
-
- private void verifyResponse(CharSequence result) {
- Assert.assertEquals(
- "Sent message to [wife] from [husband] with body [I love you!]",
- result.toString());
- }
-
- @Test
- public void testOneway() throws Exception {
- for (int x = 0; x < 5; x++) {
- proxy.fireandforget(createMessage());
- }
- mailService.awaitMessages();
- mailService.assertAllMessagesReceived();
- }
-
- @Test
- public void testMixtureOfRequests() throws Exception {
- mailService.reset();
- for (int x = 0; x < 5; x++) {
- Message createMessage = createMessage();
- proxy.fireandforget(createMessage);
- verifyResponse(proxy.send(createMessage));
- }
- mailService.awaitMessages();
- mailService.assertAllMessagesReceived();
-
- }
-
- private Message createMessage() {
Message msg = new Message();
msg.to = new Utf8("wife");
msg.from = new Utf8("husband");
msg.body = new Utf8("I love you!");
- return msg;
+
+ try {
+ for(int x = 0; x < 5; x++) {
+ CharSequence result = proxy.send(msg);
+ System.out.println("Result: " + result);
+ Assert.assertEquals(
+ "Sent message to [wife] from [husband] with body [I love you!]",
+ result.toString());
+ }
+ } finally {
+ transceiver.close();
+ server.close();
+ }
}
}
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestNettyServerWithCallbacks.java b/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestNettyServerWithCallbacks.java
deleted file mode 100644
index 536a074..0000000
--- a/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestNettyServerWithCallbacks.java
+++ /dev/null
@@ -1,547 +0,0 @@
-/**
- * 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.
- */
-
-package org.apache.avro.ipc;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.nio.ByteBuffer;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Semaphore;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicLong;
-import java.util.concurrent.atomic.AtomicReference;
-
-import org.apache.avro.AvroRemoteException;
-import org.apache.avro.ipc.specific.SpecificRequestor;
-import org.apache.avro.ipc.specific.SpecificResponder;
-import org.apache.avro.test.Simple;
-import org.apache.avro.test.TestError;
-import org.apache.avro.test.TestRecord;
-import org.apache.avro.util.Utf8;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-
-/**
- * Tests asynchronous RPCs with Netty.
- */
-public class TestNettyServerWithCallbacks {
- private static Server server;
- private static Transceiver transceiver;
- private static Simple.Callback simpleClient;
- private static final AtomicBoolean ackFlag = new AtomicBoolean(false);
- private static final AtomicReference<CountDownLatch> ackLatch =
- new AtomicReference<CountDownLatch>(new CountDownLatch(1));
- private static Simple simpleService = new SimpleImpl(ackFlag);
-
- @BeforeClass
- public static void initializeConnections() throws Exception {
- // start server
- Responder responder = new SpecificResponder(Simple.class, simpleService);
- server = new NettyServer(responder, new InetSocketAddress(0));
- server.start();
-
- int serverPort = server.getPort();
- System.out.println("server port : " + serverPort);
-
- transceiver = new NettyTransceiver(new InetSocketAddress(
- serverPort));
- simpleClient = SpecificRequestor.getClient(Simple.Callback.class, transceiver);
- }
-
- @AfterClass
- public static void tearDownConnections() throws Exception {
- if (transceiver != null) {
- transceiver.close();
- }
- if (server != null) {
- server.close();
- }
- }
-
- @Test
- public void greeting() throws Exception {
- // Test synchronous RPC:
- Assert.assertEquals(new Utf8("Hello, how are you?"), simpleClient.hello("how are you?"));
-
- // Test asynchronous RPC (future):
- CallFuture<CharSequence> future1 = new CallFuture<CharSequence>();
- simpleClient.hello("World!", future1);
- Assert.assertEquals(new Utf8("Hello, World!"), future1.get(2, TimeUnit.SECONDS));
- Assert.assertNull(future1.getError());
-
- // Test asynchronous RPC (callback):
- final CallFuture<CharSequence> future2 = new CallFuture<CharSequence>();
- simpleClient.hello("what's up?", new Callback<CharSequence>() {
- @Override
- public void handleResult(CharSequence result) {
- future2.handleResult(result);
- }
- @Override
- public void handleError(Throwable error) {
- future2.handleError(error);
- }
- });
- Assert.assertEquals(new Utf8("Hello, what's up?"), future2.get(2, TimeUnit.SECONDS));
- Assert.assertNull(future2.getError());
- }
-
- @Test
- public void echo() throws Exception {
- TestRecord record = new TestRecord();
- record.hash = new org.apache.avro.test.MD5();
- record.hash.bytes(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8 } );
- record.kind = org.apache.avro.test.Kind.FOO;
- record.name = "My Record";
-
- // Test synchronous RPC:
- Assert.assertEquals(record, simpleClient.echo(record));
-
- // Test asynchronous RPC (future):
- CallFuture<TestRecord> future1 = new CallFuture<TestRecord>();
- simpleClient.echo(record, future1);
- Assert.assertEquals(record, future1.get(2, TimeUnit.SECONDS));
- Assert.assertNull(future1.getError());
-
- // Test asynchronous RPC (callback):
- final CallFuture<TestRecord> future2 = new CallFuture<TestRecord>();
- simpleClient.echo(record, new Callback<TestRecord>() {
- @Override
- public void handleResult(TestRecord result) {
- future2.handleResult(result);
- }
- @Override
- public void handleError(Throwable error) {
- future2.handleError(error);
- }
- });
- Assert.assertEquals(record, future2.get(2, TimeUnit.SECONDS));
- Assert.assertNull(future2.getError());
- }
-
- @Test
- public void add() throws Exception {
- // Test synchronous RPC:
- Assert.assertEquals(8, simpleClient.add(2, 6));
-
- // Test asynchronous RPC (future):
- CallFuture<Integer> future1 = new CallFuture<Integer>();
- simpleClient.add(8, 8, future1);
- Assert.assertEquals(new Integer(16), future1.get(2, TimeUnit.SECONDS));
- Assert.assertNull(future1.getError());
-
- // Test asynchronous RPC (callback):
- final CallFuture<Integer> future2 = new CallFuture<Integer>();
- simpleClient.add(512, 256, new Callback<Integer>() {
- @Override
- public void handleResult(Integer result) {
- future2.handleResult(result);
- }
- @Override
- public void handleError(Throwable error) {
- future2.handleError(error);
- }
- });
- Assert.assertEquals(new Integer(768), future2.get(2, TimeUnit.SECONDS));
- Assert.assertNull(future2.getError());
- }
-
- @Test
- public void echoBytes() throws Exception {
- ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 });
-
- // Test synchronous RPC:
- Assert.assertEquals(byteBuffer, simpleClient.echoBytes(byteBuffer));
-
- // Test asynchronous RPC (future):
- CallFuture<ByteBuffer> future1 = new CallFuture<ByteBuffer>();
- simpleClient.echoBytes(byteBuffer, future1);
- Assert.assertEquals(byteBuffer, future1.get(2, TimeUnit.SECONDS));
- Assert.assertNull(future1.getError());
-
- // Test asynchronous RPC (callback):
- final CallFuture<ByteBuffer> future2 = new CallFuture<ByteBuffer>();
- simpleClient.echoBytes(byteBuffer, new Callback<ByteBuffer>() {
- @Override
- public void handleResult(ByteBuffer result) {
- future2.handleResult(result);
- }
- @Override
- public void handleError(Throwable error) {
- future2.handleError(error);
- }
- });
- Assert.assertEquals(byteBuffer, future2.get(2, TimeUnit.SECONDS));
- Assert.assertNull(future2.getError());
- }
-
- @Test()
- public void error() throws IOException, InterruptedException, TimeoutException {
- // Test synchronous RPC:
- try {
- simpleClient.error();
- Assert.fail("Expected " + TestError.class.getCanonicalName());
- } catch (TestError e) {
- // Expected
- } catch (AvroRemoteException e) {
- e.printStackTrace();
- Assert.fail("Unexpected error: " + e.toString());
- }
-
- // Test asynchronous RPC (future):
- CallFuture<Void> future = new CallFuture<Void>();
- simpleClient.error(future);
- try {
- future.get(2, TimeUnit.SECONDS);
- Assert.fail("Expected " + TestError.class.getCanonicalName() + " to be thrown");
- } catch (ExecutionException e) {
- Assert.assertTrue("Expected " + TestError.class.getCanonicalName(),
- e.getCause() instanceof TestError);
- }
- Assert.assertNotNull(future.getError());
- Assert.assertTrue("Expected " + TestError.class.getCanonicalName(),
- future.getError() instanceof TestError);
- Assert.assertNull(future.getResult());
-
- // Test asynchronous RPC (callback):
- final CountDownLatch latch = new CountDownLatch(1);
- final AtomicReference<Throwable> errorRef = new AtomicReference<Throwable>();
- simpleClient.error(new Callback<Void>() {
- @Override
- public void handleResult(Void result) {
- Assert.fail("Expected " + TestError.class.getCanonicalName());
- }
- @Override
- public void handleError(Throwable error) {
- errorRef.set(error);
- latch.countDown();
- }
- });
- Assert.assertTrue("Timed out waiting for error", latch.await(2, TimeUnit.SECONDS));
- Assert.assertNotNull(errorRef.get());
- Assert.assertTrue(errorRef.get() instanceof TestError);
- }
-
- @Test
- public void ack() throws Exception {
- simpleClient.ack();
- ackLatch.get().await(2, TimeUnit.SECONDS);
- Assert.assertTrue("Expected ack flag to be set", ackFlag.get());
-
- ackLatch.set(new CountDownLatch(1));
- simpleClient.ack();
- ackLatch.get().await(2, TimeUnit.SECONDS);
- Assert.assertFalse("Expected ack flag to be cleared", ackFlag.get());
- }
-
- @Test
- public void testSendAfterChannelClose() throws Exception {
- // Start up a second server so that closing the server doesn't
- // interfere with the other unit tests:
- Server server2 = new NettyServer(new SpecificResponder(Simple.class, simpleService),
- new InetSocketAddress(0));
- server2.start();
- try {
- int serverPort = server2.getPort();
- System.out.println("server2 port : " + serverPort);
-
- Transceiver transceiver2 = new NettyTransceiver(new InetSocketAddress(
- serverPort));
- try {
- Simple.Callback simpleClient2 =
- SpecificRequestor.getClient(Simple.Callback.class, transceiver2);
-
- // Verify that connection works:
- Assert.assertEquals(3, simpleClient2.add(1, 2));
-
- // Try again with callbacks:
- CallFuture<Integer> addFuture = new CallFuture<Integer>();
- simpleClient2.add(1, 2, addFuture);
- Assert.assertEquals(new Integer(3), addFuture.get());
-
- // Shut down server:
- server2.close();
-
- // Send a new RPC, and verify that it throws an Exception that
- // can be detected by the client:
- boolean ioeCaught = false;
- try {
- simpleClient2.add(1, 2);
- Assert.fail("Send after server close should have thrown Exception");
- } catch (AvroRemoteException e) {
- ioeCaught = e.getCause() instanceof IOException;
- Assert.assertTrue("Expected IOException", ioeCaught);
- } catch (Exception e) {
- e.printStackTrace();
- throw e;
- }
- Assert.assertTrue("Expected IOException", ioeCaught);
-
- // Send a new RPC with callback, and verify that the correct Exception
- // is thrown:
- ioeCaught = false;
- try {
- addFuture = new CallFuture<Integer>();
- simpleClient2.add(1, 2, addFuture);
- addFuture.get();
- Assert.fail("Send after server close should have thrown Exception");
- } catch (IOException e) {
- ioeCaught = true;
- } catch (Exception e) {
- e.printStackTrace();
- throw e;
- }
- Assert.assertTrue("Expected IOException", ioeCaught);
- } finally {
- transceiver2.close();
- }
- } finally {
- server2.close();
- }
- }
-
- @Test
- public void cancelPendingRequestsOnTransceiverClose() throws Exception {
- // Start up a second server so that closing the server doesn't
- // interfere with the other unit tests:
- BlockingSimpleImpl blockingSimpleImpl = new BlockingSimpleImpl();
- Server server2 = new NettyServer(new SpecificResponder(Simple.class,
- blockingSimpleImpl), new InetSocketAddress(0));
- server2.start();
- try {
- int serverPort = server2.getPort();
- System.out.println("server2 port : " + serverPort);
-
- CallFuture<Integer> addFuture = new CallFuture<Integer>();
- Transceiver transceiver2 = new NettyTransceiver(new InetSocketAddress(
- serverPort));
- try {
- Simple.Callback simpleClient2 =
- SpecificRequestor.getClient(Simple.Callback.class, transceiver2);
-
- // The first call has to block for the handshake:
- Assert.assertEquals(3, simpleClient2.add(1, 2));
-
- // Now acquire the semaphore so that the server will block:
- blockingSimpleImpl.acquirePermit();
- simpleClient2.add(1, 2, addFuture);
- } finally {
- // When the transceiver is closed, the CallFuture should get
- // an IOException
- transceiver2.close();
- }
- boolean ioeThrown = false;
- try {
- addFuture.get();
- } catch (ExecutionException e) {
- ioeThrown = e.getCause() instanceof IOException;
- Assert.assertTrue(e.getCause() instanceof IOException);
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail("Unexpected Exception: " + e.toString());
- }
- Assert.assertTrue("Expected IOException to be thrown", ioeThrown);
- } finally {
- blockingSimpleImpl.releasePermit();
- server2.close();
- }
- }
-
- @Ignore
- @Test
- public void performanceTest() throws Exception {
- final int threadCount = 8;
- final long runTimeMillis = 10 * 1000L;
- ExecutorService threadPool = Executors.newFixedThreadPool(threadCount);
-
- System.out.println("Running performance test for " + runTimeMillis + "ms...");
- final AtomicLong rpcCount = new AtomicLong(0L);
- final AtomicBoolean runFlag = new AtomicBoolean(true);
- final CountDownLatch startLatch = new CountDownLatch(threadCount);
- for (int ii = 0; ii < threadCount; ii++) {
- threadPool.submit(new Runnable() {
- @Override
- public void run() {
- try {
- startLatch.countDown();
- startLatch.await(2, TimeUnit.SECONDS);
- while (runFlag.get()) {
- rpcCount.incrementAndGet();
- Assert.assertEquals(new Utf8("Hello, World!"), simpleClient.hello("World!"));
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
-
- startLatch.await(2, TimeUnit.SECONDS);
- Thread.sleep(runTimeMillis);
- runFlag.set(false);
- threadPool.shutdown();
- Assert.assertTrue("Timed out shutting down thread pool", threadPool.awaitTermination(2, TimeUnit.SECONDS));
- System.out.println("Completed " + rpcCount.get() + " RPCs in " + runTimeMillis +
- "ms => " + (((double)rpcCount.get() / (double)runTimeMillis) * 1000) + " RPCs/sec, " +
- ((double)runTimeMillis / (double)rpcCount.get()) + " ms/RPC.");
- }
-
- /**
- * Implementation of the Simple interface.
- */
- private static class SimpleImpl implements Simple {
- private final AtomicBoolean ackFlag;
-
- /**
- * Creates a SimpleImpl.
- * @param ackFlag the AtomicBoolean to toggle when ack() is called.
- */
- public SimpleImpl(final AtomicBoolean ackFlag) {
- this.ackFlag = ackFlag;
- }
-
- @Override
- public CharSequence hello(CharSequence greeting) throws AvroRemoteException {
- return "Hello, " + greeting;
- }
-
- @Override
- public TestRecord echo(TestRecord record) throws AvroRemoteException {
- return record;
- }
-
- @Override
- public int add(int arg1, int arg2) throws AvroRemoteException {
- return arg1 + arg2;
- }
-
- @Override
- public ByteBuffer echoBytes(ByteBuffer data) throws AvroRemoteException {
- return data;
- }
-
- @Override
- public Void error() throws AvroRemoteException, TestError {
- TestError error = new TestError();
- error.message = "Test Message";
- throw error;
- }
-
- @Override
- synchronized public void ack() {
- ackFlag.set(!ackFlag.get());
- ackLatch.get().countDown();
- }
- }
-
- /**
- * A SimpleImpl that requires a semaphore permit before executing any method.
- */
- private static class BlockingSimpleImpl extends SimpleImpl {
- private final Semaphore semaphore = new Semaphore(1);
-
- /**
- * Creates a BlockingSimpleImpl.
- */
- public BlockingSimpleImpl() {
- super(new AtomicBoolean());
- }
-
- @Override
- public CharSequence hello(CharSequence greeting) throws AvroRemoteException {
- acquirePermit();
- try {
- return super.hello(greeting);
- } finally {
- releasePermit();
- }
- }
-
- @Override
- public TestRecord echo(TestRecord record) throws AvroRemoteException {
- acquirePermit();
- try {
- return super.echo(record);
- } finally {
- releasePermit();
- }
- }
-
- @Override
- public int add(int arg1, int arg2) throws AvroRemoteException {
- acquirePermit();
- try {
- return super.add(arg1, arg2);
- } finally {
- releasePermit();
- }
- }
-
- @Override
- public ByteBuffer echoBytes(ByteBuffer data) throws AvroRemoteException {
- acquirePermit();
- try {
- return super.echoBytes(data);
- } finally {
- releasePermit();
- }
- }
-
- @Override
- public Void error() throws AvroRemoteException, TestError {
- acquirePermit();
- try {
- return super.error();
- } finally {
- releasePermit();
- }
- }
-
- @Override
- public void ack() {
- acquirePermit();
- try {
- super.ack();
- } finally {
- releasePermit();
- }
- }
-
- /**
- * Acquires a single permit from the semaphore.
- */
- public void acquirePermit() {
- semaphore.acquireUninterruptibly();
- }
-
- /**
- * Releases a single permit to the semaphore.
- */
- public void releasePermit() {
- semaphore.release();
- }
- }
-}
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestRpcPluginOrdering.java b/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestRpcPluginOrdering.java
index c658d47..ab87e27 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestRpcPluginOrdering.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestRpcPluginOrdering.java
@@ -94,7 +94,5 @@
public CharSequence send(Message message) throws AvroRemoteException {
return new Utf8("Received");
}
- public void fireandforget(Message message) {
- }
}
}
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestSaslAnonymous.java b/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestSaslAnonymous.java
index 68b40bf..b9ffae1 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestSaslAnonymous.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestSaslAnonymous.java
@@ -24,14 +24,11 @@
import org.apache.avro.ipc.generic.GenericRequestor;
import org.apache.avro.TestProtocolGeneric;
-import org.apache.avro.ipc.reflect.ReflectRequestor;
-import org.apache.avro.ipc.reflect.ReflectResponder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.junit.Before;
-import org.junit.Test;
public class TestSaslAnonymous extends TestProtocolGeneric {
@@ -48,29 +45,5 @@
}
@Override public void testHandshake() throws IOException {}
- @Override public void testResponseChange() throws IOException {}
-
- public interface ProtoInterface {
- byte[] test(byte[] b);
- }
-
- // test big enough to fill socket output buffer
- @Test
- public void test64kRequest() throws Exception {
- SaslSocketServer s = new SaslSocketServer
- (new ReflectResponder(ProtoInterface.class, new ProtoInterface() {
- public byte[] test(byte[] b) { return b; }
- }), new InetSocketAddress(0));
- s.start();
- SaslSocketTransceiver client =
- new SaslSocketTransceiver(new InetSocketAddress(s.getPort()));
- ProtoInterface proxy =
- (ProtoInterface)ReflectRequestor.getClient(ProtoInterface.class, client);
-
- byte[] result = proxy.test(new byte[64*1024]);
-
- client.close();
- s.close();
- }
}
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestSaslDigestMd5.java b/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestSaslDigestMd5.java
index fda6ce9..ead6dde 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestSaslDigestMd5.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestSaslDigestMd5.java
@@ -163,6 +163,5 @@
}
@Override public void testHandshake() throws IOException {}
- @Override public void testResponseChange() throws IOException {}
}
diff --git a/lang/java/mapred/pom.xml b/lang/java/mapred/pom.xml
index 4c1c18e..8c574e7 100644
--- a/lang/java/mapred/pom.xml
+++ b/lang/java/mapred/pom.xml
@@ -22,7 +22,7 @@
<parent>
<artifactId>avro-parent</artifactId>
<groupId>org.apache.avro</groupId>
- <version>1.5.2</version>
+ <version>1.5.0</version>
<relativePath>../</relativePath>
</parent>
<artifactId>avro-mapred</artifactId>
diff --git a/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroAsTextInputFormat.java b/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroAsTextInputFormat.java
deleted file mode 100644
index 2210cfa..0000000
--- a/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroAsTextInputFormat.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * 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.
- */
-
-package org.apache.avro.mapred;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.hadoop.fs.FileStatus;
-import org.apache.hadoop.io.Text;
-import org.apache.hadoop.mapred.FileInputFormat;
-import org.apache.hadoop.mapred.FileSplit;
-import org.apache.hadoop.mapred.InputSplit;
-import org.apache.hadoop.mapred.JobConf;
-import org.apache.hadoop.mapred.RecordReader;
-import org.apache.hadoop.mapred.Reporter;
-
-/**
- * An {@link org.apache.hadoop.mapred.InputFormat} for Avro data files, which
- * converts each datum to string form in the input key. The input value is
- * always empty. The string representation is
- * <a href="http://www.json.org/">JSON</a>.
- * <p>
- * This {@link org.apache.hadoop.mapred.InputFormat} is useful for applications
- * that wish to process Avro data using tools like MapReduce Streaming.
- */
-public class AvroAsTextInputFormat extends FileInputFormat<Text, Text> {
-
- @Override
- protected FileStatus[] listStatus(JobConf job) throws IOException {
- List<FileStatus> result = new ArrayList<FileStatus>();
- for (FileStatus file : super.listStatus(job))
- if (file.getPath().getName().endsWith(AvroOutputFormat.EXT))
- result.add(file);
- return result.toArray(new FileStatus[0]);
- }
-
- @Override
- public RecordReader<Text, Text>
- getRecordReader(InputSplit split, JobConf job, Reporter reporter)
- throws IOException {
- reporter.setStatus(split.toString());
- return new AvroAsTextRecordReader(job, (FileSplit) split);
- }
-}
diff --git a/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroAsTextRecordReader.java b/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroAsTextRecordReader.java
deleted file mode 100644
index 04f8ebe..0000000
--- a/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroAsTextRecordReader.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/**
- * 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.
- */
-
-package org.apache.avro.mapred;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-
-import org.apache.avro.file.DataFileReader;
-import org.apache.avro.file.FileReader;
-import org.apache.avro.generic.GenericDatumReader;
-import org.apache.hadoop.io.Text;
-import org.apache.hadoop.mapred.FileSplit;
-import org.apache.hadoop.mapred.JobConf;
-import org.apache.hadoop.mapred.RecordReader;
-
-class AvroAsTextRecordReader<T> implements RecordReader<Text, Text> {
-
- private FileReader<T> reader;
- private T datum;
- private long start;
- private long end;
-
- public AvroAsTextRecordReader(JobConf job, FileSplit split)
- throws IOException {
- this(DataFileReader.openReader
- (new FsInput(split.getPath(), job), new GenericDatumReader<T>()), split);
- }
-
- protected AvroAsTextRecordReader(FileReader<T> reader, FileSplit split)
- throws IOException {
- this.reader = reader;
- reader.sync(split.getStart()); // sync to start
- this.start = reader.tell();
- this.end = split.getStart() + split.getLength();
- }
-
- public Text createKey() {
- return new Text();
- }
-
- public Text createValue() {
- return new Text();
- }
-
- public boolean next(Text key, Text ignore) throws IOException {
- if (!reader.hasNext() || reader.pastSync(end))
- return false;
- datum = reader.next(datum);
- if (datum instanceof ByteBuffer) {
- ByteBuffer b = (ByteBuffer) datum;
- if (b.hasArray()) {
- int offset = b.arrayOffset();
- int start = b.position();
- int length = b.remaining();
- key.set(b.array(), offset + start, offset + start + length);
- } else {
- byte[] bytes = new byte[b.remaining()];
- b.duplicate().get(bytes);
- key.set(bytes);
- }
- } else {
- key.set(datum.toString());
- }
- return true;
- }
-
- public float getProgress() throws IOException {
- if (end == start) {
- return 0.0f;
- } else {
- return Math.min(1.0f, (getPos() - start) / (float)(end - start));
- }
- }
-
- public long getPos() throws IOException {
- return reader.tell();
- }
-
- public void close() throws IOException { reader.close(); }
-
-
-}
diff --git a/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroJob.java b/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroJob.java
index 324a634..37cf0f7 100644
--- a/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroJob.java
+++ b/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroJob.java
@@ -42,8 +42,6 @@
public static final String MAP_OUTPUT_SCHEMA = "avro.map.output.schema";
/** The configuration key for a job's output schema. */
public static final String OUTPUT_SCHEMA = "avro.output.schema";
- /** The configuration key for a job's output compression codec. */
- public static final String OUTPUT_CODEC = "avro.output.codec";
/** The configuration key prefix for a text output metadata. */
public static final String TEXT_PREFIX = "avro.meta.text.";
/** The configuration key prefix for a binary output metadata. */
@@ -84,11 +82,6 @@
configureAvroOutput(job);
}
- /** Configure a job's output compression codec. */
- public static void setOutputCodec(JobConf job, String codec) {
- job.set(OUTPUT_CODEC, codec);
- }
-
/** Add metadata to job output files.*/
public static void setOutputMeta(JobConf job, String key, String value) {
job.set(TEXT_PREFIX+key, value);
diff --git a/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroMapper.java b/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroMapper.java
index f4af97f..a6b5c79 100644
--- a/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroMapper.java
+++ b/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroMapper.java
@@ -18,20 +18,17 @@
package org.apache.avro.mapred;
-import java.io.Closeable;
import java.io.IOException;
-import org.apache.hadoop.conf.Configured;
-import org.apache.hadoop.mapred.JobConf;
-import org.apache.hadoop.mapred.JobConfigurable;
import org.apache.hadoop.mapred.Reporter;
+import org.apache.hadoop.conf.Configured;
/** A mapper for Avro data.
*
* <p>Applications subclass this class and pass their subclass to {@link
- * AvroJob#setMapperClass(JobConf, Class)}, overriding {@link #map(Object, AvroCollector, Reporter)}.
+ * AvroJob#setMapperClass}, overriding {@link #map}.
*/
-public class AvroMapper<IN, OUT> extends Configured implements JobConfigurable, Closeable {
+public class AvroMapper<IN,OUT> extends Configured {
/** Called with each map input datum. By default, collects inputs. */
@SuppressWarnings("unchecked")
@@ -41,15 +38,4 @@
}
- /** Subclasses can override this as desired. */
- @Override
- public void close() throws IOException {
- // no op
- }
-
- /** Subclasses can override this as desired. */
- @Override
- public void configure(JobConf jobConf) {
- // no op
- }
}
diff --git a/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroOutputFormat.java b/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroOutputFormat.java
index 3386190..1d03f4d 100644
--- a/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroOutputFormat.java
+++ b/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroOutputFormat.java
@@ -19,7 +19,6 @@
package org.apache.avro.mapred;
import java.io.IOException;
-import java.io.UnsupportedEncodingException;
import java.util.Map;
import java.net.URLDecoder;
@@ -37,7 +36,6 @@
import org.apache.avro.file.DataFileWriter;
import org.apache.avro.file.CodecFactory;
import static org.apache.avro.file.DataFileConstants.DEFAULT_SYNC_INTERVAL;
-import static org.apache.avro.file.DataFileConstants.DEFLATE_CODEC;
/** An {@link org.apache.hadoop.mapred.OutputFormat} for Avro data files. */
public class AvroOutputFormat <T>
@@ -65,31 +63,6 @@
public static void setSyncInterval(JobConf job, int syncIntervalInBytes) {
job.setInt(SYNC_INTERVAL_KEY, syncIntervalInBytes);
}
-
- static <T> void configureDataFileWriter(DataFileWriter<T> writer,
- JobConf job) throws UnsupportedEncodingException {
- if (FileOutputFormat.getCompressOutput(job)) {
- int level = job.getInt(DEFLATE_LEVEL_KEY, DEFAULT_DEFLATE_LEVEL);
- String codecName = job.get(AvroJob.OUTPUT_CODEC, DEFLATE_CODEC);
- CodecFactory factory = codecName.equals(DEFLATE_CODEC)
- ? CodecFactory.deflateCodec(level)
- : CodecFactory.fromString(codecName);
- writer.setCodec(factory);
- }
-
- writer.setSyncInterval(job.getInt(SYNC_INTERVAL_KEY, DEFAULT_SYNC_INTERVAL));
-
- // copy metadata from job
- for (Map.Entry<String,String> e : job) {
- if (e.getKey().startsWith(AvroJob.TEXT_PREFIX))
- writer.setMeta(e.getKey().substring(AvroJob.TEXT_PREFIX.length()),
- e.getValue());
- if (e.getKey().startsWith(AvroJob.BINARY_PREFIX))
- writer.setMeta(e.getKey().substring(AvroJob.BINARY_PREFIX.length()),
- URLDecoder.decode(e.getValue(), "ISO-8859-1")
- .getBytes("ISO-8859-1"));
- }
- }
@Override
public RecordWriter<AvroWrapper<T>, NullWritable>
@@ -104,8 +77,24 @@
final DataFileWriter<T> writer =
new DataFileWriter<T>(new ReflectDatumWriter<T>());
-
- configureDataFileWriter(writer, job);
+
+ if (FileOutputFormat.getCompressOutput(job)) {
+ int level = job.getInt(DEFLATE_LEVEL_KEY, DEFAULT_DEFLATE_LEVEL);
+ writer.setCodec(CodecFactory.deflateCodec(level));
+ }
+
+ writer.setSyncInterval(job.getInt(SYNC_INTERVAL_KEY, DEFAULT_SYNC_INTERVAL));
+
+ // copy metadata from job
+ for (Map.Entry<String,String> e : job) {
+ if (e.getKey().startsWith(AvroJob.TEXT_PREFIX))
+ writer.setMeta(e.getKey().substring(AvroJob.TEXT_PREFIX.length()),
+ e.getValue());
+ if (e.getKey().startsWith(AvroJob.BINARY_PREFIX))
+ writer.setMeta(e.getKey().substring(AvroJob.BINARY_PREFIX.length()),
+ URLDecoder.decode(e.getValue(), "ISO-8859-1")
+ .getBytes("ISO-8859-1"));
+ }
Path path = FileOutputFormat.getTaskOutputPath(job, name+EXT);
writer.create(schema, path.getFileSystem(job).create(path));
diff --git a/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroReducer.java b/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroReducer.java
index d7c0103..1258590 100644
--- a/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroReducer.java
+++ b/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroReducer.java
@@ -18,22 +18,19 @@
package org.apache.avro.mapred;
-import java.io.Closeable;
import java.io.IOException;
-import org.apache.hadoop.conf.Configured;
-import org.apache.hadoop.mapred.JobConf;
-import org.apache.hadoop.mapred.JobConfigurable;
import org.apache.hadoop.mapred.Reporter;
+import org.apache.hadoop.conf.Configured;
/** A reducer for Avro data.
*
* <p>Applications should subclass this class and pass their subclass to {@link
- * AvroJob#setReducerClass(JobConf, Class)} and perhaps {@link AvroJob#setCombinerClass(JobConf, Class)}.
- * Subclasses override {@link #reduce(Object, Iterable, AvroCollector, Reporter)}.
+ * AvroJob#setReducerClass} and perhaps {@link AvroJob#setCombinerClass}.
+ * Subclasses override {@link #reduce}.
*/
-public class AvroReducer<K,V,OUT> extends Configured implements JobConfigurable, Closeable {
+public class AvroReducer<K,V,OUT> extends Configured {
private Pair<K,V> outputPair;
@@ -51,15 +48,4 @@
}
}
- /** Subclasses can override this as desired. */
- @Override
- public void close() throws IOException {
- // no op
- }
-
- /** Subclasses can override this as desired. */
- @Override
- public void configure(JobConf jobConf) {
- // no op
- }
}
diff --git a/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroTextOutputFormat.java b/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroTextOutputFormat.java
deleted file mode 100644
index ef1fae9..0000000
--- a/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroTextOutputFormat.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/**
- * 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.
- */
-
-package org.apache.avro.mapred;
-
-import static org.apache.avro.mapred.AvroOutputFormat.EXT;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-
-import org.apache.avro.Schema;
-import org.apache.avro.file.DataFileWriter;
-import org.apache.avro.reflect.ReflectDatumWriter;
-import org.apache.hadoop.fs.FileSystem;
-import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.io.NullWritable;
-import org.apache.hadoop.io.Text;
-import org.apache.hadoop.mapred.FileOutputFormat;
-import org.apache.hadoop.mapred.JobConf;
-import org.apache.hadoop.mapred.RecordWriter;
-import org.apache.hadoop.mapred.Reporter;
-import org.apache.hadoop.util.Progressable;
-
-/** The equivalent of {@link org.apache.hadoop.mapred.TextOutputFormat} for
- * writing to Avro Data Files with a <code>"bytes"</code> schema. */
-public class AvroTextOutputFormat<K, V> extends FileOutputFormat<K, V> {
-
- private static final String UTF8 = "UTF-8";
-
- @Override
- public RecordWriter<K, V>
- getRecordWriter(FileSystem ignore, JobConf job,
- String name, Progressable prog)
- throws IOException {
-
- Schema schema = Schema.create(Schema.Type.BYTES);
-
- final byte[] keyValueSeparator =
- job.get("mapreduce.output.textoutputformat.separator", "\t").getBytes(UTF8);
-
- final DataFileWriter<ByteBuffer> writer =
- new DataFileWriter<ByteBuffer>(new ReflectDatumWriter<ByteBuffer>());
-
- AvroOutputFormat.configureDataFileWriter(writer, job);
-
- Path path = FileOutputFormat.getTaskOutputPath(job, name+EXT);
- writer.create(schema, path.getFileSystem(job).create(path));
-
- return new AvroTextRecordWriter(writer, keyValueSeparator);
- }
-
- class AvroTextRecordWriter implements RecordWriter<K, V> {
- private final DataFileWriter<ByteBuffer> writer;
- private final byte[] keyValueSeparator;
-
- public AvroTextRecordWriter(DataFileWriter<ByteBuffer> writer,
- byte[] keyValueSeparator) {
- this.writer = writer;
- this.keyValueSeparator = keyValueSeparator;
- }
-
- public void write(K key, V value) throws IOException {
- boolean nullKey = key == null || key instanceof NullWritable;
- boolean nullValue = value == null || value instanceof NullWritable;
- if (nullKey && nullValue) {
- return;
- } else if (!nullKey && nullValue) {
- writer.append(toByteBuffer(key));
- } else if (nullKey && !nullValue) {
- writer.append(toByteBuffer(value));
- } else {
- writer.append(toByteBuffer(key, keyValueSeparator, value));
- }
- }
-
- public void close(Reporter reporter) throws IOException {
- writer.close();
- }
-
- private ByteBuffer toByteBuffer(Object o) throws IOException {
- if (o instanceof Text) {
- Text to = (Text) o;
- return ByteBuffer.wrap(to.getBytes(), 0, to.getLength());
- } else {
- return ByteBuffer.wrap(o.toString().getBytes(UTF8));
- }
- }
-
- private ByteBuffer toByteBuffer(Object key, byte[] sep, Object value)
- throws IOException {
- byte[] keyBytes, valBytes;
- int keyLength, valLength;
- if (key instanceof Text) {
- Text tkey = (Text) key;
- keyBytes = tkey.getBytes();
- keyLength = tkey.getLength();
- } else {
- keyBytes = key.toString().getBytes(UTF8);
- keyLength = keyBytes.length;
- }
- if (value instanceof Text) {
- Text tval = (Text) value;
- valBytes = tval.getBytes();
- valLength = tval.getLength();
- } else {
- valBytes = value.toString().getBytes(UTF8);
- valLength = valBytes.length;
- }
- ByteBuffer buf = ByteBuffer.allocate(keyLength + sep.length + valLength);
- buf.put(keyBytes, 0, keyLength);
- buf.put(sep);
- buf.put(valBytes, 0, valLength);
- buf.rewind();
- return buf;
- }
-
- }
-
-}
diff --git a/lang/java/mapred/src/main/java/org/apache/avro/mapred/HadoopMapper.java b/lang/java/mapred/src/main/java/org/apache/avro/mapred/HadoopMapper.java
index e225828..e932739 100644
--- a/lang/java/mapred/src/main/java/org/apache/avro/mapred/HadoopMapper.java
+++ b/lang/java/mapred/src/main/java/org/apache/avro/mapred/HadoopMapper.java
@@ -21,11 +21,11 @@
import java.io.IOException;
import org.apache.hadoop.io.NullWritable;
-import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.MapReduceBase;
-import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;
+import org.apache.hadoop.mapred.Mapper;
+import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.util.ReflectionUtils;
/** Bridge between a {@link org.apache.hadoop.mapred.Mapper} and an {@link
@@ -45,7 +45,6 @@
(conf.getClass(AvroJob.MAPPER, AvroMapper.class, AvroMapper.class),
conf);
this.isMapOnly = conf.getNumReduceTasks() == 0;
- this.mapper.configure(conf);
}
@SuppressWarnings("unchecked")
@@ -81,9 +80,4 @@
mapper.map(wrapper.datum(), out, reporter);
}
- @Override
- public void close() throws IOException {
- this.mapper.close();
- }
-
}
diff --git a/lang/java/mapred/src/main/java/org/apache/avro/mapred/HadoopReducerBase.java b/lang/java/mapred/src/main/java/org/apache/avro/mapred/HadoopReducerBase.java
index a4d34cf..4285dc0 100644
--- a/lang/java/mapred/src/main/java/org/apache/avro/mapred/HadoopReducerBase.java
+++ b/lang/java/mapred/src/main/java/org/apache/avro/mapred/HadoopReducerBase.java
@@ -39,7 +39,6 @@
@Override
public void configure(JobConf conf) {
this.reducer = getReducer(conf);
- this.reducer.configure(conf);
}
class ReduceIterable implements Iterable<V>, Iterator<V> {
@@ -61,8 +60,4 @@
reducer.reduce(key.datum(), reduceIterable, collector, reporter);
}
- @Override
- public void close() throws IOException {
- this.reducer.close();
- }
}
diff --git a/lang/java/mapred/src/main/java/org/apache/avro/mapred/package.html b/lang/java/mapred/src/main/java/org/apache/avro/mapred/package.html
index 9a40fcf..a9b4ff7 100644
--- a/lang/java/mapred/src/main/java/org/apache/avro/mapred/package.html
+++ b/lang/java/mapred/src/main/java/org/apache/avro/mapred/package.html
@@ -96,23 +96,5 @@
</ul>
</p>
-<p>For jobs whose input is non-Avro data file and which use a
- non-Avro {@link org.apache.hadoop.mapred.Mapper} and no reducer,
- i.e., a <i>map-only</i> job:
- <ul>
- <li>Set your input file format with {@link
- org.apache.hadoop.mapred.JobConf#setInputFormat}.</li>
- <li>Implement {@link org.apache.hadoop.mapred.Mapper} and specify
- your job's mapper with {@link
- org.apache.hadoop.mapred.JobConf#setMapperClass}. The output key
- and value type should be {@link org.apache.avro.mapred.AvroWrapper} and
- {@link org.apache.hadoop.io.NullWritable}.</li>
- <li>Call {@link
- org.apache.hadoop.mapred.JobConf#setNumReduceTasks(int)} with zero.
- <li>Call {@link org.apache.avro.mapred.AvroJob#setOutputSchema} with your
- job's output schema.</li>
- </ul>
-</p>
-
</body>
</html>
diff --git a/lang/java/mapred/src/test/java/org/apache/avro/mapred/TestAvroTextOutputFormat.java b/lang/java/mapred/src/test/java/org/apache/avro/mapred/TestAvroTextOutputFormat.java
deleted file mode 100644
index 264251a..0000000
--- a/lang/java/mapred/src/test/java/org/apache/avro/mapred/TestAvroTextOutputFormat.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/**
- * 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.
- */
-
-package org.apache.avro.mapred;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-
-import java.io.File;
-import java.io.UnsupportedEncodingException;
-import java.nio.ByteBuffer;
-
-import org.apache.avro.Schema;
-import org.apache.avro.file.DataFileReader;
-import org.apache.avro.file.DataFileWriter;
-import org.apache.avro.generic.GenericDatumReader;
-import org.apache.avro.generic.GenericDatumWriter;
-import org.apache.avro.io.DatumReader;
-import org.apache.avro.io.DatumWriter;
-import org.apache.hadoop.io.NullWritable;
-import org.apache.hadoop.io.Text;
-import org.apache.hadoop.mapred.RecordWriter;
-import org.junit.Test;
-
-public class TestAvroTextOutputFormat {
-
- private static final String UTF8 = "UTF-8";
-
- @Test
- public void testAvroTextRecordWriter() throws Exception {
- File file = new File(System.getProperty("test.dir", "."), "writer");
- Schema schema = Schema.create(Schema.Type.BYTES);
- DatumWriter<ByteBuffer> datumWriter =
- new GenericDatumWriter<ByteBuffer>(schema);
- DataFileWriter<ByteBuffer> fileWriter =
- new DataFileWriter<ByteBuffer>(datumWriter);
- fileWriter.create(schema, file);
- RecordWriter<Object, Object> rw = new AvroTextOutputFormat<Object, Object>()
- .new AvroTextRecordWriter(fileWriter, "\t".getBytes(UTF8));
-
- rw.write(null, null);
- rw.write(null, NullWritable.get());
- rw.write(NullWritable.get(), null);
- rw.write(NullWritable.get(), NullWritable.get());
-
- rw.write("k1", null);
- rw.write("k2", NullWritable.get());
-
- rw.write(null, "v1");
- rw.write(NullWritable.get(), "v2");
-
- rw.write("k3", "v3");
- rw.write(new Text("k4"), new Text("v4"));
-
- rw.close(null);
-
- DatumReader<ByteBuffer> reader = new GenericDatumReader<ByteBuffer>();
- DataFileReader<ByteBuffer> fileReader =
- new DataFileReader<ByteBuffer>(file, reader);
- assertEquals("k1", asString(fileReader.next()));
- assertEquals("k2", asString(fileReader.next()));
- assertEquals("v1", asString(fileReader.next()));
- assertEquals("v2", asString(fileReader.next()));
- assertEquals("k3\tv3", asString(fileReader.next()));
- assertEquals("k4\tv4", asString(fileReader.next()));
- assertFalse("End", fileReader.hasNext());
- }
-
- private String asString(ByteBuffer buf) throws UnsupportedEncodingException {
- byte[] b = new byte[buf.remaining()];
- buf.get(b);
- return new String(b, UTF8);
- }
-
-}
diff --git a/lang/java/mapred/src/test/java/org/apache/avro/mapred/TestAvroTextSort.java b/lang/java/mapred/src/test/java/org/apache/avro/mapred/TestAvroTextSort.java
deleted file mode 100644
index 7273bdd..0000000
--- a/lang/java/mapred/src/test/java/org/apache/avro/mapred/TestAvroTextSort.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * 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.
- */
-
-package org.apache.avro.mapred;
-
-import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.io.Text;
-import org.apache.hadoop.mapred.FileInputFormat;
-import org.apache.hadoop.mapred.FileOutputFormat;
-import org.apache.hadoop.mapred.JobClient;
-import org.apache.hadoop.mapred.JobConf;
-import org.junit.Test;
-
-public class TestAvroTextSort {
-
- @Test
- /**
- * Run the identity job on a "bytes" Avro file using AvroAsTextInputFormat
- * and AvroTextOutputFormat to produce a sorted "bytes" Avro file.
- */
- public void testSort() throws Exception {
- JobConf job = new JobConf();
- String dir = System.getProperty("test.dir", ".") + "/mapred";
- Path outputPath = new Path(dir + "/out");
-
- outputPath.getFileSystem(job).delete(outputPath);
- WordCountUtil.writeLinesBytesFile();
-
- job.setInputFormat(AvroAsTextInputFormat.class);
- job.setOutputFormat(AvroTextOutputFormat.class);
- job.setOutputKeyClass(Text.class);
-
- FileInputFormat.setInputPaths(job, new Path(dir + "/in"));
- FileOutputFormat.setOutputPath(job, outputPath);
-
- JobClient.runJob(job);
-
- WordCountUtil.validateSortedFile();
- }
-
-}
diff --git a/lang/java/mapred/src/test/java/org/apache/avro/mapred/TestSequenceFileReader.java b/lang/java/mapred/src/test/java/org/apache/avro/mapred/TestSequenceFileReader.java
index 1a3c966..a3acc17 100644
--- a/lang/java/mapred/src/test/java/org/apache/avro/mapred/TestSequenceFileReader.java
+++ b/lang/java/mapred/src/test/java/org/apache/avro/mapred/TestSequenceFileReader.java
@@ -30,7 +30,6 @@
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
-import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.FileInputFormat;
@@ -56,7 +55,7 @@
private static final int COUNT =
Integer.parseInt(System.getProperty("test.count", "10"));
private static final File DIR
- = new File(System.getProperty("test.dir", "."));
+ = new File(System.getProperty("test.dir", "/tmp"));
private static final File FILE = new File(DIR, "test.seq");
private static final Schema SCHEMA
@@ -163,45 +162,6 @@
new SpecificDatumReader<Pair<Long,CharSequence>>()));
}
- private static class NonAvroOnlyMapper
- extends MapReduceBase
- implements Mapper<LongWritable,Text,AvroWrapper<Pair<Long,Utf8>>,NullWritable> {
-
- public void map(LongWritable key, Text value,
- OutputCollector<AvroWrapper<Pair<Long,Utf8>>,NullWritable> out,
- Reporter reporter) throws IOException {
- out.collect(new AvroWrapper<Pair<Long,Utf8>>(new Pair<Long,Utf8>(key.get(), new Utf8(value.toString()))),
- NullWritable.get());
- }
- }
-
- @Test
- public void testNonAvroMapOnly() throws Exception {
- JobConf job = new JobConf();
- Path output = new Path(System.getProperty("test.dir",".")+"/seq-out");
-
- output.getFileSystem(job).delete(output);
-
-
- // configure input for non-Avro sequence file
- job.setInputFormat(SequenceFileInputFormat.class);
- FileInputFormat.setInputPaths(job, FILE.toURI().toString());
-
- // use a hadoop mapper that emits Avro output
- job.setMapperClass(NonAvroOnlyMapper.class);
-
- // configure output for avro
- job.setNumReduceTasks(0); // map-only
- FileOutputFormat.setOutputPath(job, output);
- AvroJob.setOutputSchema(job, SCHEMA);
-
- JobClient.runJob(job);
-
- checkFile(new DataFileReader<Pair<Long,CharSequence>>
- (new File(output.toString()+"/part-00000.avro"),
- new SpecificDatumReader<Pair<Long,CharSequence>>()));
- }
-
private static class NonAvroReducer
extends MapReduceBase
implements Reducer<AvroKey<Long>,AvroValue<Utf8>,LongWritable,Text> {
diff --git a/lang/java/mapred/src/test/java/org/apache/avro/mapred/TestWeather.java b/lang/java/mapred/src/test/java/org/apache/avro/mapred/TestWeather.java
index ca73c97..955318c 100644
--- a/lang/java/mapred/src/test/java/org/apache/avro/mapred/TestWeather.java
+++ b/lang/java/mapred/src/test/java/org/apache/avro/mapred/TestWeather.java
@@ -20,7 +20,6 @@
import java.io.IOException;
import java.io.File;
-import java.util.concurrent.atomic.AtomicInteger;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.mapred.JobClient;
@@ -34,32 +33,15 @@
import org.apache.avro.io.DatumReader;
import org.apache.avro.specific.SpecificDatumReader;
import org.apache.avro.file.DataFileReader;
-import static org.apache.avro.file.DataFileConstants.SNAPPY_CODEC;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import org.junit.After;
import org.junit.Test;
+import static org.junit.Assert.*;
import test.Weather;
/** Tests mapred API with a specific record. */
public class TestWeather {
- private static final AtomicInteger mapCloseCalls = new AtomicInteger();
- private static final AtomicInteger mapConfigureCalls = new AtomicInteger();
- private static final AtomicInteger reducerCloseCalls = new AtomicInteger();
- private static final AtomicInteger reducerConfigureCalls = new AtomicInteger();
-
-
- @After
- public void tearDown() {
- mapCloseCalls.set(0);
- mapConfigureCalls.set(0);
- reducerCloseCalls.set(0);
- reducerConfigureCalls.set(0);
- }
-
/** Uses default mapper with no reduces for a map-only identity job. */
@Test
@SuppressWarnings("deprecation")
@@ -81,7 +63,7 @@
FileOutputFormat.setCompressOutput(job, true);
job.setNumReduceTasks(0); // map-only
-
+
JobClient.runJob(job);
// check output is correct
@@ -105,18 +87,8 @@
Reporter reporter) throws IOException {
collector.collect(new Pair<Weather,Void>(w, (Void)null));
}
-
- @Override
- public void close() throws IOException {
- mapCloseCalls.incrementAndGet();
- }
-
- @Override
- public void configure(JobConf jobConf) {
- mapConfigureCalls.incrementAndGet();
- }
}
-
+
// output keys only, since values are empty
public static class SortReducer
extends AvroReducer<Weather, Void, Weather> {
@@ -126,17 +98,7 @@
Reporter reporter) throws IOException {
collector.collect(w);
}
-
- @Override
- public void close() throws IOException {
- reducerCloseCalls.incrementAndGet();
- }
-
- @Override
- public void configure(JobConf jobConf) {
- reducerConfigureCalls.incrementAndGet();
- }
- }
+ }
@Test
@SuppressWarnings("deprecation")
@@ -161,7 +123,6 @@
FileInputFormat.setInputPaths(job, input);
FileOutputFormat.setOutputPath(job, output);
FileOutputFormat.setCompressOutput(job, true);
- AvroJob.setOutputCodec(job, SNAPPY_CODEC);
JobClient.runJob(job);
@@ -177,15 +138,6 @@
check.close();
sorted.close();
-
- // check that AvroMapper and AvroReducer get close() and configure() called
- assertEquals(1, mapCloseCalls.get());
- assertEquals(1, reducerCloseCalls.get());
- // gets called twice for some reason, so loosen this check
- assertTrue(mapConfigureCalls.get() >= 1);
- assertTrue(reducerConfigureCalls.get() >= 1);
-
-
}
diff --git a/lang/java/mapred/src/test/java/org/apache/avro/mapred/WordCountUtil.java b/lang/java/mapred/src/test/java/org/apache/avro/mapred/WordCountUtil.java
index 4d0e073..9825ef7 100644
--- a/lang/java/mapred/src/test/java/org/apache/avro/mapred/WordCountUtil.java
+++ b/lang/java/mapred/src/test/java/org/apache/avro/mapred/WordCountUtil.java
@@ -20,19 +20,13 @@
import static org.junit.Assert.*;
-import java.io.BufferedReader;
-import java.io.FileReader;
import java.io.IOException;
import java.io.File;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.BufferedInputStream;
import java.io.PrintStream;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.TreeMap;
@@ -44,7 +38,6 @@
import org.apache.avro.util.Utf8;
import org.apache.avro.io.DatumReader;
import org.apache.avro.io.DatumWriter;
-import org.apache.avro.generic.GenericDatumReader;
import org.apache.avro.generic.GenericDatumWriter;
import org.apache.avro.specific.SpecificDatumReader;
import org.apache.avro.file.DataFileWriter;
@@ -60,8 +53,6 @@
= new File(new File(DIR, "in"), "lines.txt");
private static final File COUNTS_FILE
= new File(new File(DIR, "out"), "part-00000.avro");
- private static final File SORTED_FILE
- = new File(new File(DIR, "out"), "part-00000.avro");
public static final String[] LINES = new String[] {
"the quick brown fox jumps over the lazy dog",
@@ -93,17 +84,6 @@
out.append(new Utf8(line));
out.close();
}
-
- public static void writeLinesBytesFile() throws IOException {
- FileUtil.fullyDelete(DIR);
- DatumWriter<ByteBuffer> writer = new GenericDatumWriter<ByteBuffer>();
- DataFileWriter<ByteBuffer> out = new DataFileWriter<ByteBuffer>(writer);
- LINES_FILE.getParentFile().mkdirs();
- out.create(Schema.create(Schema.Type.BYTES), LINES_FILE);
- for (String line : LINES)
- out.append(ByteBuffer.wrap(line.getBytes("UTF-8")));
- out.close();
- }
public static void writeLinesTextFile() throws IOException {
FileUtil.fullyDelete(DIR);
@@ -130,27 +110,7 @@
in.close();
assertEquals(COUNTS.size(), numWords);
}
-
- public static void validateSortedFile() throws Exception {
- DatumReader<ByteBuffer> reader = new GenericDatumReader<ByteBuffer>();
- InputStream in = new BufferedInputStream(
- new FileInputStream(SORTED_FILE));
- DataFileStream<ByteBuffer> lines =
- new DataFileStream<ByteBuffer>(in,reader);
- List<String> sortedLines = new ArrayList<String>();
- for (String line : LINES) {
- sortedLines.add(line);
- }
- Collections.sort(sortedLines);
- for (String expectedLine : sortedLines) {
- ByteBuffer buf = lines.next();
- byte[] b = new byte[buf.remaining()];
- buf.get(b);
- assertEquals(expectedLine, new String(b, "UTF-8").trim());
- }
- assertFalse(lines.hasNext());
- }
-
+
// metadata tests
private static final String STRING_KEY = "string-key";
private static final String LONG_KEY = "long-key";
diff --git a/lang/java/maven-plugin/pom.xml b/lang/java/maven-plugin/pom.xml
index 8f45283..e1d1eb9 100644
--- a/lang/java/maven-plugin/pom.xml
+++ b/lang/java/maven-plugin/pom.xml
@@ -22,12 +22,12 @@
<parent>
<artifactId>avro-parent</artifactId>
<groupId>org.apache.avro</groupId>
- <version>1.5.2</version>
+ <version>1.5.0</version>
<relativePath>../</relativePath>
</parent>
<artifactId>avro-maven-plugin</artifactId>
<name>Apache Avro Maven Plugin</name>
- <description>Maven plugin for Avro IDL and Specific API Compilers</description>
+ <description>Maven plulgin for Avro IDL and Specific API Compilers</description>
<packaging>maven-plugin</packaging>
<properties>
@@ -39,21 +39,6 @@
</prerequisites>
<build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-plugin-plugin</artifactId>
- <version>2.7</version>
- <executions>
- <execution>
- <id>generated-helpmojo</id>
- <goals>
- <goal>helpmojo</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
</build>
<dependencies>
diff --git a/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/IDLProtocolMojo.java b/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/IDLProtocolMojo.java
index d1df97e..1b6b601 100644
--- a/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/IDLProtocolMojo.java
+++ b/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/IDLProtocolMojo.java
@@ -27,7 +27,7 @@
import org.apache.avro.compiler.specific.SpecificCompiler;
/**
- * Generate Java classes and interfaces from AvroIDL files (.avdl)
+ * Compile an Avro schema file.
*
* @goal idl-protocol
* @phase generate-sources
diff --git a/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/ProtocolMojo.java b/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/ProtocolMojo.java
index 8b9a193..68935b3 100644
--- a/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/ProtocolMojo.java
+++ b/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/ProtocolMojo.java
@@ -24,7 +24,7 @@
import org.apache.avro.compiler.specific.SpecificCompiler;
/**
- * Generate Java classes and interfaces from Avro protocol files (.avpr)
+ * Compile an Avro protocol schema file.
*
* @goal protocol
* @phase generate-sources
diff --git a/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/SchemaMojo.java b/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/SchemaMojo.java
index 065583a..a23fe03 100644
--- a/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/SchemaMojo.java
+++ b/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/SchemaMojo.java
@@ -24,7 +24,7 @@
import org.apache.avro.compiler.specific.SpecificCompiler;
/**
- * Generate Java classes from Avro schema files (.avsc)
+ * Compile an Avro schema file.
*
* @goal schema
* @phase generate-sources
diff --git a/lang/java/pom.xml b/lang/java/pom.xml
index e300740..7059a1d 100644
--- a/lang/java/pom.xml
+++ b/lang/java/pom.xml
@@ -27,7 +27,7 @@
<groupId>org.apache.avro</groupId>
<artifactId>avro-parent</artifactId>
- <version>1.5.2</version>
+ <version>1.5.0</version>
<packaging>pom</packaging>
<name>Apache Avro Java</name>
@@ -41,11 +41,10 @@
<slf4j-version>1.6.1</slf4j-version>
<jackson-version>1.7.3</jackson-version>
<hadoop-version>0.20.2</hadoop-version>
- <velocity-version>1.7</velocity-version>
+ <velocity-version>1.6.4</velocity-version>
<jetty-version>6.1.26</jetty-version>
<netty-version>3.2.4.Final</netty-version>
<jopt-simple-version>3.2</jopt-simple-version>
- <snappy-version>1.0.1-rc3</snappy-version>
</properties>
<issueManagement>
@@ -187,6 +186,19 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-gpg-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>sign-artifacts</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>sign</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
@@ -277,26 +289,6 @@
</plugins>
</build>
</profile>
- <profile>
- <id>sign</id>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-gpg-plugin</artifactId>
- <executions>
- <execution>
- <id>sign-artifacts</id>
- <phase>verify</phase>
- <goals>
- <goal>sign</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
</profiles>
<!-- dependencyManagement can be used to define dependency versions, scopes, and
@@ -347,13 +339,6 @@
<version>${hadoop-version}</version>
<scope>compile</scope>
</dependency>
- <dependency>
- <groupId>org.xerial.snappy</groupId>
- <artifactId>snappy-java</artifactId>
- <version>${snappy-version}</version>
- <type>jar</type>
- <scope>compile</scope>
- </dependency>
</dependencies>
</dependencyManagement>
diff --git a/lang/java/tools/pom.xml b/lang/java/tools/pom.xml
index a1015c9..5ffd49e 100644
--- a/lang/java/tools/pom.xml
+++ b/lang/java/tools/pom.xml
@@ -22,7 +22,7 @@
<parent>
<artifactId>avro-parent</artifactId>
<groupId>org.apache.avro</groupId>
- <version>1.5.2</version>
+ <version>1.5.0</version>
<relativePath>../</relativePath>
</parent>
<artifactId>avro-tools</artifactId>
@@ -50,7 +50,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.4</version>
- <!-- primary artifact is shaded -->
<executions>
<execution>
<goals>
@@ -67,22 +66,6 @@
</execution>
</executions>
</plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <!-- 'nodeps' artifact is standalone -->
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>jar</goal>
- </goals>
- <configuration>
- <classifier>nodeps</classifier>
- </configuration>
- </execution>
- </executions>
- </plugin>
</plugins>
</build>
diff --git a/lang/java/tools/src/main/java/org/apache/avro/tool/FromTextTool.java b/lang/java/tools/src/main/java/org/apache/avro/tool/FromTextTool.java
index a1f438f..a8d6afc 100644
--- a/lang/java/tools/src/main/java/org/apache/avro/tool/FromTextTool.java
+++ b/lang/java/tools/src/main/java/org/apache/avro/tool/FromTextTool.java
@@ -19,7 +19,9 @@
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.PrintStream;
import java.nio.ByteBuffer;
import java.util.List;
@@ -32,7 +34,6 @@
import org.apache.avro.file.CodecFactory;
import org.apache.avro.file.DataFileWriter;
import org.apache.avro.generic.GenericDatumWriter;
-import static org.apache.avro.file.DataFileConstants.DEFLATE_CODEC;
/** Reads a text file into an Avro data file.
*
@@ -60,68 +61,36 @@
OptionSpec<Integer> level = p.accepts("level", "compression level")
.withOptionalArg().ofType(Integer.class);
- OptionSpec<String> codec = p.accepts("codec", "compression codec")
- .withOptionalArg().ofType(String.class);
-
OptionSet opts = p.parse(args.toArray(new String[0]));
- List<String> nargs = opts.nonOptionArguments();
- if (nargs.size() != 2) {
+ if (opts.nonOptionArguments().size() != 2) {
err.println("Expected 2 args: from_file to_file (local filenames," +
" Hadoop URI's, or '-' for stdin/stdout");
p.printHelpOn(err);
return 1;
}
+ BufferedInputStream inStream = Util.fileOrStdin(args.get(0), stdin);
+ BufferedOutputStream outStream = Util.fileOrStdout(args.get(1), out);
+
int compressionLevel = 1; // Default compression level
if (opts.hasArgument(level)) {
compressionLevel = level.value(opts);
}
- String codecName = opts.hasArgument(codec)
- ? codec.value(opts)
- : DEFLATE_CODEC;
- CodecFactory codecFactory = codecName.equals(DEFLATE_CODEC)
- ? CodecFactory.deflateCodec(compressionLevel)
- : CodecFactory.fromString(codecName);
-
- BufferedInputStream inStream = Util.fileOrStdin(nargs.get(0), stdin);
- BufferedOutputStream outStream = Util.fileOrStdout(nargs.get(1), out);
-
+ BufferedReader reader = new BufferedReader(new InputStreamReader(inStream));
DataFileWriter<ByteBuffer> writer =
new DataFileWriter<ByteBuffer>(new GenericDatumWriter<ByteBuffer>());
- writer.setCodec(codecFactory);
+ writer.setCodec(CodecFactory.deflateCodec(compressionLevel));
writer.create(Schema.parse(TEXT_FILE_SCHEMA), outStream);
- ByteBuffer line = ByteBuffer.allocate(128);
- boolean returnSeen = false;
- byte[] buf = new byte[8192];
- for (int end = inStream.read(buf); end != -1; end = inStream.read(buf)) {
- for (int i = 0; i < end; i++) {
- int b = buf[i] & 0xFF;
- if (b == '\n') { // newline
- System.out.println("Writing line = "+line.position());
- line.flip();
- writer.append(line);
- line.clear();
- returnSeen = false;
- } else if (b == '\r') { // return
- line.flip();
- writer.append(line);
- line.clear();
- returnSeen = true;
- } else {
- if (line.position() == line.limit()) { // reallocate longer line
- ByteBuffer tempLine = ByteBuffer.allocate(line.limit()*2);
- line.flip();
- tempLine.put(line);
- line = tempLine;
- }
- line.put((byte)b);
- returnSeen = false;
- }
- }
+ String line;
+ while((line = reader.readLine()) != null) {
+ ByteBuffer buff = ByteBuffer.wrap(line.getBytes());
+ writer.append(buff);
}
+
+ writer.flush();
writer.close();
inStream.close();
return 0;
diff --git a/lang/java/tools/src/main/java/org/apache/avro/tool/ToTextTool.java b/lang/java/tools/src/main/java/org/apache/avro/tool/ToTextTool.java
index 7363afc..e63a02b 100644
--- a/lang/java/tools/src/main/java/org/apache/avro/tool/ToTextTool.java
+++ b/lang/java/tools/src/main/java/org/apache/avro/tool/ToTextTool.java
@@ -35,7 +35,7 @@
public class ToTextTool implements Tool {
private static final String TEXT_FILE_SCHEMA =
"\"bytes\"";
- private static final byte[] LINE_SEPARATOR =
+ private static final byte[] LINE_SEPERATOR =
System.getProperty("line.separator").getBytes();
@Override
@@ -45,7 +45,7 @@
@Override
public String getShortDescription() {
- return "Converts an Avro data file to a text file.";
+ return "Converts and avro file to a text file.";
}
@Override
@@ -77,7 +77,7 @@
while (fileReader.hasNext()) {
ByteBuffer outBuff = (ByteBuffer) fileReader.next();
outStream.write(outBuff.array());
- outStream.write(LINE_SEPARATOR);
+ outStream.write(LINE_SEPERATOR);
}
outStream.close();
diff --git a/lang/java/tools/src/test/java/org/apache/avro/tool/TestTextFileTools.java b/lang/java/tools/src/test/java/org/apache/avro/tool/TestTextFileTools.java
deleted file mode 100644
index 100ab81..0000000
--- a/lang/java/tools/src/test/java/org/apache/avro/tool/TestTextFileTools.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/**
- * 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.
- */
-package org.apache.avro.tool;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.OutputStream;
-import java.io.InputStream;
-import java.io.FileOutputStream;
-import java.io.FileInputStream;
-import java.io.BufferedOutputStream;
-import java.io.BufferedInputStream;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Random;
-
-import org.apache.avro.AvroTestUtil;
-import org.apache.avro.Schema;
-import org.apache.avro.Schema.Type;
-import org.apache.avro.file.DataFileReader;
-import org.apache.avro.file.DataFileWriter;
-import org.apache.avro.generic.GenericDatumReader;
-import org.junit.BeforeClass;
-import org.junit.AfterClass;
-import org.junit.Test;
-
-@SuppressWarnings("deprecation")
-public class TestTextFileTools {
- private static final int COUNT =
- Integer.parseInt(System.getProperty("test.count", "10"));
-
- static File linesFile;
- static ByteBuffer[] lines;
- static Schema schema;
- static File schemaFile;
-
- @BeforeClass
- public static void writeRandomFile() throws IOException {
- schema = Schema.create(Type.BYTES);
- lines = new ByteBuffer[COUNT];
- linesFile = AvroTestUtil.tempFile("random.lines");
-
- OutputStream out =
- new BufferedOutputStream(new FileOutputStream(linesFile));
- Random rand = new Random();
- for (int j = 0; j < COUNT; j++) {
- byte[] line = new byte[rand.nextInt(512)];
- System.out.println("Creating line = "+line.length);
- for (int i = 0; i < line.length; i++) {
- int b = rand.nextInt(256);
- while (b == '\n' || b == '\r')
- b = rand.nextInt(256);
- line[i] = (byte)b;
- }
- out.write(line);
- out.write('\n');
- lines[j] = ByteBuffer.wrap(line);
- }
- out.close();
- }
-
- private void fromText(String name, String... args) throws Exception {
- File avroFile = AvroTestUtil.tempFile(name + ".avro");
-
- ArrayList<String> arglist = new ArrayList<String>();
- arglist.addAll(Arrays.asList(args));
- arglist.add(linesFile.toString());
- arglist.add(avroFile.toString());
-
- new FromTextTool().run(null, null, null, arglist);
-
- // Read it back, and make sure it's valid.
- DataFileReader<ByteBuffer> file = new DataFileReader<ByteBuffer>
- (avroFile, new GenericDatumReader<ByteBuffer>());
- int i = 0;
- for (ByteBuffer line : file) {
- System.out.println("Reading line = "+line.remaining());
- assertEquals(line, lines[i]);
- i++;
- }
- assertEquals(COUNT, i);
- }
-
- @Test
- public void testFromText() throws Exception {
- fromText("null", "--codec", "null");
- fromText("deflate", "--codec", "deflate");
- fromText("snappy", "--codec", "snappy");
- }
-
- @AfterClass
- public static void testToText() throws Exception {
- toText("null");
- toText("deflate");
- toText("snappy");
- }
-
- private static void toText(String name) throws Exception {
- File avroFile = AvroTestUtil.tempFile(name + ".avro");
- File outFile = AvroTestUtil.tempFile(name + ".lines");
-
- ArrayList<String> arglist = new ArrayList<String>();
- arglist.add(avroFile.toString());
- arglist.add(outFile.toString());
-
- new ToTextTool().run(null, null, null, arglist);
-
- // Read it back, and make sure it's valid.
- InputStream orig = new BufferedInputStream(new FileInputStream(linesFile));
- InputStream after = new BufferedInputStream(new FileInputStream(outFile));
-
- int b;
- while ((b = orig.read()) != -1)
- assertEquals(b, after.read());
- assertEquals(-1, after.read());
-
- orig.close();
- after.close();
- }
-
-}
diff --git a/lang/py/src/avro/schema.py b/lang/py/src/avro/schema.py
index b868031..24718c0 100644
--- a/lang/py/src/avro/schema.py
+++ b/lang/py/src/avro/schema.py
@@ -113,18 +113,18 @@
# add members
if not hasattr(self, '_props'): self._props = {}
self.set_prop('type', type)
- self.type = type
# Read-only properties dict. Printing schemas
# creates JSON properties directly from this dict.
props = property(lambda self: self._props)
+ type = property(lambda self: self.get_prop('type'))
# utility functions to manipulate properties dict
def get_prop(self, key):
- return self._props.get(key)
+ return self.props.get(key)
def set_prop(self, key, value):
- self._props[key] = value
+ self.props[key] = value
def __str__(self):
names = Names()
@@ -310,13 +310,13 @@
raise SchemaParseException(fail_msg)
self.set_prop('type', type_schema)
self.set_prop('name', name)
- self.type = type_schema
- self.name = name
# TODO(hammer): check to ensure default is valid
if has_default: self.set_prop('default', default)
if order is not None: self.set_prop('order', order)
# read-only properties
+ type = property(lambda self: self.get_prop('type'))
+ name = property(lambda self: self.get_prop('name'))
default = property(lambda self: self.get_prop('default'))
has_default = property(lambda self: self._has_default)
order = property(lambda self: self.get_prop('order'))
@@ -324,9 +324,9 @@
# utility functions to manipulate properties dict
def get_prop(self, key):
- return self._props.get(key)
+ return self.props.get(key)
def set_prop(self, key, value):
- self._props[key] = value
+ self.props[key] = value
def to_json(self, names):
to_dump = self.props.copy()
diff --git a/lang/py/test/av_bench.py b/lang/py/test/av_bench.py
deleted file mode 100644
index 5725997..0000000
--- a/lang/py/test/av_bench.py
+++ /dev/null
@@ -1,77 +0,0 @@
-#!/usr/bin/env python
-
-# 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.
-
-import sys
-import time
-from random import sample, choice, randint
-from string import lowercase
-
-import avro.datafile
-import avro.schema
-import avro.io
-
-
-types = ["A", "CNAME"]
-
-def rand_name():
- return ''.join(sample(lowercase, 15))
-
-def rand_ip():
- return "%s.%s.%s.%s" %(randint(0,255), randint(0,255), randint(0,255), randint(0,255))
-
-def write(n):
- schema_s="""
- { "type": "record",
- "name": "Query",
- "fields" : [
- {"name": "query", "type": "string"},
- {"name": "response", "type": "string"},
- {"name": "type", "type": "string", "default": "A"}
- ]}"""
- out = open("datafile.avr",'w')
-
- schema = avro.schema.parse(schema_s)
- writer = avro.io.DatumWriter(schema)
- dw = avro.datafile.DataFileWriter(out, writer, schema) #,codec='deflate')
- for _ in xrange(n):
- response = rand_ip()
- query = rand_name()
- type = choice(types)
- dw.append({'query': query, 'response': response, 'type': type})
-
- dw.close()
-
-def read():
- f = open("datafile.avr")
- reader = avro.io.DatumReader()
- af=avro.datafile.DataFileReader(f,reader)
-
- x=0
- for _ in af:
- pass
-
-def t(f, *args):
- s = time.time()
- f(*args)
- e = time.time()
- return e-s
-
-if __name__ == "__main__":
- n = int(sys.argv[1])
- print "Write %0.4f" % t(write, n)
- print "Read %0.4f" % t(read)
diff --git a/lang/ruby/lib/avro.rb b/lang/ruby/lib/avro.rb
index 03949fc..3208867 100644
--- a/lang/ruby/lib/avro.rb
+++ b/lang/ruby/lib/avro.rb
@@ -16,7 +16,7 @@
require 'yajl'
require 'set'
-require 'digest/md5'
+require 'md5'
require 'net/http'
require 'stringio'
diff --git a/lang/ruby/lib/avro/io.rb b/lang/ruby/lib/avro/io.rb
index b548b46..773976a 100644
--- a/lang/ruby/lib/avro/io.rb
+++ b/lang/ruby/lib/avro/io.rb
@@ -43,9 +43,9 @@
end
def byte!
- @reader.read(1).unpack('C').first
+ @reader.read(1)[0]
end
-
+
def read_null
# null is written as zero byte's
nil
diff --git a/lang/ruby/lib/avro/ipc.rb b/lang/ruby/lib/avro/ipc.rb
index 8aad1c1..f5fb429 100644
--- a/lang/ruby/lib/avro/ipc.rb
+++ b/lang/ruby/lib/avro/ipc.rb
@@ -399,7 +399,7 @@
message_length = message.size
total_bytes_sent = 0
while message_length - total_bytes_sent > 0
- if message_length - total_bytes_sent > BUFFER_SIZE
+ if message_length - total_bytes_sent > BUFFER_SIZE:
buffer_length = BUFFER_SIZE
else
buffer_length = message_length - total_bytes_sent
diff --git a/lang/ruby/lib/avro/schema.rb b/lang/ruby/lib/avro/schema.rb
index ac783c7..96769fb 100644
--- a/lang/ruby/lib/avro/schema.rb
+++ b/lang/ruby/lib/avro/schema.rb
@@ -102,7 +102,7 @@
when 'array'
datum.is_a?(Array) &&
datum.all?{|d| validate(expected_schema.items, d) }
- when 'map'
+ when 'map':
datum.keys.all?{|k| k.is_a? String } &&
datum.values.all?{|v| validate(expected_schema.values, v) }
when 'union'
diff --git a/lang/ruby/test/test_io.rb b/lang/ruby/test/test_io.rb
index 171403a..248caa4 100644
--- a/lang/ruby/test/test_io.rb
+++ b/lang/ruby/test/test_io.rb
@@ -145,7 +145,7 @@
bytes = []
current_byte = reader.read(1)
bytes << hexlify(current_byte)
- while (current_byte.unpack('C').first & 0x80) != 0
+ while (current_byte[0] & 0x80) != 0
current_byte = reader.read(1)
bytes << hexlify(current_byte)
end
@@ -153,7 +153,7 @@
end
def hexlify(msg)
- msg.unpack("H*")
+ msg.split("").collect { |c| c[0].to_s(16).rjust(2, '0') }.join
end
def test_binary_int_encoding
diff --git a/share/VERSION.txt b/share/VERSION.txt
index a73b432..3e1ad72 100644
--- a/share/VERSION.txt
+++ b/share/VERSION.txt
@@ -1 +1 @@
-1.5.2
\ No newline at end of file
+1.5.0
\ No newline at end of file
diff --git a/share/rat-excludes.txt b/share/rat-excludes.txt
index b935c2ae..0f97df8 100644
--- a/share/rat-excludes.txt
+++ b/share/rat-excludes.txt
@@ -32,8 +32,6 @@
lang/c/src/queue.h
lang/c/src/st.h
lang/c/src/st.c
-lang/csharp/Avro.sln
-lang/csharp/Avro.nunit
lang/java/ipc/src/main/java/org/apache/avro/ipc/stats/static/*.js
lang/java/ipc/src/main/java/org/apache/avro/ipc/stats/static/*.css
share/test/data/test.avro12
diff --git a/share/test/schemas/mail.avpr b/share/test/schemas/mail.avpr
index 7410592..2925d3c 100644
--- a/share/test/schemas/mail.avpr
+++ b/share/test/schemas/mail.avpr
@@ -15,12 +15,6 @@
"send": {
"request": [{"name": "message", "type": "Message"}],
"response": "string"
- },
- "fireandforget": {
- "request": [{"name": "message", "type": "Message"}],
- "response": "null",
- "one-way": true
}
-
}
-}
+}
\ No newline at end of file