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
This commit is contained in:
Roger Meier 2011-01-22 21:32:50 +00:00
parent c7cd68eb86
commit 4b3f1c3181
3 changed files with 14 additions and 1 deletions

View File

@ -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 File

@ -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;
}

View File

@ -128,3 +128,7 @@ TApplicationException.prototype.write = function(output){
output.writeFieldStop()
output.writeStructEnd()
}
exports.objectLength = function(obj) {
return Object.keys(obj).length;
}