Repair error in Decoder.nextbytes
This commit is contained in:
parent
ab8acf2154
commit
80c55e4f30
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "preserves",
|
"name": "preserves",
|
||||||
"version": "0.0.2",
|
"version": "0.0.3",
|
||||||
"description": "Experimental data serialization format",
|
"description": "Experimental data serialization format",
|
||||||
"homepage": "https://gitlab.com/tonyg/preserves",
|
"homepage": "https://gitlab.com/tonyg/preserves",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|
|
@ -56,7 +56,7 @@ class Decoder {
|
||||||
const start = this.advance(n);
|
const start = this.advance(n);
|
||||||
if (this.index > this.packet.length) throw new DecodeError("Short packet");
|
if (this.index > this.packet.length) throw new DecodeError("Short packet");
|
||||||
// ^ NOTE: greater-than, not greater-than-or-equal-to.
|
// ^ 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) {
|
nextvalues(n) {
|
||||||
|
|
|
@ -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");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue