Skip to content

Commit fed2000

Browse files
committed
Added legacy groups support to pbjs, see #568
1 parent 974a132 commit fed2000

13 files changed

+43
-24
lines changed

cli/targets/proto.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ function buildRanges(keyword, ranges) {
153153
}
154154

155155
function buildType(type) {
156+
if (type.group)
157+
return; // built with the sister-field
156158
push("");
157159
push("message " + type.name + " {");
158160
++indent;
@@ -172,12 +174,16 @@ function buildField(field, passExtend) {
172174
return;
173175
if (first)
174176
first = false, push("");
177+
if (field.resolvedType && field.resolvedType.group) {
178+
buildGroup(field);
179+
return;
180+
}
175181
var sb = [];
176182
if (field.map)
177183
sb.push("map<" + field.keyType + ", " + field.type + ">");
178184
else if (field.repeated)
179185
sb.push("repeated", field.type);
180-
else if (syntax === 2)
186+
else if (syntax === 2 || field.parent.group)
181187
sb.push(field.required ? "required" : "optional", field.type);
182188
else
183189
sb.push(field.type);
@@ -188,6 +194,18 @@ function buildField(field, passExtend) {
188194
push(sb.join(" ") + ";");
189195
}
190196

197+
function buildGroup(field) {
198+
push(field.rule + " group " + field.resolvedType.name + " = " + field.id + " {");
199+
++indent;
200+
buildOptions(field.resolvedType);
201+
first = true;
202+
field.resolvedType.fieldsArray.forEach(function(field) {
203+
buildField(field);
204+
});
205+
--indent;
206+
push("}");
207+
}
208+
191209
function buildFieldOptions(field) {
192210
var keys;
193211
if (!field.options || !(keys = Object.keys(field.options)).length)

dist/protobuf.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/protobuf.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/protobuf.min.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/protobuf.min.js.gz

-5 Bytes
Binary file not shown.

dist/protobuf.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/runtime/protobuf.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/runtime/protobuf.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/runtime/protobuf.min.js.gz

0 Bytes
Binary file not shown.

src/service.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ ServicePrototype.remove = function remove(object) {
171171
ServicePrototype.create = function create(rpcImpl, requestDelimited, responseDelimited) {
172172
var rpcService = new rpc.Service(rpcImpl);
173173
this.getMethodsArray().forEach(function(method) {
174-
rpcService[method.name.substring(0, 1).toLowerCase() + method.name.substring(1)] = function callVirtual(request, /* optional */ callback) {
174+
rpcService[util.lcFirst(method.name)] = function callVirtual(request, /* optional */ callback) {
175175
if (!rpcService.$rpc) // already ended?
176176
return;
177177
if (!request)

tests/data/groups.proto

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
message Test {
22
required group MyGroup = 1 {
3+
option foo = "bar";
34
required uint32 a = 2;
45
};
56
}

tests/data/mapbox/vector_tile.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -350,15 +350,15 @@ $root.vector_tile = (function() {
350350
return"invalid value for field .vector_tile.Tile.Value.doubleValue (number expected)"
351351
}
352352
if(m["intValue"]!==undefined){
353-
if(!(util.isInteger(m["intValue"])||m["intValue"]&&util.isInteger(m["intValue"].low)&&util.isInteger(m["intValue"].high)))
353+
if(!util.isInteger(m["intValue"])&&!(m["intValue"]&&util.isInteger(m["intValue"].low)&&util.isInteger(m["intValue"].high)))
354354
return"invalid value for field .vector_tile.Tile.Value.intValue (integer|Long expected)"
355355
}
356356
if(m["uintValue"]!==undefined){
357-
if(!(util.isInteger(m["uintValue"])||m["uintValue"]&&util.isInteger(m["uintValue"].low)&&util.isInteger(m["uintValue"].high)))
357+
if(!util.isInteger(m["uintValue"])&&!(m["uintValue"]&&util.isInteger(m["uintValue"].low)&&util.isInteger(m["uintValue"].high)))
358358
return"invalid value for field .vector_tile.Tile.Value.uintValue (integer|Long expected)"
359359
}
360360
if(m["sintValue"]!==undefined){
361-
if(!(util.isInteger(m["sintValue"])||m["sintValue"]&&util.isInteger(m["sintValue"].low)&&util.isInteger(m["sintValue"].high)))
361+
if(!util.isInteger(m["sintValue"])&&!(m["sintValue"]&&util.isInteger(m["sintValue"].low)&&util.isInteger(m["sintValue"].high)))
362362
return"invalid value for field .vector_tile.Tile.Value.sintValue (integer|Long expected)"
363363
}
364364
if(m["boolValue"]!==undefined){
@@ -438,18 +438,18 @@ $root.vector_tile = (function() {
438438
if(m["id"]!==undefined&&util.longNe(m["id"],0,0))
439439
w.uint32(8).uint64(m["id"])
440440
if(m["tags"]&&m["tags"].length){
441-
w.fork()
441+
w.uint32(18).fork()
442442
for(var i=0;i<m["tags"].length;++i)
443443
w.uint32(m["tags"][i])
444-
w.ldelim(2)
444+
w.ldelim()
445445
}
446446
if(m["type"]!==undefined&&m["type"]!=="UNKNOWN")
447447
w.uint32(24).uint32(m["type"])
448448
if(m["geometry"]&&m["geometry"].length){
449-
w.fork()
449+
w.uint32(34).fork()
450450
for(var i=0;i<m["geometry"].length;++i)
451451
w.uint32(m["geometry"][i])
452-
w.ldelim(4)
452+
w.ldelim()
453453
}
454454
return w
455455
}
@@ -539,7 +539,7 @@ $root.vector_tile = (function() {
539539
var types; $lazyTypes.push(types = [null,null,"vector_tile.Tile.GeomType",null]);
540540
return function verify(m) {
541541
if(m["id"]!==undefined){
542-
if(!(util.isInteger(m["id"])||m["id"]&&util.isInteger(m["id"].low)&&util.isInteger(m["id"].high)))
542+
if(!util.isInteger(m["id"])&&!(m["id"]&&util.isInteger(m["id"].low)&&util.isInteger(m["id"].high)))
543543
return"invalid value for field .vector_tile.Tile.Feature.id (integer|Long expected)"
544544
}
545545
if(m["tags"]!==undefined){

tests/groups.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ tape.test("legacy groups", function(test) {
4848
});
4949

5050
function verifyEncode(test, buf) {
51-
test.equal(buf.length, 4, "should encode a total of 4 bytes");
52-
test.equal(buf[0], 1 << 3 | 3, "should encode id 1, wireType 3");
53-
test.equal(buf[1], 2 << 3 | 0, "should encode id 2, wireType 0");
54-
test.equal(buf[2], 111, "should encode value 111");
55-
test.equal(buf[3], 1 << 3 | 4, "should encode id 1, wireType 4");
51+
test.equal(buf.length, 4, "a total of 4 bytes");
52+
test.equal(buf[0], 1 << 3 | 3, "id 1, wireType 3");
53+
test.equal(buf[1], 2 << 3 | 0, "id 2, wireType 0");
54+
test.equal(buf[2], 111, "111");
55+
test.equal(buf[3], 1 << 3 | 4, "id 1, wireType 4");
5656
}

0 commit comments

Comments
 (0)