Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@solana/codecs-numbers

Package Overview
Dependencies
Maintainers
14
Versions
1182
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solana/codecs-numbers - npm Package Compare versions

Comparing version 2.0.0-experimental.8c5ac55 to 2.0.0-experimental.8de8e11

208

dist/index.browser.js

@@ -1,2 +0,2 @@

import { combineCodec, assertByteArrayIsNotEmptyForCodec, assertByteArrayHasEnoughBytesForCodec } from '@solana/codecs-core';
import { combineCodec, createEncoder, createDecoder, assertByteArrayIsNotEmptyForCodec, assertByteArrayHasEnoughBytesForCodec } from '@solana/codecs-core';

@@ -18,21 +18,9 @@ // src/assertions.ts

})(Endian || {});
function sharedNumberFactory(input) {
let littleEndian;
let defaultDescription = input.name;
if (input.size > 1) {
littleEndian = !("endian" in input.options) || input.options.endian === 0 /* LITTLE */;
defaultDescription += littleEndian ? "(le)" : "(be)";
}
return {
description: input.options.description ?? defaultDescription,
fixedSize: input.size,
littleEndian,
maxSize: input.size
};
function isLittleEndian(config) {
return config?.endian === 1 /* BIG */ ? false : true;
}
function numberEncoderFactory(input) {
const codecData = sharedNumberFactory(input);
return {
description: codecData.description,
encode(value) {
return createEncoder({
fixedSize: input.size,
write(value, bytes, offset) {
if (input.range) {

@@ -42,22 +30,18 @@ assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);

const arrayBuffer = new ArrayBuffer(input.size);
input.set(new DataView(arrayBuffer), value, codecData.littleEndian);
return new Uint8Array(arrayBuffer);
},
fixedSize: codecData.fixedSize,
maxSize: codecData.maxSize
};
input.set(new DataView(arrayBuffer), value, isLittleEndian(input.config));
bytes.set(new Uint8Array(arrayBuffer), offset);
return offset + input.size;
}
});
}
function numberDecoderFactory(input) {
const codecData = sharedNumberFactory(input);
return {
decode(bytes, offset = 0) {
assertByteArrayIsNotEmptyForCodec(codecData.description, bytes, offset);
assertByteArrayHasEnoughBytesForCodec(codecData.description, input.size, bytes, offset);
return createDecoder({
fixedSize: input.size,
read(bytes, offset = 0) {
assertByteArrayIsNotEmptyForCodec(input.name, bytes, offset);
assertByteArrayHasEnoughBytesForCodec(input.name, input.size, bytes, offset);
const view = new DataView(toArrayBuffer(bytes, offset, input.size));
return [input.get(view, codecData.littleEndian), offset + input.size];
},
description: codecData.description,
fixedSize: codecData.fixedSize,
maxSize: codecData.maxSize
};
return [input.get(view, isLittleEndian(input.config)), offset + input.size];
}
});
}

@@ -71,31 +55,31 @@ function toArrayBuffer(bytes, offset, length) {

// src/f32.ts
var getF32Encoder = (options = {}) => numberEncoderFactory({
var getF32Encoder = (config = {}) => numberEncoderFactory({
config,
name: "f32",
options,
set: (view, value, le) => view.setFloat32(0, value, le),
size: 4
});
var getF32Decoder = (options = {}) => numberDecoderFactory({
var getF32Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getFloat32(0, le),
name: "f32",
options,
size: 4
});
var getF32Codec = (options = {}) => combineCodec(getF32Encoder(options), getF32Decoder(options));
var getF64Encoder = (options = {}) => numberEncoderFactory({
var getF32Codec = (config = {}) => combineCodec(getF32Encoder(config), getF32Decoder(config));
var getF64Encoder = (config = {}) => numberEncoderFactory({
config,
name: "f64",
options,
set: (view, value, le) => view.setFloat64(0, value, le),
size: 8
});
var getF64Decoder = (options = {}) => numberDecoderFactory({
var getF64Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getFloat64(0, le),
name: "f64",
options,
size: 8
});
var getF64Codec = (options = {}) => combineCodec(getF64Encoder(options), getF64Decoder(options));
var getI128Encoder = (options = {}) => numberEncoderFactory({
var getF64Codec = (config = {}) => combineCodec(getF64Encoder(config), getF64Decoder(config));
var getI128Encoder = (config = {}) => numberEncoderFactory({
config,
name: "i128",
options,
range: [-BigInt("0x7fffffffffffffffffffffffffffffff") - 1n, BigInt("0x7fffffffffffffffffffffffffffffff")],

@@ -111,3 +95,4 @@ set: (view, value, le) => {

});
var getI128Decoder = (options = {}) => numberDecoderFactory({
var getI128Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => {

@@ -121,9 +106,8 @@ const leftOffset = le ? 8 : 0;

name: "i128",
options,
size: 16
});
var getI128Codec = (options = {}) => combineCodec(getI128Encoder(options), getI128Decoder(options));
var getI16Encoder = (options = {}) => numberEncoderFactory({
var getI128Codec = (config = {}) => combineCodec(getI128Encoder(config), getI128Decoder(config));
var getI16Encoder = (config = {}) => numberEncoderFactory({
config,
name: "i16",
options,
range: [-Number("0x7fff") - 1, Number("0x7fff")],

@@ -133,12 +117,12 @@ set: (view, value, le) => view.setInt16(0, value, le),

});
var getI16Decoder = (options = {}) => numberDecoderFactory({
var getI16Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getInt16(0, le),
name: "i16",
options,
size: 2
});
var getI16Codec = (options = {}) => combineCodec(getI16Encoder(options), getI16Decoder(options));
var getI32Encoder = (options = {}) => numberEncoderFactory({
var getI16Codec = (config = {}) => combineCodec(getI16Encoder(config), getI16Decoder(config));
var getI32Encoder = (config = {}) => numberEncoderFactory({
config,
name: "i32",
options,
range: [-Number("0x7fffffff") - 1, Number("0x7fffffff")],

@@ -148,12 +132,12 @@ set: (view, value, le) => view.setInt32(0, value, le),

});
var getI32Decoder = (options = {}) => numberDecoderFactory({
var getI32Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getInt32(0, le),
name: "i32",
options,
size: 4
});
var getI32Codec = (options = {}) => combineCodec(getI32Encoder(options), getI32Decoder(options));
var getI64Encoder = (options = {}) => numberEncoderFactory({
var getI32Codec = (config = {}) => combineCodec(getI32Encoder(config), getI32Decoder(config));
var getI64Encoder = (config = {}) => numberEncoderFactory({
config,
name: "i64",
options,
range: [-BigInt("0x7fffffffffffffff") - 1n, BigInt("0x7fffffffffffffff")],

@@ -163,12 +147,11 @@ set: (view, value, le) => view.setBigInt64(0, BigInt(value), le),

});
var getI64Decoder = (options = {}) => numberDecoderFactory({
var getI64Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getBigInt64(0, le),
name: "i64",
options,
size: 8
});
var getI64Codec = (options = {}) => combineCodec(getI64Encoder(options), getI64Decoder(options));
var getI8Encoder = (options = {}) => numberEncoderFactory({
var getI64Codec = (config = {}) => combineCodec(getI64Encoder(config), getI64Decoder(config));
var getI8Encoder = () => numberEncoderFactory({
name: "i8",
options,
range: [-Number("0x7f") - 1, Number("0x7f")],

@@ -178,14 +161,20 @@ set: (view, value) => view.setInt8(0, value),

});
var getI8Decoder = (options = {}) => numberDecoderFactory({
var getI8Decoder = () => numberDecoderFactory({
get: (view) => view.getInt8(0),
name: "i8",
options,
size: 1
});
var getI8Codec = (options = {}) => combineCodec(getI8Encoder(options), getI8Decoder(options));
var getShortU16Encoder = (options = {}) => ({
description: options.description ?? "shortU16",
encode: (value) => {
var getI8Codec = () => combineCodec(getI8Encoder(), getI8Decoder());
var getShortU16Encoder = () => createEncoder({
getSizeFromValue: (value) => {
if (value <= 127)
return 1;
if (value <= 16383)
return 2;
return 3;
},
maxSize: 3,
write: (value, bytes, offset) => {
assertNumberIsBetweenForCodec("shortU16", 0, 65535, value);
const bytes = [0];
const shortU16Bytes = [0];
for (let ii = 0; ; ii += 1) {

@@ -197,14 +186,14 @@ const alignedValue = value >> ii * 7;

const nextSevenBits = 127 & alignedValue;
bytes[ii] = nextSevenBits;
shortU16Bytes[ii] = nextSevenBits;
if (ii > 0) {
bytes[ii - 1] |= 128;
shortU16Bytes[ii - 1] |= 128;
}
}
return new Uint8Array(bytes);
},
fixedSize: null,
maxSize: 3
bytes.set(shortU16Bytes, offset);
return offset + shortU16Bytes.length;
}
});
var getShortU16Decoder = (options = {}) => ({
decode: (bytes, offset = 0) => {
var getShortU16Decoder = () => createDecoder({
maxSize: 3,
read: (bytes, offset) => {
let value = 0;

@@ -222,11 +211,8 @@ let byteCount = 0;

return [value, offset + byteCount];
},
description: options.description ?? "shortU16",
fixedSize: null,
maxSize: 3
}
});
var getShortU16Codec = (options = {}) => combineCodec(getShortU16Encoder(options), getShortU16Decoder(options));
var getU128Encoder = (options = {}) => numberEncoderFactory({
var getShortU16Codec = () => combineCodec(getShortU16Encoder(), getShortU16Decoder());
var getU128Encoder = (config = {}) => numberEncoderFactory({
config,
name: "u128",
options,
range: [0, BigInt("0xffffffffffffffffffffffffffffffff")],

@@ -242,3 +228,4 @@ set: (view, value, le) => {

});
var getU128Decoder = (options = {}) => numberDecoderFactory({
var getU128Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => {

@@ -252,9 +239,8 @@ const leftOffset = le ? 8 : 0;

name: "u128",
options,
size: 16
});
var getU128Codec = (options = {}) => combineCodec(getU128Encoder(options), getU128Decoder(options));
var getU16Encoder = (options = {}) => numberEncoderFactory({
var getU128Codec = (config = {}) => combineCodec(getU128Encoder(config), getU128Decoder(config));
var getU16Encoder = (config = {}) => numberEncoderFactory({
config,
name: "u16",
options,
range: [0, Number("0xffff")],

@@ -264,12 +250,12 @@ set: (view, value, le) => view.setUint16(0, value, le),

});
var getU16Decoder = (options = {}) => numberDecoderFactory({
var getU16Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getUint16(0, le),
name: "u16",
options,
size: 2
});
var getU16Codec = (options = {}) => combineCodec(getU16Encoder(options), getU16Decoder(options));
var getU32Encoder = (options = {}) => numberEncoderFactory({
var getU16Codec = (config = {}) => combineCodec(getU16Encoder(config), getU16Decoder(config));
var getU32Encoder = (config = {}) => numberEncoderFactory({
config,
name: "u32",
options,
range: [0, Number("0xffffffff")],

@@ -279,12 +265,12 @@ set: (view, value, le) => view.setUint32(0, value, le),

});
var getU32Decoder = (options = {}) => numberDecoderFactory({
var getU32Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getUint32(0, le),
name: "u32",
options,
size: 4
});
var getU32Codec = (options = {}) => combineCodec(getU32Encoder(options), getU32Decoder(options));
var getU64Encoder = (options = {}) => numberEncoderFactory({
var getU32Codec = (config = {}) => combineCodec(getU32Encoder(config), getU32Decoder(config));
var getU64Encoder = (config = {}) => numberEncoderFactory({
config,
name: "u64",
options,
range: [0, BigInt("0xffffffffffffffff")],

@@ -294,12 +280,11 @@ set: (view, value, le) => view.setBigUint64(0, BigInt(value), le),

});
var getU64Decoder = (options = {}) => numberDecoderFactory({
var getU64Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getBigUint64(0, le),
name: "u64",
options,
size: 8
});
var getU64Codec = (options = {}) => combineCodec(getU64Encoder(options), getU64Decoder(options));
var getU8Encoder = (options = {}) => numberEncoderFactory({
var getU64Codec = (config = {}) => combineCodec(getU64Encoder(config), getU64Decoder(config));
var getU8Encoder = () => numberEncoderFactory({
name: "u8",
options,
range: [0, Number("0xff")],

@@ -309,9 +294,8 @@ set: (view, value) => view.setUint8(0, value),

});
var getU8Decoder = (options = {}) => numberDecoderFactory({
var getU8Decoder = () => numberDecoderFactory({
get: (view) => view.getUint8(0),
name: "u8",
options,
size: 1
});
var getU8Codec = (options = {}) => combineCodec(getU8Encoder(options), getU8Decoder(options));
var getU8Codec = () => combineCodec(getU8Encoder(), getU8Decoder());

@@ -318,0 +302,0 @@ export { Endian, assertNumberIsBetweenForCodec, getF32Codec, getF32Decoder, getF32Encoder, getF64Codec, getF64Decoder, getF64Encoder, getI128Codec, getI128Decoder, getI128Encoder, getI16Codec, getI16Decoder, getI16Encoder, getI32Codec, getI32Decoder, getI32Encoder, getI64Codec, getI64Decoder, getI64Encoder, getI8Codec, getI8Decoder, getI8Encoder, getShortU16Codec, getShortU16Decoder, getShortU16Encoder, getU128Codec, getU128Decoder, getU128Encoder, getU16Codec, getU16Decoder, getU16Encoder, getU32Codec, getU32Decoder, getU32Encoder, getU64Codec, getU64Decoder, getU64Encoder, getU8Codec, getU8Decoder, getU8Encoder };

@@ -33,4 +33,29 @@ this.globalThis = this.globalThis || {};

}
function combineCodec(encoder, decoder, description) {
if (encoder.fixedSize !== decoder.fixedSize) {
function getEncodedSize(value, encoder) {
return "fixedSize" in encoder ? encoder.fixedSize : encoder.getSizeFromValue(value);
}
function createEncoder(encoder) {
return Object.freeze({
...encoder,
encode: (value) => {
const bytes = new Uint8Array(getEncodedSize(value, encoder));
encoder.write(value, bytes, 0);
return bytes;
}
});
}
function createDecoder(decoder) {
return Object.freeze({
...decoder,
decode: (bytes, offset = 0) => decoder.read(bytes, offset)[0]
});
}
function isFixedSize(codec) {
return "fixedSize" in codec && typeof codec.fixedSize === "number";
}
function combineCodec(encoder, decoder) {
if (isFixedSize(encoder) !== isFixedSize(decoder)) {
throw new Error(`Encoder and decoder must either both be fixed-size or variable-size.`);
}
if (isFixedSize(encoder) && isFixedSize(decoder) && encoder.fixedSize !== decoder.fixedSize) {
throw new Error(

@@ -40,3 +65,3 @@ `Encoder and decoder must have the same fixed size, got [${encoder.fixedSize}] and [${decoder.fixedSize}].`

}
if (encoder.maxSize !== decoder.maxSize) {
if (!isFixedSize(encoder) && !isFixedSize(decoder) && encoder.maxSize !== decoder.maxSize) {
throw new Error(

@@ -46,13 +71,9 @@ `Encoder and decoder must have the same max size, got [${encoder.maxSize}] and [${decoder.maxSize}].`

}
if (description === void 0 && encoder.description !== decoder.description) {
throw new Error(
`Encoder and decoder must have the same description, got [${encoder.description}] and [${decoder.description}]. Pass a custom description as a third argument if you want to override the description and bypass this error.`
);
}
return {
...decoder,
...encoder,
decode: decoder.decode,
description: description ?? encoder.description,
encode: encoder.encode,
fixedSize: encoder.fixedSize,
maxSize: encoder.maxSize
read: decoder.read,
write: encoder.write
};

@@ -62,21 +83,9 @@ }

// src/utils.ts
function sharedNumberFactory(input) {
let littleEndian;
let defaultDescription = input.name;
if (input.size > 1) {
littleEndian = !("endian" in input.options) || input.options.endian === 0 /* LITTLE */;
defaultDescription += littleEndian ? "(le)" : "(be)";
}
return {
description: input.options.description ?? defaultDescription,
fixedSize: input.size,
littleEndian,
maxSize: input.size
};
function isLittleEndian(config) {
return (config == null ? void 0 : config.endian) === 1 /* BIG */ ? false : true;
}
function numberEncoderFactory(input) {
const codecData = sharedNumberFactory(input);
return {
description: codecData.description,
encode(value) {
return createEncoder({
fixedSize: input.size,
write(value, bytes, offset) {
if (input.range) {

@@ -86,26 +95,22 @@ assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);

const arrayBuffer = new ArrayBuffer(input.size);
input.set(new DataView(arrayBuffer), value, codecData.littleEndian);
return new Uint8Array(arrayBuffer);
},
fixedSize: codecData.fixedSize,
maxSize: codecData.maxSize
};
input.set(new DataView(arrayBuffer), value, isLittleEndian(input.config));
bytes.set(new Uint8Array(arrayBuffer), offset);
return offset + input.size;
}
});
}
function numberDecoderFactory(input) {
const codecData = sharedNumberFactory(input);
return {
decode(bytes, offset = 0) {
assertByteArrayIsNotEmptyForCodec(codecData.description, bytes, offset);
assertByteArrayHasEnoughBytesForCodec(codecData.description, input.size, bytes, offset);
return createDecoder({
fixedSize: input.size,
read(bytes, offset = 0) {
assertByteArrayIsNotEmptyForCodec(input.name, bytes, offset);
assertByteArrayHasEnoughBytesForCodec(input.name, input.size, bytes, offset);
const view = new DataView(toArrayBuffer(bytes, offset, input.size));
return [input.get(view, codecData.littleEndian), offset + input.size];
},
description: codecData.description,
fixedSize: codecData.fixedSize,
maxSize: codecData.maxSize
};
return [input.get(view, isLittleEndian(input.config)), offset + input.size];
}
});
}
function toArrayBuffer(bytes, offset, length) {
const bytesOffset = bytes.byteOffset + (offset ?? 0);
const bytesLength = length ?? bytes.byteLength;
const bytesOffset = bytes.byteOffset + (offset != null ? offset : 0);
const bytesLength = length != null ? length : bytes.byteLength;
return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);

@@ -115,35 +120,35 @@ }

// src/f32.ts
var getF32Encoder = (options = {}) => numberEncoderFactory({
var getF32Encoder = (config = {}) => numberEncoderFactory({
config,
name: "f32",
options,
set: (view, value, le) => view.setFloat32(0, value, le),
size: 4
});
var getF32Decoder = (options = {}) => numberDecoderFactory({
var getF32Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getFloat32(0, le),
name: "f32",
options,
size: 4
});
var getF32Codec = (options = {}) => combineCodec(getF32Encoder(options), getF32Decoder(options));
var getF32Codec = (config = {}) => combineCodec(getF32Encoder(config), getF32Decoder(config));
// src/f64.ts
var getF64Encoder = (options = {}) => numberEncoderFactory({
var getF64Encoder = (config = {}) => numberEncoderFactory({
config,
name: "f64",
options,
set: (view, value, le) => view.setFloat64(0, value, le),
size: 8
});
var getF64Decoder = (options = {}) => numberDecoderFactory({
var getF64Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getFloat64(0, le),
name: "f64",
options,
size: 8
});
var getF64Codec = (options = {}) => combineCodec(getF64Encoder(options), getF64Decoder(options));
var getF64Codec = (config = {}) => combineCodec(getF64Encoder(config), getF64Decoder(config));
// src/i128.ts
var getI128Encoder = (options = {}) => numberEncoderFactory({
var getI128Encoder = (config = {}) => numberEncoderFactory({
config,
name: "i128",
options,
range: [-BigInt("0x7fffffffffffffffffffffffffffffff") - 1n, BigInt("0x7fffffffffffffffffffffffffffffff")],

@@ -159,3 +164,4 @@ set: (view, value, le) => {

});
var getI128Decoder = (options = {}) => numberDecoderFactory({
var getI128Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => {

@@ -169,11 +175,10 @@ const leftOffset = le ? 8 : 0;

name: "i128",
options,
size: 16
});
var getI128Codec = (options = {}) => combineCodec(getI128Encoder(options), getI128Decoder(options));
var getI128Codec = (config = {}) => combineCodec(getI128Encoder(config), getI128Decoder(config));
// src/i16.ts
var getI16Encoder = (options = {}) => numberEncoderFactory({
var getI16Encoder = (config = {}) => numberEncoderFactory({
config,
name: "i16",
options,
range: [-Number("0x7fff") - 1, Number("0x7fff")],

@@ -183,14 +188,14 @@ set: (view, value, le) => view.setInt16(0, value, le),

});
var getI16Decoder = (options = {}) => numberDecoderFactory({
var getI16Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getInt16(0, le),
name: "i16",
options,
size: 2
});
var getI16Codec = (options = {}) => combineCodec(getI16Encoder(options), getI16Decoder(options));
var getI16Codec = (config = {}) => combineCodec(getI16Encoder(config), getI16Decoder(config));
// src/i32.ts
var getI32Encoder = (options = {}) => numberEncoderFactory({
var getI32Encoder = (config = {}) => numberEncoderFactory({
config,
name: "i32",
options,
range: [-Number("0x7fffffff") - 1, Number("0x7fffffff")],

@@ -200,14 +205,14 @@ set: (view, value, le) => view.setInt32(0, value, le),

});
var getI32Decoder = (options = {}) => numberDecoderFactory({
var getI32Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getInt32(0, le),
name: "i32",
options,
size: 4
});
var getI32Codec = (options = {}) => combineCodec(getI32Encoder(options), getI32Decoder(options));
var getI32Codec = (config = {}) => combineCodec(getI32Encoder(config), getI32Decoder(config));
// src/i64.ts
var getI64Encoder = (options = {}) => numberEncoderFactory({
var getI64Encoder = (config = {}) => numberEncoderFactory({
config,
name: "i64",
options,
range: [-BigInt("0x7fffffffffffffff") - 1n, BigInt("0x7fffffffffffffff")],

@@ -217,14 +222,13 @@ set: (view, value, le) => view.setBigInt64(0, BigInt(value), le),

});
var getI64Decoder = (options = {}) => numberDecoderFactory({
var getI64Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getBigInt64(0, le),
name: "i64",
options,
size: 8
});
var getI64Codec = (options = {}) => combineCodec(getI64Encoder(options), getI64Decoder(options));
var getI64Codec = (config = {}) => combineCodec(getI64Encoder(config), getI64Decoder(config));
// src/i8.ts
var getI8Encoder = (options = {}) => numberEncoderFactory({
var getI8Encoder = () => numberEncoderFactory({
name: "i8",
options,
range: [-Number("0x7f") - 1, Number("0x7f")],

@@ -234,16 +238,22 @@ set: (view, value) => view.setInt8(0, value),

});
var getI8Decoder = (options = {}) => numberDecoderFactory({
var getI8Decoder = () => numberDecoderFactory({
get: (view) => view.getInt8(0),
name: "i8",
options,
size: 1
});
var getI8Codec = (options = {}) => combineCodec(getI8Encoder(options), getI8Decoder(options));
var getI8Codec = () => combineCodec(getI8Encoder(), getI8Decoder());
// src/short-u16.ts
var getShortU16Encoder = (options = {}) => ({
description: options.description ?? "shortU16",
encode: (value) => {
var getShortU16Encoder = () => createEncoder({
getSizeFromValue: (value) => {
if (value <= 127)
return 1;
if (value <= 16383)
return 2;
return 3;
},
maxSize: 3,
write: (value, bytes, offset) => {
assertNumberIsBetweenForCodec("shortU16", 0, 65535, value);
const bytes = [0];
const shortU16Bytes = [0];
for (let ii = 0; ; ii += 1) {

@@ -255,14 +265,14 @@ const alignedValue = value >> ii * 7;

const nextSevenBits = 127 & alignedValue;
bytes[ii] = nextSevenBits;
shortU16Bytes[ii] = nextSevenBits;
if (ii > 0) {
bytes[ii - 1] |= 128;
shortU16Bytes[ii - 1] |= 128;
}
}
return new Uint8Array(bytes);
},
fixedSize: null,
maxSize: 3
bytes.set(shortU16Bytes, offset);
return offset + shortU16Bytes.length;
}
});
var getShortU16Decoder = (options = {}) => ({
decode: (bytes, offset = 0) => {
var getShortU16Decoder = () => createDecoder({
maxSize: 3,
read: (bytes, offset) => {
let value = 0;

@@ -280,13 +290,10 @@ let byteCount = 0;

return [value, offset + byteCount];
},
description: options.description ?? "shortU16",
fixedSize: null,
maxSize: 3
}
});
var getShortU16Codec = (options = {}) => combineCodec(getShortU16Encoder(options), getShortU16Decoder(options));
var getShortU16Codec = () => combineCodec(getShortU16Encoder(), getShortU16Decoder());
// src/u128.ts
var getU128Encoder = (options = {}) => numberEncoderFactory({
var getU128Encoder = (config = {}) => numberEncoderFactory({
config,
name: "u128",
options,
range: [0, BigInt("0xffffffffffffffffffffffffffffffff")],

@@ -302,3 +309,4 @@ set: (view, value, le) => {

});
var getU128Decoder = (options = {}) => numberDecoderFactory({
var getU128Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => {

@@ -312,11 +320,10 @@ const leftOffset = le ? 8 : 0;

name: "u128",
options,
size: 16
});
var getU128Codec = (options = {}) => combineCodec(getU128Encoder(options), getU128Decoder(options));
var getU128Codec = (config = {}) => combineCodec(getU128Encoder(config), getU128Decoder(config));
// src/u16.ts
var getU16Encoder = (options = {}) => numberEncoderFactory({
var getU16Encoder = (config = {}) => numberEncoderFactory({
config,
name: "u16",
options,
range: [0, Number("0xffff")],

@@ -326,14 +333,14 @@ set: (view, value, le) => view.setUint16(0, value, le),

});
var getU16Decoder = (options = {}) => numberDecoderFactory({
var getU16Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getUint16(0, le),
name: "u16",
options,
size: 2
});
var getU16Codec = (options = {}) => combineCodec(getU16Encoder(options), getU16Decoder(options));
var getU16Codec = (config = {}) => combineCodec(getU16Encoder(config), getU16Decoder(config));
// src/u32.ts
var getU32Encoder = (options = {}) => numberEncoderFactory({
var getU32Encoder = (config = {}) => numberEncoderFactory({
config,
name: "u32",
options,
range: [0, Number("0xffffffff")],

@@ -343,14 +350,14 @@ set: (view, value, le) => view.setUint32(0, value, le),

});
var getU32Decoder = (options = {}) => numberDecoderFactory({
var getU32Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getUint32(0, le),
name: "u32",
options,
size: 4
});
var getU32Codec = (options = {}) => combineCodec(getU32Encoder(options), getU32Decoder(options));
var getU32Codec = (config = {}) => combineCodec(getU32Encoder(config), getU32Decoder(config));
// src/u64.ts
var getU64Encoder = (options = {}) => numberEncoderFactory({
var getU64Encoder = (config = {}) => numberEncoderFactory({
config,
name: "u64",
options,
range: [0, BigInt("0xffffffffffffffff")],

@@ -360,14 +367,13 @@ set: (view, value, le) => view.setBigUint64(0, BigInt(value), le),

});
var getU64Decoder = (options = {}) => numberDecoderFactory({
var getU64Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getBigUint64(0, le),
name: "u64",
options,
size: 8
});
var getU64Codec = (options = {}) => combineCodec(getU64Encoder(options), getU64Decoder(options));
var getU64Codec = (config = {}) => combineCodec(getU64Encoder(config), getU64Decoder(config));
// src/u8.ts
var getU8Encoder = (options = {}) => numberEncoderFactory({
var getU8Encoder = () => numberEncoderFactory({
name: "u8",
options,
range: [0, Number("0xff")],

@@ -377,9 +383,8 @@ set: (view, value) => view.setUint8(0, value),

});
var getU8Decoder = (options = {}) => numberDecoderFactory({
var getU8Decoder = () => numberDecoderFactory({
get: (view) => view.getUint8(0),
name: "u8",
options,
size: 1
});
var getU8Codec = (options = {}) => combineCodec(getU8Encoder(options), getU8Decoder(options));
var getU8Codec = () => combineCodec(getU8Encoder(), getU8Decoder());

@@ -386,0 +391,0 @@ exports.Endian = Endian;

@@ -1,2 +0,2 @@

import { combineCodec, assertByteArrayIsNotEmptyForCodec, assertByteArrayHasEnoughBytesForCodec } from '@solana/codecs-core';
import { combineCodec, createEncoder, createDecoder, assertByteArrayIsNotEmptyForCodec, assertByteArrayHasEnoughBytesForCodec } from '@solana/codecs-core';

@@ -18,21 +18,9 @@ // src/assertions.ts

})(Endian || {});
function sharedNumberFactory(input) {
let littleEndian;
let defaultDescription = input.name;
if (input.size > 1) {
littleEndian = !("endian" in input.options) || input.options.endian === 0 /* LITTLE */;
defaultDescription += littleEndian ? "(le)" : "(be)";
}
return {
description: input.options.description ?? defaultDescription,
fixedSize: input.size,
littleEndian,
maxSize: input.size
};
function isLittleEndian(config) {
return config?.endian === 1 /* BIG */ ? false : true;
}
function numberEncoderFactory(input) {
const codecData = sharedNumberFactory(input);
return {
description: codecData.description,
encode(value) {
return createEncoder({
fixedSize: input.size,
write(value, bytes, offset) {
if (input.range) {

@@ -42,22 +30,18 @@ assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);

const arrayBuffer = new ArrayBuffer(input.size);
input.set(new DataView(arrayBuffer), value, codecData.littleEndian);
return new Uint8Array(arrayBuffer);
},
fixedSize: codecData.fixedSize,
maxSize: codecData.maxSize
};
input.set(new DataView(arrayBuffer), value, isLittleEndian(input.config));
bytes.set(new Uint8Array(arrayBuffer), offset);
return offset + input.size;
}
});
}
function numberDecoderFactory(input) {
const codecData = sharedNumberFactory(input);
return {
decode(bytes, offset = 0) {
assertByteArrayIsNotEmptyForCodec(codecData.description, bytes, offset);
assertByteArrayHasEnoughBytesForCodec(codecData.description, input.size, bytes, offset);
return createDecoder({
fixedSize: input.size,
read(bytes, offset = 0) {
assertByteArrayIsNotEmptyForCodec(input.name, bytes, offset);
assertByteArrayHasEnoughBytesForCodec(input.name, input.size, bytes, offset);
const view = new DataView(toArrayBuffer(bytes, offset, input.size));
return [input.get(view, codecData.littleEndian), offset + input.size];
},
description: codecData.description,
fixedSize: codecData.fixedSize,
maxSize: codecData.maxSize
};
return [input.get(view, isLittleEndian(input.config)), offset + input.size];
}
});
}

@@ -71,31 +55,31 @@ function toArrayBuffer(bytes, offset, length) {

// src/f32.ts
var getF32Encoder = (options = {}) => numberEncoderFactory({
var getF32Encoder = (config = {}) => numberEncoderFactory({
config,
name: "f32",
options,
set: (view, value, le) => view.setFloat32(0, value, le),
size: 4
});
var getF32Decoder = (options = {}) => numberDecoderFactory({
var getF32Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getFloat32(0, le),
name: "f32",
options,
size: 4
});
var getF32Codec = (options = {}) => combineCodec(getF32Encoder(options), getF32Decoder(options));
var getF64Encoder = (options = {}) => numberEncoderFactory({
var getF32Codec = (config = {}) => combineCodec(getF32Encoder(config), getF32Decoder(config));
var getF64Encoder = (config = {}) => numberEncoderFactory({
config,
name: "f64",
options,
set: (view, value, le) => view.setFloat64(0, value, le),
size: 8
});
var getF64Decoder = (options = {}) => numberDecoderFactory({
var getF64Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getFloat64(0, le),
name: "f64",
options,
size: 8
});
var getF64Codec = (options = {}) => combineCodec(getF64Encoder(options), getF64Decoder(options));
var getI128Encoder = (options = {}) => numberEncoderFactory({
var getF64Codec = (config = {}) => combineCodec(getF64Encoder(config), getF64Decoder(config));
var getI128Encoder = (config = {}) => numberEncoderFactory({
config,
name: "i128",
options,
range: [-BigInt("0x7fffffffffffffffffffffffffffffff") - 1n, BigInt("0x7fffffffffffffffffffffffffffffff")],

@@ -111,3 +95,4 @@ set: (view, value, le) => {

});
var getI128Decoder = (options = {}) => numberDecoderFactory({
var getI128Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => {

@@ -121,9 +106,8 @@ const leftOffset = le ? 8 : 0;

name: "i128",
options,
size: 16
});
var getI128Codec = (options = {}) => combineCodec(getI128Encoder(options), getI128Decoder(options));
var getI16Encoder = (options = {}) => numberEncoderFactory({
var getI128Codec = (config = {}) => combineCodec(getI128Encoder(config), getI128Decoder(config));
var getI16Encoder = (config = {}) => numberEncoderFactory({
config,
name: "i16",
options,
range: [-Number("0x7fff") - 1, Number("0x7fff")],

@@ -133,12 +117,12 @@ set: (view, value, le) => view.setInt16(0, value, le),

});
var getI16Decoder = (options = {}) => numberDecoderFactory({
var getI16Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getInt16(0, le),
name: "i16",
options,
size: 2
});
var getI16Codec = (options = {}) => combineCodec(getI16Encoder(options), getI16Decoder(options));
var getI32Encoder = (options = {}) => numberEncoderFactory({
var getI16Codec = (config = {}) => combineCodec(getI16Encoder(config), getI16Decoder(config));
var getI32Encoder = (config = {}) => numberEncoderFactory({
config,
name: "i32",
options,
range: [-Number("0x7fffffff") - 1, Number("0x7fffffff")],

@@ -148,12 +132,12 @@ set: (view, value, le) => view.setInt32(0, value, le),

});
var getI32Decoder = (options = {}) => numberDecoderFactory({
var getI32Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getInt32(0, le),
name: "i32",
options,
size: 4
});
var getI32Codec = (options = {}) => combineCodec(getI32Encoder(options), getI32Decoder(options));
var getI64Encoder = (options = {}) => numberEncoderFactory({
var getI32Codec = (config = {}) => combineCodec(getI32Encoder(config), getI32Decoder(config));
var getI64Encoder = (config = {}) => numberEncoderFactory({
config,
name: "i64",
options,
range: [-BigInt("0x7fffffffffffffff") - 1n, BigInt("0x7fffffffffffffff")],

@@ -163,12 +147,11 @@ set: (view, value, le) => view.setBigInt64(0, BigInt(value), le),

});
var getI64Decoder = (options = {}) => numberDecoderFactory({
var getI64Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getBigInt64(0, le),
name: "i64",
options,
size: 8
});
var getI64Codec = (options = {}) => combineCodec(getI64Encoder(options), getI64Decoder(options));
var getI8Encoder = (options = {}) => numberEncoderFactory({
var getI64Codec = (config = {}) => combineCodec(getI64Encoder(config), getI64Decoder(config));
var getI8Encoder = () => numberEncoderFactory({
name: "i8",
options,
range: [-Number("0x7f") - 1, Number("0x7f")],

@@ -178,14 +161,20 @@ set: (view, value) => view.setInt8(0, value),

});
var getI8Decoder = (options = {}) => numberDecoderFactory({
var getI8Decoder = () => numberDecoderFactory({
get: (view) => view.getInt8(0),
name: "i8",
options,
size: 1
});
var getI8Codec = (options = {}) => combineCodec(getI8Encoder(options), getI8Decoder(options));
var getShortU16Encoder = (options = {}) => ({
description: options.description ?? "shortU16",
encode: (value) => {
var getI8Codec = () => combineCodec(getI8Encoder(), getI8Decoder());
var getShortU16Encoder = () => createEncoder({
getSizeFromValue: (value) => {
if (value <= 127)
return 1;
if (value <= 16383)
return 2;
return 3;
},
maxSize: 3,
write: (value, bytes, offset) => {
assertNumberIsBetweenForCodec("shortU16", 0, 65535, value);
const bytes = [0];
const shortU16Bytes = [0];
for (let ii = 0; ; ii += 1) {

@@ -197,14 +186,14 @@ const alignedValue = value >> ii * 7;

const nextSevenBits = 127 & alignedValue;
bytes[ii] = nextSevenBits;
shortU16Bytes[ii] = nextSevenBits;
if (ii > 0) {
bytes[ii - 1] |= 128;
shortU16Bytes[ii - 1] |= 128;
}
}
return new Uint8Array(bytes);
},
fixedSize: null,
maxSize: 3
bytes.set(shortU16Bytes, offset);
return offset + shortU16Bytes.length;
}
});
var getShortU16Decoder = (options = {}) => ({
decode: (bytes, offset = 0) => {
var getShortU16Decoder = () => createDecoder({
maxSize: 3,
read: (bytes, offset) => {
let value = 0;

@@ -222,11 +211,8 @@ let byteCount = 0;

return [value, offset + byteCount];
},
description: options.description ?? "shortU16",
fixedSize: null,
maxSize: 3
}
});
var getShortU16Codec = (options = {}) => combineCodec(getShortU16Encoder(options), getShortU16Decoder(options));
var getU128Encoder = (options = {}) => numberEncoderFactory({
var getShortU16Codec = () => combineCodec(getShortU16Encoder(), getShortU16Decoder());
var getU128Encoder = (config = {}) => numberEncoderFactory({
config,
name: "u128",
options,
range: [0, BigInt("0xffffffffffffffffffffffffffffffff")],

@@ -242,3 +228,4 @@ set: (view, value, le) => {

});
var getU128Decoder = (options = {}) => numberDecoderFactory({
var getU128Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => {

@@ -252,9 +239,8 @@ const leftOffset = le ? 8 : 0;

name: "u128",
options,
size: 16
});
var getU128Codec = (options = {}) => combineCodec(getU128Encoder(options), getU128Decoder(options));
var getU16Encoder = (options = {}) => numberEncoderFactory({
var getU128Codec = (config = {}) => combineCodec(getU128Encoder(config), getU128Decoder(config));
var getU16Encoder = (config = {}) => numberEncoderFactory({
config,
name: "u16",
options,
range: [0, Number("0xffff")],

@@ -264,12 +250,12 @@ set: (view, value, le) => view.setUint16(0, value, le),

});
var getU16Decoder = (options = {}) => numberDecoderFactory({
var getU16Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getUint16(0, le),
name: "u16",
options,
size: 2
});
var getU16Codec = (options = {}) => combineCodec(getU16Encoder(options), getU16Decoder(options));
var getU32Encoder = (options = {}) => numberEncoderFactory({
var getU16Codec = (config = {}) => combineCodec(getU16Encoder(config), getU16Decoder(config));
var getU32Encoder = (config = {}) => numberEncoderFactory({
config,
name: "u32",
options,
range: [0, Number("0xffffffff")],

@@ -279,12 +265,12 @@ set: (view, value, le) => view.setUint32(0, value, le),

});
var getU32Decoder = (options = {}) => numberDecoderFactory({
var getU32Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getUint32(0, le),
name: "u32",
options,
size: 4
});
var getU32Codec = (options = {}) => combineCodec(getU32Encoder(options), getU32Decoder(options));
var getU64Encoder = (options = {}) => numberEncoderFactory({
var getU32Codec = (config = {}) => combineCodec(getU32Encoder(config), getU32Decoder(config));
var getU64Encoder = (config = {}) => numberEncoderFactory({
config,
name: "u64",
options,
range: [0, BigInt("0xffffffffffffffff")],

@@ -294,12 +280,11 @@ set: (view, value, le) => view.setBigUint64(0, BigInt(value), le),

});
var getU64Decoder = (options = {}) => numberDecoderFactory({
var getU64Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getBigUint64(0, le),
name: "u64",
options,
size: 8
});
var getU64Codec = (options = {}) => combineCodec(getU64Encoder(options), getU64Decoder(options));
var getU8Encoder = (options = {}) => numberEncoderFactory({
var getU64Codec = (config = {}) => combineCodec(getU64Encoder(config), getU64Decoder(config));
var getU8Encoder = () => numberEncoderFactory({
name: "u8",
options,
range: [0, Number("0xff")],

@@ -309,9 +294,8 @@ set: (view, value) => view.setUint8(0, value),

});
var getU8Decoder = (options = {}) => numberDecoderFactory({
var getU8Decoder = () => numberDecoderFactory({
get: (view) => view.getUint8(0),
name: "u8",
options,
size: 1
});
var getU8Codec = (options = {}) => combineCodec(getU8Encoder(options), getU8Decoder(options));
var getU8Codec = () => combineCodec(getU8Encoder(), getU8Decoder());

@@ -318,0 +302,0 @@ export { Endian, assertNumberIsBetweenForCodec, getF32Codec, getF32Decoder, getF32Encoder, getF64Codec, getF64Decoder, getF64Encoder, getI128Codec, getI128Decoder, getI128Encoder, getI16Codec, getI16Decoder, getI16Encoder, getI32Codec, getI32Decoder, getI32Encoder, getI64Codec, getI64Decoder, getI64Encoder, getI8Codec, getI8Decoder, getI8Encoder, getShortU16Codec, getShortU16Decoder, getShortU16Encoder, getU128Codec, getU128Decoder, getU128Encoder, getU16Codec, getU16Decoder, getU16Encoder, getU32Codec, getU32Decoder, getU32Encoder, getU64Codec, getU64Decoder, getU64Encoder, getU8Codec, getU8Decoder, getU8Encoder };

@@ -1,2 +0,2 @@

import { combineCodec, assertByteArrayIsNotEmptyForCodec, assertByteArrayHasEnoughBytesForCodec } from '@solana/codecs-core';
import { combineCodec, createEncoder, createDecoder, assertByteArrayIsNotEmptyForCodec, assertByteArrayHasEnoughBytesForCodec } from '@solana/codecs-core';

@@ -18,21 +18,9 @@ // src/assertions.ts

})(Endian || {});
function sharedNumberFactory(input) {
let littleEndian;
let defaultDescription = input.name;
if (input.size > 1) {
littleEndian = !("endian" in input.options) || input.options.endian === 0 /* LITTLE */;
defaultDescription += littleEndian ? "(le)" : "(be)";
}
return {
description: input.options.description ?? defaultDescription,
fixedSize: input.size,
littleEndian,
maxSize: input.size
};
function isLittleEndian(config) {
return config?.endian === 1 /* BIG */ ? false : true;
}
function numberEncoderFactory(input) {
const codecData = sharedNumberFactory(input);
return {
description: codecData.description,
encode(value) {
return createEncoder({
fixedSize: input.size,
write(value, bytes, offset) {
if (input.range) {

@@ -42,22 +30,18 @@ assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);

const arrayBuffer = new ArrayBuffer(input.size);
input.set(new DataView(arrayBuffer), value, codecData.littleEndian);
return new Uint8Array(arrayBuffer);
},
fixedSize: codecData.fixedSize,
maxSize: codecData.maxSize
};
input.set(new DataView(arrayBuffer), value, isLittleEndian(input.config));
bytes.set(new Uint8Array(arrayBuffer), offset);
return offset + input.size;
}
});
}
function numberDecoderFactory(input) {
const codecData = sharedNumberFactory(input);
return {
decode(bytes, offset = 0) {
assertByteArrayIsNotEmptyForCodec(codecData.description, bytes, offset);
assertByteArrayHasEnoughBytesForCodec(codecData.description, input.size, bytes, offset);
return createDecoder({
fixedSize: input.size,
read(bytes, offset = 0) {
assertByteArrayIsNotEmptyForCodec(input.name, bytes, offset);
assertByteArrayHasEnoughBytesForCodec(input.name, input.size, bytes, offset);
const view = new DataView(toArrayBuffer(bytes, offset, input.size));
return [input.get(view, codecData.littleEndian), offset + input.size];
},
description: codecData.description,
fixedSize: codecData.fixedSize,
maxSize: codecData.maxSize
};
return [input.get(view, isLittleEndian(input.config)), offset + input.size];
}
});
}

@@ -71,31 +55,31 @@ function toArrayBuffer(bytes, offset, length) {

// src/f32.ts
var getF32Encoder = (options = {}) => numberEncoderFactory({
var getF32Encoder = (config = {}) => numberEncoderFactory({
config,
name: "f32",
options,
set: (view, value, le) => view.setFloat32(0, value, le),
size: 4
});
var getF32Decoder = (options = {}) => numberDecoderFactory({
var getF32Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getFloat32(0, le),
name: "f32",
options,
size: 4
});
var getF32Codec = (options = {}) => combineCodec(getF32Encoder(options), getF32Decoder(options));
var getF64Encoder = (options = {}) => numberEncoderFactory({
var getF32Codec = (config = {}) => combineCodec(getF32Encoder(config), getF32Decoder(config));
var getF64Encoder = (config = {}) => numberEncoderFactory({
config,
name: "f64",
options,
set: (view, value, le) => view.setFloat64(0, value, le),
size: 8
});
var getF64Decoder = (options = {}) => numberDecoderFactory({
var getF64Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getFloat64(0, le),
name: "f64",
options,
size: 8
});
var getF64Codec = (options = {}) => combineCodec(getF64Encoder(options), getF64Decoder(options));
var getI128Encoder = (options = {}) => numberEncoderFactory({
var getF64Codec = (config = {}) => combineCodec(getF64Encoder(config), getF64Decoder(config));
var getI128Encoder = (config = {}) => numberEncoderFactory({
config,
name: "i128",
options,
range: [-BigInt("0x7fffffffffffffffffffffffffffffff") - 1n, BigInt("0x7fffffffffffffffffffffffffffffff")],

@@ -111,3 +95,4 @@ set: (view, value, le) => {

});
var getI128Decoder = (options = {}) => numberDecoderFactory({
var getI128Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => {

@@ -121,9 +106,8 @@ const leftOffset = le ? 8 : 0;

name: "i128",
options,
size: 16
});
var getI128Codec = (options = {}) => combineCodec(getI128Encoder(options), getI128Decoder(options));
var getI16Encoder = (options = {}) => numberEncoderFactory({
var getI128Codec = (config = {}) => combineCodec(getI128Encoder(config), getI128Decoder(config));
var getI16Encoder = (config = {}) => numberEncoderFactory({
config,
name: "i16",
options,
range: [-Number("0x7fff") - 1, Number("0x7fff")],

@@ -133,12 +117,12 @@ set: (view, value, le) => view.setInt16(0, value, le),

});
var getI16Decoder = (options = {}) => numberDecoderFactory({
var getI16Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getInt16(0, le),
name: "i16",
options,
size: 2
});
var getI16Codec = (options = {}) => combineCodec(getI16Encoder(options), getI16Decoder(options));
var getI32Encoder = (options = {}) => numberEncoderFactory({
var getI16Codec = (config = {}) => combineCodec(getI16Encoder(config), getI16Decoder(config));
var getI32Encoder = (config = {}) => numberEncoderFactory({
config,
name: "i32",
options,
range: [-Number("0x7fffffff") - 1, Number("0x7fffffff")],

@@ -148,12 +132,12 @@ set: (view, value, le) => view.setInt32(0, value, le),

});
var getI32Decoder = (options = {}) => numberDecoderFactory({
var getI32Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getInt32(0, le),
name: "i32",
options,
size: 4
});
var getI32Codec = (options = {}) => combineCodec(getI32Encoder(options), getI32Decoder(options));
var getI64Encoder = (options = {}) => numberEncoderFactory({
var getI32Codec = (config = {}) => combineCodec(getI32Encoder(config), getI32Decoder(config));
var getI64Encoder = (config = {}) => numberEncoderFactory({
config,
name: "i64",
options,
range: [-BigInt("0x7fffffffffffffff") - 1n, BigInt("0x7fffffffffffffff")],

@@ -163,12 +147,11 @@ set: (view, value, le) => view.setBigInt64(0, BigInt(value), le),

});
var getI64Decoder = (options = {}) => numberDecoderFactory({
var getI64Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getBigInt64(0, le),
name: "i64",
options,
size: 8
});
var getI64Codec = (options = {}) => combineCodec(getI64Encoder(options), getI64Decoder(options));
var getI8Encoder = (options = {}) => numberEncoderFactory({
var getI64Codec = (config = {}) => combineCodec(getI64Encoder(config), getI64Decoder(config));
var getI8Encoder = () => numberEncoderFactory({
name: "i8",
options,
range: [-Number("0x7f") - 1, Number("0x7f")],

@@ -178,14 +161,20 @@ set: (view, value) => view.setInt8(0, value),

});
var getI8Decoder = (options = {}) => numberDecoderFactory({
var getI8Decoder = () => numberDecoderFactory({
get: (view) => view.getInt8(0),
name: "i8",
options,
size: 1
});
var getI8Codec = (options = {}) => combineCodec(getI8Encoder(options), getI8Decoder(options));
var getShortU16Encoder = (options = {}) => ({
description: options.description ?? "shortU16",
encode: (value) => {
var getI8Codec = () => combineCodec(getI8Encoder(), getI8Decoder());
var getShortU16Encoder = () => createEncoder({
getSizeFromValue: (value) => {
if (value <= 127)
return 1;
if (value <= 16383)
return 2;
return 3;
},
maxSize: 3,
write: (value, bytes, offset) => {
assertNumberIsBetweenForCodec("shortU16", 0, 65535, value);
const bytes = [0];
const shortU16Bytes = [0];
for (let ii = 0; ; ii += 1) {

@@ -197,14 +186,14 @@ const alignedValue = value >> ii * 7;

const nextSevenBits = 127 & alignedValue;
bytes[ii] = nextSevenBits;
shortU16Bytes[ii] = nextSevenBits;
if (ii > 0) {
bytes[ii - 1] |= 128;
shortU16Bytes[ii - 1] |= 128;
}
}
return new Uint8Array(bytes);
},
fixedSize: null,
maxSize: 3
bytes.set(shortU16Bytes, offset);
return offset + shortU16Bytes.length;
}
});
var getShortU16Decoder = (options = {}) => ({
decode: (bytes, offset = 0) => {
var getShortU16Decoder = () => createDecoder({
maxSize: 3,
read: (bytes, offset) => {
let value = 0;

@@ -222,11 +211,8 @@ let byteCount = 0;

return [value, offset + byteCount];
},
description: options.description ?? "shortU16",
fixedSize: null,
maxSize: 3
}
});
var getShortU16Codec = (options = {}) => combineCodec(getShortU16Encoder(options), getShortU16Decoder(options));
var getU128Encoder = (options = {}) => numberEncoderFactory({
var getShortU16Codec = () => combineCodec(getShortU16Encoder(), getShortU16Decoder());
var getU128Encoder = (config = {}) => numberEncoderFactory({
config,
name: "u128",
options,
range: [0, BigInt("0xffffffffffffffffffffffffffffffff")],

@@ -242,3 +228,4 @@ set: (view, value, le) => {

});
var getU128Decoder = (options = {}) => numberDecoderFactory({
var getU128Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => {

@@ -252,9 +239,8 @@ const leftOffset = le ? 8 : 0;

name: "u128",
options,
size: 16
});
var getU128Codec = (options = {}) => combineCodec(getU128Encoder(options), getU128Decoder(options));
var getU16Encoder = (options = {}) => numberEncoderFactory({
var getU128Codec = (config = {}) => combineCodec(getU128Encoder(config), getU128Decoder(config));
var getU16Encoder = (config = {}) => numberEncoderFactory({
config,
name: "u16",
options,
range: [0, Number("0xffff")],

@@ -264,12 +250,12 @@ set: (view, value, le) => view.setUint16(0, value, le),

});
var getU16Decoder = (options = {}) => numberDecoderFactory({
var getU16Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getUint16(0, le),
name: "u16",
options,
size: 2
});
var getU16Codec = (options = {}) => combineCodec(getU16Encoder(options), getU16Decoder(options));
var getU32Encoder = (options = {}) => numberEncoderFactory({
var getU16Codec = (config = {}) => combineCodec(getU16Encoder(config), getU16Decoder(config));
var getU32Encoder = (config = {}) => numberEncoderFactory({
config,
name: "u32",
options,
range: [0, Number("0xffffffff")],

@@ -279,12 +265,12 @@ set: (view, value, le) => view.setUint32(0, value, le),

});
var getU32Decoder = (options = {}) => numberDecoderFactory({
var getU32Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getUint32(0, le),
name: "u32",
options,
size: 4
});
var getU32Codec = (options = {}) => combineCodec(getU32Encoder(options), getU32Decoder(options));
var getU64Encoder = (options = {}) => numberEncoderFactory({
var getU32Codec = (config = {}) => combineCodec(getU32Encoder(config), getU32Decoder(config));
var getU64Encoder = (config = {}) => numberEncoderFactory({
config,
name: "u64",
options,
range: [0, BigInt("0xffffffffffffffff")],

@@ -294,12 +280,11 @@ set: (view, value, le) => view.setBigUint64(0, BigInt(value), le),

});
var getU64Decoder = (options = {}) => numberDecoderFactory({
var getU64Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getBigUint64(0, le),
name: "u64",
options,
size: 8
});
var getU64Codec = (options = {}) => combineCodec(getU64Encoder(options), getU64Decoder(options));
var getU8Encoder = (options = {}) => numberEncoderFactory({
var getU64Codec = (config = {}) => combineCodec(getU64Encoder(config), getU64Decoder(config));
var getU8Encoder = () => numberEncoderFactory({
name: "u8",
options,
range: [0, Number("0xff")],

@@ -309,12 +294,9 @@ set: (view, value) => view.setUint8(0, value),

});
var getU8Decoder = (options = {}) => numberDecoderFactory({
var getU8Decoder = () => numberDecoderFactory({
get: (view) => view.getUint8(0),
name: "u8",
options,
size: 1
});
var getU8Codec = (options = {}) => combineCodec(getU8Encoder(options), getU8Decoder(options));
var getU8Codec = () => combineCodec(getU8Encoder(), getU8Decoder());
export { Endian, assertNumberIsBetweenForCodec, getF32Codec, getF32Decoder, getF32Encoder, getF64Codec, getF64Decoder, getF64Encoder, getI128Codec, getI128Decoder, getI128Encoder, getI16Codec, getI16Decoder, getI16Encoder, getI32Codec, getI32Decoder, getI32Encoder, getI64Codec, getI64Decoder, getI64Encoder, getI8Codec, getI8Decoder, getI8Encoder, getShortU16Codec, getShortU16Decoder, getShortU16Encoder, getU128Codec, getU128Decoder, getU128Encoder, getU16Codec, getU16Decoder, getU16Encoder, getU32Codec, getU32Decoder, getU32Encoder, getU64Codec, getU64Decoder, getU64Encoder, getU8Codec, getU8Decoder, getU8Encoder };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.node.js.map

@@ -5,45 +5,45 @@ this.globalThis = this.globalThis || {};

function u(e,r,o,t){if(t<r||t>o)throw new Error(`Codec [${e}] expected number to be in the range [${r}, ${o}], got ${t}.`)}var C=(o=>(o[o.LITTLE=0]="LITTLE",o[o.BIG=1]="BIG",o))(C||{});function a(e,r,o=0){if(r.length-o<=0)throw new Error(`Codec [${e}] cannot decode empty byte arrays.`)}function b(e,r,o,t=0){let d=o.length-t;if(d<r)throw new Error(`Codec [${e}] expected ${r} bytes, got ${d}.`)}function n(e,r,o){if(e.fixedSize!==r.fixedSize)throw new Error(`Encoder and decoder must have the same fixed size, got [${e.fixedSize}] and [${r.fixedSize}].`);if(e.maxSize!==r.maxSize)throw new Error(`Encoder and decoder must have the same max size, got [${e.maxSize}] and [${r.maxSize}].`);if(o===void 0&&e.description!==r.description)throw new Error(`Encoder and decoder must have the same description, got [${e.description}] and [${r.description}]. Pass a custom description as a third argument if you want to override the description and bypass this error.`);return {decode:r.decode,description:o??e.description,encode:e.encode,fixedSize:e.fixedSize,maxSize:e.maxSize}}function p(e){let r,o=e.name;return e.size>1&&(r=!("endian"in e.options)||e.options.endian===0,o+=r?"(le)":"(be)"),{description:e.options.description??o,fixedSize:e.size,littleEndian:r,maxSize:e.size}}function i(e){let r=p(e);return {description:r.description,encode(o){e.range&&u(e.name,e.range[0],e.range[1],o);let t=new ArrayBuffer(e.size);return e.set(new DataView(t),o,r.littleEndian),new Uint8Array(t)},fixedSize:r.fixedSize,maxSize:r.maxSize}}function c(e){let r=p(e);return {decode(o,t=0){a(r.description,o,t),b(r.description,e.size,o,t);let d=new DataView(x(o,t,e.size));return [e.get(d,r.littleEndian),t+e.size]},description:r.description,fixedSize:r.fixedSize,maxSize:r.maxSize}}function x(e,r,o){let t=e.byteOffset+(r??0),d=o??e.byteLength;return e.buffer.slice(t,t+d)}var E=(e={})=>i({name:"f32",options:e,set:(r,o,t)=>r.setFloat32(0,o,t),size:4}),z=(e={})=>c({get:(r,o)=>r.getFloat32(0,o),name:"f32",options:e,size:4}),me=(e={})=>n(E(e),z(e));var N=(e={})=>i({name:"f64",options:e,set:(r,o,t)=>r.setFloat64(0,o,t),size:8}),D=(e={})=>c({get:(r,o)=>r.getFloat64(0,o),name:"f64",options:e,size:8}),xe=(e={})=>n(N(e),D(e));var O=(e={})=>i({name:"i128",options:e,range:[-BigInt("0x7fffffffffffffffffffffffffffffff")-1n,BigInt("0x7fffffffffffffffffffffffffffffff")],set:(r,o,t)=>{let d=t?8:0,m=t?0:8,s=0xffffffffffffffffn;r.setBigInt64(d,BigInt(o)>>64n,t),r.setBigUint64(m,BigInt(o)&s,t);},size:16}),y=(e={})=>c({get:(r,o)=>{let t=o?8:0,d=o?0:8,m=r.getBigInt64(t,o),s=r.getBigUint64(d,o);return (m<<64n)+s},name:"i128",options:e,size:16}),Se=(e={})=>n(O(e),y(e));var l=(e={})=>i({name:"i16",options:e,range:[-+"0x7fff"-1,+"0x7fff"],set:(r,o,t)=>r.setInt16(0,o,t),size:2}),S=(e={})=>c({get:(r,o)=>r.getInt16(0,o),name:"i16",options:e,size:2}),Te=(e={})=>n(l(e),S(e));var h=(e={})=>i({name:"i32",options:e,range:[-+"0x7fffffff"-1,+"0x7fffffff"],set:(r,o,t)=>r.setInt32(0,o,t),size:4}),B=(e={})=>c({get:(r,o)=>r.getInt32(0,o),name:"i32",options:e,size:4}),Me=(e={})=>n(h(e),B(e));var I=(e={})=>i({name:"i64",options:e,range:[-BigInt("0x7fffffffffffffff")-1n,BigInt("0x7fffffffffffffff")],set:(r,o,t)=>r.setBigInt64(0,BigInt(o),t),size:8}),F=(e={})=>c({get:(r,o)=>r.getBigInt64(0,o),name:"i64",options:e,size:8}),Re=(e={})=>n(I(e),F(e));var U=(e={})=>i({name:"i8",options:e,range:[-+"0x7f"-1,+"0x7f"],set:(r,o)=>r.setInt8(0,o),size:1}),w=(e={})=>c({get:r=>r.getInt8(0),name:"i8",options:e,size:1}),tr=(e={})=>n(U(e),w(e));var v=(e={})=>({description:e.description??"shortU16",encode:r=>{u("shortU16",0,65535,r);let o=[0];for(let t=0;;t+=1){let d=r>>t*7;if(d===0)break;let m=127&d;o[t]=m,t>0&&(o[t-1]|=128);}return new Uint8Array(o)},fixedSize:null,maxSize:3}),T=(e={})=>({decode:(r,o=0)=>{let t=0,d=0;for(;++d;){let m=d-1,s=r[o+m],g=127&s;if(t|=g<<m*7,!(s&128))break}return [t,o+d]},description:e.description??"shortU16",fixedSize:null,maxSize:3}),ar=(e={})=>n(v(e),T(e));var $=(e={})=>i({name:"u128",options:e,range:[0,BigInt("0xffffffffffffffffffffffffffffffff")],set:(r,o,t)=>{let d=t?8:0,m=t?0:8,s=0xffffffffffffffffn;r.setBigUint64(d,BigInt(o)>>64n,t),r.setBigUint64(m,BigInt(o)&s,t);},size:16}),A=(e={})=>c({get:(r,o)=>{let t=o?8:0,d=o?0:8,m=r.getBigUint64(t,o),s=r.getBigUint64(d,o);return (m<<64n)+s},name:"u128",options:e,size:16}),Nr=(e={})=>n($(e),A(e));var L=(e={})=>i({name:"u16",options:e,range:[0,+"0xffff"],set:(r,o,t)=>r.setUint16(0,o,t),size:2}),V=(e={})=>c({get:(r,o)=>r.getUint16(0,o),name:"u16",options:e,size:2}),Ir=(e={})=>n(L(e),V(e));var _=(e={})=>i({name:"u32",options:e,range:[0,+"0xffffffff"],set:(r,o,t)=>r.setUint32(0,o,t),size:4}),k=(e={})=>c({get:(r,o)=>r.getUint32(0,o),name:"u32",options:e,size:4}),Lr=(e={})=>n(_(e),k(e));var H=(e={})=>i({name:"u64",options:e,range:[0,BigInt("0xffffffffffffffff")],set:(r,o,t)=>r.setBigUint64(0,BigInt(o),t),size:8}),M=(e={})=>c({get:(r,o)=>r.getBigUint64(0,o),name:"u64",options:e,size:8}),jr=(e={})=>n(H(e),M(e));var G=(e={})=>i({name:"u8",options:e,range:[0,+"0xff"],set:(r,o)=>r.setUint8(0,o),size:1}),P=(e={})=>c({get:r=>r.getUint8(0),name:"u8",options:e,size:1}),Yr=(e={})=>n(G(e),P(e));
function x(e,r,o,t){if(t<r||t>o)throw new Error(`Codec [${e}] expected number to be in the range [${r}, ${o}], got ${t}.`)}var S=(o=>(o[o.LITTLE=0]="LITTLE",o[o.BIG=1]="BIG",o))(S||{});function s(e,r,o=0){if(r.length-o<=0)throw new Error(`Codec [${e}] cannot decode empty byte arrays.`)}function z(e,r,o,t=0){let n=o.length-t;if(n<r)throw new Error(`Codec [${e}] expected ${r} bytes, got ${n}.`)}function F(e,r){return "fixedSize"in r?r.fixedSize:r.getSizeFromValue(e)}function a(e){return Object.freeze({...e,encode:r=>{let o=new Uint8Array(F(r,e));return e.write(r,o,0),o}})}function g(e){return Object.freeze({...e,decode:(r,o=0)=>e.read(r,o)[0]})}function b(e){return "fixedSize"in e&&typeof e.fixedSize=="number"}function i(e,r){if(b(e)!==b(r))throw new Error("Encoder and decoder must either both be fixed-size or variable-size.");if(b(e)&&b(r)&&e.fixedSize!==r.fixedSize)throw new Error(`Encoder and decoder must have the same fixed size, got [${e.fixedSize}] and [${r.fixedSize}].`);if(!b(e)&&!b(r)&&e.maxSize!==r.maxSize)throw new Error(`Encoder and decoder must have the same max size, got [${e.maxSize}] and [${r.maxSize}].`);return {...r,...e,decode:r.decode,encode:e.encode,read:r.read,write:e.write}}function C(e){return (e==null?void 0:e.endian)!==1}function c(e){return a({fixedSize:e.size,write(r,o,t){e.range&&x(e.name,e.range[0],e.range[1],r);let n=new ArrayBuffer(e.size);return e.set(new DataView(n),r,C(e.config)),o.set(new Uint8Array(n),t),t+e.size}})}function d(e){return g({fixedSize:e.size,read(r,o=0){s(e.name,r,o),z(e.name,e.size,r,o);let t=new DataView(p(r,o,e.size));return [e.get(t,C(e.config)),o+e.size]}})}function p(e,r,o){let t=e.byteOffset+(r!=null?r:0),n=o!=null?o:e.byteLength;return e.buffer.slice(t,t+n)}var E=(e={})=>c({config:e,name:"f32",set:(r,o,t)=>r.setFloat32(0,o,t),size:4}),D=(e={})=>d({config:e,get:(r,o)=>r.getFloat32(0,o),name:"f32",size:4}),xe=(e={})=>i(E(e),D(e));var N=(e={})=>c({config:e,name:"f64",set:(r,o,t)=>r.setFloat64(0,o,t),size:8}),y=(e={})=>d({config:e,get:(r,o)=>r.getFloat64(0,o),name:"f64",size:8}),pe=(e={})=>i(N(e),y(e));var I=(e={})=>c({config:e,name:"i128",range:[-BigInt("0x7fffffffffffffffffffffffffffffff")-1n,BigInt("0x7fffffffffffffffffffffffffffffff")],set:(r,o,t)=>{let n=t?8:0,m=t?0:8,u=0xffffffffffffffffn;r.setBigInt64(n,BigInt(o)>>64n,t),r.setBigUint64(m,BigInt(o)&u,t);},size:16}),l=(e={})=>d({config:e,get:(r,o)=>{let t=o?8:0,n=o?0:8,m=r.getBigInt64(t,o),u=r.getBigUint64(n,o);return (m<<64n)+u},name:"i128",size:16}),we=(e={})=>i(I(e),l(e));var h=(e={})=>c({config:e,name:"i16",range:[-+"0x7fff"-1,+"0x7fff"],set:(r,o,t)=>r.setInt16(0,o,t),size:2}),w=(e={})=>d({config:e,get:(r,o)=>r.getInt16(0,o),name:"i16",size:2}),$e=(e={})=>i(h(e),w(e));var U=(e={})=>c({config:e,name:"i32",range:[-+"0x7fffffff"-1,+"0x7fffffff"],set:(r,o,t)=>r.setInt32(0,o,t),size:4}),B=(e={})=>d({config:e,get:(r,o)=>r.getInt32(0,o),name:"i32",size:4}),qe=(e={})=>i(U(e),B(e));var T=(e={})=>c({config:e,name:"i64",range:[-BigInt("0x7fffffffffffffff")-1n,BigInt("0x7fffffffffffffff")],set:(r,o,t)=>r.setBigInt64(0,BigInt(o),t),size:8}),O=(e={})=>d({config:e,get:(r,o)=>r.getBigInt64(0,o),name:"i64",size:8}),Ye=(e={})=>i(T(e),O(e));var v=()=>c({name:"i8",range:[-+"0x7f"-1,+"0x7f"],set:(e,r)=>e.setInt8(0,r),size:1}),V=()=>d({get:e=>e.getInt8(0),name:"i8",size:1}),cr=()=>i(v(),V());var A=()=>a({getSizeFromValue:e=>e<=127?1:e<=16383?2:3,maxSize:3,write:(e,r,o)=>{x("shortU16",0,65535,e);let t=[0];for(let n=0;;n+=1){let m=e>>n*7;if(m===0)break;let u=127&m;t[n]=u,n>0&&(t[n-1]|=128);}return r.set(t,o),o+t.length}}),$=()=>g({maxSize:3,read:(e,r)=>{let o=0,t=0;for(;++t;){let n=t-1,m=e[r+n],u=127&m;if(o|=u<<n*7,!(m&128))break}return [o,r+t]}}),sr=()=>i(A(),$());var L=(e={})=>c({config:e,name:"u128",range:[0,BigInt("0xffffffffffffffffffffffffffffffff")],set:(r,o,t)=>{let n=t?8:0,m=t?0:8,u=0xffffffffffffffffn;r.setBigUint64(n,BigInt(o)>>64n,t),r.setBigUint64(m,BigInt(o)&u,t);},size:16}),_=(e={})=>d({config:e,get:(r,o)=>{let t=o?8:0,n=o?0:8,m=r.getBigUint64(t,o),u=r.getBigUint64(n,o);return (m<<64n)+u},name:"u128",size:16}),Nr=(e={})=>i(L(e),_(e));var k=(e={})=>c({config:e,name:"u16",range:[0,+"0xffff"],set:(r,o,t)=>r.setUint16(0,o,t),size:2}),j=(e={})=>d({config:e,get:(r,o)=>r.getUint16(0,o),name:"u16",size:2}),Tr=(e={})=>i(k(e),j(e));var G=(e={})=>c({config:e,name:"u32",range:[0,+"0xffffffff"],set:(r,o,t)=>r.setUint32(0,o,t),size:4}),H=(e={})=>d({config:e,get:(r,o)=>r.getUint32(0,o),name:"u32",size:4}),kr=(e={})=>i(G(e),H(e));var M=(e={})=>c({config:e,name:"u64",range:[0,BigInt("0xffffffffffffffff")],set:(r,o,t)=>r.setBigUint64(0,BigInt(o),t),size:8}),q=(e={})=>d({config:e,get:(r,o)=>r.getBigUint64(0,o),name:"u64",size:8}),Pr=(e={})=>i(M(e),q(e));var J=()=>c({name:"u8",range:[0,+"0xff"],set:(e,r)=>e.setUint8(0,r),size:1}),K=()=>d({get:e=>e.getUint8(0),name:"u8",size:1}),ro=()=>i(J(),K());
exports.Endian = C;
exports.assertNumberIsBetweenForCodec = u;
exports.getF32Codec = me;
exports.getF32Decoder = z;
exports.Endian = S;
exports.assertNumberIsBetweenForCodec = x;
exports.getF32Codec = xe;
exports.getF32Decoder = D;
exports.getF32Encoder = E;
exports.getF64Codec = xe;
exports.getF64Decoder = D;
exports.getF64Codec = pe;
exports.getF64Decoder = y;
exports.getF64Encoder = N;
exports.getI128Codec = Se;
exports.getI128Decoder = y;
exports.getI128Encoder = O;
exports.getI16Codec = Te;
exports.getI16Decoder = S;
exports.getI16Encoder = l;
exports.getI32Codec = Me;
exports.getI128Codec = we;
exports.getI128Decoder = l;
exports.getI128Encoder = I;
exports.getI16Codec = $e;
exports.getI16Decoder = w;
exports.getI16Encoder = h;
exports.getI32Codec = qe;
exports.getI32Decoder = B;
exports.getI32Encoder = h;
exports.getI64Codec = Re;
exports.getI64Decoder = F;
exports.getI64Encoder = I;
exports.getI8Codec = tr;
exports.getI8Decoder = w;
exports.getI8Encoder = U;
exports.getShortU16Codec = ar;
exports.getShortU16Decoder = T;
exports.getShortU16Encoder = v;
exports.getI32Encoder = U;
exports.getI64Codec = Ye;
exports.getI64Decoder = O;
exports.getI64Encoder = T;
exports.getI8Codec = cr;
exports.getI8Decoder = V;
exports.getI8Encoder = v;
exports.getShortU16Codec = sr;
exports.getShortU16Decoder = $;
exports.getShortU16Encoder = A;
exports.getU128Codec = Nr;
exports.getU128Decoder = A;
exports.getU128Encoder = $;
exports.getU16Codec = Ir;
exports.getU16Decoder = V;
exports.getU16Encoder = L;
exports.getU32Codec = Lr;
exports.getU32Decoder = k;
exports.getU32Encoder = _;
exports.getU64Codec = jr;
exports.getU64Decoder = M;
exports.getU64Encoder = H;
exports.getU8Codec = Yr;
exports.getU8Decoder = P;
exports.getU8Encoder = G;
exports.getU128Decoder = _;
exports.getU128Encoder = L;
exports.getU16Codec = Tr;
exports.getU16Decoder = j;
exports.getU16Encoder = k;
exports.getU32Codec = kr;
exports.getU32Decoder = H;
exports.getU32Encoder = G;
exports.getU64Codec = Pr;
exports.getU64Decoder = q;
exports.getU64Encoder = M;
exports.getU8Codec = ro;
exports.getU8Decoder = K;
exports.getU8Encoder = J;

@@ -50,0 +50,0 @@ return exports;

@@ -1,12 +0,16 @@

import { BaseCodecOptions, Codec, Decoder, Encoder } from '@solana/codecs-core';
import { Codec, Decoder, Encoder, FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder } from '@solana/codecs-core';
/** Defines a encoder for numbers and bigints. */
export type NumberEncoder = Encoder<number> | Encoder<number | bigint>;
/** Defines a fixed-size encoder for numbers and bigints. */
export type FixedSizeNumberEncoder<TSize extends number = number> = FixedSizeEncoder<number, TSize> | FixedSizeEncoder<number | bigint, TSize>;
/** Defines a decoder for numbers and bigints. */
export type NumberDecoder = Decoder<number> | Decoder<bigint>;
/** Defines a fixed-size decoder for numbers and bigints. */
export type FixedSizeNumberDecoder<TSize extends number = number> = FixedSizeDecoder<number, TSize> | FixedSizeDecoder<bigint, TSize>;
/** Defines a codec for numbers and bigints. */
export type NumberCodec = Codec<number> | Codec<number | bigint, bigint>;
/** Defines the options for u8 and i8 codecs. */
export type SingleByteNumberCodecOptions = BaseCodecOptions;
/** Defines the options for number codecs that use more than one byte. */
export type NumberCodecOptions = BaseCodecOptions & {
/** Defines a fixed-size codec for numbers and bigints. */
export type FixedSizeNumberCodec<TSize extends number = number> = FixedSizeCodec<number, number, TSize> | FixedSizeCodec<number | bigint, bigint, TSize>;
/** Defines the config for number codecs that use more than one byte. */
export type NumberCodecConfig = {
/**

@@ -13,0 +17,0 @@ * Whether the serializer should use little-endian or big-endian encoding.

@@ -1,6 +0,6 @@

import { Codec, Decoder, Encoder } from '@solana/codecs-core';
import { NumberCodecOptions } from './common';
export declare const getF32Encoder: (options?: NumberCodecOptions) => Encoder<number>;
export declare const getF32Decoder: (options?: NumberCodecOptions) => Decoder<number>;
export declare const getF32Codec: (options?: NumberCodecOptions) => Codec<number>;
import { FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder } from '@solana/codecs-core';
import { NumberCodecConfig } from './common.js';
export declare const getF32Encoder: (config?: NumberCodecConfig) => FixedSizeEncoder<number, 4>;
export declare const getF32Decoder: (config?: NumberCodecConfig) => FixedSizeDecoder<number, 4>;
export declare const getF32Codec: (config?: NumberCodecConfig) => FixedSizeCodec<number, number, 4>;
//# sourceMappingURL=f32.d.ts.map

@@ -1,6 +0,6 @@

import { Codec, Decoder, Encoder } from '@solana/codecs-core';
import { NumberCodecOptions } from './common';
export declare const getF64Encoder: (options?: NumberCodecOptions) => Encoder<number>;
export declare const getF64Decoder: (options?: NumberCodecOptions) => Decoder<number>;
export declare const getF64Codec: (options?: NumberCodecOptions) => Codec<number>;
import { FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder } from '@solana/codecs-core';
import { NumberCodecConfig } from './common.js';
export declare const getF64Encoder: (config?: NumberCodecConfig) => FixedSizeEncoder<number, 8>;
export declare const getF64Decoder: (config?: NumberCodecConfig) => FixedSizeDecoder<number, 8>;
export declare const getF64Codec: (config?: NumberCodecConfig) => FixedSizeCodec<number, number, 8>;
//# sourceMappingURL=f64.d.ts.map

@@ -1,6 +0,6 @@

import { Codec, Decoder, Encoder } from '@solana/codecs-core';
import { NumberCodecOptions } from './common';
export declare const getI128Encoder: (options?: NumberCodecOptions) => Encoder<number | bigint>;
export declare const getI128Decoder: (options?: NumberCodecOptions) => Decoder<bigint>;
export declare const getI128Codec: (options?: NumberCodecOptions) => Codec<number | bigint, bigint>;
import { FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder } from '@solana/codecs-core';
import { NumberCodecConfig } from './common.js';
export declare const getI128Encoder: (config?: NumberCodecConfig) => FixedSizeEncoder<number | bigint, 16>;
export declare const getI128Decoder: (config?: NumberCodecConfig) => FixedSizeDecoder<bigint, 16>;
export declare const getI128Codec: (config?: NumberCodecConfig) => FixedSizeCodec<number | bigint, bigint, 16>;
//# sourceMappingURL=i128.d.ts.map

@@ -1,6 +0,6 @@

import { Codec, Decoder, Encoder } from '@solana/codecs-core';
import { NumberCodecOptions } from './common';
export declare const getI16Encoder: (options?: NumberCodecOptions) => Encoder<number>;
export declare const getI16Decoder: (options?: NumberCodecOptions) => Decoder<number>;
export declare const getI16Codec: (options?: NumberCodecOptions) => Codec<number>;
import { FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder } from '@solana/codecs-core';
import { NumberCodecConfig } from './common.js';
export declare const getI16Encoder: (config?: NumberCodecConfig) => FixedSizeEncoder<number, 2>;
export declare const getI16Decoder: (config?: NumberCodecConfig) => FixedSizeDecoder<number, 2>;
export declare const getI16Codec: (config?: NumberCodecConfig) => FixedSizeCodec<number, number, 2>;
//# sourceMappingURL=i16.d.ts.map

@@ -1,6 +0,6 @@

import { Codec, Decoder, Encoder } from '@solana/codecs-core';
import { NumberCodecOptions } from './common';
export declare const getI32Encoder: (options?: NumberCodecOptions) => Encoder<number>;
export declare const getI32Decoder: (options?: NumberCodecOptions) => Decoder<number>;
export declare const getI32Codec: (options?: NumberCodecOptions) => Codec<number>;
import { FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder } from '@solana/codecs-core';
import { NumberCodecConfig } from './common.js';
export declare const getI32Encoder: (config?: NumberCodecConfig) => FixedSizeEncoder<number, 4>;
export declare const getI32Decoder: (config?: NumberCodecConfig) => FixedSizeDecoder<number, 4>;
export declare const getI32Codec: (config?: NumberCodecConfig) => FixedSizeCodec<number, number, 4>;
//# sourceMappingURL=i32.d.ts.map

@@ -1,6 +0,6 @@

import { Codec, Decoder, Encoder } from '@solana/codecs-core';
import { NumberCodecOptions } from './common';
export declare const getI64Encoder: (options?: NumberCodecOptions) => Encoder<number | bigint>;
export declare const getI64Decoder: (options?: NumberCodecOptions) => Decoder<bigint>;
export declare const getI64Codec: (options?: NumberCodecOptions) => Codec<number | bigint, bigint>;
import { FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder } from '@solana/codecs-core';
import { NumberCodecConfig } from './common.js';
export declare const getI64Encoder: (config?: NumberCodecConfig) => FixedSizeEncoder<number | bigint, 8>;
export declare const getI64Decoder: (config?: NumberCodecConfig) => FixedSizeDecoder<bigint, 8>;
export declare const getI64Codec: (config?: NumberCodecConfig) => FixedSizeCodec<number | bigint, bigint, 8>;
//# sourceMappingURL=i64.d.ts.map

@@ -1,6 +0,5 @@

import { Codec, Decoder, Encoder } from '@solana/codecs-core';
import { SingleByteNumberCodecOptions } from './common';
export declare const getI8Encoder: (options?: SingleByteNumberCodecOptions) => Encoder<number>;
export declare const getI8Decoder: (options?: SingleByteNumberCodecOptions) => Decoder<number>;
export declare const getI8Codec: (options?: SingleByteNumberCodecOptions) => Codec<number>;
import { FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder } from '@solana/codecs-core';
export declare const getI8Encoder: () => FixedSizeEncoder<number, 1>;
export declare const getI8Decoder: () => FixedSizeDecoder<number, 1>;
export declare const getI8Codec: () => FixedSizeCodec<number, number, 1>;
//# sourceMappingURL=i8.d.ts.map

@@ -1,16 +0,16 @@

export * from './assertions';
export * from './common';
export * from './f32';
export * from './f64';
export * from './i128';
export * from './i16';
export * from './i32';
export * from './i64';
export * from './i8';
export * from './short-u16';
export * from './u128';
export * from './u16';
export * from './u32';
export * from './u64';
export * from './u8';
export * from './assertions.js';
export * from './common.js';
export * from './f32.js';
export * from './f64.js';
export * from './i128.js';
export * from './i16.js';
export * from './i32.js';
export * from './i64.js';
export * from './i8.js';
export * from './short-u16.js';
export * from './u128.js';
export * from './u16.js';
export * from './u32.js';
export * from './u64.js';
export * from './u8.js';
//# sourceMappingURL=index.d.ts.map

@@ -1,11 +0,7 @@

import { BaseCodecOptions, Codec, Decoder, Encoder } from '@solana/codecs-core';
import { VariableSizeCodec, VariableSizeDecoder, VariableSizeEncoder } from '@solana/codecs-core';
/**
* Defines the options for the shortU16 serializer.
*/
export type ShortU16CodecOptions = BaseCodecOptions;
/**
* Encodes short u16 numbers.
* @see {@link getShortU16Codec} for a more detailed description.
*/
export declare const getShortU16Encoder: (options?: ShortU16CodecOptions) => Encoder<number>;
export declare const getShortU16Encoder: () => VariableSizeEncoder<number>;
/**

@@ -15,3 +11,3 @@ * Decodes short u16 numbers.

*/
export declare const getShortU16Decoder: (options?: ShortU16CodecOptions) => Decoder<number>;
export declare const getShortU16Decoder: () => VariableSizeDecoder<number>;
/**

@@ -26,3 +22,3 @@ * Encodes and decodes short u16 numbers.

*/
export declare const getShortU16Codec: (options?: ShortU16CodecOptions) => Codec<number>;
export declare const getShortU16Codec: () => VariableSizeCodec<number>;
//# sourceMappingURL=short-u16.d.ts.map

@@ -1,6 +0,6 @@

import { Codec, Decoder, Encoder } from '@solana/codecs-core';
import { NumberCodecOptions } from './common';
export declare const getU128Encoder: (options?: NumberCodecOptions) => Encoder<number | bigint>;
export declare const getU128Decoder: (options?: NumberCodecOptions) => Decoder<bigint>;
export declare const getU128Codec: (options?: NumberCodecOptions) => Codec<number | bigint, bigint>;
import { FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder } from '@solana/codecs-core';
import { NumberCodecConfig } from './common.js';
export declare const getU128Encoder: (config?: NumberCodecConfig) => FixedSizeEncoder<number | bigint, 16>;
export declare const getU128Decoder: (config?: NumberCodecConfig) => FixedSizeDecoder<bigint, 16>;
export declare const getU128Codec: (config?: NumberCodecConfig) => FixedSizeCodec<number | bigint, bigint, 16>;
//# sourceMappingURL=u128.d.ts.map

@@ -1,6 +0,6 @@

import { Codec, Decoder, Encoder } from '@solana/codecs-core';
import { NumberCodecOptions } from './common';
export declare const getU16Encoder: (options?: NumberCodecOptions) => Encoder<number>;
export declare const getU16Decoder: (options?: NumberCodecOptions) => Decoder<number>;
export declare const getU16Codec: (options?: NumberCodecOptions) => Codec<number>;
import { FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder } from '@solana/codecs-core';
import { NumberCodecConfig } from './common.js';
export declare const getU16Encoder: (config?: NumberCodecConfig) => FixedSizeEncoder<number, 2>;
export declare const getU16Decoder: (config?: NumberCodecConfig) => FixedSizeDecoder<number, 2>;
export declare const getU16Codec: (config?: NumberCodecConfig) => FixedSizeCodec<number, number, 2>;
//# sourceMappingURL=u16.d.ts.map

@@ -1,6 +0,6 @@

import { Codec, Decoder, Encoder } from '@solana/codecs-core';
import { NumberCodecOptions } from './common';
export declare const getU32Encoder: (options?: NumberCodecOptions) => Encoder<number>;
export declare const getU32Decoder: (options?: NumberCodecOptions) => Decoder<number>;
export declare const getU32Codec: (options?: NumberCodecOptions) => Codec<number>;
import { FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder } from '@solana/codecs-core';
import { NumberCodecConfig } from './common.js';
export declare const getU32Encoder: (config?: NumberCodecConfig) => FixedSizeEncoder<number, 4>;
export declare const getU32Decoder: (config?: NumberCodecConfig) => FixedSizeDecoder<number, 4>;
export declare const getU32Codec: (config?: NumberCodecConfig) => FixedSizeCodec<number, number, 4>;
//# sourceMappingURL=u32.d.ts.map

@@ -1,6 +0,6 @@

import { Codec, Decoder, Encoder } from '@solana/codecs-core';
import { NumberCodecOptions } from './common';
export declare const getU64Encoder: (options?: NumberCodecOptions) => Encoder<number | bigint>;
export declare const getU64Decoder: (options?: NumberCodecOptions) => Decoder<bigint>;
export declare const getU64Codec: (options?: NumberCodecOptions) => Codec<number | bigint, bigint>;
import { FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder } from '@solana/codecs-core';
import { NumberCodecConfig } from './common.js';
export declare const getU64Encoder: (config?: NumberCodecConfig) => FixedSizeEncoder<number | bigint, 8>;
export declare const getU64Decoder: (config?: NumberCodecConfig) => FixedSizeDecoder<bigint, 8>;
export declare const getU64Codec: (config?: NumberCodecConfig) => FixedSizeCodec<number | bigint, bigint, 8>;
//# sourceMappingURL=u64.d.ts.map

@@ -1,6 +0,5 @@

import { Codec, Decoder, Encoder } from '@solana/codecs-core';
import { SingleByteNumberCodecOptions } from './common';
export declare const getU8Encoder: (options?: SingleByteNumberCodecOptions) => Encoder<number>;
export declare const getU8Decoder: (options?: SingleByteNumberCodecOptions) => Decoder<number>;
export declare const getU8Codec: (options?: SingleByteNumberCodecOptions) => Codec<number>;
import { FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder } from '@solana/codecs-core';
export declare const getU8Encoder: () => FixedSizeEncoder<number, 1>;
export declare const getU8Decoder: () => FixedSizeDecoder<number, 1>;
export declare const getU8Codec: () => FixedSizeCodec<number, number, 1>;
//# sourceMappingURL=u8.d.ts.map

@@ -1,18 +0,18 @@

import { Decoder, Encoder } from '@solana/codecs-core';
import { NumberCodecOptions, SingleByteNumberCodecOptions } from './common';
type NumberFactorySharedInput = {
import { FixedSizeDecoder, FixedSizeEncoder } from '@solana/codecs-core';
import { NumberCodecConfig } from './common.js';
type NumberFactorySharedInput<TSize extends number> = {
name: string;
size: number;
options: SingleByteNumberCodecOptions | NumberCodecOptions;
size: TSize;
config?: NumberCodecConfig;
};
type NumberFactoryEncoderInput<T> = NumberFactorySharedInput & {
type NumberFactoryEncoderInput<TFrom, TSize extends number> = NumberFactorySharedInput<TSize> & {
range?: [number | bigint, number | bigint];
set: (view: DataView, value: T, littleEndian?: boolean) => void;
set: (view: DataView, value: TFrom, littleEndian?: boolean) => void;
};
type NumberFactoryDecoderInput<T> = NumberFactorySharedInput & {
get: (view: DataView, littleEndian?: boolean) => T;
type NumberFactoryDecoderInput<TTo, TSize extends number> = NumberFactorySharedInput<TSize> & {
get: (view: DataView, littleEndian?: boolean) => TTo;
};
export declare function numberEncoderFactory<T extends number | bigint>(input: NumberFactoryEncoderInput<T>): Encoder<T>;
export declare function numberDecoderFactory<T extends number | bigint>(input: NumberFactoryDecoderInput<T>): Decoder<T>;
export declare function numberEncoderFactory<TFrom extends number | bigint, TSize extends number>(input: NumberFactoryEncoderInput<TFrom, TSize>): FixedSizeEncoder<TFrom, TSize>;
export declare function numberDecoderFactory<TTo extends number | bigint, TSize extends number>(input: NumberFactoryDecoderInput<TTo, TSize>): FixedSizeDecoder<TTo, TSize>;
export {};
//# sourceMappingURL=utils.d.ts.map
{
"name": "@solana/codecs-numbers",
"version": "2.0.0-experimental.8c5ac55",
"version": "2.0.0-experimental.8de8e11",
"description": "Codecs for numbers of different sizes and endianness",

@@ -52,3 +52,3 @@ "exports": {

"dependencies": {
"@solana/codecs-core": "2.0.0-experimental.8c5ac55"
"@solana/codecs-core": "2.0.0-experimental.8de8e11"
},

@@ -58,3 +58,3 @@ "devDependencies": {

"@swc/jest": "^0.2.29",
"@types/jest": "^29.5.6",
"@types/jest": "^29.5.11",
"@typescript-eslint/eslint-plugin": "^6.7.0",

@@ -70,4 +70,4 @@ "@typescript-eslint/parser": "^6.3.0",

"jest-runner-prettier": "^1.0.0",
"prettier": "^2.8",
"tsup": "7.2.0",
"prettier": "^3.1",
"tsup": "^8.0.1",
"typescript": "^5.2.2",

@@ -89,3 +89,3 @@ "version-from-git": "^1.1.1",

"compile:js": "tsup --config build-scripts/tsup.config.library.ts",
"compile:typedefs": "tsc -p ./tsconfig.declarations.json",
"compile:typedefs": "tsc -p ./tsconfig.declarations.json && node node_modules/build-scripts/add-js-extension-to-types.mjs",
"dev": "jest -c node_modules/test-config/jest-dev.config.ts --rootDir . --watch",

@@ -92,0 +92,0 @@ "publish-packages": "pnpm publish --tag experimental --access public --no-git-checks",

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

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

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

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

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc