You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ns...@apache.org on 2016/01/05 20:35:54 UTC
[3/3] thrift git commit: THRIFT-2994 Node.js TJSONProtocol cannot be
used for object serialization Client: Node.js Patch: Tim Sebastian
THRIFT-2994 Node.js TJSONProtocol cannot be used for object serialization
Client: Node.js
Patch: Tim Sebastian
This closes #379
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/fe3f3361
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/fe3f3361
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/fe3f3361
Branch: refs/heads/master
Commit: fe3f33619ed268c1dcbea2523bed4b5f935d404b
Parents: 378b727
Author: Tim Sebastian <ti...@gmail.com>
Authored: Tue Oct 6 11:03:07 2015 +0200
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Wed Jan 6 04:35:12 2016 +0900
----------------------------------------------------------------------
lib/nodejs/lib/thrift/json_protocol.js | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/fe3f3361/lib/nodejs/lib/thrift/json_protocol.js
----------------------------------------------------------------------
diff --git a/lib/nodejs/lib/thrift/json_protocol.js b/lib/nodejs/lib/thrift/json_protocol.js
index b98f131..2e0d29a 100644
--- a/lib/nodejs/lib/thrift/json_protocol.js
+++ b/lib/nodejs/lib/thrift/json_protocol.js
@@ -92,9 +92,16 @@ TJSONProtocol.RType.set = Type.SET;
TJSONProtocol.Version = 1;
TJSONProtocol.prototype.flush = function() {
+ this.writeToTransportIfStackIsFlushable();
return this.trans.flush();
};
+TJSONProtocol.prototype.writeToTransportIfStackIsFlushable = function() {
+ if (this.tstack.length === 1) {
+ this.trans.write(this.tstack.pop());
+ }
+};
+
/**
* Serializes the beginning of a Thrift RPC message.
* @param {string} name - The service method to call.
@@ -102,9 +109,6 @@ TJSONProtocol.prototype.flush = function() {
* @param {number} seqid - The sequence number of this call (always 0 in Apache Thrift).
*/
TJSONProtocol.prototype.writeMessageBegin = function(name, messageType, seqid) {
- this.tstack = [];
- this.tpos = [];
-
this.tstack.push([TJSONProtocol.Version, '"' + name + '"', messageType, seqid]);
};
@@ -119,6 +123,7 @@ TJSONProtocol.prototype.writeMessageEnd = function() {
this.wbuf = '[' + this.wobj.join(',') + ']';
+ // we assume there is nothing more to come so we write
this.trans.write(this.wbuf);
};
@@ -151,6 +156,8 @@ TJSONProtocol.prototype.writeStructEnd = function() {
str += '}';
this.tstack[p] = str;
+
+ this.writeToTransportIfStackIsFlushable();
};
/**
@@ -181,6 +188,8 @@ TJSONProtocol.prototype.writeFieldEnd = function() {
fieldInfo.fieldType + ':' + value + '}';
}
this.tpos.pop();
+
+ this.writeToTransportIfStackIsFlushable();
};
/**
@@ -237,6 +246,8 @@ TJSONProtocol.prototype.writeMapEnd = function() {
this.tstack[p].push(map);
this.tstack[p] = '[' + this.tstack[p].join(',') + ']';
+
+ this.writeToTransportIfStackIsFlushable();
};
/**
@@ -262,6 +273,8 @@ TJSONProtocol.prototype.writeListEnd = function() {
}
this.tstack[p] = '[' + this.tstack[p].join(',') + ']';
+
+ this.writeToTransportIfStackIsFlushable();
};
/**
@@ -287,6 +300,8 @@ TJSONProtocol.prototype.writeSetEnd = function() {
}
this.tstack[p] = '[' + this.tstack[p].join(',') + ']';
+
+ this.writeToTransportIfStackIsFlushable();
};
/** Serializes a boolean */