Fixed extra output in array data. (#220)

This commit is contained in:
Richard Moore 2018-06-30 22:40:20 -04:00
parent 6faa978767
commit ebf42dc9e0
No known key found for this signature in database
GPG Key ID: 525F70A6FCABC295

@ -357,6 +357,17 @@ abstract class Coder {
abstract decode(data: Uint8Array, offset: number): DecodedResult; abstract decode(data: Uint8Array, offset: number): DecodedResult;
} }
// Clones the functionality of an existing Coder, but without a localName
class CoderAnonymous extends Coder {
private coder: Coder;
constructor(coder: Coder) {
super(coder.coerceFunc, coder.name, coder.type, undefined, coder.dynamic);
defineReadOnly(this, 'coder', coder);
}
encode(value: any): Uint8Array { return this.coder.encode(value); }
decode(data: Uint8Array, offset: number): DecodedResult { return this.coder.decode(data, offset); }
}
class CoderNull extends Coder { class CoderNull extends Coder {
constructor(coerceFunc: CoerceFunc, localName: string) { constructor(coerceFunc: CoerceFunc, localName: string) {
super(coerceFunc, 'null', '', localName, false); super(coerceFunc, 'null', '', localName, false);
@ -801,7 +812,7 @@ class CoderArray extends Coder {
} }
var coders = []; var coders = [];
for (var i = 0; i < count; i++) { coders.push(this.coder); } for (var i = 0; i < count; i++) { coders.push(new CoderAnonymous(this.coder)); }
var result = unpack(coders, data, offset); var result = unpack(coders, data, offset);
result.consumed += consumed; result.consumed += consumed;