You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by th...@apache.org on 2017/02/19 16:17:18 UTC
avro git commit: Fix for AVRO-1994: C++ Code Generator Generates
Invalid Code if Field is of type Null
Repository: avro
Updated Branches:
refs/heads/master ec8514f71 -> 230c7e753
Fix for AVRO-1994: C++ Code Generator Generates Invalid Code if Field is of type Null
Project: http://git-wip-us.apache.org/repos/asf/avro/repo
Commit: http://git-wip-us.apache.org/repos/asf/avro/commit/230c7e75
Tree: http://git-wip-us.apache.org/repos/asf/avro/tree/230c7e75
Diff: http://git-wip-us.apache.org/repos/asf/avro/diff/230c7e75
Branch: refs/heads/master
Commit: 230c7e75392d3c3dc2598f027603b4fc9d78d041
Parents: ec8514f
Author: Thiruvalluvan M. G <th...@apache.org>
Authored: Sun Feb 19 21:47:01 2017 +0530
Committer: Thiruvalluvan M G <th...@startsmartlabs.com>
Committed: Sun Feb 19 21:47:01 2017 +0530
----------------------------------------------------------------------
CHANGES.txt | 2 ++
lang/c++/CMakeLists.txt | 3 ++-
lang/c++/api/Specific.hh | 24 ++++++++++++++++++++++++
lang/c++/impl/avrogencpp.cc | 2 ++
lang/c++/jsonschemas/bigrecord | 4 ++++
lang/c++/test/AvrogencppTests.cc | 1 +
6 files changed, 35 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/avro/blob/230c7e75/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 83c9a4d..93ea0d7 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -141,6 +141,8 @@ Trunk (not yet released)
AVRO-1892. C++ library cannot parse unions with default values (Hua Zhang via thiru)
+ AVRO-1994. C++ Code Generator Generates Invalid Code if Field is of type Null (Darryl Green via thiru)
+
Avro 1.8.1 (14 May 2016)
INCOMPATIBLE CHANGES
http://git-wip-us.apache.org/repos/asf/avro/blob/230c7e75/lang/c++/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/lang/c++/CMakeLists.txt b/lang/c++/CMakeLists.txt
index c9ba587..cf18243 100644
--- a/lang/c++/CMakeLists.txt
+++ b/lang/c++/CMakeLists.txt
@@ -128,6 +128,7 @@ gen (circulardep cd)
gen (tree1 tr1)
gen (tree2 tr2)
gen (crossref cr)
+gen (primitivetypes pt)
add_executable (avrogencpp impl/avrogencpp.cc)
target_link_libraries (avrogencpp avrocpp_s ${Boost_LIBRARIES})
@@ -157,7 +158,7 @@ add_dependencies (AvrogencppTests bigrecord_hh bigrecord_r_hh bigrecord2_hh
tweet_hh
union_array_union_hh union_map_union_hh union_conflict_hh
recursive_hh reuse_hh circulardep_hh tree1_hh tree2_hh crossref_hh
- empty_record_hh)
+ primitivetypes_hh empty_record_hh)
include (InstallRequiredSystemLibraries)
http://git-wip-us.apache.org/repos/asf/avro/blob/230c7e75/lang/c++/api/Specific.hh
----------------------------------------------------------------------
diff --git a/lang/c++/api/Specific.hh b/lang/c++/api/Specific.hh
index ef50318..0a00fb3 100644
--- a/lang/c++/api/Specific.hh
+++ b/lang/c++/api/Specific.hh
@@ -25,6 +25,7 @@
#include <algorithm>
#include "boost/array.hpp"
+#include "boost/blank.hpp"
#include "Config.hh"
#include "Encoder.hh"
@@ -46,6 +47,8 @@
*/
namespace avro {
+typedef boost::blank null;
+
template <typename T> void encode(Encoder& e, const T& t);
template <typename T> void decode(Decoder& d, T& t);
@@ -290,6 +293,27 @@ template <typename T> struct codec_traits<std::map<std::string, T> > {
};
/**
+* codec_traits for Avro null.
+*/
+template <> struct codec_traits<avro::null> {
+ /**
+ * Encodes a given value.
+ */
+ static void encode(Encoder& e, const avro::null&) {
+ e.encodeNull();
+ }
+
+ /**
+ * Decodes into a given value.
+ */
+ static void decode(Decoder& d, avro::null&) {
+ d.decodeNull();
+ }
+};
+
+
+
+/**
* Generic encoder function that makes use of the codec_traits.
*/
template <typename T>
http://git-wip-us.apache.org/repos/asf/avro/blob/230c7e75/lang/c++/impl/avrogencpp.cc
----------------------------------------------------------------------
diff --git a/lang/c++/impl/avrogencpp.cc b/lang/c++/impl/avrogencpp.cc
index 1bf0e19..a44fe7d 100644
--- a/lang/c++/impl/avrogencpp.cc
+++ b/lang/c++/impl/avrogencpp.cc
@@ -173,6 +173,8 @@ string CodeGen::cppTypeOf(const NodePtr& n)
return cppTypeOf(resolveSymbol(n));
case avro::AVRO_UNION:
return fullname(done[n]);
+ case avro::AVRO_NULL:
+ return "avro::null";
default:
return "$Undefined$";
}
http://git-wip-us.apache.org/repos/asf/avro/blob/230c7e75/lang/c++/jsonschemas/bigrecord
----------------------------------------------------------------------
diff --git a/lang/c++/jsonschemas/bigrecord b/lang/c++/jsonschemas/bigrecord
index 02dbccb..ba430a0 100644
--- a/lang/c++/jsonschemas/bigrecord
+++ b/lang/c++/jsonschemas/bigrecord
@@ -102,6 +102,10 @@
{
"name": "bytes",
"type": "bytes"
+ },
+ {
+ "name": "null",
+ "type": "null"
}
]
}
http://git-wip-us.apache.org/repos/asf/avro/blob/230c7e75/lang/c++/test/AvrogencppTests.cc
----------------------------------------------------------------------
diff --git a/lang/c++/test/AvrogencppTests.cc b/lang/c++/test/AvrogencppTests.cc
index add78f5..1b42943 100644
--- a/lang/c++/test/AvrogencppTests.cc
+++ b/lang/c++/test/AvrogencppTests.cc
@@ -30,6 +30,7 @@
#include "tree1.hh"
#include "tree2.hh"
#include "crossref.hh"
+#include "primitivetypes.hh"
#include "Compiler.hh"
#include <fstream>