This is an automated email from the ASF dual-hosted git repository.
jking pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git
The following commit(s) were added to refs/heads/master by this push:
new 67fbc1f THRIFT-4722 Netcore union "data" should be strongly-typed
Client: netcore Patch: Jens Geyer
67fbc1f is described below
commit 67fbc1f6159602fbb0d5859f67edf760d40d155d
Author: Jens Geyer <[email protected]>
AuthorDate: Wed Jan 23 00:13:15 2019 +0100
THRIFT-4722 Netcore union "data" should be strongly-typed
Client: netcore
Patch: Jens Geyer
---
.../cpp/src/thrift/generate/t_netcore_generator.cc | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/compiler/cpp/src/thrift/generate/t_netcore_generator.cc
b/compiler/cpp/src/thrift/generate/t_netcore_generator.cc
index d2e7da0..6f346a3 100644
--- a/compiler/cpp/src/thrift/generate/t_netcore_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_netcore_generator.cc
@@ -1347,9 +1347,9 @@ void
t_netcore_generator::generate_netcore_union_definition(ostream& out, t_stru
indent_up();
out << indent() << "public abstract Task WriteAsync(TProtocol tProtocol,
CancellationToken cancellationToken);" << endl
- << indent() << "public readonly bool Isset;" << endl
+ << indent() << "public readonly int Isset;" << endl
<< indent() << "public abstract object Data { get; }" << endl
- << indent() << "protected " << tunion->get_name() << "(bool isset)" <<
endl
+ << indent() << "protected " << tunion->get_name() << "(int isset)" <<
endl
<< indent() << "{" << endl;
indent_up();
out << indent() << "Isset = isset;" << endl;
@@ -1361,7 +1361,7 @@ void
t_netcore_generator::generate_netcore_union_definition(ostream& out, t_stru
indent_up();
out << indent() << "public override object Data { get { return null; } }"
<< endl
- << indent() << "public ___undefined() : base(false) {}" << endl <<
endl;
+ << indent() << "public ___undefined() : base(0) {}" << endl << endl;
out << indent() << "public override Task WriteAsync(TProtocol oprot,
CancellationToken cancellationToken)" << endl
<< indent() << "{" << endl;
@@ -1390,13 +1390,27 @@ void
t_netcore_generator::generate_netcore_union_definition(ostream& out, t_stru
void t_netcore_generator::generate_netcore_union_class(ostream& out, t_struct*
tunion, t_field* tfield)
{
+ out << indent() << "public " << type_name(tfield->get_type()) << " As_" <<
tfield->get_name() << endl;
+ out << indent() << "{" << endl;
+ indent_up();
+ out << indent() << "get" << endl;
+ out << indent() << "{" << endl;
+ indent_up();
+ out << indent() << "return (" << tfield->get_key() << " == Isset) ? (" <<
type_name(tfield->get_type()) << ")Data : default(" <<
type_name(tfield->get_type()) << ");" << endl;
+ indent_down();
+ out << indent() << "}" << endl;
+ indent_down();
+ out << indent() << "}" << endl
+ << endl;
+
+
out << indent() << "public class " << tfield->get_name() << " : " <<
tunion->get_name() << endl
<< indent() << "{" << endl;
indent_up();
out << indent() << "private " << type_name(tfield->get_type()) << "
_data;" << endl
<< indent() << "public override object Data { get { return _data; } }"
<< endl
- << indent() << "public " << tfield->get_name() << "(" <<
type_name(tfield->get_type()) << " data) : base(true)" << endl
+ << indent() << "public " << tfield->get_name() << "(" <<
type_name(tfield->get_type()) << " data) : base("<< tfield->get_key() <<")" <<
endl
<< indent() << "{" << endl;
indent_up();
out << indent() << "this._data = data;" << endl;