-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench_pbf.js
81 lines (68 loc) · 2.81 KB
/
bench_pbf.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
'use strict'; // code generated by pbf v3.0.5
// Test ========================================
var Test = exports.Test = {};
Test.read = function (pbf, end) {
return pbf.readFields(Test._readField, {string: "", uint32: 0, inner: null, float: 0}, end);
};
Test._readField = function (tag, obj, pbf) {
if (tag === 1) obj.string = pbf.readString();
else if (tag === 2) obj.uint32 = pbf.readVarint();
else if (tag === 3) obj.inner = Test.Inner.read(pbf, pbf.readVarint() + pbf.pos);
else if (tag === 4) obj.float = pbf.readFloat();
};
Test.write = function (obj, pbf) {
if (obj.string) pbf.writeStringField(1, obj.string);
if (obj.uint32) pbf.writeVarintField(2, obj.uint32);
if (obj.inner) pbf.writeMessage(3, Test.Inner.write, obj.inner);
if (obj.float) pbf.writeFloatField(4, obj.float);
};
Test.Enum = {
"ONE": 0,
"TWO": 1,
"THREE": 2,
"FOUR": 3,
"FIVE": 4
};
// Test.Inner ========================================
Test.Inner = {};
Test.Inner.read = function (pbf, end) {
return pbf.readFields(Test.Inner._readField, {int32: 0, innerInner: null, outer: null}, end);
};
Test.Inner._readField = function (tag, obj, pbf) {
if (tag === 1) obj.int32 = pbf.readVarint(true);
else if (tag === 2) obj.innerInner = Test.Inner.InnerInner.read(pbf, pbf.readVarint() + pbf.pos);
else if (tag === 3) obj.outer = Outer.read(pbf, pbf.readVarint() + pbf.pos);
};
Test.Inner.write = function (obj, pbf) {
if (obj.int32) pbf.writeVarintField(1, obj.int32);
if (obj.innerInner) pbf.writeMessage(2, Test.Inner.InnerInner.write, obj.innerInner);
if (obj.outer) pbf.writeMessage(3, Outer.write, obj.outer);
};
// Test.Inner.InnerInner ========================================
Test.Inner.InnerInner = {};
Test.Inner.InnerInner.read = function (pbf, end) {
return pbf.readFields(Test.Inner.InnerInner._readField, {long: 0, enum: 0, sint32: 0}, end);
};
Test.Inner.InnerInner._readField = function (tag, obj, pbf) {
if (tag === 1) obj.long = pbf.readVarint(true);
else if (tag === 2) obj.enum = pbf.readVarint();
else if (tag === 3) obj.sint32 = pbf.readSVarint();
};
Test.Inner.InnerInner.write = function (obj, pbf) {
if (obj.long) pbf.writeVarintField(1, obj.long);
if (obj.enum) pbf.writeVarintField(2, obj.enum);
if (obj.sint32) pbf.writeSVarintField(3, obj.sint32);
};
// Outer ========================================
var Outer = exports.Outer = {};
Outer.read = function (pbf, end) {
return pbf.readFields(Outer._readField, {bool: [], double: 0}, end);
};
Outer._readField = function (tag, obj, pbf) {
if (tag === 1) pbf.readPackedBoolean(obj.bool);
else if (tag === 2) obj.double = pbf.readDouble();
};
Outer.write = function (obj, pbf) {
if (obj.bool) pbf.writePackedBoolean(1, obj.bool);
if (obj.double) pbf.writeDoubleField(2, obj.double);
};