Permalink
Browse files

THRIFT-1043 Fix how the length of a map is calculated

Patch: Wade Simmons


git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1062278 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent c7cd68e commit 4b3f1c31817b26385ec1a802dd4beffcf88c4caa @bufferoverflow bufferoverflow committed Jan 22, 2011
Showing with 14 additions and 1 deletion.
  1. +1 −1 compiler/cpp/src/generate/t_js_generator.cc
  2. +9 −0 lib/js/thrift.js
  3. +4 −0 lib/nodejs/lib/thrift/thrift.js
@@ -1478,7 +1478,7 @@ void t_js_generator::generate_serialize_container(ofstream &out,
"output.writeMapBegin(" <<
type_to_enum(((t_map*)ttype)->get_key_type()) << ", " <<
type_to_enum(((t_map*)ttype)->get_val_type()) << ", " <<
- prefix << ".length)" << endl;
+ "Thrift.objectLength(" << prefix << "))" << endl;
} else if (ttype->is_set()) {
indent(out) <<
"output.writeSetBegin(" <<
View
@@ -713,5 +713,14 @@ Thrift.Protocol.prototype = {
}
+Thrift.objectLength = function(obj) {
+ var length = 0;
+ for (k in obj) {
+ if (obj.hasOwnProperty(k)) {
+ length++;
+ }
+ }
+ return length;
+}
@@ -128,3 +128,7 @@ TApplicationException.prototype.write = function(output){
output.writeFieldStop()
output.writeStructEnd()
}
+
+exports.objectLength = function(obj) {
+ return Object.keys(obj).length;
+}

0 comments on commit 4b3f1c3

Please sign in to comment.