From 0b9b1d8505743995c5328daab1f1e124debc63bd Mon Sep 17 00:00:00 2001 From: dcodeIO Date: Wed, 14 Dec 2016 14:00:51 +0100 Subject: [PATCH] Test case for #556 --- package.json | 2 +- tests/tag.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 tests/tag.js diff --git a/package.json b/package.json index dc01cf214..e0a0adb60 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "protobufjs", - "version": "6.1.1", + "version": "6.1.2", "description": "Protocol Buffers for JavaScript (& TypeScript).", "author": "Daniel Wirtz ", "license": "Apache-2.0", diff --git a/tests/tag.js b/tests/tag.js new file mode 100644 index 000000000..8776a84bb --- /dev/null +++ b/tests/tag.js @@ -0,0 +1,35 @@ +var tape = require("tape"); + +var protobuf = require(".."); + +var root = protobuf.Root.fromJSON({ + nested: { + Message: { + fields: { + val: { + type: "uint32", + id: 0x1FFFFFFF + } + } + } + } +}); + +tape.test("long tags", function(test) { + + var Message = root.lookup("Message"); + var message = { val: 1 }; + var buf = Message.encode(message).finish(); + + test.equal(buf[0], 0xF8, "should write F8 (78)"); + test.equal(buf[1], 0xff, "should write FF (7F)"); + test.equal(buf[2], 0xff, "should write FF (7F)"); + test.equal(buf[3], 0xff, "should write FF (7F)"); + test.equal(buf[4], 0b1111, "should write 1111b"); + test.equal(buf[5], 1, "should write value 1"); + + var comp = Message.decode(buf); + test.deepEqual(comp, message, "should decode back the original data"); + + test.end(); +});