[
https://issues.apache.org/jira/browse/THRIFT-2994?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14322499#comment-14322499
]
ASF GitHub Bot commented on THRIFT-2994:
----------------------------------------
GitHub user timse opened a pull request:
https://github.com/apache/thrift/pull/379
Trying to fix json protocol for nodejs
this fixes: https://issues.apache.org/jira/browse/THRIFT-2994 (not sure if
that is the correct way to link a jira ticket :smile: )
It initializes the arrays used to build up the json on construct and writes
to transport whenever a `writeEnd` method is encountered and the stack lenth is
1, assuming its finished now.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/timse/thrift
trying-to-fix-json_protocol-for-nodejs
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/thrift/pull/379.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #379
----
commit 6855c207152f24d341f7783d1098bde3f275c0b8
Author: Tim Sebastian <[email protected]>
Date: 2015-02-13T17:18:23Z
initialize "tstack" and "tpos" in constructor
as all write methods require them to exist it does not seem to make too
much sense to only make them available in the "writeMessageBegin" method
commit 2cd5e95b367c73981bff470cc7db1e04699871a6
Author: Tim Sebastian <[email protected]>
Date: 2015-02-13T17:23:56Z
introduce method "writeToTransport" to write to transport
- removed direct writing to transport from "writeMessageEnd"
- "writeToTransport" only acts if "tstack.length === 1", it assumed that we
are finished then and the last item is the final json string
- call "writeToTranport" in the "flush" method
commit 6ce537a0ba93ff3af205360d804e41539b112e3b
Author: Tim Sebastian <[email protected]>
Date: 2015-02-13T17:26:13Z
call "writeToTransport" if we are the last item in the queue
----
> Node.js TJSONProtocol cannot be used for object serialization.
> --------------------------------------------------------------
>
> Key: THRIFT-2994
> URL: https://issues.apache.org/jira/browse/THRIFT-2994
> Project: Thrift
> Issue Type: Bug
> Components: Node.js - Library
> Reporter: Jan Brauer
>
> Consider the following code using the Thrift example types.
> {code:title=serialize.js|borderStyle=solid}
> var thrift = require('thrift');
> var test_types = require('gen-nodejs/ThriftTest_types.js');
> var bonk = new test_types.Bonk({message: "message", type: 6})
> var t_out = new thrift.TBufferedTransport();
> var p_out = new thrift.TJSONProtocol(t_out);
> bonk.write(p_out);
> var out
> t_out.flush(function (b) { out = b;});
> console.log(out)
> {code}
> My expectation would be for {{out}} to contain the serialized {{Bonk}} struct.
> But due to
> [TJSONProtocol|https://github.com/apache/thrift/blob/master/lib/nodejs/lib/thrift/protocol.js#L1287]
> only writing to the underlying transport in {{writeMessageEnd}} the above
> code does not work.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)