-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
fixed64.js
39 lines (30 loc) · 1009 Bytes
/
fixed64.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
var tape = require("tape");
var protobuf = require("..");
tape.test("fixed64", function(test) {
var root = protobuf.Root.fromJSON({
nested: {
test: {
nested: {
Test: {
fields: {
int_64: {
type: 'fixed64',
id: 1
}
}
}
}
}
}
});
var Test = root.lookup("test.Test");
var buffer = Test.encode({
int_64: '314159265358979'
}).finish();
test.equal(buffer.length, 9, "should encode a total of 9 bytes");
test.equal(buffer[0], 9, "should encode id 1, wireType 1");
var decoded = Test.decode(buffer);
// decoded.int_64 is a Long here, so this implicitly calls Long#toString:
test.ok(decoded.int_64 == '314159265358979', "should decode back the original value");
test.end();
});