Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 15 additions & 20 deletions src/IonParserBinaryRaw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,6 @@ function get_ion_type(rt: number): IonType {
}
}

const TS_SHIFT = 5;
const TS_MASK = 0x1f;

function encode_type_stack(type_, len) {
const ts = (len << TS_SHIFT) | (type_ & TS_MASK);
return ts;
}

function decode_type_stack_type(ts) {
return ts & TS_MASK;
}

function decode_type_stack_len(ts) {
return ts >>> TS_SHIFT;
}

const VINT_SHIFT = 7;
const VINT_MASK = 0x7f;
const VINT_FLAG = 0x80;
Expand All @@ -131,6 +115,17 @@ const ivm_image_1 = IVM.binary[1];
const ivm_image_2 = IVM.binary[2];
const ivm_image_3 = IVM.binary[3];

// to store length and type information of container for _ts
class EncodingContainer {
type: number;
length: number;

constructor(type: number, length: number) {
this.type = type;
this.length = length;
}
}

export class ParserBinaryRaw {
private _in: BinarySpan;
private _raw_type: number = EOF;
Expand All @@ -141,7 +136,7 @@ export class ParserBinaryRaw {
private _as: number = -1;
private _ae: number = -1;
private _a = [];
private _ts = [TB_DATAGRAM];
private _ts = [new EncodingContainer(TB_DATAGRAM, 0)];
private _in_struct: boolean = false;

constructor(source: BinarySpan) {
Expand Down Expand Up @@ -345,7 +340,7 @@ export class ParserBinaryRaw {
throw new Error("you can only 'stepIn' to a container");
}
len = t._in.getRemaining() - t._len; // when we stepOut we'll have consumed this value
ts = encode_type_stack(t._raw_type, len); // (l << TS_SHIFT) | (t._raw_type & TS_MASK);
ts = new EncodingContainer(t._raw_type, len); // add len and type information to stack
t._ts.push(ts);
t._in_struct = t._raw_type === IonBinary.TB_STRUCT;
t._in.setRemaining(t._len);
Expand All @@ -359,8 +354,8 @@ export class ParserBinaryRaw {
throw new Error("Cannot stepOut any further, already at top level");
}
ts = t._ts.pop();
l = decode_type_stack_len(ts);
parent_type = decode_type_stack_type(t._ts[t._ts.length - 1]);
l = ts.length;
parent_type = t._ts[t._ts.length - 1].type;
t._in_struct = parent_type === IonBinary.TB_STRUCT;
t.clear_value();

Expand Down