[ 
https://issues.apache.org/jira/browse/THRIFT-2476?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13980817#comment-13980817
 ] 

Jens Geyer commented on THRIFT-2476:
------------------------------------

Hi [~xiaodongma],

thanks for the patch. I have a few comments:

 1. The patch does not apply against current trunk. Seems there are a few 
commits missing?
{code}
$ git apply /d/simplejson.patch
error: lib/cpp/src/thrift/protocol/TSimpleJSONProtocol.cpp: No such file or 
directory
error: lib/cpp/src/thrift/protocol/TSimpleJSONProtocol.h: No such file or 
directory
{code}

2. SimpleJSON is [only intended to be 
writtten|http://wiki.apache.org/thrift/ThriftUsageJava], at least as far as I 
know: 
{quote}
The "Simple" JSON protocol produces output suitable for AJAX or scripting 
languages. It does not preserve Thrift's field tags and cannot be read back in 
by Thrift. 
{quote}
How did you overcome that limitation? It's not fully clear to me from the patch 
alone, that's why I'm asking.

3. The {{readJSONEscapeChar()}} method suffers from the problem laid out in 
THRIFT-2411: It expects unicode characters to be in the range 
{{\u0000..\u00FF}} which is an incorrect assumption. You probably copied that 
part from the normal JSON protocol, but it is wrong there too and needs to be 
addressed. If you could fix it in both places while you're at it, that would be 
great.




> Thrift SimpleJSON protocol support for cpp 
> -------------------------------------------
>
>                 Key: THRIFT-2476
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2476
>             Project: Thrift
>          Issue Type: New Feature
>          Components: C++ - Compiler, C++ - Library
>            Reporter: Xiaodong Ma
>         Attachments: cpp_simplejson.diff
>
>
> Currently TJSONProtocol generate private json format, while in many use case, 
> a standard json format is required in order to talk with external software 
> modules. 
> For example: 
> If you have thrift IDL like this:
>  struct example {
>       1: required string          field1,
>       2: optional list<string>    field2,
>  }
>  With TJSONProtocol, you will get:
>  
> {"1":{"str":"field1-value"},"2":{"lst":["str",2,"field2-value1","field2-value2"]}}
>  With TSimpleJSONProtocol, you will get:
>  {"field1":"field1-value","field2":["field2-value1","field2-value2"]}
> Attached patch provide support on this.
> Test passed: 
> ama@ubuntu:~/thrift/test/cpp$ ./TestServer --protocol simplejson
> Starting "simple" server (buffered/simplejson) listen on: 9090
> testVoid()
> testString("Test")
> testByte(1)
> testI32(-1)
> testI64(-34359738368)
> testDouble(-5.209852)
> testStruct({"Zero", 1, -3, -5})
> testNest({1, {"Zero", 1, -3, -5}, 5})
> testMap({0 => -10, 1 => -9, 2 => -8, 3 => -7, 4 => -6})
> testSet({-2, -1, 0, 1, 2})
> testList({-2, -1, 0, 1, 2})
> testEnum(1)
> testEnum(2)
> testEnum(3)
> testEnum(5)
> testEnum(8)
> testTypedef(309858235082523)
> testMapMap(1)
> testInsanity()
> return = {1 => {2 => {{5 => 5, 8 => 8, }, {{"Goodbye4", 4, 4, 4}, {"Hello2", 
> 2, 2, 2}, }}, 3 => {{5 => 5, 8 => 8, }, {{"Goodbye4", 4, 4, 4}, {"Hello2", 2, 
> 2, 2}, }}, }, 2 => {6 => {{}, {}}, }, }
> testException(Xception)
> testException(TException)
> testException(success)
> testMultiException(Xception, test 1)
> testMultiException(Xception2, test 2)
> testMultiException(success, test 3)
> testOneway(1): Sleeping...
> testOneway(1): done sleeping!
> testI32(-1)
> ama@ubuntu:~/thrift/test/cpp$ ./TestClient --protocol simplejson
> Connecting (buffered/simplejson) to: localhost:9090
> Test #1, connect localhost:9090
> testVoid() = void
> testString("Test") = "Test"
> testByte(1) = 1
> testI32(-1) = -1
> testI64(-34359738368) = -34359738368
> testDouble(-5.2098523) = -5.209852
> testStruct({"Zero", 1, -3, -5}) = {"Zero", 1, -3, -5}
> testNest({1, {"Zero", 1, -3, -5}), 5} = {1, {"Zero", 1, -3, -5}, 5}
> testMap({0 => -10, 1 => -9, 2 => -8, 3 => -7, 4 => -6}) = {0 => -10, 1 => -9, 
> 2 => -8, 3 => -7, 4 => -6}
> testSet({-2, -1, 0, 1, 2}) = {-2, -1, 0, 1, 2}
> testList({-2, -1, 0, 1, 2}) = {-2, -1, 0, 1, 2}
> testEnum(ONE) = 1
> testEnum(TWO) = 2
> testEnum(THREE) = 3
> testEnum(FIVE) = 5
> testEnum(EIGHT) = 8
> testTypedef(309858235082523) = 309858235082523
> testMapMap(1) = {-4 => {-4 => -4, -3 => -3, -2 => -2, -1 => -1, }, 4 => {1 => 
> 1, 2 => 2, 3 => 3, 4 => 4, }, }
> testInsanity() = {1 => {2 => {{5 => 5, 8 => 8, }, {{"Goodbye4", 4, 4, 4}, 
> {"Hello2", 2, 2, 2}, }}, 3 => {{5 => 5, 8 => 8, }, {{"Goodbye4", 4, 4, 4}, 
> {"Hello2", 2, 2, 2}, }}, }, 2 => {6 => {{}, {}}, }, }
> testClient.testException("Xception") =>  {1001, "Xception"}
> testClient.testException("TException") =>  Caught TException : Default 
> TException.
> testClient.testException("success") =>  void
> testClient.testMultiException("Xception", "test 1") =>  {1001, "This is an 
> Xception"}
> testClient.testMultiException("Xception2", "test 2") =>  {2002, {"This is an 
> Xception2"}}
> testClient.testMultiException("success", "test 3") =>  {{"test 3"}}
> testClient.testOneway(1) =>  success - took 0.01 ms
> re-test testI32(-1) = -1
> Total time: 1009072 us
> All tests done.
> Min time: 1009072 us
> Max time: 1009072 us
> Avg time: 1009072 us



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to