Repair error in Decoder.nextbytes

This commit is contained in:
Tony Garnock-Jones 2018-11-15 23:40:48 +00:00
parent ab8acf2154
commit 80c55e4f30
3 changed files with 10 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{
"name": "preserves",
"version": "0.0.2",
"version": "0.0.3",
"description": "Experimental data serialization format",
"homepage": "https://gitlab.com/tonyg/preserves",
"license": "MIT",

View File

@ -56,7 +56,7 @@ class Decoder {
const start = this.advance(n);
if (this.index > this.packet.length) throw new DecodeError("Short packet");
// ^ NOTE: greater-than, not greater-than-or-equal-to.
return new DataView(this.packet.buffer, start, n);
return new DataView(this.packet.buffer, this.packet.byteOffset + start, n);
}
nextvalues(n) {

View File

@ -141,3 +141,11 @@ describe('hex samples', () => {
});
});
});
describe('parsing from subarray', () => {
it('should maintain alignment of nextbytes', () => {
const u = Uint8Array.of(57, 57, 57, 57, 83, 51, 51, 51);
const bs = Bytes.from(u.subarray(4));
expect(new Decoder(bs).next()).to.equal("333");
});
});