You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2016/04/06 22:54:45 UTC

thrift git commit: THRIFT-3467 Go Maps for Thrift Sets Should Have Values of Type struct{} Client: Go Patch: artem antonenko

Repository: thrift
Updated Branches:
  refs/heads/master 51850abb7 -> ca714c439


THRIFT-3467 Go Maps for Thrift Sets Should Have Values of Type struct{}
Client: Go
Patch: artem antonenko <sa...@yandex.ru>

This closes #976


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/ca714c43
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/ca714c43
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/ca714c43

Branch: refs/heads/master
Commit: ca714c4397ed78bd880f0dd76526e3817ecc08f0
Parents: 51850ab
Author: creker <sa...@yandex.ru>
Authored: Mon Apr 4 19:19:47 2016 +0300
Committer: Jens Geyer <je...@apache.org>
Committed: Wed Apr 6 22:53:25 2016 +0200

----------------------------------------------------------------------
 compiler/cpp/src/generate/t_go_generator.cc | 10 ++++----
 lib/go/test/tests/client_error_test.go      |  4 ++--
 lib/go/test/tests/thrifttest_driver.go      |  2 +-
 lib/go/test/tests/thrifttest_handler.go     |  2 +-
 lib/go/thrift/serializer_test.go            |  4 ++--
 lib/go/thrift/serializer_types_test.go      | 30 ++++++++++++------------
 test/go/src/bin/stress/main.go              |  7 +++---
 test/go/src/bin/testclient/main.go          |  2 +-
 test/go/src/common/clientserver_test.go     |  4 ++--
 test/go/src/common/mock_handler.go          |  4 ++--
 test/go/src/common/printing_handler.go      |  2 +-
 test/go/src/common/simple_handler.go        |  2 +-
 12 files changed, 36 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/ca714c43/compiler/cpp/src/generate/t_go_generator.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_go_generator.cc b/compiler/cpp/src/generate/t_go_generator.cc
index 3f9b858..6efff0e 100644
--- a/compiler/cpp/src/generate/t_go_generator.cc
+++ b/compiler/cpp/src/generate/t_go_generator.cc
@@ -1150,12 +1150,12 @@ string t_go_generator::render_const_value(t_type* type, t_const_value* value, co
   } else if (type->is_set()) {
     t_type* etype = ((t_set*)type)->get_elem_type();
     const vector<t_const_value*>& val = value->get_list();
-    out << "map[" << type_to_go_key_type(etype) << "]bool{" << endl;
+    out << "map[" << type_to_go_key_type(etype) << "]struct{}{" << endl;
     indent_up();
     vector<t_const_value*>::const_iterator v_iter;
 
     for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
-      out << indent() << render_const_value(etype, *v_iter, name) << ": true," << endl;
+      out << indent() << render_const_value(etype, *v_iter, name) << ": struct{}{}," << endl;
     }
 
     indent_down();
