@jprochazk/cbor
Advanced tools
Comparing version 0.4.3 to 0.4.4
@@ -1,2 +0,2 @@ | ||
import { View } from '../common/view'; | ||
import { View } from "common/view"; | ||
export declare class Parser { | ||
@@ -3,0 +3,0 @@ private readonly view; |
@@ -7,2 +7,3 @@ export declare class Writer { | ||
write(value: any): void; | ||
getType(value: any): number; | ||
} |
@@ -379,2 +379,3 @@ 'use strict'; | ||
// Copyright (C) 2020 Jan Procházka. | ||
var DECODER = new TextDecoder; | ||
var Parser = /** @class */ (function () { | ||
@@ -385,3 +386,3 @@ function Parser(view, max_depth) { | ||
this.sax = new SAX(max_depth); | ||
this.textDecoder = new TextDecoder(); | ||
this.textDecoder = DECODER; | ||
} | ||
@@ -585,10 +586,2 @@ Parser.prototype.parse = function () { | ||
// Copyright (C) 2020 Jan Procházka. | ||
var NUMERIC_LIMITS = { | ||
UINT8: Math.pow(2, 8) - 1, | ||
UINT16: Math.pow(2, 16) - 1, | ||
UINT32: Math.pow(2, 32) - 1, | ||
//UINT64: BigInt("18446744073709552000"), | ||
FLOAT32: Math.pow(2, 23) - 1, | ||
FLOAT64: Number.MAX_SAFE_INTEGER | ||
}; | ||
var ErrorCode$1; | ||
@@ -620,7 +613,7 @@ (function (ErrorCode) { | ||
case ErrorCode$1.STRING_TOO_LARGE: | ||
return new WriteError("Max String length is " + NUMERIC_LIMITS.UINT32 + ", found: " + info.size); | ||
return new WriteError("Max String length is 4294967295, found: " + info.size); | ||
case ErrorCode$1.ARRAY_TOO_LARGE: | ||
return new WriteError("Max Array length is " + NUMERIC_LIMITS.UINT32 + ", found: " + info.size); | ||
return new WriteError("Max Array length is 4294967295, found: " + info.size); | ||
case ErrorCode$1.OBJECT_TOO_LARGE: | ||
return new WriteError("Max Object length is " + NUMERIC_LIMITS.UINT32 + ", found: " + info.size); | ||
return new WriteError("Max Object length is 4294967295, found: " + info.size); | ||
case ErrorCode$1.NUMBER_TOO_LARGE: | ||
@@ -636,38 +629,7 @@ return new WriteError("Max Number is " + Number.MAX_SAFE_INTEGER + ", found: " + info.number); | ||
// Copyright (C) 2020 Jan Procházka. | ||
var NUMERIC_LIMITS$1 = { | ||
UINT8: Math.pow(2, 8) - 1, | ||
UINT16: Math.pow(2, 16) - 1, | ||
UINT32: Math.pow(2, 32) - 1, | ||
//UINT64: BigInt("18446744073709552000"), | ||
FLOAT32: Math.pow(2, 23) - 1, | ||
FLOAT64: Number.MAX_SAFE_INTEGER | ||
}; | ||
function getType(value) { | ||
switch (true) { | ||
case (typeof value === "undefined"): | ||
return 0; | ||
case (value === null): | ||
return 1; | ||
case (typeof value === "boolean"): | ||
return 2; | ||
case (typeof value === "number"): | ||
return 3; | ||
case (typeof value === "bigint"): | ||
throw WriteError.build(ErrorCode$1.UNSUPPORTED_BIGINT); | ||
case (typeof value === "string"): | ||
return 4; | ||
case (Array.isArray(value)): | ||
return 5; | ||
case (typeof value === "object"): | ||
return 6; | ||
default: | ||
throw WriteError.build(ErrorCode$1.UNEXPECTED_TOKEN, { token: value }); | ||
} | ||
} | ||
// Copyright (C) 2020 Jan Procházka. | ||
var ENCODER = new TextEncoder; | ||
var Writer = /** @class */ (function () { | ||
function Writer(buffer) { | ||
this.view = new View(buffer); | ||
this.textEncoder = new TextEncoder(); | ||
this.textEncoder = ENCODER; | ||
} | ||
@@ -678,3 +640,3 @@ Writer.prototype.finalize = function () { | ||
Writer.prototype.write = function (value) { | ||
switch (getType(value)) { | ||
switch (this.getType(value)) { | ||
case 0: { // undefined | ||
@@ -696,3 +658,3 @@ this.view.setUint8(0xF7); | ||
// TODO: encode Infinity as Float16 instead (less bytes, same value) | ||
if (isNaN(value) || !isFinite(value) || (-NUMERIC_LIMITS$1.FLOAT32 <= value && value <= NUMERIC_LIMITS$1.FLOAT32)) { | ||
if (isNaN(value) || !isFinite(value) || (-8388607 <= value && value <= 8388607)) { | ||
this.view.setUint8(0xFA); | ||
@@ -711,11 +673,11 @@ this.view.setFloat32(value); | ||
} | ||
else if (value <= NUMERIC_LIMITS$1.UINT8) { | ||
else if (value <= 255) { | ||
this.view.setUint8(0x18); | ||
this.view.setUint8(value); | ||
} | ||
else if (value <= NUMERIC_LIMITS$1.UINT16) { | ||
else if (value <= 65535) { | ||
this.view.setUint8(0x19); | ||
this.view.setUint16(value); | ||
} | ||
else if (value <= NUMERIC_LIMITS$1.UINT32) { | ||
else if (value <= 4294967295) { | ||
this.view.setUint8(0x1A); | ||
@@ -739,11 +701,11 @@ this.view.setUint32(value); | ||
} | ||
else if (positive_number <= NUMERIC_LIMITS$1.UINT8) { | ||
else if (positive_number <= 255) { | ||
this.view.setUint8(0x38); | ||
this.view.setUint8(positive_number); | ||
} | ||
else if (positive_number <= NUMERIC_LIMITS$1.UINT16) { | ||
else if (positive_number <= 65535) { | ||
this.view.setUint8(0x39); | ||
this.view.setUint16(positive_number); | ||
} | ||
else if (positive_number <= NUMERIC_LIMITS$1.UINT32) { | ||
else if (positive_number <= 4294967295) { | ||
this.view.setUint8(0x3A); | ||
@@ -769,11 +731,11 @@ this.view.setUint32(positive_number); | ||
} | ||
else if (size <= NUMERIC_LIMITS$1.UINT8) { | ||
else if (size <= 255) { | ||
this.view.setUint8(0x78); | ||
this.view.setUint8(size); | ||
} | ||
else if (size <= NUMERIC_LIMITS$1.UINT16) { | ||
else if (size <= 65535) { | ||
this.view.setUint8(0x79); | ||
this.view.setUint16(size); | ||
} | ||
else if (size <= NUMERIC_LIMITS$1.UINT32) { | ||
else if (size <= 4294967295) { | ||
this.view.setUint8(0x7A); | ||
@@ -799,11 +761,11 @@ this.view.setUint32(size); | ||
} | ||
else if (size <= NUMERIC_LIMITS$1.UINT8) { | ||
else if (size <= 255) { | ||
this.view.setUint8(0x98); | ||
this.view.setUint8(size); | ||
} | ||
else if (size <= NUMERIC_LIMITS$1.UINT16) { | ||
else if (size <= 65535) { | ||
this.view.setUint8(0x99); | ||
this.view.setUint16(size); | ||
} | ||
else if (size <= NUMERIC_LIMITS$1.UINT32) { | ||
else if (size <= 4294967295) { | ||
this.view.setUint8(0x9A); | ||
@@ -830,11 +792,11 @@ this.view.setUint32(size); | ||
} | ||
else if (size <= NUMERIC_LIMITS$1.UINT8) { | ||
else if (size <= 255) { | ||
this.view.setUint8(0xB8); | ||
this.view.setUint8(size); | ||
} | ||
else if (size <= NUMERIC_LIMITS$1.UINT16) { | ||
else if (size <= 65535) { | ||
this.view.setUint8(0xB9); | ||
this.view.setUint16(size); | ||
} | ||
else if (size <= NUMERIC_LIMITS$1.UINT32) { | ||
else if (size <= 4294967295) { | ||
this.view.setUint8(0xBA); | ||
@@ -859,2 +821,24 @@ this.view.setUint32(size); | ||
}; | ||
Writer.prototype.getType = function (value) { | ||
switch (true) { | ||
case (typeof value === "undefined"): | ||
return 0; | ||
case (value === null): | ||
return 1; | ||
case (typeof value === "boolean"): | ||
return 2; | ||
case (typeof value === "number"): | ||
return 3; | ||
case (typeof value === "bigint"): | ||
throw WriteError.build(ErrorCode$1.UNSUPPORTED_BIGINT); | ||
case (typeof value === "string"): | ||
return 4; | ||
case (Array.isArray(value)): | ||
return 5; | ||
case (typeof value === "object"): | ||
return 6; | ||
default: | ||
throw WriteError.build(ErrorCode$1.UNEXPECTED_TOKEN, { token: value }); | ||
} | ||
}; | ||
return Writer; | ||
@@ -871,3 +855,3 @@ }()); | ||
function encode(data, allowErrors, out) { | ||
var buffer = out !== null && out !== void 0 ? out : new ArrayBuffer(1024); | ||
var buffer = out || new ArrayBuffer(1024); | ||
var writer = new Writer(buffer); | ||
@@ -874,0 +858,0 @@ if (!allowErrors) { |
@@ -377,2 +377,3 @@ /*! ***************************************************************************** | ||
// Copyright (C) 2020 Jan Procházka. | ||
var DECODER = new TextDecoder; | ||
var Parser = /** @class */ (function () { | ||
@@ -383,3 +384,3 @@ function Parser(view, max_depth) { | ||
this.sax = new SAX(max_depth); | ||
this.textDecoder = new TextDecoder(); | ||
this.textDecoder = DECODER; | ||
} | ||
@@ -583,10 +584,2 @@ Parser.prototype.parse = function () { | ||
// Copyright (C) 2020 Jan Procházka. | ||
var NUMERIC_LIMITS = { | ||
UINT8: Math.pow(2, 8) - 1, | ||
UINT16: Math.pow(2, 16) - 1, | ||
UINT32: Math.pow(2, 32) - 1, | ||
//UINT64: BigInt("18446744073709552000"), | ||
FLOAT32: Math.pow(2, 23) - 1, | ||
FLOAT64: Number.MAX_SAFE_INTEGER | ||
}; | ||
var ErrorCode$1; | ||
@@ -618,7 +611,7 @@ (function (ErrorCode) { | ||
case ErrorCode$1.STRING_TOO_LARGE: | ||
return new WriteError("Max String length is " + NUMERIC_LIMITS.UINT32 + ", found: " + info.size); | ||
return new WriteError("Max String length is 4294967295, found: " + info.size); | ||
case ErrorCode$1.ARRAY_TOO_LARGE: | ||
return new WriteError("Max Array length is " + NUMERIC_LIMITS.UINT32 + ", found: " + info.size); | ||
return new WriteError("Max Array length is 4294967295, found: " + info.size); | ||
case ErrorCode$1.OBJECT_TOO_LARGE: | ||
return new WriteError("Max Object length is " + NUMERIC_LIMITS.UINT32 + ", found: " + info.size); | ||
return new WriteError("Max Object length is 4294967295, found: " + info.size); | ||
case ErrorCode$1.NUMBER_TOO_LARGE: | ||
@@ -634,38 +627,7 @@ return new WriteError("Max Number is " + Number.MAX_SAFE_INTEGER + ", found: " + info.number); | ||
// Copyright (C) 2020 Jan Procházka. | ||
var NUMERIC_LIMITS$1 = { | ||
UINT8: Math.pow(2, 8) - 1, | ||
UINT16: Math.pow(2, 16) - 1, | ||
UINT32: Math.pow(2, 32) - 1, | ||
//UINT64: BigInt("18446744073709552000"), | ||
FLOAT32: Math.pow(2, 23) - 1, | ||
FLOAT64: Number.MAX_SAFE_INTEGER | ||
}; | ||
function getType(value) { | ||
switch (true) { | ||
case (typeof value === "undefined"): | ||
return 0; | ||
case (value === null): | ||
return 1; | ||
case (typeof value === "boolean"): | ||
return 2; | ||
case (typeof value === "number"): | ||
return 3; | ||
case (typeof value === "bigint"): | ||
throw WriteError.build(ErrorCode$1.UNSUPPORTED_BIGINT); | ||
case (typeof value === "string"): | ||
return 4; | ||
case (Array.isArray(value)): | ||
return 5; | ||
case (typeof value === "object"): | ||
return 6; | ||
default: | ||
throw WriteError.build(ErrorCode$1.UNEXPECTED_TOKEN, { token: value }); | ||
} | ||
} | ||
// Copyright (C) 2020 Jan Procházka. | ||
var ENCODER = new TextEncoder; | ||
var Writer = /** @class */ (function () { | ||
function Writer(buffer) { | ||
this.view = new View(buffer); | ||
this.textEncoder = new TextEncoder(); | ||
this.textEncoder = ENCODER; | ||
} | ||
@@ -676,3 +638,3 @@ Writer.prototype.finalize = function () { | ||
Writer.prototype.write = function (value) { | ||
switch (getType(value)) { | ||
switch (this.getType(value)) { | ||
case 0: { // undefined | ||
@@ -694,3 +656,3 @@ this.view.setUint8(0xF7); | ||
// TODO: encode Infinity as Float16 instead (less bytes, same value) | ||
if (isNaN(value) || !isFinite(value) || (-NUMERIC_LIMITS$1.FLOAT32 <= value && value <= NUMERIC_LIMITS$1.FLOAT32)) { | ||
if (isNaN(value) || !isFinite(value) || (-8388607 <= value && value <= 8388607)) { | ||
this.view.setUint8(0xFA); | ||
@@ -709,11 +671,11 @@ this.view.setFloat32(value); | ||
} | ||
else if (value <= NUMERIC_LIMITS$1.UINT8) { | ||
else if (value <= 255) { | ||
this.view.setUint8(0x18); | ||
this.view.setUint8(value); | ||
} | ||
else if (value <= NUMERIC_LIMITS$1.UINT16) { | ||
else if (value <= 65535) { | ||
this.view.setUint8(0x19); | ||
this.view.setUint16(value); | ||
} | ||
else if (value <= NUMERIC_LIMITS$1.UINT32) { | ||
else if (value <= 4294967295) { | ||
this.view.setUint8(0x1A); | ||
@@ -737,11 +699,11 @@ this.view.setUint32(value); | ||
} | ||
else if (positive_number <= NUMERIC_LIMITS$1.UINT8) { | ||
else if (positive_number <= 255) { | ||
this.view.setUint8(0x38); | ||
this.view.setUint8(positive_number); | ||
} | ||
else if (positive_number <= NUMERIC_LIMITS$1.UINT16) { | ||
else if (positive_number <= 65535) { | ||
this.view.setUint8(0x39); | ||
this.view.setUint16(positive_number); | ||
} | ||
else if (positive_number <= NUMERIC_LIMITS$1.UINT32) { | ||
else if (positive_number <= 4294967295) { | ||
this.view.setUint8(0x3A); | ||
@@ -767,11 +729,11 @@ this.view.setUint32(positive_number); | ||
} | ||
else if (size <= NUMERIC_LIMITS$1.UINT8) { | ||
else if (size <= 255) { | ||
this.view.setUint8(0x78); | ||
this.view.setUint8(size); | ||
} | ||
else if (size <= NUMERIC_LIMITS$1.UINT16) { | ||
else if (size <= 65535) { | ||
this.view.setUint8(0x79); | ||
this.view.setUint16(size); | ||
} | ||
else if (size <= NUMERIC_LIMITS$1.UINT32) { | ||
else if (size <= 4294967295) { | ||
this.view.setUint8(0x7A); | ||
@@ -797,11 +759,11 @@ this.view.setUint32(size); | ||
} | ||
else if (size <= NUMERIC_LIMITS$1.UINT8) { | ||
else if (size <= 255) { | ||
this.view.setUint8(0x98); | ||
this.view.setUint8(size); | ||
} | ||
else if (size <= NUMERIC_LIMITS$1.UINT16) { | ||
else if (size <= 65535) { | ||
this.view.setUint8(0x99); | ||
this.view.setUint16(size); | ||
} | ||
else if (size <= NUMERIC_LIMITS$1.UINT32) { | ||
else if (size <= 4294967295) { | ||
this.view.setUint8(0x9A); | ||
@@ -828,11 +790,11 @@ this.view.setUint32(size); | ||
} | ||
else if (size <= NUMERIC_LIMITS$1.UINT8) { | ||
else if (size <= 255) { | ||
this.view.setUint8(0xB8); | ||
this.view.setUint8(size); | ||
} | ||
else if (size <= NUMERIC_LIMITS$1.UINT16) { | ||
else if (size <= 65535) { | ||
this.view.setUint8(0xB9); | ||
this.view.setUint16(size); | ||
} | ||
else if (size <= NUMERIC_LIMITS$1.UINT32) { | ||
else if (size <= 4294967295) { | ||
this.view.setUint8(0xBA); | ||
@@ -857,2 +819,24 @@ this.view.setUint32(size); | ||
}; | ||
Writer.prototype.getType = function (value) { | ||
switch (true) { | ||
case (typeof value === "undefined"): | ||
return 0; | ||
case (value === null): | ||
return 1; | ||
case (typeof value === "boolean"): | ||
return 2; | ||
case (typeof value === "number"): | ||
return 3; | ||
case (typeof value === "bigint"): | ||
throw WriteError.build(ErrorCode$1.UNSUPPORTED_BIGINT); | ||
case (typeof value === "string"): | ||
return 4; | ||
case (Array.isArray(value)): | ||
return 5; | ||
case (typeof value === "object"): | ||
return 6; | ||
default: | ||
throw WriteError.build(ErrorCode$1.UNEXPECTED_TOKEN, { token: value }); | ||
} | ||
}; | ||
return Writer; | ||
@@ -869,3 +853,3 @@ }()); | ||
function encode(data, allowErrors, out) { | ||
var buffer = out !== null && out !== void 0 ? out : new ArrayBuffer(1024); | ||
var buffer = out || new ArrayBuffer(1024); | ||
var writer = new Writer(buffer); | ||
@@ -872,0 +856,0 @@ if (!allowErrors) { |
@@ -383,2 +383,3 @@ (function (global, factory) { | ||
// Copyright (C) 2020 Jan Procházka. | ||
var DECODER = new TextDecoder; | ||
var Parser = /** @class */ (function () { | ||
@@ -389,3 +390,3 @@ function Parser(view, max_depth) { | ||
this.sax = new SAX(max_depth); | ||
this.textDecoder = new TextDecoder(); | ||
this.textDecoder = DECODER; | ||
} | ||
@@ -589,10 +590,2 @@ Parser.prototype.parse = function () { | ||
// Copyright (C) 2020 Jan Procházka. | ||
var NUMERIC_LIMITS = { | ||
UINT8: Math.pow(2, 8) - 1, | ||
UINT16: Math.pow(2, 16) - 1, | ||
UINT32: Math.pow(2, 32) - 1, | ||
//UINT64: BigInt("18446744073709552000"), | ||
FLOAT32: Math.pow(2, 23) - 1, | ||
FLOAT64: Number.MAX_SAFE_INTEGER | ||
}; | ||
var ErrorCode$1; | ||
@@ -624,7 +617,7 @@ (function (ErrorCode) { | ||
case ErrorCode$1.STRING_TOO_LARGE: | ||
return new WriteError("Max String length is " + NUMERIC_LIMITS.UINT32 + ", found: " + info.size); | ||
return new WriteError("Max String length is 4294967295, found: " + info.size); | ||
case ErrorCode$1.ARRAY_TOO_LARGE: | ||
return new WriteError("Max Array length is " + NUMERIC_LIMITS.UINT32 + ", found: " + info.size); | ||
return new WriteError("Max Array length is 4294967295, found: " + info.size); | ||
case ErrorCode$1.OBJECT_TOO_LARGE: | ||
return new WriteError("Max Object length is " + NUMERIC_LIMITS.UINT32 + ", found: " + info.size); | ||
return new WriteError("Max Object length is 4294967295, found: " + info.size); | ||
case ErrorCode$1.NUMBER_TOO_LARGE: | ||
@@ -640,38 +633,7 @@ return new WriteError("Max Number is " + Number.MAX_SAFE_INTEGER + ", found: " + info.number); | ||
// Copyright (C) 2020 Jan Procházka. | ||
var NUMERIC_LIMITS$1 = { | ||
UINT8: Math.pow(2, 8) - 1, | ||
UINT16: Math.pow(2, 16) - 1, | ||
UINT32: Math.pow(2, 32) - 1, | ||
//UINT64: BigInt("18446744073709552000"), | ||
FLOAT32: Math.pow(2, 23) - 1, | ||
FLOAT64: Number.MAX_SAFE_INTEGER | ||
}; | ||
function getType(value) { | ||
switch (true) { | ||
case (typeof value === "undefined"): | ||
return 0; | ||
case (value === null): | ||
return 1; | ||
case (typeof value === "boolean"): | ||
return 2; | ||
case (typeof value === "number"): | ||
return 3; | ||
case (typeof value === "bigint"): | ||
throw WriteError.build(ErrorCode$1.UNSUPPORTED_BIGINT); | ||
case (typeof value === "string"): | ||
return 4; | ||
case (Array.isArray(value)): | ||
return 5; | ||
case (typeof value === "object"): | ||
return 6; | ||
default: | ||
throw WriteError.build(ErrorCode$1.UNEXPECTED_TOKEN, { token: value }); | ||
} | ||
} | ||
// Copyright (C) 2020 Jan Procházka. | ||
var ENCODER = new TextEncoder; | ||
var Writer = /** @class */ (function () { | ||
function Writer(buffer) { | ||
this.view = new View(buffer); | ||
this.textEncoder = new TextEncoder(); | ||
this.textEncoder = ENCODER; | ||
} | ||
@@ -682,3 +644,3 @@ Writer.prototype.finalize = function () { | ||
Writer.prototype.write = function (value) { | ||
switch (getType(value)) { | ||
switch (this.getType(value)) { | ||
case 0: { // undefined | ||
@@ -700,3 +662,3 @@ this.view.setUint8(0xF7); | ||
// TODO: encode Infinity as Float16 instead (less bytes, same value) | ||
if (isNaN(value) || !isFinite(value) || (-NUMERIC_LIMITS$1.FLOAT32 <= value && value <= NUMERIC_LIMITS$1.FLOAT32)) { | ||
if (isNaN(value) || !isFinite(value) || (-8388607 <= value && value <= 8388607)) { | ||
this.view.setUint8(0xFA); | ||
@@ -715,11 +677,11 @@ this.view.setFloat32(value); | ||
} | ||
else if (value <= NUMERIC_LIMITS$1.UINT8) { | ||
else if (value <= 255) { | ||
this.view.setUint8(0x18); | ||
this.view.setUint8(value); | ||
} | ||
else if (value <= NUMERIC_LIMITS$1.UINT16) { | ||
else if (value <= 65535) { | ||
this.view.setUint8(0x19); | ||
this.view.setUint16(value); | ||
} | ||
else if (value <= NUMERIC_LIMITS$1.UINT32) { | ||
else if (value <= 4294967295) { | ||
this.view.setUint8(0x1A); | ||
@@ -743,11 +705,11 @@ this.view.setUint32(value); | ||
} | ||
else if (positive_number <= NUMERIC_LIMITS$1.UINT8) { | ||
else if (positive_number <= 255) { | ||
this.view.setUint8(0x38); | ||
this.view.setUint8(positive_number); | ||
} | ||
else if (positive_number <= NUMERIC_LIMITS$1.UINT16) { | ||
else if (positive_number <= 65535) { | ||
this.view.setUint8(0x39); | ||
this.view.setUint16(positive_number); | ||
} | ||
else if (positive_number <= NUMERIC_LIMITS$1.UINT32) { | ||
else if (positive_number <= 4294967295) { | ||
this.view.setUint8(0x3A); | ||
@@ -773,11 +735,11 @@ this.view.setUint32(positive_number); | ||
} | ||
else if (size <= NUMERIC_LIMITS$1.UINT8) { | ||
else if (size <= 255) { | ||
this.view.setUint8(0x78); | ||
this.view.setUint8(size); | ||
} | ||
else if (size <= NUMERIC_LIMITS$1.UINT16) { | ||
else if (size <= 65535) { | ||
this.view.setUint8(0x79); | ||
this.view.setUint16(size); | ||
} | ||
else if (size <= NUMERIC_LIMITS$1.UINT32) { | ||
else if (size <= 4294967295) { | ||
this.view.setUint8(0x7A); | ||
@@ -803,11 +765,11 @@ this.view.setUint32(size); | ||
} | ||
else if (size <= NUMERIC_LIMITS$1.UINT8) { | ||
else if (size <= 255) { | ||
this.view.setUint8(0x98); | ||
this.view.setUint8(size); | ||
} | ||
else if (size <= NUMERIC_LIMITS$1.UINT16) { | ||
else if (size <= 65535) { | ||
this.view.setUint8(0x99); | ||
this.view.setUint16(size); | ||
} | ||
else if (size <= NUMERIC_LIMITS$1.UINT32) { | ||
else if (size <= 4294967295) { | ||
this.view.setUint8(0x9A); | ||
@@ -834,11 +796,11 @@ this.view.setUint32(size); | ||
} | ||
else if (size <= NUMERIC_LIMITS$1.UINT8) { | ||
else if (size <= 255) { | ||
this.view.setUint8(0xB8); | ||
this.view.setUint8(size); | ||
} | ||
else if (size <= NUMERIC_LIMITS$1.UINT16) { | ||
else if (size <= 65535) { | ||
this.view.setUint8(0xB9); | ||
this.view.setUint16(size); | ||
} | ||
else if (size <= NUMERIC_LIMITS$1.UINT32) { | ||
else if (size <= 4294967295) { | ||
this.view.setUint8(0xBA); | ||
@@ -863,2 +825,24 @@ this.view.setUint32(size); | ||
}; | ||
Writer.prototype.getType = function (value) { | ||
switch (true) { | ||
case (typeof value === "undefined"): | ||
return 0; | ||
case (value === null): | ||
return 1; | ||
case (typeof value === "boolean"): | ||
return 2; | ||
case (typeof value === "number"): | ||
return 3; | ||
case (typeof value === "bigint"): | ||
throw WriteError.build(ErrorCode$1.UNSUPPORTED_BIGINT); | ||
case (typeof value === "string"): | ||
return 4; | ||
case (Array.isArray(value)): | ||
return 5; | ||
case (typeof value === "object"): | ||
return 6; | ||
default: | ||
throw WriteError.build(ErrorCode$1.UNEXPECTED_TOKEN, { token: value }); | ||
} | ||
}; | ||
return Writer; | ||
@@ -875,3 +859,3 @@ }()); | ||
function encode(data, allowErrors, out) { | ||
var buffer = out !== null && out !== void 0 ? out : new ArrayBuffer(1024); | ||
var buffer = out || new ArrayBuffer(1024); | ||
var writer = new Writer(buffer); | ||
@@ -878,0 +862,0 @@ if (!allowErrors) { |
{ | ||
"name": "@jprochazk/cbor", | ||
"version": "0.4.3", | ||
"version": "0.4.4", | ||
"description": "Partial implementation of RFC 7049 (CBOR)", | ||
@@ -5,0 +5,0 @@ "author": "Jan Procházka", |
@@ -49,3 +49,3 @@ # cbor | ||
Results are on a i5-8600k intel processor. The JSON data used in the test is 2 KB decoded and 1.8 KB encoded. This means the library can decode at 13 MB/s and encode at 10 MB/s. | ||
Results are on a i5-8600k intel processor. The JSON data used in the test is 2 KB decoded and 1.8 KB encoded. This means the library can decode at 13 MB/s and encode at 10 MB/s in Chrome, and around 2.5~4x as much in Firefox. | ||
@@ -56,3 +56,3 @@ You can squeeze out a bit more performance if you use `CBOR.encodeInto` with a sufficiently large buffer. the `CBOR.encode` default is 1024 bytes, which should be enough for the vast majority of uses, but if you ever find yourself using more than that, utilize `CBOR.encodeInto`. | ||
This library is meant for use in both Node & browsers. | ||
This library is meant for use in both Node & browsers. Minimum supported Node version is 11. | ||
@@ -59,0 +59,0 @@ There are a few things from the specification which are currently unimplemented: |
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
121387
2848