uint8-varint
Advanced tools
Comparing version 1.0.2 to 1.0.3
import type { Uint8ArrayList } from 'uint8arraylist'; | ||
export declare const unsigned: { | ||
encodingLength(value: bigint): number; | ||
encode(value: bigint, buf?: Uint8ArrayList | Uint8Array, offset?: number): Uint8ArrayList | Uint8Array; | ||
decode(buf: Uint8ArrayList | Uint8Array, offset?: number): bigint; | ||
}; | ||
export declare const signed: { | ||
encodingLength(value: bigint): number; | ||
encode(value: bigint, buf?: Uint8ArrayList | Uint8Array, offset?: number): Uint8ArrayList | Uint8Array; | ||
decode(buf: Uint8ArrayList | Uint8Array, offset?: number): bigint; | ||
}; | ||
export declare const zigzag: { | ||
encodingLength(value: bigint): number; | ||
encode(value: bigint, buf?: Uint8ArrayList | Uint8Array, offset?: number): Uint8ArrayList | Uint8Array; | ||
decode(buf: Uint8ArrayList | Uint8Array, offset?: number): bigint; | ||
}; | ||
interface BigVarintCodec { | ||
encodingLength: (value: bigint) => number; | ||
encode: ((value: bigint) => Uint8Array) & ((value: bigint, buf: Uint8Array, offset?: number) => Uint8Array) & ((value: bigint, buf: Uint8ArrayList, offset?: number) => Uint8ArrayList); | ||
decode: (buf: Uint8ArrayList | Uint8Array, offset?: number) => bigint; | ||
} | ||
export declare const unsigned: BigVarintCodec; | ||
export declare const signed: BigVarintCodec; | ||
export declare const zigzag: BigVarintCodec; | ||
export {}; | ||
//# sourceMappingURL=big.d.ts.map |
import accessor from 'byte-access'; | ||
import { LongBits } from 'longbits'; | ||
import { allocUnsafe } from './alloc.js'; | ||
import { allocUnsafe } from 'uint8arrays/alloc'; | ||
const LIMIT = 0x7fn; | ||
@@ -37,3 +37,3 @@ // https://github.com/joeltg/big-varint/blob/main/src/unsigned.ts | ||
}, | ||
encode(value, buf, offset = 0) { | ||
encode(value, buf, offset) { | ||
if (buf == null) { | ||
@@ -56,3 +56,3 @@ buf = allocUnsafe(signed.encodingLength(value)); | ||
}, | ||
encode(value, buf, offset = 0) { | ||
encode(value, buf, offset) { | ||
if (buf == null) { | ||
@@ -59,0 +59,0 @@ buf = allocUnsafe(zigzag.encodingLength(value)); |
import type { Uint8ArrayList } from 'uint8arraylist'; | ||
export declare const unsigned: { | ||
encodingLength(value: number): number; | ||
encode(value: number, buf?: Uint8ArrayList | Uint8Array, offset?: number): Uint8ArrayList | Uint8Array; | ||
decode(buf: Uint8ArrayList | Uint8Array, offset?: number): number; | ||
}; | ||
export declare const signed: { | ||
encodingLength(value: number): number; | ||
encode(value: number, buf?: Uint8ArrayList | Uint8Array, offset?: number): Uint8ArrayList | Uint8Array; | ||
decode(buf: Uint8ArrayList | Uint8Array, offset?: number): number; | ||
}; | ||
export declare const zigzag: { | ||
encodingLength(value: number): number; | ||
encode(value: number, buf?: Uint8ArrayList | Uint8Array, offset?: number): Uint8ArrayList | Uint8Array; | ||
decode(buf: Uint8ArrayList | Uint8Array, offset?: number): number; | ||
}; | ||
interface VarintCodec { | ||
encodingLength: (value: number) => number; | ||
encode: ((value: number) => Uint8Array) & ((value: number, buf: Uint8Array, offset?: number) => Uint8Array) & ((value: number, buf: Uint8ArrayList, offset?: number) => Uint8ArrayList); | ||
decode: (buf: Uint8ArrayList | Uint8Array, offset?: number) => number; | ||
} | ||
export declare const unsigned: VarintCodec; | ||
export declare const signed: VarintCodec; | ||
export declare const zigzag: VarintCodec; | ||
export {}; | ||
//# sourceMappingURL=index.d.ts.map |
import { LongBits } from 'longbits'; | ||
import { allocUnsafe } from './alloc.js'; | ||
import { allocUnsafe } from 'uint8arrays/alloc'; | ||
const N1 = Math.pow(2, 7); | ||
@@ -64,3 +64,3 @@ const N2 = Math.pow(2, 14); | ||
}, | ||
encode(value, buf, offset = 0) { | ||
encode(value, buf, offset) { | ||
if (buf == null) { | ||
@@ -73,3 +73,3 @@ buf = allocUnsafe(signed.encodingLength(value)); | ||
} | ||
return unsigned.encode(value, buf); | ||
return unsigned.encode(value, buf, offset); | ||
}, | ||
@@ -84,3 +84,4 @@ decode(buf, offset = 0) { | ||
}, | ||
encode(value, buf, offset = 0) { | ||
// @ts-expect-error | ||
encode(value, buf, offset) { | ||
value = value >= 0 ? value * 2 : (value * -2) - 1; | ||
@@ -87,0 +88,0 @@ return unsigned.encode(value, buf, offset); |
{ | ||
"name": "uint8-varint", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Read/write varints from Uint8Arrays and Uint8ArrayLists", | ||
@@ -160,3 +160,4 @@ "license": "Apache-2.0 OR MIT", | ||
"longbits": "^1.1.0", | ||
"uint8arraylist": "^2.0.0" | ||
"uint8arraylist": "^2.0.0", | ||
"uint8arrays": "^3.1.0" | ||
}, | ||
@@ -166,4 +167,5 @@ "devDependencies": { | ||
"aegir": "^37.4.6", | ||
"benchmark": "^2.1.4", | ||
"varint": "^6.0.0" | ||
} | ||
} |
import type { Uint8ArrayList } from 'uint8arraylist' | ||
import accessor from 'byte-access' | ||
import { LongBits } from 'longbits' | ||
import { allocUnsafe } from './alloc.js' | ||
import { allocUnsafe } from 'uint8arrays/alloc' | ||
const LIMIT = 0x7fn | ||
interface BigVarintCodec { | ||
encodingLength: (value: bigint) => number | ||
encode: ((value: bigint) => Uint8Array) & ((value: bigint, buf: Uint8Array, offset?: number) => Uint8Array) & ((value: bigint, buf: Uint8ArrayList, offset?: number) => Uint8ArrayList) | ||
decode: (buf: Uint8ArrayList | Uint8Array, offset?: number) => bigint | ||
} | ||
// https://github.com/joeltg/big-varint/blob/main/src/unsigned.ts | ||
export const unsigned = { | ||
export const unsigned: BigVarintCodec = { | ||
encodingLength (value: bigint): number { | ||
@@ -18,3 +24,3 @@ let i = 0 | ||
encode (value: bigint, buf?: Uint8ArrayList | Uint8Array, offset = 0): Uint8ArrayList | Uint8Array { | ||
encode (value: any, buf?: any, offset: any = 0) { | ||
if (buf == null) { | ||
@@ -41,3 +47,3 @@ buf = allocUnsafe(unsigned.encodingLength(value)) | ||
export const signed = { | ||
export const signed: BigVarintCodec = { | ||
encodingLength (value: bigint): number { | ||
@@ -51,3 +57,3 @@ if (value < 0n) { | ||
encode (value: bigint, buf?: Uint8ArrayList | Uint8Array, offset = 0): Uint8ArrayList | Uint8Array { | ||
encode (value: any, buf?: any, offset?: any) { | ||
if (buf == null) { | ||
@@ -71,3 +77,3 @@ buf = allocUnsafe(signed.encodingLength(value)) | ||
export const zigzag = { | ||
export const zigzag: BigVarintCodec = { | ||
encodingLength (value: bigint): number { | ||
@@ -77,3 +83,3 @@ return unsigned.encodingLength(value >= 0 ? value * 2n : value * -2n - 1n) | ||
encode (value: bigint, buf?: Uint8ArrayList | Uint8Array, offset = 0): Uint8ArrayList | Uint8Array { | ||
encode (value: any, buf?: any, offset?: any) { | ||
if (buf == null) { | ||
@@ -80,0 +86,0 @@ buf = allocUnsafe(zigzag.encodingLength(value)) |
import type { Uint8ArrayList } from 'uint8arraylist' | ||
import { LongBits } from 'longbits' | ||
import { allocUnsafe } from './alloc.js' | ||
import { allocUnsafe } from 'uint8arrays/alloc' | ||
@@ -15,3 +15,9 @@ const N1 = Math.pow(2, 7) | ||
export const unsigned = { | ||
interface VarintCodec { | ||
encodingLength: (value: number) => number | ||
encode: ((value: number) => Uint8Array) & ((value: number, buf: Uint8Array, offset?: number) => Uint8Array) & ((value: number, buf: Uint8ArrayList, offset?: number) => Uint8ArrayList) | ||
decode: (buf: Uint8ArrayList | Uint8Array, offset?: number) => number | ||
} | ||
export const unsigned: VarintCodec = { | ||
encodingLength (value: number): number { | ||
@@ -57,3 +63,3 @@ if (value < N1) { | ||
encode (value: number, buf?: Uint8ArrayList | Uint8Array, offset = 0): Uint8ArrayList | Uint8Array { | ||
encode (value: number, buf?: any, offset: number = 0) { | ||
if (Number.MAX_SAFE_INTEGER != null && value > Number.MAX_SAFE_INTEGER) { | ||
@@ -77,3 +83,3 @@ throw new RangeError('Could not encode varint') | ||
export const signed = { | ||
export const signed: VarintCodec = { | ||
encodingLength (value: number): number { | ||
@@ -87,3 +93,3 @@ if (value < 0) { | ||
encode (value: number, buf?: Uint8ArrayList | Uint8Array, offset = 0): Uint8ArrayList | Uint8Array { | ||
encode (value: any, buf?: any, offset?: any) { | ||
if (buf == null) { | ||
@@ -99,3 +105,3 @@ buf = allocUnsafe(signed.encodingLength(value)) | ||
return unsigned.encode(value, buf) | ||
return unsigned.encode(value, buf, offset) | ||
}, | ||
@@ -108,3 +114,3 @@ | ||
export const zigzag = { | ||
export const zigzag: VarintCodec = { | ||
encodingLength (value: number): number { | ||
@@ -114,3 +120,4 @@ return unsigned.encodingLength(value >= 0 ? value * 2 : value * -2 - 1) | ||
encode (value: number, buf?: Uint8ArrayList | Uint8Array, offset = 0): Uint8ArrayList | Uint8Array { | ||
// @ts-expect-error | ||
encode (value: any, buf?: any, offset?: any) { | ||
value = value >= 0 ? value * 2 : (value * -2) - 1 | ||
@@ -117,0 +124,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
23655
4
4
13
344
+ Addeduint8arrays@^3.1.0
+ Addedmultiformats@9.9.0(transitive)
+ Addeduint8arrays@3.1.1(transitive)