Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Tag 1.5.1 release.

git-svn-id: https://svn.apache.org/repos/asf/avro/tags/release-1.5.1@1100312 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
commit cb6560b1ad29c12ff7ddd4bfba646424e99f6bb6 1 parent 12e0994
@cutting cutting authored
Showing with 119 additions and 13,952 deletions.
  1. +0 −3  doc/src/content/xdocs/idl.xml
  2. +1 −10 doc/src/content/xdocs/spec.xml
  3. +4 −42 lang/c++/CMakeLists.txt
  4. 0  lang/c++/Makefile.am
  5. +0 −287 lang/c++/api/DataFile.hh
  6. +0 −278 lang/c++/api/Generic.hh
  7. +0 −207 lang/c++/api/Specific.hh
  8. +0 −18 lang/c++/api/Stream.hh
  9. +0 −3  lang/c++/build.sh
  10. +0 −324 lang/c++/impl/DataFile.cc
  11. +2 −3 lang/c++/impl/FileStream.cc
  12. +0 −437 lang/c++/impl/Generic.cc
  13. +0 −533 lang/c++/impl/avrogencpp.cc
  14. +0 −1  lang/c++/impl/parsing/ResolvingDecoder.cc
  15. +0 −6 lang/c++/impl/parsing/Symbol.hh
  16. +0 −8 lang/c++/jsonschemas/union_array_union
  17. +0 −8 lang/c++/jsonschemas/union_map_union
  18. +2 −2 lang/c++/parser/AvroLex.ll
  19. +0 −191 lang/c++/test/AvrogencppTests.cc
  20. +1 −136 lang/c++/test/CodecTests.cc
  21. +0 −366 lang/c++/test/DataFileTests.cc
  22. +0 −200 lang/c++/test/SpecificTests.cc
  23. +0 −15 lang/csharp/Avro.nunit
  24. +0 −55 lang/csharp/Avro.sln
  25. +0 −34 lang/csharp/README
  26. +0 −38 lang/csharp/build.sh
  27. BIN  lang/csharp/lib/main/Newtonsoft.Json.dll
  28. BIN  lang/csharp/lib/main/log4net.dll
  29. BIN  lang/csharp/lib/test/nunit.framework.dll
  30. +0 −162 lang/csharp/src/apache/codegen/Avro.codegen.csproj
  31. +0 −84 lang/csharp/src/apache/codegen/AvroGen.cs
  32. +0 −54 lang/csharp/src/apache/codegen/Properties/AssemblyInfo.cs
  33. +0 −19 lang/csharp/src/apache/codegen/app.config
  34. +0 −155 lang/csharp/src/apache/main/Avro.main.csproj
  35. +0 −38 lang/csharp/src/apache/main/CodeGen/AvroRuntimeException.cs
  36. +0 −659 lang/csharp/src/apache/main/CodeGen/CodeGen.cs
  37. +0 −38 lang/csharp/src/apache/main/CodeGen/CodeGenException.cs
  38. +0 −105 lang/csharp/src/apache/main/CodeGen/CodeGenUtil.cs
  39. +0 −325 lang/csharp/src/apache/main/Generic/DatumReader.cs
  40. +0 −28 lang/csharp/src/apache/main/Generic/DatumWriter.cs
  41. +0 −63 lang/csharp/src/apache/main/Generic/GenericEnum.cs
  42. +0 −109 lang/csharp/src/apache/main/Generic/GenericFixed.cs
  43. +0 −632 lang/csharp/src/apache/main/Generic/GenericReader.cs
  44. +0 −137 lang/csharp/src/apache/main/Generic/GenericRecord.cs
  45. +0 −445 lang/csharp/src/apache/main/Generic/GenericWriter.cs
  46. +0 −299 lang/csharp/src/apache/main/IO/BinaryDecoder.cs
  47. +0 −190 lang/csharp/src/apache/main/IO/BinaryEncoder.cs
  48. +0 −188 lang/csharp/src/apache/main/IO/Decoder.cs
  49. +0 −50 lang/csharp/src/apache/main/IO/Encoder.cs
  50. +0 −166 lang/csharp/src/apache/main/IO/Resolver.cs
  51. +0 −53 lang/csharp/src/apache/main/Properties/AssemblyInfo.cs
  52. +0 −44 lang/csharp/src/apache/main/Properties/Settings.Designer.cs
  53. +0 −145 lang/csharp/src/apache/main/Protocol/Message.cs
  54. +0 −191 lang/csharp/src/apache/main/Protocol/Protocol.cs
  55. +0 −36 lang/csharp/src/apache/main/Protocol/ProtocolParseException.cs
  56. +0 −111 lang/csharp/src/apache/main/Schema/ArraySchema.cs
  57. +0 −36 lang/csharp/src/apache/main/Schema/AvroException.cs
  58. +0 −31 lang/csharp/src/apache/main/Schema/AvroTypeException.cs
  59. +0 −206 lang/csharp/src/apache/main/Schema/EnumSchema.cs
  60. +0 −245 lang/csharp/src/apache/main/Schema/Field.cs
  61. +0 −120 lang/csharp/src/apache/main/Schema/FixedSchema.cs
  62. +0 −122 lang/csharp/src/apache/main/Schema/JsonHelper.cs
  63. +0 −112 lang/csharp/src/apache/main/Schema/MapSchema.cs
  64. +0 −206 lang/csharp/src/apache/main/Schema/NamedSchema.cs
  65. +0 −130 lang/csharp/src/apache/main/Schema/PrimitiveSchema.cs
  66. +0 −124 lang/csharp/src/apache/main/Schema/Property.cs
  67. +0 −338 lang/csharp/src/apache/main/Schema/RecordSchema.cs
  68. +0 −306 lang/csharp/src/apache/main/Schema/Schema.cs
  69. +0 −222 lang/csharp/src/apache/main/Schema/SchemaName.cs
  70. +0 −31 lang/csharp/src/apache/main/Schema/SchemaParseException.cs
  71. +0 −164 lang/csharp/src/apache/main/Schema/UnionSchema.cs
  72. +0 −39 lang/csharp/src/apache/main/Schema/UnnamedSchema.cs
  73. +0 −195 lang/csharp/src/apache/main/Specific/ObjectCreator.cs
  74. +0 −34 lang/csharp/src/apache/main/Specific/SpecificFixed.cs
  75. +0 −277 lang/csharp/src/apache/main/Specific/SpecificReader.cs
  76. +0 −34 lang/csharp/src/apache/main/Specific/SpecificRecord.cs
  77. +0 −215 lang/csharp/src/apache/main/Specific/SpecificWriter.cs
  78. +0 −131 lang/csharp/src/apache/test/Avro.test.csproj
  79. +0 −122 lang/csharp/src/apache/test/CodGen/CodeGenTest.cs
  80. +0 −455 lang/csharp/src/apache/test/Generic/GenericTests.cs
  81. +0 −334 lang/csharp/src/apache/test/IO/BinaryCodecTests.cs
  82. +0 −53 lang/csharp/src/apache/test/Properties/AssemblyInfo.cs
  83. +0 −184 lang/csharp/src/apache/test/Protocol/ProtocolTest.cs
  84. +0 −239 lang/csharp/src/apache/test/Schema/AliasTest.cs
  85. +0 −276 lang/csharp/src/apache/test/Schema/SchemaTests.cs
  86. +0 −186 lang/csharp/src/apache/test/Specific/SpecificTests.cs
  87. +1 −5 lang/java/avro/pom.xml
  88. +0 −6 lang/java/avro/src/main/java/org/apache/avro/Schema.java
  89. +0 −6 lang/java/avro/src/main/java/org/apache/avro/file/CodecFactory.java
  90. +0 −1  lang/java/avro/src/main/java/org/apache/avro/file/DataFileConstants.java
  91. +0 −92 lang/java/avro/src/main/java/org/apache/avro/file/SnappyCodec.java
  92. +5 −14 lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java
  93. +1 −1  lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java
  94. +0 −1  lang/java/avro/src/main/java/org/apache/avro/io/parsing/Symbol.java
  95. +3 −4 lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
  96. +1 −1  lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectDatumWriter.java
  97. +2 −2 lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java
  98. +0 −1  lang/java/avro/src/test/java/org/apache/avro/TestDataFile.java
  99. +0 −8 lang/java/avro/src/test/java/org/apache/avro/TestReflect.java
  100. +0 −12 lang/java/avro/src/test/java/org/apache/avro/io/TestResolvingIOResolving.java
  101. +1 −1  lang/java/compiler/pom.xml
  102. +18 −27 lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj
  103. +0 −4 lang/java/compiler/src/test/idl/input/simple.avdl
  104. +0 −4 lang/java/compiler/src/test/idl/output/simple.avpr
  105. +1 −1  lang/java/ipc/pom.xml
  106. +3 −16 lang/java/ipc/src/main/java/org/apache/avro/ipc/SaslSocketTransceiver.java
  107. +4 −42 lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java
  108. +0 −26 lang/java/ipc/src/test/java/org/apache/avro/ipc/TestSaslAnonymous.java
  109. +1 −1  lang/java/mapred/pom.xml
  110. +0 −61 lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroAsTextInputFormat.java
  111. +0 −98 lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroAsTextRecordReader.java
  112. +0 −7 lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroJob.java
  113. +3 −17 lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroMapper.java
  114. +1 −6 lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroOutputFormat.java
  115. +4 −18 lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroReducer.java
  116. +2 −8 lang/java/mapred/src/main/java/org/apache/avro/mapred/HadoopMapper.java
  117. +0 −5 lang/java/mapred/src/main/java/org/apache/avro/mapred/HadoopReducerBase.java
  118. +0 −18 lang/java/mapred/src/main/java/org/apache/avro/mapred/package.html
  119. +0 −61 lang/java/mapred/src/test/java/org/apache/avro/mapred/TestAvroAsTextInputFormat.java
  120. +1 −41 lang/java/mapred/src/test/java/org/apache/avro/mapred/TestSequenceFileReader.java
  121. +4 −52 lang/java/mapred/src/test/java/org/apache/avro/mapred/TestWeather.java
  122. +0 −32 lang/java/mapred/src/test/java/org/apache/avro/mapred/WordCountUtil.java
  123. +2 −17 lang/java/maven-plugin/pom.xml
  124. +1 −1  lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/IDLProtocolMojo.java
  125. +1 −1  lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/ProtocolMojo.java
  126. +1 −1  lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/SchemaMojo.java
  127. +15 −30 lang/java/pom.xml
  128. +1 −18 lang/java/tools/pom.xml
  129. +14 −45 lang/java/tools/src/main/java/org/apache/avro/tool/FromTextTool.java
  130. +3 −3 lang/java/tools/src/main/java/org/apache/avro/tool/ToTextTool.java
  131. +0 −144 lang/java/tools/src/test/java/org/apache/avro/tool/TestTextFileTools.java
  132. +7 −7 lang/py/src/avro/schema.py
  133. +0 −77 lang/py/test/av_bench.py
  134. +1 −1  lang/ruby/lib/avro.rb
  135. +2 −2 lang/ruby/lib/avro/io.rb
  136. +1 −1  lang/ruby/lib/avro/ipc.rb
  137. +1 −1  lang/ruby/lib/avro/schema.rb
  138. +2 −2 lang/ruby/test/test_io.rb
  139. +1 −1  share/VERSION.txt
  140. +0 −2  share/rat-excludes.txt
