protocol-buffers
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -1,3 +0,4 @@ | ||
var protobuf = require('../require') | ||
var messages = protobuf('./bench.proto') | ||
var protobuf = require('../') | ||
var fs = require('fs') | ||
var messages = protobuf(fs.readFileSync(__dirname + '/bench.proto')) | ||
@@ -4,0 +5,0 @@ var TIMES = 1000000 |
@@ -350,7 +350,16 @@ var encodings = require('./encodings') | ||
// compile proto | ||
// compile decode | ||
var Message = genfun() | ||
var invalid = m.fields | ||
.map(function(f, i) { | ||
return f.required && '!found'+i | ||
}) | ||
.filter(function(f) { | ||
return f | ||
}) | ||
.join(' || ') | ||
Message('function Message() {') | ||
var decode = genfun() | ||
var objectKeys = [] | ||
forEach(function(e, f) { | ||
@@ -363,6 +372,6 @@ var def = f.options && f.options.default | ||
if (f.repeated) { | ||
Message('%s = []', genobj('this', f.name)) | ||
objectKeys.push(genobj.property(f.name) + ': []') | ||
} else { | ||
def = (def && def in vals) ? vals[def] : vals[Object.keys(vals)[0]] | ||
Message('%s = %s', genobj('this', f.name), ''+parseInt(def || 0)) | ||
objectKeys.push(genobj.property(f.name) + ': ' + parseInt(def || 0)) | ||
} | ||
@@ -373,22 +382,7 @@ return | ||
if (!f.oneof) { | ||
Message('%s = %s', genobj('this', f.name), defaultValue(f, def)) | ||
objectKeys.push(genobj.property(f.name) + ': ' + defaultValue(f, def)) | ||
} | ||
}) | ||
Message('}') | ||
Message = Message.toFunction() | ||
// compile decode | ||
var invalid = m.fields | ||
.map(function(f, i) { | ||
return f.required && '!found'+i | ||
}) | ||
.filter(function(f) { | ||
return f | ||
}) | ||
.join(' || ') | ||
var decode = genfun() | ||
decode() | ||
@@ -400,4 +394,10 @@ ('function decode(buf, offset, end) {') | ||
('var oldOffset = offset') | ||
('var obj = new Message()') | ||
('var obj = {') | ||
objectKeys.forEach(function (prop, i) { | ||
decode(prop + (i === objectKeys.length - 1 ? '' : ',')) | ||
}) | ||
decode('}') | ||
forEach(function(e, f, val, i) { | ||
@@ -473,3 +473,2 @@ if (f.required) decode('var found%d = false', i) | ||
decode = decode.toFunction({ | ||
Message: Message, | ||
varint: varint, | ||
@@ -480,3 +479,2 @@ skip: skip, | ||
// end of compilation - return all the things | ||
@@ -483,0 +481,0 @@ |
{ | ||
"name": "protocol-buffers", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Protocol Buffers for Node.js", | ||
@@ -5,0 +5,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41733
13