Permalink
Browse files

Added legacy groups support to pbjs, see #568

  • Loading branch information...
dcodeIO committed Dec 18, 2016
1 parent 974a132 commit fed2000e7e461efdb1c3a1a1aeefa8b255a7c20b
@@ -153,6 +153,8 @@ function buildRanges(keyword, ranges) {
}
function buildType(type) {
if (type.group)
return; // built with the sister-field
push("");
push("message " + type.name + " {");
++indent;
@@ -172,12 +174,16 @@ function buildField(field, passExtend) {
return;
if (first)
first = false, push("");
if (field.resolvedType && field.resolvedType.group) {
buildGroup(field);
return;
}
var sb = [];
if (field.map)
sb.push("map<" + field.keyType + ", " + field.type + ">");
else if (field.repeated)
sb.push("repeated", field.type);
else if (syntax === 2)
else if (syntax === 2 || field.parent.group)
sb.push(field.required ? "required" : "optional", field.type);
else
sb.push(field.type);
@@ -188,6 +194,18 @@ function buildField(field, passExtend) {
push(sb.join(" ") + ";");
}
function buildGroup(field) {
push(field.rule + " group " + field.resolvedType.name + " = " + field.id + " {");
++indent;
buildOptions(field.resolvedType);
first = true;
field.resolvedType.fieldsArray.forEach(function(field) {
buildField(field);
});
--indent;
push("}");
}
function buildFieldOptions(field) {
var keys;
if (!field.options || !(keys = Object.keys(field.options)).length)

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
BIN -5 Bytes (100%) dist/protobuf.min.js.gz
Binary file not shown.

Large diffs are not rendered by default.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
BIN +0 Bytes (100%) dist/runtime/protobuf.min.js.gz
Binary file not shown.
@@ -171,7 +171,7 @@ ServicePrototype.remove = function remove(object) {
ServicePrototype.create = function create(rpcImpl, requestDelimited, responseDelimited) {
var rpcService = new rpc.Service(rpcImpl);
this.getMethodsArray().forEach(function(method) {
rpcService[method.name.substring(0, 1).toLowerCase() + method.name.substring(1)] = function callVirtual(request, /* optional */ callback) {
rpcService[util.lcFirst(method.name)] = function callVirtual(request, /* optional */ callback) {
if (!rpcService.$rpc) // already ended?
return;
if (!request)
@@ -1,5 +1,6 @@
message Test {
required group MyGroup = 1 {
option foo = "bar";
required uint32 a = 2;
};
}
@@ -350,15 +350,15 @@ $root.vector_tile = (function() {
return"invalid value for field .vector_tile.Tile.Value.doubleValue (number expected)"
}
if(m["intValue"]!==undefined){
if(!(util.isInteger(m["intValue"])||m["intValue"]&&util.isInteger(m["intValue"].low)&&util.isInteger(m["intValue"].high)))
if(!util.isInteger(m["intValue"])&&!(m["intValue"]&&util.isInteger(m["intValue"].low)&&util.isInteger(m["intValue"].high)))
return"invalid value for field .vector_tile.Tile.Value.intValue (integer|Long expected)"
}
if(m["uintValue"]!==undefined){
if(!(util.isInteger(m["uintValue"])||m["uintValue"]&&util.isInteger(m["uintValue"].low)&&util.isInteger(m["uintValue"].high)))
if(!util.isInteger(m["uintValue"])&&!(m["uintValue"]&&util.isInteger(m["uintValue"].low)&&util.isInteger(m["uintValue"].high)))
return"invalid value for field .vector_tile.Tile.Value.uintValue (integer|Long expected)"
}
if(m["sintValue"]!==undefined){
if(!(util.isInteger(m["sintValue"])||m["sintValue"]&&util.isInteger(m["sintValue"].low)&&util.isInteger(m["sintValue"].high)))
if(!util.isInteger(m["sintValue"])&&!(m["sintValue"]&&util.isInteger(m["sintValue"].low)&&util.isInteger(m["sintValue"].high)))
return"invalid value for field .vector_tile.Tile.Value.sintValue (integer|Long expected)"
}
if(m["boolValue"]!==undefined){
@@ -438,18 +438,18 @@ $root.vector_tile = (function() {
if(m["id"]!==undefined&&util.longNe(m["id"],0,0))
w.uint32(8).uint64(m["id"])
if(m["tags"]&&m["tags"].length){
w.fork()
w.uint32(18).fork()
for(var i=0;i<m["tags"].length;++i)
w.uint32(m["tags"][i])
w.ldelim(2)
w.ldelim()
}
if(m["type"]!==undefined&&m["type"]!=="UNKNOWN")
w.uint32(24).uint32(m["type"])
if(m["geometry"]&&m["geometry"].length){
w.fork()
w.uint32(34).fork()
for(var i=0;i<m["geometry"].length;++i)
w.uint32(m["geometry"][i])
w.ldelim(4)
w.ldelim()
}
return w
}
@@ -539,7 +539,7 @@ $root.vector_tile = (function() {
var types; $lazyTypes.push(types = [null,null,"vector_tile.Tile.GeomType",null]);
return function verify(m) {
if(m["id"]!==undefined){
if(!(util.isInteger(m["id"])||m["id"]&&util.isInteger(m["id"].low)&&util.isInteger(m["id"].high)))
if(!util.isInteger(m["id"])&&!(m["id"]&&util.isInteger(m["id"].low)&&util.isInteger(m["id"].high)))
return"invalid value for field .vector_tile.Tile.Feature.id (integer|Long expected)"
}
if(m["tags"]!==undefined){
@@ -48,9 +48,9 @@ tape.test("legacy groups", function(test) {
});
function verifyEncode(test, buf) {
test.equal(buf.length, 4, "should encode a total of 4 bytes");
test.equal(buf[0], 1 << 3 | 3, "should encode id 1, wireType 3");
test.equal(buf[1], 2 << 3 | 0, "should encode id 2, wireType 0");
test.equal(buf[2], 111, "should encode value 111");
test.equal(buf[3], 1 << 3 | 4, "should encode id 1, wireType 4");
test.equal(buf.length, 4, "a total of 4 bytes");
test.equal(buf[0], 1 << 3 | 3, "id 1, wireType 3");
test.equal(buf[1], 2 << 3 | 0, "id 2, wireType 0");
test.equal(buf[2], 111, "111");
test.equal(buf[3], 1 << 3 | 4, "id 1, wireType 4");
}

0 comments on commit fed2000

Please sign in to comment.