Comparing version 0.2.0 to 0.3.0
{ | ||
"name": "preserves", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Experimental data serialization format", | ||
@@ -5,0 +5,0 @@ "homepage": "https://gitlab.com/preserves/preserves", |
@@ -31,3 +31,2 @@ "use strict"; | ||
this.index = 0; | ||
this.placeholders = fromJS(options.placeholders || {}); | ||
this.includeAnnotations = options.includeAnnotations || false; | ||
@@ -90,6 +89,12 @@ } | ||
while (!this.peekend()) { | ||
const chunk = this.next(); | ||
const chunk = Annotations.stripAnnotations(this.next()); | ||
if (ArrayBuffer.isView(chunk)) { | ||
if (chunk.byteLength == 0) { | ||
throw new DecodeError("Empty binary chunks are forbidden"); | ||
} | ||
result.push(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength)); | ||
} else if (chunk instanceof Bytes) { | ||
if (chunk._view.length == 0) { | ||
throw new DecodeError("Empty binary chunks are forbidden"); | ||
} | ||
result.push(chunk._view); | ||
@@ -181,12 +186,3 @@ } else { | ||
} | ||
case 1: { | ||
const n = this.wirelength(arg); | ||
const v = this.placeholders.get(n, void 0); | ||
if (typeof v === 'undefined') { | ||
const e = new DecodeError("Invalid Preserves placeholder"); | ||
e.irritant = n; | ||
throw e; | ||
} | ||
return this.wrap(v); | ||
} | ||
case 1: throw new DecodeError("Illegal format A lead byte"); | ||
case 2: { | ||
@@ -249,3 +245,2 @@ const t = arg >> 2; | ||
this.index = 0; | ||
this.placeholders = fromJS(options.placeholders || {}); | ||
} | ||
@@ -334,7 +329,3 @@ | ||
push(v) { | ||
const placeholder = this.placeholders.get(v, void 0); | ||
if (typeof placeholder !== 'undefined') { | ||
this.header(0, 1, placeholder); | ||
} | ||
else if (typeof v === 'object' && v !== null && typeof v[PreserveOn] === 'function') { | ||
if (typeof v === 'object' && v !== null && typeof v[PreserveOn] === 'function') { | ||
v[PreserveOn](this); | ||
@@ -341,0 +332,0 @@ } |
@@ -84,18 +84,12 @@ "use strict"; | ||
const TestCases = Record.makeConstructor('TestCases', ['mapping', 'cases']); | ||
const ExpectedPlaceholderMapping = | ||
Record.makeConstructor('ExpectedPlaceholderMapping', ['table']); | ||
const TestCases = Record.makeConstructor('TestCases', ['cases']); | ||
const expectedPlaceholderMapping = TestCases._mapping(samples.peel()).strip(); | ||
const placeholders_decode = ExpectedPlaceholderMapping._table(expectedPlaceholderMapping); | ||
const placeholders_encode = placeholders_decode.mapEntries((e) => [e[1],e[0]]); | ||
function DS(bs) { | ||
return decode(bs, {placeholders: placeholders_decode}); | ||
return decode(bs); | ||
} | ||
function D(bs) { | ||
return decodeWithAnnotations(bs, {placeholders: placeholders_decode}); | ||
return decodeWithAnnotations(bs); | ||
} | ||
function E(v) { | ||
return encode(v, {placeholders: placeholders_encode}); | ||
return encode(v); | ||
} | ||
@@ -212,2 +206,3 @@ | ||
break; | ||
case Symbol.for('DecodeEOF'): // fall through | ||
case Symbol.for('DecodeShort'): | ||
@@ -226,2 +221,3 @@ describe(tName, () => { | ||
case Symbol.for('ParseError'): | ||
case Symbol.for('ParseEOF'): | ||
case Symbol.for('ParseShort'): | ||
@@ -228,0 +224,0 @@ /* Skipped for now, until we have an implementation of text syntax */ |
42343
1194