Comparing version 0.1.1 to 0.2.0
{ | ||
"name": "preserves", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Experimental data serialization format", | ||
@@ -5,0 +5,0 @@ "homepage": "https://gitlab.com/preserves/preserves", |
@@ -160,48 +160,55 @@ "use strict"; | ||
next() { | ||
const [major, minor, arg] = this.nextop(); | ||
switch (major) { | ||
case 0: | ||
switch (minor) { | ||
case 0: | ||
switch (arg) { | ||
case 0: return this.wrap(false); | ||
case 1: return this.wrap(true); | ||
case 2: return this.wrap(Single(this.nextbytes(4).getFloat32(0, false))); | ||
case 3: return this.wrap(Double(this.nextbytes(8).getFloat64(0, false))); | ||
case 4: throw new DecodeError("Unexpected end-of-stream marker"); | ||
case 5: { | ||
const a = this.next(); | ||
const v = this.next(); | ||
return this.unshiftAnnotation(a, v); | ||
while (true) { // we loop because we may need to consume an arbitrary number of no-ops | ||
const [major, minor, arg] = this.nextop(); | ||
switch (major) { | ||
case 0: | ||
switch (minor) { | ||
case 0: | ||
switch (arg) { | ||
case 0: return this.wrap(false); | ||
case 1: return this.wrap(true); | ||
case 2: return this.wrap(Single(this.nextbytes(4).getFloat32(0, false))); | ||
case 3: return this.wrap(Double(this.nextbytes(8).getFloat64(0, false))); | ||
case 4: throw new DecodeError("Unexpected end-of-stream marker"); | ||
case 5: { | ||
const a = this.next(); | ||
const v = this.next(); | ||
return this.unshiftAnnotation(a, v); | ||
} | ||
default: throw new DecodeError("Illegal format A lead byte"); | ||
} | ||
default: throw new DecodeError("Illegal format A lead byte"); | ||
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: { | ||
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; | ||
case 2: { | ||
const t = arg >> 2; | ||
const n = arg & 3; | ||
switch (t) { | ||
case 1: return this.wrap(this.binarystream(n)); | ||
case 2: return this.wrap(this.valuestream(n)); | ||
default: throw new DecodeError("Invalid format C start byte"); | ||
} | ||
} | ||
return this.wrap(v); | ||
case 3: | ||
return this.wrap((arg > 12) ? arg - 16 : arg); | ||
} | ||
case 2: { | ||
const t = arg >> 2; | ||
const n = arg & 3; | ||
switch (t) { | ||
case 1: return this.wrap(this.binarystream(n)); | ||
case 2: return this.wrap(this.valuestream(n)); | ||
default: throw new DecodeError("Invalid format C start byte"); | ||
} | ||
case 1: | ||
return this.wrap(this.decodebinary(minor, Bytes.from(this.nextbytes(this.wirelength(arg))))); | ||
case 2: | ||
return this.wrap(this.decodecompound(minor, this.nextvalues(this.wirelength(arg)))); | ||
case 3: | ||
if (minor === 3 && arg === 15) { | ||
// no-op. | ||
continue; | ||
} else { | ||
throw new DecodeError("Invalid lead byte (major 3)"); | ||
} | ||
case 3: | ||
return this.wrap((arg > 12) ? arg - 16 : arg); | ||
} | ||
case 1: | ||
return this.wrap(this.decodebinary(minor, Bytes.from(this.nextbytes(this.wirelength(arg))))); | ||
case 2: | ||
return this.wrap(this.decodecompound(minor, this.nextvalues(this.wirelength(arg)))); | ||
case 3: | ||
throw new DecodeError("Invalid lead byte (major 3)"); | ||
} | ||
} | ||
@@ -319,2 +326,6 @@ } | ||
encodenoop() { | ||
this.leadbyte(3, 3, 15); | ||
} | ||
push(v) { | ||
@@ -321,0 +332,0 @@ const placeholder = this.placeholders.get(v, void 0); |
@@ -168,3 +168,3 @@ "use strict"; | ||
() => assert(is(D(E(annotatedTextForm)), annotatedTextForm))); | ||
if (variety !== 'nondeterministic') { | ||
if (variety !== 'decode' && variety !== 'nondeterministic') { | ||
it('should encode correctly', | ||
@@ -174,3 +174,3 @@ () => assert(is(E(forward), binaryForm), | ||
} | ||
if (variety !== 'nondeterministic' && variety !== 'streaming') { | ||
if (variety !== 'decode' && variety !== 'nondeterministic' && variety !== 'streaming') { | ||
it('should encode correctly with annotations', | ||
@@ -197,2 +197,5 @@ () => assert(is(E(annotatedTextForm), binaryForm), | ||
break; | ||
case Symbol.for('DecodeTest'): | ||
runTestCase('decode', tName, t.get(0).strip(), t.get(1)); | ||
break; | ||
case Symbol.for('DecodeError'): | ||
@@ -199,0 +202,0 @@ describe(tName, () => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43049
1206