Skip to content

Commit

Permalink
Fixes keichi#3 Array encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericbla committed Dec 21, 2018
1 parent ad27cfe commit 75379a7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/binary_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ Parser.prototype.generate_encodeArray = function(ctx) {
ctx.pushCode("var {0} = 0;", itemCounter);
if (
typeof this.options.encodeUntil === "function" ||
this.options.readUntil
typeof this.options.readUntil === "function"
) {
ctx.pushCode("do {");
} else {
Expand Down
20 changes: 20 additions & 0 deletions test/zz_encoder_bugs.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,25 @@ describe("Specific bugs testing", function() {
// Missing parms 179 as encodeUntil stops at 178
assert.deepEqual(encoded, Buffer.from("0008AAB1B2FFFF", "hex"));
});

it("should accept readUntil=eof and no encodeUntil provided", function() {
var parser = Parser.start()
.array("arr", {
type: 'uint8',
readUntil: 'eof' // Read until end of buffer
});

var buffer = Buffer.from("01020304050607", "hex");
var decoded = parser.parse(buffer);

assert.deepEqual(decoded, {
arr: [
1,2,3,4,5,6,7
]
});

var encoded = parser.encode(decoded);
assert.deepEqual(encoded, Buffer.from("01020304050607", "hex"));
});
});
});

0 comments on commit 75379a7

Please sign in to comment.