Skip to content

Commit 63eeff9

Browse files
CJCombrinkJens-G
authored andcommitted
THRIFT-5865: Fix TBinayProtocol with list<UUID>
Client: cpp Patch: Carel Combrink This closes #3136
1 parent ce696f3 commit 63eeff9

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

lib/cpp/src/thrift/protocol/TBinaryProtocol.tcc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ int TBinaryProtocolT<Transport_, ByteOrder_>::getMinSerializedSize(TType type)
493493
case T_MAP: return sizeof(int); // element count
494494
case T_SET: return sizeof(int); // element count
495495
case T_LIST: return sizeof(int); // element count
496+
case T_UUID: return 16; // 16 bytes
496497
default: throw TProtocolException(TProtocolException::UNKNOWN, "unrecognized type code");
497498
}
498499
}

lib/cpp/test/DebugProtoTest.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ BOOST_AUTO_TEST_CASE(test_debug_proto_1) {
7878
" [raw] = \"\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\",\n"
7979
" [enc] = \"00000000-0000-0000-0000-000000000000\"\n"
8080
" }\n"
81+
" 16: rfc4122_uuid_list (list) = list<uuid>[0] {\n"
82+
" },\n"
8183
"}");
8284
const std::string result(apache::thrift::ThriftDebugString(*ooe));
8385