@@ -2969,7 +2969,7 @@ void t_go_generator::generate_deserialize_container(ofstream& out,
     out << indent() << "  return thrift.PrependError(\"error reading set begin: \", err)" << endl;
     out << indent() << "}" << endl;
     out << indent() << "tSet := make(map["
-        << type_to_go_key_type(t->get_elem_type()->get_true_type()) << "]bool, size)" << endl;
+        << type_to_go_key_type(t->get_elem_type()->get_true_type()) << "]struct{}, size)" << endl;
     out << indent() << prefix << eq << " " << (pointer_field ? "&" : "") << "tSet" << endl;
   } else if (ttype->is_list()) {
     out << indent() << "_, size, err := iprot.ReadListBegin()" << endl;
@@ -3048,7 +3048,7 @@ void t_go_generator::generate_deserialize_set_element(ofstream& out,
   t_field felem(tset->get_elem_type(), elem);
   felem.set_req(t_field::T_OPT_IN_REQ_OUT);
   generate_deserialize_field(out, &felem, true, "", false, false, false, true, true);
-  indent(out) << prefix << "[" << elem << "] = true" << endl;
+  indent(out) << prefix << "[" << elem << "] = struct{}{}" << endl;
 }
 
 /**
@@ -3611,7 +3611,7 @@ string t_go_generator::type_to_go_type_with_opt(t_type* type,
   } else if (type->is_set()) {
     t_set* t = (t_set*)type;
     string elemType = type_to_go_key_type(t->get_elem_type());
-    return maybe_pointer + string("map[") + elemType + string("]bool");
+    return maybe_pointer + string("map[") + elemType + string("]struct{}");
   } else if (type->is_list()) {
     t_list* t = (t_list*)type;
     string elemType = type_to_go_type(t->get_elem_type());

http://git-wip-us.apache.org/repos/asf/thrift/blob/ca714c43/lib/go/test/tests/client_error_test.go
----------------------------------------------------------------------
diff --git a/lib/go/test/tests/client_error_test.go b/lib/go/test/tests/client_error_test.go
index 829a1dd..838883d 100644
--- a/lib/go/test/tests/client_error_test.go
+++ b/lib/go/test/tests/client_error_test.go
@@ -402,7 +402,7 @@ func TestClientReportTTransportErrors(t *testing.T) {
 	thing := errortest.NewTestStruct()
 	thing.M = make(map[string]string)
 	thing.L = make([]string, 0)
-	thing.S = make(map[string]bool)
+	thing.S = make(map[string]struct{})
 	thing.I = 3
 
 	err := thrift.NewTTransportException(thrift.TIMED_OUT, "test")
@@ -434,7 +434,7 @@ func TestClientReportTProtocolErrors(t *testing.T) {
 	thing := errortest.NewTestStruct()
 	thing.M = make(map[string]string)
 	thing.L = make([]string, 0)
-	thing.S = make(map[string]bool)
+	thing.S = make(map[string]struct{})
 	thing.I = 3
 
 	err := thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, errors.New("test"))

http://git-wip-us.apache.org/repos/asf/thrift/blob/ca714c43/lib/go/test/tests/thrifttest_driver.go
----------------------------------------------------------------------
diff --git a/lib/go/test/tests/thrifttest_driver.go b/lib/go/test/tests/thrifttest_driver.go
index 915383f..1e0cf86 100644
--- a/lib/go/test/tests/thrifttest_driver.go
+++ b/lib/go/test/tests/thrifttest_driver.go
@@ -162,7 +162,7 @@ func (p *ThriftTestDriver) Start() {
 		t.Fatal("TestStringMap failed")
 	}
 
-	setTestInput := map[int32]bool{1: true, 2: true, 3: true}
+	setTestInput := map[int32]struct{}{1: {}, 2: {}, 3: {}}
 	if r, err := client.TestSet(setTestInput); !reflect.DeepEqual(r, setTestInput) || err != nil {
 		t.Fatal("TestSet failed")
 	}

http://git-wip-us.apache.org/repos/asf/thrift/blob/ca714c43/lib/go/test/tests/thrifttest_handler.go
----------------------------------------------------------------------
diff --git a/lib/go/test/tests/thrifttest_handler.go b/lib/go/test/tests/thrifttest_handler.go
index 50fe718..822a6c7 100644
--- a/lib/go/test/tests/thrifttest_handler.go
+++ b/lib/go/test/tests/thrifttest_handler.go
@@ -96,7 +96,7 @@ func (p *ThriftTestHandler) TestStringMap(thing map[string]string) (r map[string
 	return thing, nil
 }
 
-func (p *ThriftTestHandler) TestSet(thing map[int32]bool) (r map[int32]bool, err error) {
+func (p *ThriftTestHandler) TestSet(thing map[int32]struct{}) (r map[int32]struct{}, err error) {
 	return thing, nil
 }
 

http://git-wip-us.apache.org/repos/asf/thrift/blob/ca714c43/lib/go/thrift/serializer_test.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/serializer_test.go b/lib/go/thrift/serializer_test.go
index 3cdb387..06d27a1 100644
--- a/lib/go/thrift/serializer_test.go
+++ b/lib/go/thrift/serializer_test.go
@@ -85,7 +85,7 @@ func ProtocolTest1(test *testing.T, pf ProtocolFactory) (bool, error) {
 	m.Bin = make([]byte, 10)
 	m.StringMap = make(map[string]string, 5)
 	m.StringList = make([]string, 5)
-	m.StringSet = make(map[string]bool, 5)
+	m.StringSet = make(map[string]struct{}, 5)
 	m.E = 2
 
 	s, err := t.WriteString(&m)
@@ -119,7 +119,7 @@ func ProtocolTest2(test *testing.T, pf ProtocolFactory) (bool, error) {
 	m.Bin = make([]byte, 10)
 	m.StringMap = make(map[string]string, 5)
 	m.StringList = make([]string, 5)
-	m.StringSet = make(map[string]bool, 5)
+	m.StringSet = make(map[string]struct{}, 5)
 	m.E = 2
 
 	s, err := t.WriteString(&m)

http://git-wip-us.apache.org/repos/asf/thrift/blob/ca714c43/lib/go/thrift/serializer_types_test.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/serializer_types_test.go b/lib/go/thrift/serializer_types_test.go
index 10f4737..38ab8d6 100644
--- a/lib/go/thrift/serializer_types_test.go
+++ b/lib/go/thrift/serializer_types_test.go
@@ -97,18 +97,18 @@ func MyTestEnumFromString(s string) (MyTestEnum, error) {
 func MyTestEnumPtr(v MyTestEnum) *MyTestEnum { return &v }
 
 type MyTestStruct struct {
-	On         bool              `thrift:"on,1" json:"on"`
-	B          int8              `thrift:"b,2" json:"b"`
-	Int16      int16             `thrift:"int16,3" json:"int16"`
-	Int32      int32             `thrift:"int32,4" json:"int32"`
-	Int64      int64             `thrift:"int64,5" json:"int64"`
-	D          float64           `thrift:"d,6" json:"d"`
-	St         string            `thrift:"st,7" json:"st"`
-	Bin        []byte            `thrift:"bin,8" json:"bin"`
-	StringMap  map[string]string `thrift:"stringMap,9" json:"stringMap"`
-	StringList []string          `thrift:"stringList,10" json:"stringList"`
-	StringSet  map[string]bool   `thrift:"stringSet,11" json:"stringSet"`
-	E          MyTestEnum        `thrift:"e,12" json:"e"`
+	On         bool                `thrift:"on,1" json:"on"`
+	B          int8                `thrift:"b,2" json:"b"`
+	Int16      int16               `thrift:"int16,3" json:"int16"`
+	Int32      int32               `thrift:"int32,4" json:"int32"`
+	Int64      int64               `thrift:"int64,5" json:"int64"`
+	D          float64             `thrift:"d,6" json:"d"`
+	St         string              `thrift:"st,7" json:"st"`
+	Bin        []byte              `thrift:"bin,8" json:"bin"`
+	StringMap  map[string]string   `thrift:"stringMap,9" json:"stringMap"`
+	StringList []string            `thrift:"stringList,10" json:"stringList"`
+	StringSet  map[string]struct{} `thrift:"stringSet,11" json:"stringSet"`
+	E          MyTestEnum          `thrift:"e,12" json:"e"`
 }
 
 func NewMyTestStruct() *MyTestStruct {
@@ -155,7 +155,7 @@ func (p *MyTestStruct) GetStringList() []string {
 	return p.StringList
 }
 
-func (p *MyTestStruct) GetStringSet() map[string]bool {
+func (p *MyTestStruct) GetStringSet() map[string]struct{} {
 	return p.StringSet
 }
 
@@ -366,7 +366,7 @@ func (p *MyTestStruct) readField11(iprot TProtocol) error {
 	if err != nil {
 		return PrependError("error reading set begin: ", err)
 	}
-	tSet := make(map[string]bool, size)
+	tSet := make(map[string]struct{}, size)
 	p.StringSet = tSet
 	for i := 0; i < size; i++ {
 		var _elem3 string
@@ -375,7 +375,7 @@ func (p *MyTestStruct) readField11(iprot TProtocol) error {
 		} else {
 			_elem3 = v
 		}
-		p.StringSet[_elem3] = true
+		p.StringSet[_elem3] = struct{}{}
 	}
 	if err := iprot.ReadSetEnd(); err != nil {
 		return PrependError("error reading set end: ", err)

http://git-wip-us.apache.org/repos/asf/thrift/blob/ca714c43/test/go/src/bin/stress/main.go
----------------------------------------------------------------------
diff --git a/test/go/src/bin/stress/main.go b/test/go/src/bin/stress/main.go
index 4fc88e0..1f713bb 100644
--- a/test/go/src/bin/stress/main.go
+++ b/test/go/src/bin/stress/main.go
@@ -201,14 +201,13 @@ func client(protocolFactory thrift.TProtocolFactory) {
 			atomic.AddInt64(&clicounter, 1)
 		}
 	case echoSet:
-		s := map[int8]bool{-10: true, -9: true, -8: true, -7: true, -6: true, -5: true, -4: true, -3: true, -2: true, -1: true, 0: true, 1: true, 2: true, 3: true, 4: true, 5: true, 6: true, 7: true, 8: true}
+		s := map[int8]struct{}{-10: {}, -9: {}, -8: {}, -7: {}, -6: {}, -5: {}, -4: {}, -3: {}, -2: {}, -1: {}, 0: {}, 1: {}, 2: {}, 3: {}, 4: {}, 5: {}, 6: {}, 7: {}, 8: {}}
 		for i := 0; i < *loop; i++ {
 			client.EchoSet(s)
 			atomic.AddInt64(&clicounter, 1)
 		}
 	case echoMap:
-		m := map[int8]int8{
-			-10: 10, -9: 9, -8: 8, -7: 7, -6: 6, -5: 5, -4: 4, -3: 3, -2: 2, -1: 1, 0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8}
+		m := map[int8]int8{-10: 10, -9: 9, -8: 8, -7: 7, -6: 6, -5: 5, -4: 4, -3: 3, -2: 2, -1: 1, 0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8}
 		for i := 0; i < *loop; i++ {
 			client.EchoMap(m)
 			atomic.AddInt64(&clicounter, 1)
@@ -244,7 +243,7 @@ func (h *handler) EchoList(arg []int8) (r []int8, err error) {
 	atomic.AddInt64(&counter, 1)
 	return arg, nil
 }
-func (h *handler) EchoSet(arg map[int8]bool) (r map[int8]bool, err error) {
+func (h *handler) EchoSet(arg map[int8]struct{}) (r map[int8]struct{}, err error) {
 	atomic.AddInt64(&counter, 1)
 	return arg, nil
 }

http://git-wip-us.apache.org/repos/asf/thrift/blob/ca714c43/test/go/src/bin/testclient/main.go
----------------------------------------------------------------------
diff --git a/test/go/src/bin/testclient/main.go b/test/go/src/bin/testclient/main.go
index 7a7af72..f4a19dd 100644
--- a/test/go/src/bin/testclient/main.go
+++ b/test/go/src/bin/testclient/main.go
@@ -174,7 +174,7 @@ func callEverything(client *thrifttest.ThriftTestClient) {
 		t.Fatalf("Unexpected TestStringMap() result expected %#v, got %#v ", sm, smret)
 	}
 
-	s := map[int32]bool{1: true, 2: true, 42: true}
+	s := map[int32]struct{}{1: struct{}{}, 2: struct{}{}, 42: struct{}{}}
 	sret, err := client.TestSet(s)
 	if err != nil {
 		t.Fatalf("Unexpected error in TestSet() call: ", err)

http://git-wip-us.apache.org/repos/asf/thrift/blob/ca714c43/test/go/src/common/clientserver_test.go
----------------------------------------------------------------------
diff --git a/test/go/src/common/clientserver_test.go b/test/go/src/common/clientserver_test.go
index 3b81423..2a9d5e9 100644
--- a/test/go/src/common/clientserver_test.go
+++ b/test/go/src/common/clientserver_test.go
@@ -105,7 +105,7 @@ func callEverythingWithMock(t *testing.T, client *thrifttest.ThriftTestClient, h
 		handler.EXPECT().TestNest(&thrifttest.Xtruct2{StructThing: &thrifttest.Xtruct{StringThing: "thing", ByteThing: 42, I32Thing: 4242, I64Thing: 424242}}).Return(&thrifttest.Xtruct2{StructThing: &thrifttest.Xtruct{StringThing: "thing", ByteThing: 42, I32Thing: 4242, I64Thing: 424242}}, nil),
 		handler.EXPECT().TestMap(map[int32]int32{1: 2, 3: 4, 5: 42}).Return(map[int32]int32{1: 2, 3: 4, 5: 42}, nil),
 		handler.EXPECT().TestStringMap(map[string]string{"a": "2", "b": "blah", "some": "thing"}).Return(map[string]string{"a": "2", "b": "blah", "some": "thing"}, nil),
-		handler.EXPECT().TestSet(map[int32]bool{1: true, 2: true, 42: true}).Return(map[int32]bool{1: true, 2: true, 42: true}, nil),
+		handler.EXPECT().TestSet(map[int32]struct{}{1: struct{}{}, 2: struct{}{}, 42: struct{}{}}).Return(map[int32]struct{}{1: struct{}{}, 2: struct{}{}, 42: struct{}{}}, nil),
 		handler.EXPECT().TestList([]int32{1, 2, 42}).Return([]int32{1, 2, 42}, nil),
 		handler.EXPECT().TestEnum(thrifttest.Numberz_TWO).Return(thrifttest.Numberz_TWO, nil),
 		handler.EXPECT().TestTypedef(thrifttest.UserId(42)).Return(thrifttest.UserId(42), nil),
@@ -222,7 +222,7 @@ func callEverythingWithMock(t *testing.T, client *thrifttest.ThriftTestClient, h
 		t.Errorf("Unexpected TestStringMap() result expected %#v, got %#v ", sm, smret)
 	}
 
-	s := map[int32]bool{1: true, 2: true, 42: true}
+	s := map[int32]struct{}{1: struct{}{}, 2: struct{}{}, 42: struct{}{}}
 	sret, err := client.TestSet(s)
 	if err != nil {
 		t.Errorf("Unexpected error in TestSet() call: ", err)

http://git-wip-us.apache.org/repos/asf/thrift/blob/ca714c43/test/go/src/common/mock_handler.go
----------------------------------------------------------------------
diff --git a/test/go/src/common/mock_handler.go b/test/go/src/common/mock_handler.go
index 7495fc6..6ae8130 100644
--- a/test/go/src/common/mock_handler.go
+++ b/test/go/src/common/mock_handler.go
@@ -223,9 +223,9 @@ func (_mr *_MockThriftTestRecorder) TestOneway(arg0 interface{}) *gomock.Call {
 	return _mr.mock.ctrl.RecordCall(_mr.mock, "TestOneway", arg0)
 }
 
-func (_m *MockThriftTest) TestSet(_param0 map[int32]bool) (map[int32]bool, error) {
+func (_m *MockThriftTest) TestSet(_param0 map[int32]struct{}) (map[int32]struct{}, error) {
 	ret := _m.ctrl.Call(_m, "TestSet", _param0)
-	ret0, _ := ret[0].(map[int32]bool)
+	ret0, _ := ret[0].(map[int32]struct{})
 	ret1, _ := ret[1].(error)
 	return ret0, ret1
 }

http://git-wip-us.apache.org/repos/asf/thrift/blob/ca714c43/test/go/src/common/printing_handler.go
----------------------------------------------------------------------
diff --git a/test/go/src/common/printing_handler.go b/test/go/src/common/printing_handler.go
index 5fe3d53..afee8da 100644
--- a/test/go/src/common/printing_handler.go
+++ b/test/go/src/common/printing_handler.go
@@ -188,7 +188,7 @@ func (p *printingHandler) TestStringMap(thing map[string]string) (r map[string]s
 //
 // Parameters:
 //  - Thing
-func (p *printingHandler) TestSet(thing map[int32]bool) (r map[int32]bool, err error) {
+func (p *printingHandler) TestSet(thing map[int32]struct{}) (r map[int32]struct{}, err error) {
 	fmt.Printf("testSet({")
 	first := true
 	for k, _ := range thing {

http://git-wip-us.apache.org/repos/asf/thrift/blob/ca714c43/test/go/src/common/simple_handler.go
----------------------------------------------------------------------
diff --git a/test/go/src/common/simple_handler.go b/test/go/src/common/simple_handler.go
index 944f11c..7bd3a30 100644
--- a/test/go/src/common/simple_handler.go
+++ b/test/go/src/common/simple_handler.go
@@ -77,7 +77,7 @@ func (p *simpleHandler) TestStringMap(thing map[string]string) (r map[string]str
 	return thing, nil
 }
 
-func (p *simpleHandler) TestSet(thing map[int32]bool) (r map[int32]bool, err error) {
+func (p *simpleHandler) TestSet(thing map[int32]struct{}) (r map[int32]struct{}, err error) {
 	return thing, nil
 }