View
3  doc/src/content/xdocs/idl.xml
@@ -302,9 +302,6 @@ void fireAndForget(string message) oneway;
<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>
View
11 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>
View
46 lang/c++/CMakeLists.txt
@@ -34,18 +34,15 @@ set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${BUILD_DIRECTORY})
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,34 +80,13 @@ add_custom_target (testgen2
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)
-
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)
@@ -122,23 +98,9 @@ target_link_libraries (CodecTests avrocpp ${Boost_LIBRARIES})
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)
-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)
View
0  lang/c++/Makefile.am
No changes.
View
287 lang/c++/api/DataFile.hh
@@ -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
-
-
View
278 lang/c++/api/Generic.hh
@@ -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
-
View
207 lang/c++/api/Specific.hh
@@ -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__
-
-
-
View
18 lang/c++/api/Stream.hh
@@ -136,7 +136,6 @@ struct StreamReader {
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 @@ struct StreamWriter {
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 @@ struct StreamWriter {
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
View
3  lang/c++/build.sh
@@ -82,9 +82,6 @@ case "$target" in
./build/testgentest
./build/CodecTests
./build/StreamTests
- ./build/SpecificTests
- ./build/AvrogencppTests
- ./build/DataFileTests
;;
dist)
View
324 lang/c++/impl/DataFile.cc
@@ -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
View
5 lang/c++/impl/FileStream.cc
@@ -113,17 +113,16 @@ class FileOutputStream : public OutputStream {
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 @@ class FileOutputStream : public OutputStream {
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) {
View
437 lang/c++/impl/Generic.cc
@@ -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
View
533 lang/c++/impl/avrogencpp.cc
@@ -1,533 +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 <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::string;
-using std::vector;
-using avro::NodePtr;
-using avro::resolveSymbol;
-
-using boost::lexical_cast;
-
-using avro::ValidSchema;
-using avro::compileJsonSchema;
-
-class CodeGen {
- size_t unionNumber_;
- std::ostream& os_;
- const std::string ns_;
- const std::string headerFile_;
- const std::string schemaFile_;
- boost::mt19937 random_;
-
- 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);
- 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), 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 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)));
- }
-
- 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_++) + "__";
-}
-
-string CodeGen::generateUnionType(const NodePtr& n)
-{
- size_t c = n->leaves();
- vector<string> types;
- vector<string> names;
- for (size_t i = 0; i < c; ++i) {
- const NodePtr& nn = n->leafAt(i);
- types.push_back(generateType(nn));
- names.push_back(cppNameOf(nn));
- }
-
- 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";
- continue;
- }
- string type = types[i];
- string name = names[i];
- os_ << " " << type << " get_" << name << "() const {\n"
- << " if (idx_ != " << i << ") {\n"
- << " throw avro::Exception(\"Invalid type for "
- << "union\");\n"
- << " }\n"
- << " return boost::any_cast<" << type << " >(value_);\n"
- << " }\n";
-
- os_ << " void set_" << name << "(const " << type << "& v) {\n"
- << " idx_ = " << i << ";\n"
- << " value_ = v;\n"
- << " }\n";
- }
- os_ << " " << result << "() : idx_(0) {\n";
- if (n->leafAt(0)->type() != avro::AVRO_NULL) {
- os_ << " value_ = " << types[0] << "();\n";
- }
- os_ << " }\n";
- os_ << "};\n\n";
-
- return result;
-}
-
-string CodeGen::generateType(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:
- case avro::AVRO_MAP:
- generateType(n->leafAt(n->type() == avro::AVRO_ARRAY ? 0 : 1));
- return cppTypeOf(n);
- case avro::AVRO_RECORD:
- return generateRecordType(n);
- case avro::AVRO_ENUM:
- return generateEnumType(n);
- case avro::AVRO_UNION:
- return generateUnionType(n);
- case avro::AVRO_SYMBOLIC:
- return cppTypeOf(resolveSymbol(n));
- }
- 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 = unionName();
- 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";
- }
-
- const NodePtr& root = schema.root();
- generateType(root);
-
- if (! ns_.empty()) {
- 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");