@@ -88,6 +90,8 @@ BOOST_AUTO_TEST_CASE(test_debug_proto_1) {
8890
static ::std::shared_ptr<Nesting> n;
8991

9092
void testCaseSetup_2() {
93+
using apache::thrift::TUuid;
94+
9195
testCaseSetup_1();
9296

9397
n.reset(new Nesting);
@@ -102,9 +106,14 @@ void testCaseSetup_2() {
102106
"\xb0\xcf\x81\xe2\x84\x8e\x20\xce\x91\x74\x74"
103107
"\xce\xb1\xe2\x85\xbd\xce\xba\xc7\x83\xe2\x80"
104108
"\xbc";
105-
n->my_ooe.rfc4122_uuid = apache::thrift::TUuid{"{5e2ab188-1726-4e75-a04f-1ed9a6a89c4c}"};
109+
n->my_ooe.rfc4122_uuid = TUuid{"{5e2ab188-1726-4e75-a04f-1ed9a6a89c4c}"};
106110
n->my_bonk.type = 31337;
107111
n->my_bonk.message = "I am a bonk... xor!";
112+
113+
std::vector<TUuid> uuiid_list;
114+
uuiid_list.push_back(TUuid{"{fa1af5ec-fdc2-4355-844a-9f0dbfd00e50}"});
115+
uuiid_list.push_back(TUuid{"{1beece83-34f4-4fa3-b757-1ad1ac157fe3}"});
116+
n->my_ooe.rfc4122_uuid_list = uuiid_list;
108117
}
109118

110119
BOOST_AUTO_TEST_CASE(test_debug_proto_2) {
@@ -150,6 +159,16 @@ BOOST_AUTO_TEST_CASE(test_debug_proto_2) {
150159
" [raw] = \"^*\\xb1\\x88\\x17&Nu\\xa0O\\x1e\\xd9\\xa6\\xa8\\x9cL\",\n"
151160
" [enc] = \"5e2ab188-1726-4e75-a04f-1ed9a6a89c4c\"\n"
152161
" }\n"
162+
" 16: rfc4122_uuid_list (list) = list<uuid>[2] {\n"
163+
"{\n"
164+
" [raw] = [0] = \"\\xfa\\x1a\\xf5\\xec\\xfd\\xc2CU\\x84J\\x9f\\r\\xbf\\xd0\\x0eP\",\n"
165+
" [enc] = \"fa1af5ec-fdc2-4355-844a-9f0dbfd00e50\"\n"
166+
" }\n"
167+
"{\n"
168+
" [raw] = [1] = \"\\x1b\\xee\\xce\\x834\\xf4O\\xa3\\xb7W\\x1a\\xd1\\xac\\x15\\x7f\\xe3\",\n"
169+
" [enc] = \"1beece83-34f4-4fa3-b757-1ad1ac157fe3\"\n"
170+
" }\n"
171+
" },\n"
153172
" },\n"
154173
"}");
155174
const std::string result(apache::thrift::ThriftDebugString(*n));
@@ -241,6 +260,8 @@ BOOST_AUTO_TEST_CASE(test_debug_proto_3) {
241260
" [raw] = \"\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\",\n"
242261
" [enc] = \"00000000-0000-0000-0000-000000000000\"\n"
243262
" }\n"
263+
" 16: rfc4122_uuid_list (list) = list<uuid>[0] {\n"
264+
" },\n"
244265
" },\n"
245266
" [1] = OneOfEach {\n"
246267
" 01: im_true (bool) = true,\n"
@@ -276,6 +297,16 @@ BOOST_AUTO_TEST_CASE(test_debug_proto_3) {
276297
" [raw] = \"^*\\xb1\\x88\\x17&Nu\\xa0O\\x1e\\xd9\\xa6\\xa8\\x9cL\",\n"
277298
" [enc] = \"5e2ab188-1726-4e75-a04f-1ed9a6a89c4c\"\n"
278299
" }\n"
300+
" 16: rfc4122_uuid_list (list) = list<uuid>[2] {\n"
301+
"{\n"
302+
" [raw] = [0] = \"\\xfa\\x1a\\xf5\\xec\\xfd\\xc2CU\\x84J\\x9f\\r\\xbf\\xd0\\x0eP\",\n"
303+
" [enc] = \"fa1af5ec-fdc2-4355-844a-9f0dbfd00e50\"\n"
304+
" }\n"
305+
"{\n"
306+
" [raw] = [1] = \"\\x1b\\xee\\xce\\x834\\xf4O\\xa3\\xb7W\\x1a\\xd1\\xac\\x15\\x7f\\xe3\",\n"
307+
" [enc] = \"1beece83-34f4-4fa3-b757-1ad1ac157fe3\"\n"
308+
" }\n"
309+
" },\n"
279310
" },\n"
280311
" },\n"
281312
" 02: contain (set) = set<list>[3] {\n"

lib/cpp/test/JSONProtoTest.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ BOOST_AUTO_TEST_CASE(test_json_proto_1) {
6060
"535897931},\"8\":{\"str\":\"JSON THIS! \\\"\\u0001\"},\"9\":{\"str\":\"\xd7\\"
6161
"n\\u0007\\t\"},\"10\":{\"tf\":0},\"11\":{\"str\":\"AQIDrQ\"},\"12\":{\"lst\""
6262
":[\"i8\",3,1,2,3]},\"13\":{\"lst\":[\"i16\",3,1,2,3]},\"14\":{\"lst\":[\"i64"
63-
"\",3,1,2,3]},\"15\":{\"uid\":\"00000000-0000-0000-0000-000000000000\"}}");
63+
"\",3,1,2,3]},\"15\":{\"uid\":\"00000000-0000-0000-0000-000000000000\"},\"16\""
64+
":{\"lst\":[\"uid\",0]}}");
6465

6566
const std::string result(apache::thrift::ThriftJSONString(*ooe));
6667

@@ -86,6 +87,10 @@ void testCaseSetup_2() {
8687
"\xce\xb1\xe2\x85\xbd\xce\xba\xc7\x83\xe2\x80"
8788
"\xbc";
8889
n->my_ooe.rfc4122_uuid = apache::thrift::TUuid{"5e2ab188-1726-4e75-a04f-1ed9a6a89c4c"};
90+
std::vector<apache::thrift::TUuid> uuiid_list;
91+
uuiid_list.push_back(apache::thrift::TUuid{"{fa1af5ec-fdc2-4355-844a-9f0dbfd00e50}"});
92+
uuiid_list.push_back(apache::thrift::TUuid{"{1beece83-34f4-4fa3-b757-1ad1ac157fe3}"});
93+
n->my_ooe.rfc4122_uuid_list = uuiid_list;
8994
n->my_bonk.type = 31337;
9095
n->my_bonk.message = "I am a bonk... xor!";
9196
}
@@ -101,7 +106,8 @@ BOOST_AUTO_TEST_CASE(test_json_proto_2) {
101106
"\"str\":\"ӀⅮΝ Нοⅿоɡгаρℎ Αttαⅽκǃ‼\"},\"10\":{\"tf\":0},\"11\":{\"str\":\""
102107
"AQIDrQ\"},\"12\":{\"lst\":[\"i8\",3,1,2,3]},\"13\":{\"lst\":[\"i16\",3,1,2"
103108
",3]},\"14\":{\"lst\":[\"i64\",3,1,2,3]},\"15\":{\"uid\":\"5e2ab188-1726-"
104-
"4e75-a04f-1ed9a6a89c4c\"}}}}"
109+
"4e75-a04f-1ed9a6a89c4c\"},\"16\":{\"lst\":[\"uid\",2,\"fa1af5ec-fdc2-4355-"
110+
"844a-9f0dbfd00e50\",\"1beece83-34f4-4fa3-b757-1ad1ac157fe3\"]}}}}"
105111
);
106112

107113
const std::string result(apache::thrift::ThriftJSONString(*n));
@@ -166,13 +172,14 @@ BOOST_AUTO_TEST_CASE(test_json_proto_3) {
166172
"\"},\"9\":{\"str\":\"\xd7\\n\\u0007\\t\"},\"10\":{\"tf\":0},\"11\":{\"str\":"
167173
"\"AQIDrQ\"},\"12\":{\"lst\":[\"i8\",3,1,2,3]},\"13\":{\"lst\":[\"i16\",3,1,2"
168174
",3]},\"14\":{\"lst\":[\"i64\",3,1,2,3]},\"15\":{\"uid\":\"00000000-0000-0000"
169-
"-0000-000000000000\"}},{\"1\":{\"tf\":1},\"2\":{\"tf\":0},"
175+
"-0000-000000000000\"},\"16\":{\"lst\":[\"uid\",0]}},{\"1\":{\"tf\":1},\"2\":{\"tf\":0},"
170176
"\"3\":{\"i8\":51},\"4\":{\"i16\":16},\"5\":{\"i32\":32},\"6\":{\"i64\":64},"
171177
"\"7\":{\"dbl\":1.6180339887498949},\"8\":{\"str\":\":R (me going \\\"rrrr\\\""
172178
")\"},\"9\":{\"str\":\"ӀⅮΝ Нοⅿоɡгаρℎ Αttαⅽκǃ‼\"},\"10\":{\"tf\":0},\"11\":{"
173179
"\"str\":\"AQIDrQ\"},\"12\":{\"lst\":[\"i8\",3,1,2,3]},\"13\":{\"lst\":[\"i16"
174180
"\",3,1,2,3]},\"14\":{\"lst\":[\"i64\",3,1,2,3]},\"15\":{\"uid\":\"5e2ab188-"
175-
"1726-4e75-a04f-1ed9a6a89c4c\"}}]},\"2\":{\"set\":[\"lst\",3"
181+
"1726-4e75-a04f-1ed9a6a89c4c\"},\"16\":{\"lst\":[\"uid\",2,\"fa1af5ec-fdc2-4355-"
182+
"844a-9f0dbfd00e50\",\"1beece83-34f4-4fa3-b757-1ad1ac157fe3\"]}}]},\"2\":{\"set\":[\"lst\",3"
176183
",[\"str\",0],[\"str\",2,\"and a one\",\"and a two\"],[\"str\",3,\"then a one"
177184
", two\",\"three!\",\"FOUR!!\"]]},\"3\":{\"map\":[\"str\",\"lst\",3,{\"nothin"
178185
"g\":[\"rec\",0],\"poe\":[\"rec\",3,{\"1\":{\"i32\":3},\"2\":{\"str\":\"quoth"

test/DebugProtoTest.thrift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ struct OneOfEach {
4747
11: binary base64,
4848
12: list<i8> byte_list = [1, 2, 3],
4949
13: list<i16> i16_list = [1,2,3],
50-
14: list<i64> i64_list = [1,2,3]
51-
15: uuid rfc4122_uuid
50+
14: list<i64> i64_list = [1,2,3],
51+
15: uuid rfc4122_uuid,
52+
16: list<uuid> rfc4122_uuid_list,
5253
}
5354

5455
struct Bonk {

0 commit comments

Comments
 (0)