protobufjs 3.6.0 → 3.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/proto2js +16 -4
- package/bower.json +1 -1
- package/dist/ProtoBuf.js +645 -441
- package/dist/ProtoBuf.min.js +96 -96
- package/dist/ProtoBuf.min.js.gz +0 -0
- package/dist/ProtoBuf.min.map +2 -2
- package/dist/ProtoBuf.noparse.js +520 -357
- package/dist/ProtoBuf.noparse.min.js +68 -66
- package/dist/ProtoBuf.noparse.min.js.gz +0 -0
- package/dist/ProtoBuf.noparse.min.map +3 -3
- package/docs/ProtoBuf.Builder.Message.html +673 -135
- package/docs/ProtoBuf.Builder.Service.html +58 -19
- package/docs/ProtoBuf.Builder.html +374 -46
- package/docs/ProtoBuf.DotProto.Parser.html +58 -19
- package/docs/ProtoBuf.DotProto.Tokenizer.html +104 -19
- package/docs/ProtoBuf.DotProto.html +16 -10
- package/docs/ProtoBuf.Reflect.Enum.Value.html +207 -33
- package/docs/ProtoBuf.Reflect.Enum.html +318 -56
- package/docs/ProtoBuf.Reflect.Extension.html +53 -13
- package/docs/ProtoBuf.Reflect.Message.ExtensionField.html +450 -68
- package/docs/ProtoBuf.Reflect.Message.Field.html +454 -51
- package/docs/ProtoBuf.Reflect.Message.OneOf.html +1044 -0
- package/docs/ProtoBuf.Reflect.Message.html +378 -64
- package/docs/ProtoBuf.Reflect.Namespace.html +333 -51
- package/docs/ProtoBuf.Reflect.Service.Method.html +228 -35
- package/docs/ProtoBuf.Reflect.Service.RPCMethod.html +262 -41
- package/docs/ProtoBuf.Reflect.Service.html +318 -56
- package/docs/ProtoBuf.Reflect.T.html +210 -25
- package/docs/ProtoBuf.Reflect.html +17 -11
- package/docs/ProtoBuf.Util.html +59 -13
- package/docs/ProtoBuf.html +235 -67
- package/docs/ProtoBuf.js.html +648 -443
- package/docs/index.html +4 -2
- package/docs/styles/jsdoc-default.css +2 -2
- package/examples/protoify/.npmignore +2 -0
- package/examples/protoify/README.md +28 -0
- package/examples/protoify/index.js +147 -0
- package/examples/protoify/json.js +123 -0
- package/examples/protoify/json.json +123 -0
- package/examples/protoify/json.proto +30 -0
- package/examples/protoify/package.json +15 -0
- package/examples/protoify/test.js +56 -0
- package/examples/websocket/README.md +1 -0
- package/examples/websocket/package.json +1 -1
- package/externs/ProtoBuf.js +922 -922
- package/package.json +3 -3
- package/scripts/build.js +58 -58
- package/src/ProtoBuf/Builder/Message.js +107 -77
- package/src/ProtoBuf/Builder/Service.js +8 -5
- package/src/ProtoBuf/Builder.js +71 -37
- package/src/ProtoBuf/DotProto/Parser.js +108 -72
- package/src/ProtoBuf/DotProto/Tokenizer.js +17 -11
- package/src/ProtoBuf/Lang.js +1 -1
- package/src/ProtoBuf/Reflect/Enum/Value.js +3 -2
- package/src/ProtoBuf/Reflect/Enum.js +9 -5
- package/src/ProtoBuf/Reflect/Extension.js +4 -3
- package/src/ProtoBuf/Reflect/Message/ExtensionField.js +4 -3
- package/src/ProtoBuf/Reflect/Message/Field.js +45 -26
- package/src/ProtoBuf/Reflect/Message/OneOf.js +19 -0
- package/src/ProtoBuf/Reflect/Message.js +36 -19
- package/src/ProtoBuf/Reflect/Namespace.js +19 -15
- package/src/ProtoBuf/Reflect/Service/Method.js +9 -5
- package/src/ProtoBuf/Reflect/Service/RPCMethod.js +3 -2
- package/src/ProtoBuf/Reflect/Service.js +9 -5
- package/src/ProtoBuf/Reflect/T.js +20 -6
- package/src/ProtoBuf/Reflect.js +9 -0
- package/src/ProtoBuf/Util.js +132 -132
- package/src/ProtoBuf.js +15 -17
- package/src/google/protobuf/descriptor.json +33 -13
- package/tests/bench.txt +373 -373
- package/tests/complex.json +8 -4
- package/tests/custom-options.json +169 -169
- package/tests/extend.json +71 -71
- package/tests/nodeunit-browser/nodeunit.css +70 -70
- package/tests/nodeunit-browser/nodeunit.js +2108 -2108
- package/tests/oneof.proto +6 -0
- package/tests/options.json +32 -32
- package/tests/options.proto +2 -0
- package/tests/proto2js/Bar.json +46 -46
- package/tests/suite.js +83 -12
- package/.idea/.name +0 -1
- package/.idea/ProtoBuf.iml +0 -9
- package/.idea/dictionaries/Daniel.xml +0 -7
- package/.idea/encodings.xml +0 -5
- package/.idea/misc.xml +0 -5
- package/.idea/modules.xml +0 -9
- package/.idea/scopes/scope_settings.xml +0 -5
- package/.idea/vcs.xml +0 -7
- package/.idea/workspace.xml +0 -551
- package/NOTICE +0 -2
- package/sandbox/issue146/MyOptions.proto +0 -28
- package/sandbox/issue146/Sample.proto +0 -21
- package/sandbox/issue146/main.js +0 -3
- package/sandbox/issue147/enum.proto +0 -8
- package/sandbox/issue147/main.js +0 -3
- package/sandbox/issue42/innerextend.proto +0 -18
- package/sandbox/issue42/main.js +0 -8
- package/sandbox/issue42/outerextend.proto +0 -17
- package/v8.log +0 -3828
package/tests/options.json
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
{
|
|
2
|
-
"package": "My",
|
|
3
|
-
"messages": [
|
|
4
|
-
{
|
|
5
|
-
"name": "Test",
|
|
6
|
-
"fields": [
|
|
7
|
-
{
|
|
8
|
-
"rule": "optional",
|
|
9
|
-
"options": {
|
|
10
|
-
"default": "Max"
|
|
11
|
-
},
|
|
12
|
-
"type": "string",
|
|
13
|
-
"name": "name",
|
|
14
|
-
"id": 1
|
|
15
|
-
}
|
|
16
|
-
],
|
|
17
|
-
"enums": [],
|
|
18
|
-
"messages": [],
|
|
19
|
-
"options": {
|
|
20
|
-
"(inmessage)": "My.Test",
|
|
21
|
-
"(foo.my_option).bar": false
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
],
|
|
25
|
-
"enums": [],
|
|
26
|
-
"imports": [],
|
|
27
|
-
"options": {
|
|
28
|
-
"(toplevel_1)": 10,
|
|
29
|
-
"(toplevel_2)": "Hello world!"
|
|
30
|
-
},
|
|
31
|
-
"services": []
|
|
32
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"package": "My",
|
|
3
|
+
"messages": [
|
|
4
|
+
{
|
|
5
|
+
"name": "Test",
|
|
6
|
+
"fields": [
|
|
7
|
+
{
|
|
8
|
+
"rule": "optional",
|
|
9
|
+
"options": {
|
|
10
|
+
"default": "Max"
|
|
11
|
+
},
|
|
12
|
+
"type": "string",
|
|
13
|
+
"name": "name",
|
|
14
|
+
"id": 1
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"enums": [],
|
|
18
|
+
"messages": [],
|
|
19
|
+
"options": {
|
|
20
|
+
"(inmessage)": "My.Test",
|
|
21
|
+
"(foo.my_option).bar": false
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"enums": [],
|
|
26
|
+
"imports": [],
|
|
27
|
+
"options": {
|
|
28
|
+
"(toplevel_1)": 10,
|
|
29
|
+
"(toplevel_2)": "Hello world!"
|
|
30
|
+
},
|
|
31
|
+
"services": []
|
|
32
|
+
}
|
package/tests/options.proto
CHANGED
|
@@ -4,6 +4,8 @@ option (toplevel_2) = "Hello world!";
|
|
|
4
4
|
|
|
5
5
|
message Test {
|
|
6
6
|
optional string name = 1 [default="Max"];
|
|
7
|
+
optional string desc1 = 2 [default="Shouldn't mix quotes"];
|
|
8
|
+
optional string desc2 = 3 [default='Shouldn"t mix quotes'];
|
|
7
9
|
option (inmessage) = My.Test;
|
|
8
10
|
option (foo.my_option).bar = false;
|
|
9
11
|
}
|
package/tests/proto2js/Bar.json
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
{
|
|
2
|
-
"package": null,
|
|
3
|
-
"messages": [
|
|
4
|
-
{
|
|
5
|
-
"ref": "Foo",
|
|
6
|
-
"fields": [
|
|
7
|
-
{
|
|
8
|
-
"rule": "required",
|
|
9
|
-
"type": "string",
|
|
10
|
-
"name": "buzz",
|
|
11
|
-
"id": 2,
|
|
12
|
-
"options": {}
|
|
13
|
-
}
|
|
14
|
-
]
|
|
15
|
-
}
|
|
16
|
-
],
|
|
17
|
-
"enums": [],
|
|
18
|
-
"imports": [
|
|
19
|
-
{
|
|
20
|
-
"package": null,
|
|
21
|
-
"messages": [
|
|
22
|
-
{
|
|
23
|
-
"name": "Foo",
|
|
24
|
-
"fields": [
|
|
25
|
-
{
|
|
26
|
-
"rule": "required",
|
|
27
|
-
"type": "string",
|
|
28
|
-
"name": "fizz",
|
|
29
|
-
"id": 1,
|
|
30
|
-
"options": {}
|
|
31
|
-
}
|
|
32
|
-
],
|
|
33
|
-
"enums": [],
|
|
34
|
-
"messages": [],
|
|
35
|
-
"options": {}
|
|
36
|
-
}
|
|
37
|
-
],
|
|
38
|
-
"enums": [],
|
|
39
|
-
"imports": [],
|
|
40
|
-
"options": {},
|
|
41
|
-
"services": []
|
|
42
|
-
}
|
|
43
|
-
],
|
|
44
|
-
"options": {},
|
|
45
|
-
"services": []
|
|
46
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"package": null,
|
|
3
|
+
"messages": [
|
|
4
|
+
{
|
|
5
|
+
"ref": "Foo",
|
|
6
|
+
"fields": [
|
|
7
|
+
{
|
|
8
|
+
"rule": "required",
|
|
9
|
+
"type": "string",
|
|
10
|
+
"name": "buzz",
|
|
11
|
+
"id": 2,
|
|
12
|
+
"options": {}
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"enums": [],
|
|
18
|
+
"imports": [
|
|
19
|
+
{
|
|
20
|
+
"package": null,
|
|
21
|
+
"messages": [
|
|
22
|
+
{
|
|
23
|
+
"name": "Foo",
|
|
24
|
+
"fields": [
|
|
25
|
+
{
|
|
26
|
+
"rule": "required",
|
|
27
|
+
"type": "string",
|
|
28
|
+
"name": "fizz",
|
|
29
|
+
"id": 1,
|
|
30
|
+
"options": {}
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
"enums": [],
|
|
34
|
+
"messages": [],
|
|
35
|
+
"options": {}
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
"enums": [],
|
|
39
|
+
"imports": [],
|
|
40
|
+
"options": {},
|
|
41
|
+
"services": []
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
"options": {},
|
|
45
|
+
"services": []
|
|
46
|
+
}
|
package/tests/suite.js
CHANGED
|
@@ -877,6 +877,28 @@
|
|
|
877
877
|
}
|
|
878
878
|
test.done();
|
|
879
879
|
},
|
|
880
|
+
|
|
881
|
+
"importExtensions": function(test) {
|
|
882
|
+
var x = "package x; \
|
|
883
|
+
message Test { \
|
|
884
|
+
extensions 1 to 10; \
|
|
885
|
+
} \
|
|
886
|
+
extend Test { \
|
|
887
|
+
optional int32 first_val = 1; \
|
|
888
|
+
}";
|
|
889
|
+
var y = "package y; \
|
|
890
|
+
extend x.Test { \
|
|
891
|
+
optional int32 second_val = 2; \
|
|
892
|
+
}";
|
|
893
|
+
var builder = ProtoBuf.newBuilder();
|
|
894
|
+
ProtoBuf.loadProto(x, builder);
|
|
895
|
+
ProtoBuf.loadProto(y, builder);
|
|
896
|
+
var Test = builder.build('x.Test');
|
|
897
|
+
var inst = new Test();
|
|
898
|
+
test.strictEqual(inst[".x.first_val"], null);
|
|
899
|
+
test.strictEqual(inst[".y.second_val"], null);
|
|
900
|
+
test.done();
|
|
901
|
+
},
|
|
880
902
|
|
|
881
903
|
"toplevel": function(test) {
|
|
882
904
|
try {
|
|
@@ -987,7 +1009,8 @@
|
|
|
987
1009
|
"extensions": [
|
|
988
1010
|
2,
|
|
989
1011
|
536870911
|
|
990
|
-
]
|
|
1012
|
+
],
|
|
1013
|
+
"oneofs": []
|
|
991
1014
|
},
|
|
992
1015
|
{
|
|
993
1016
|
"ref": "Foo",
|
|
@@ -1011,7 +1034,8 @@
|
|
|
1011
1034
|
"fields": [],
|
|
1012
1035
|
"enums": [],
|
|
1013
1036
|
"messages": [],
|
|
1014
|
-
"options": {}
|
|
1037
|
+
"options": {},
|
|
1038
|
+
"oneofs": []
|
|
1015
1039
|
},
|
|
1016
1040
|
{
|
|
1017
1041
|
"ref": ".Foo",
|
|
@@ -1026,7 +1050,8 @@
|
|
|
1026
1050
|
]
|
|
1027
1051
|
}
|
|
1028
1052
|
],
|
|
1029
|
-
"options": {}
|
|
1053
|
+
"options": {},
|
|
1054
|
+
"oneofs": []
|
|
1030
1055
|
}
|
|
1031
1056
|
],
|
|
1032
1057
|
"enums": [],
|
|
@@ -1036,7 +1061,7 @@
|
|
|
1036
1061
|
"options": {},
|
|
1037
1062
|
"services": []
|
|
1038
1063
|
});
|
|
1039
|
-
|
|
1064
|
+
|
|
1040
1065
|
var builder = ProtoBuf.loadProtoFile(__dirname+"/extend.proto");
|
|
1041
1066
|
var TFoo = builder.lookup(".Foo"),
|
|
1042
1067
|
TBar = builder.lookup(".Bar"),
|
|
@@ -1049,7 +1074,7 @@
|
|
|
1049
1074
|
test.strictEqual(fields[1].id, 3);
|
|
1050
1075
|
test.deepEqual(TFoo.extensions, [2, ProtoBuf.ID_MAX]); // Defined
|
|
1051
1076
|
test.deepEqual(TBar.extensions, [ProtoBuf.ID_MIN, ProtoBuf.ID_MAX]); // Undefined
|
|
1052
|
-
test.deepEqual(TBar.getChild("foo"), { parent: TBar, name: "foo", field: TFoo.getChild('.Bar.foo') });
|
|
1077
|
+
test.deepEqual(TBar.getChild("foo"), { builder: builder, parent: TBar, name: "foo", field: TFoo.getChild('.Bar.foo') });
|
|
1053
1078
|
test.strictEqual(TBar.getChildren(ProtoBuf.Reflect.Message.Field).length, 0);
|
|
1054
1079
|
var root = builder.build();
|
|
1055
1080
|
test.strictEqual(TFoo.getChild(".Bar.foo").resolvedType, TBarFoo); // .Bar.Foo, not .Foo
|
|
@@ -1080,6 +1105,31 @@
|
|
|
1080
1105
|
}
|
|
1081
1106
|
test.done();
|
|
1082
1107
|
},
|
|
1108
|
+
|
|
1109
|
+
"oneofs": function(test) {
|
|
1110
|
+
try {
|
|
1111
|
+
var builder = ProtoBuf.loadProtoFile(__dirname+"/oneof.proto"),
|
|
1112
|
+
MyOneOf = builder.build("MyOneOf"),
|
|
1113
|
+
TOneOf = builder.lookup(".MyOneOf");
|
|
1114
|
+
test.ok(TOneOf.getChild("my_oneof"));
|
|
1115
|
+
var myOneOf = new MyOneOf();
|
|
1116
|
+
test.strictEqual(myOneOf.my_oneof, null);
|
|
1117
|
+
myOneOf.set("id", 1);
|
|
1118
|
+
test.strictEqual(myOneOf.my_oneof, "id");
|
|
1119
|
+
myOneOf.set("name", "me");
|
|
1120
|
+
test.strictEqual(myOneOf.my_oneof, "name");
|
|
1121
|
+
test.strictEqual(myOneOf.id, null);
|
|
1122
|
+
var bb = myOneOf.encode().compact();
|
|
1123
|
+
test.strictEqual(bb.toString("debug"), "<12 02 6D 65>"); // id 2, wt 2, len 2
|
|
1124
|
+
myOneOf = MyOneOf.decode(bb);
|
|
1125
|
+
test.strictEqual(myOneOf.my_oneof, "name");
|
|
1126
|
+
test.strictEqual(myOneOf.name, "me");
|
|
1127
|
+
test.strictEqual(myOneOf.id, null);
|
|
1128
|
+
} catch (e) {
|
|
1129
|
+
fail(e);
|
|
1130
|
+
}
|
|
1131
|
+
test.done();
|
|
1132
|
+
},
|
|
1083
1133
|
|
|
1084
1134
|
"services": function(test) {
|
|
1085
1135
|
try {
|
|
@@ -1441,14 +1491,12 @@
|
|
|
1441
1491
|
|
|
1442
1492
|
"toRaw": function(test) {
|
|
1443
1493
|
try {
|
|
1444
|
-
var builder = ProtoBuf.loadProto("message MyMessage { required int32 a = 1; required int32 b = 2; }"),
|
|
1494
|
+
var builder = ProtoBuf.loadProto("message MyMessage { required int32 a = 1; required int32 b = 2; required bytes c = 3; }"),
|
|
1445
1495
|
MyMessage = builder.build("MyMessage");
|
|
1446
|
-
var raw = { a: 1, b: 2 },
|
|
1496
|
+
var raw = { a: 1, b: 2, c: "YWJj" },
|
|
1447
1497
|
myMessage = new MyMessage(raw);
|
|
1448
|
-
test.deepEqual(myMessage, raw);
|
|
1449
|
-
test.
|
|
1450
|
-
test.deepEqual(myMessage.toRaw(), raw);
|
|
1451
|
-
test.strictEqual(myMessage.toRaw().encode, undefined);
|
|
1498
|
+
test.deepEqual(myMessage.c.toBase64(), raw.c);
|
|
1499
|
+
test.deepEqual(myMessage.toRaw(true), raw);
|
|
1452
1500
|
} catch (e) {
|
|
1453
1501
|
fail(e);
|
|
1454
1502
|
}
|
|
@@ -1564,6 +1612,26 @@
|
|
|
1564
1612
|
test.done();
|
|
1565
1613
|
},
|
|
1566
1614
|
|
|
1615
|
+
"builderOptions": function(test) {
|
|
1616
|
+
try {
|
|
1617
|
+
var proto = "message Foo { optional uint32 foo_bar = 1; }";
|
|
1618
|
+
var builder = ProtoBuf.newBuilder({
|
|
1619
|
+
convertFieldsToCamelCase: true
|
|
1620
|
+
});
|
|
1621
|
+
ProtoBuf.loadProto(proto, builder, "tests/builderOptions.proto");
|
|
1622
|
+
var Foo = builder.build("Foo");
|
|
1623
|
+
test.strictEqual(ProtoBuf.convertFieldsToCamelCase, false);
|
|
1624
|
+
test.strictEqual(builder.options.convertFieldsToCamelCase, true);
|
|
1625
|
+
var foo = new Foo();
|
|
1626
|
+
test.ok(typeof foo.fooBar !== 'undefined');
|
|
1627
|
+
test.ok(typeof foo.foo_bar === 'undefined');
|
|
1628
|
+
test.done();
|
|
1629
|
+
} catch (e) {
|
|
1630
|
+
fail(e);
|
|
1631
|
+
}
|
|
1632
|
+
test.done();
|
|
1633
|
+
},
|
|
1634
|
+
|
|
1567
1635
|
// Node.js only
|
|
1568
1636
|
"loaders": BROWSER ? {} : {
|
|
1569
1637
|
|
|
@@ -1573,10 +1641,13 @@
|
|
|
1573
1641
|
, util = require('util');
|
|
1574
1642
|
|
|
1575
1643
|
var code = fs.readFileSync(__dirname+"/../dist/"+FILE);
|
|
1644
|
+
var exports = {};
|
|
1576
1645
|
var sandbox = new Sandbox({
|
|
1577
1646
|
module: {
|
|
1578
|
-
exports:
|
|
1647
|
+
exports: exports,
|
|
1648
|
+
id: "protobufjs"
|
|
1579
1649
|
},
|
|
1650
|
+
exports: exports,
|
|
1580
1651
|
require: (function() {
|
|
1581
1652
|
function require(mod) {
|
|
1582
1653
|
if (mod == 'bytebuffer') require.called = true;
|
package/.idea/.name
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
ProtoBuf
|
package/.idea/ProtoBuf.iml
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<module type="WEB_MODULE" version="4">
|
|
3
|
-
<component name="NewModuleRootManager">
|
|
4
|
-
<content url="file://$MODULE_DIR$" />
|
|
5
|
-
<orderEntry type="inheritedJdk" />
|
|
6
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
|
7
|
-
</component>
|
|
8
|
-
</module>
|
|
9
|
-
|
package/.idea/encodings.xml
DELETED
package/.idea/misc.xml
DELETED
package/.idea/modules.xml
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="ProjectModuleManager">
|
|
4
|
-
<modules>
|
|
5
|
-
<module fileurl="file://$PROJECT_DIR$/.idea/ProtoBuf.iml" filepath="$PROJECT_DIR$/.idea/ProtoBuf.iml" />
|
|
6
|
-
</modules>
|
|
7
|
-
</component>
|
|
8
|
-
</project>
|
|
9
|
-
|