first commit

This commit is contained in:
Stefan Hacker
2026-04-03 09:38:48 +02:00
commit 37ad745546
47450 changed files with 3120798 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
import type { IReader, IReaderResettable } from '@jsonjoy.com/buffers/lib';
import type { BinaryJsonDecoder } from '../types';
export declare class XdrDecoder<R extends IReader & IReaderResettable = IReader & IReaderResettable> implements BinaryJsonDecoder {
reader: R;
constructor(reader?: R);
read(uint8: Uint8Array): unknown;
decode(uint8: Uint8Array): unknown;
readAny(): unknown;
readVoid(): void;
readBoolean(): boolean;
readInt(): number;
readUnsignedInt(): number;
readHyper(): bigint;
readUnsignedHyper(): bigint;
readFloat(): number;
readDouble(): number;
readQuadruple(): number;
readOpaque(size: number): Uint8Array;
readVarlenOpaque(): Uint8Array;
readString(): string;
readEnum(): number;
readArray<T>(size: number, elementReader: () => T): T[];
readVarlenArray<T>(elementReader: () => T): T[];
}
+98
View File
@@ -0,0 +1,98 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.XdrDecoder = void 0;
const Reader_1 = require("@jsonjoy.com/buffers/lib/Reader");
class XdrDecoder {
constructor(reader = new Reader_1.Reader()) {
this.reader = reader;
}
read(uint8) {
this.reader.reset(uint8);
return this.readAny();
}
decode(uint8) {
this.reader.reset(uint8);
return this.readAny();
}
readAny() {
throw new Error('not implemented');
}
readVoid() {
}
readBoolean() {
return this.readInt() !== 0;
}
readInt() {
const reader = this.reader;
const value = reader.view.getInt32(reader.x, false);
reader.x += 4;
return value;
}
readUnsignedInt() {
const reader = this.reader;
const value = reader.view.getUint32(reader.x, false);
reader.x += 4;
return value;
}
readHyper() {
const reader = this.reader;
const value = reader.view.getBigInt64(reader.x, false);
reader.x += 8;
return value;
}
readUnsignedHyper() {
const reader = this.reader;
const value = reader.view.getBigUint64(reader.x, false);
reader.x += 8;
return value;
}
readFloat() {
const reader = this.reader;
const value = reader.view.getFloat32(reader.x, false);
reader.x += 4;
return value;
}
readDouble() {
const reader = this.reader;
const value = reader.view.getFloat64(reader.x, false);
reader.x += 8;
return value;
}
readQuadruple() {
throw new Error('not implemented');
}
readOpaque(size) {
const reader = this.reader;
const data = reader.buf(size);
const paddedSize = size % 4 === 0 ? size : size + (4 - (size % 4));
reader.skip(paddedSize - size);
return data;
}
readVarlenOpaque() {
const size = this.readUnsignedInt();
return this.readOpaque(size);
}
readString() {
const size = this.readUnsignedInt();
const reader = this.reader;
const text = reader.utf8(size);
const paddedSize = size % 4 === 0 ? size : size + (4 - (size % 4));
reader.skip(paddedSize - size);
return text;
}
readEnum() {
return this.readInt();
}
readArray(size, elementReader) {
const array = [];
for (let i = 0; i < size; i++)
array.push(elementReader());
return array;
}
readVarlenArray(elementReader) {
const size = this.readUnsignedInt();
return this.readArray(size, elementReader);
}
}
exports.XdrDecoder = XdrDecoder;
//# sourceMappingURL=XdrDecoder.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"XdrDecoder.js","sourceRoot":"","sources":["../../src/xdr/XdrDecoder.ts"],"names":[],"mappings":";;;AAAA,4DAAuD;AAcvD,MAAa,UAAU;IAGrB,YAA0B,SAAY,IAAI,eAAM,EAAS;QAA/B,WAAM,GAAN,MAAM,CAAyB;IAAG,CAAC;IAEtD,IAAI,CAAC,KAAiB;QAC3B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;IAEM,MAAM,CAAC,KAAiB;QAC7B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;IAEM,OAAO;QAGZ,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IAKM,QAAQ;IAEf,CAAC;IAMM,WAAW;QAChB,OAAO,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC9B,CAAC;IAKM,OAAO;QACZ,M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CAAC;IACd,CAAC;IAKM,QAAQ;QACb,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;IAMM,SAAS,CAAI,IAAY,EAAE,aAAsB;QACtD,MAAM,KAAK,GAAQ,EAAE,CAAC;QACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE;YAAE,KAAK,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC;QAC3D,OAAO,KAAK,CAAC;IACf,CAAC;IAMM,eAAe,CAAI,aAAsB;QAC9C,MAAM,IAAI,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QACpC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IAC7C,CAAC;CACF;AAzKD,gCAyKC"}
+29
View File
@@ -0,0 +1,29 @@
import type { IWriter, IWriterGrowable } from '@jsonjoy.com/buffers/lib';
import type { BinaryJsonEncoder } from '../types';
export declare class XdrEncoder implements BinaryJsonEncoder {
readonly writer: IWriter & IWriterGrowable;
constructor(writer: IWriter & IWriterGrowable);
encode(value: unknown): Uint8Array;
writeUnknown(value: unknown): void;
writeAny(value: unknown): void;
writeVoid(): void;
writeNull(): void;
writeBoolean(bool: boolean): void;
writeInt(int: number): void;
writeUnsignedInt(uint: number): void;
writeHyper(hyper: number | bigint): void;
writeUnsignedHyper(uhyper: number | bigint): void;
writeFloat(float: number): void;
writeDouble(double: number): void;
writeQuadruple(quad: number): void;
writeOpaque(data: Uint8Array): void;
writeVarlenOpaque(data: Uint8Array): void;
writeStr(str: string): void;
writeArr(arr: unknown[]): void;
writeObj(obj: Record<string, unknown>): void;
writeNumber(num: number): void;
writeInteger(int: number): void;
writeUInteger(uint: number): void;
writeBin(buf: Uint8Array): void;
writeAsciiStr(str: string): void;
}
+167
View File
@@ -0,0 +1,167 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.XdrEncoder = void 0;
class XdrEncoder {
constructor(writer) {
this.writer = writer;
}
encode(value) {
const writer = this.writer;
writer.reset();
this.writeAny(value);
return writer.flush();
}
writeUnknown(value) {
this.writeVoid();
}
writeAny(value) {
switch (typeof value) {
case 'boolean':
return this.writeBoolean(value);
case 'number':
return this.writeNumber(value);
case 'string':
return this.writeStr(value);
case 'object': {
if (value === null)
return this.writeVoid();
const constructor = value.constructor;
switch (constructor) {
case Uint8Array:
return this.writeBin(value);
default:
return this.writeUnknown(value);
}
}
case 'bigint':
return this.writeHyper(value);
case 'undefined':
return this.writeVoid();
default:
return this.writeUnknown(value);
}
}
writeVoid() {
}
writeNull() {
this.writeVoid();
}
writeBoolean(bool) {
this.writeInt(bool ? 1 : 0);
}
writeInt(int) {
const writer = this.writer;
writer.ensureCapacity(4);
writer.view.setInt32(writer.x, Math.trunc(int), false);
writer.move(4);
}
writeUnsignedInt(uint) {
const writer = this.writer;
writer.ensureCapacity(4);
writer.view.setUint32(writer.x, Math.trunc(uint) >>> 0, false);
writer.move(4);
}
writeHyper(hyper) {
const writer = this.writer;
writer.ensureCapacity(8);
if (typeof hyper === 'bigint') {
writer.view.setBigInt64(writer.x, hyper, false);
}
else {
const truncated = Math.trunc(hyper);
const high = Math.floor(truncated / 0x100000000);
const low = truncated >>> 0;
writer.view.setInt32(writer.x, high, false);
writer.view.setUint32(writer.x + 4, low, false);
}
writer.move(8);
}
writeUnsignedHyper(uhyper) {
const writer = this.writer;
writer.ensureCapacity(8);
if (typeof uhyper === 'bigint') {
writer.view.setBigUint64(writer.x, uhyper, false);
}
else {
const truncated = Math.trunc(Math.abs(uhyper));
const high = Math.floor(truncated / 0x100000000);
const low = truncated >>> 0;
writer.view.setUint32(writer.x, high, false);
writer.view.setUint32(writer.x + 4, low, false);
}
writer.move(8);
}
writeFloat(float) {
const writer = this.writer;
writer.ensureCapacity(4);
writer.view.setFloat32(writer.x, float, false);
writer.move(4);
}
writeDouble(double) {
const writer = this.writer;
writer.ensureCapacity(8);
writer.view.setFloat64(writer.x, double, false);
writer.move(8);
}
writeQuadruple(quad) {
throw new Error('not implemented');
}
writeOpaque(data) {
const size = data.length;
const writer = this.writer;
const paddedSize = Math.ceil(size / 4) * 4;
writer.ensureCapacity(paddedSize);
writer.buf(data, size);
const padding = paddedSize - size;
for (let i = 0; i < padding; i++)
writer.u8(0);
}
writeVarlenOpaque(data) {
this.writeUnsignedInt(data.length);
this.writeOpaque(data);
}
writeStr(str) {
const writer = this.writer;
const lengthOffset = writer.x;
writer.x += 4;
const bytesWritten = writer.utf8(str);
const paddedSize = Math.ceil(bytesWritten / 4) * 4;
const padding = paddedSize - bytesWritten;
for (let i = 0; i < padding; i++)
writer.u8(0);
const currentPos = writer.x;
writer.x = lengthOffset;
this.writeUnsignedInt(bytesWritten);
writer.x = currentPos;
}
writeArr(arr) {
throw new Error('not implemented');
}
writeObj(obj) {
throw new Error('not implemented');
}
writeNumber(num) {
if (Number.isInteger(num)) {
if (num >= -2147483648 && num <= 2147483647)
this.writeInt(num);
else
this.writeHyper(num);
}
else
this.writeDouble(num);
}
writeInteger(int) {
this.writeInt(int);
}
writeUInteger(uint) {
this.writeUnsignedInt(uint);
}
writeBin(buf) {
this.writeVarlenOpaque(buf);
}
writeAsciiStr(str) {
this.writeStr(str);
}
}
exports.XdrEncoder = XdrEncoder;
//# sourceMappingURL=XdrEncoder.js.map
File diff suppressed because one or more lines are too long
+18
View File
@@ -0,0 +1,18 @@
import type { IReader, IReaderResettable } from '@jsonjoy.com/buffers/lib';
import type { XdrSchema } from './types';
export declare class XdrSchemaDecoder {
readonly reader: IReader & IReaderResettable;
private decoder;
constructor(reader?: IReader & IReaderResettable);
decode(data: Uint8Array, schema: XdrSchema): unknown;
private readValue;
private readEnum;
private readOpaque;
private readVarlenOpaque;
private readString;
private readArray;
private readVarlenArray;
private readStruct;
private readUnion;
private readOptional;
}
+125
View File
@@ -0,0 +1,125 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.XdrSchemaDecoder = void 0;
const Reader_1 = require("@jsonjoy.com/buffers/lib/Reader");
const XdrDecoder_1 = require("./XdrDecoder");
const XdrUnion_1 = require("./XdrUnion");
class XdrSchemaDecoder {
constructor(reader = new Reader_1.Reader()) {
this.reader = reader;
this.decoder = new XdrDecoder_1.XdrDecoder(reader);
}
decode(data, schema) {
this.reader.reset(data);
return this.readValue(schema);
}
readValue(schema) {
switch (schema.type) {
case 'void':
return this.decoder.readVoid();
case 'int':
return this.decoder.readInt();
case 'unsigned_int':
return this.decoder.readUnsignedInt();
case 'boolean':
return this.decoder.readBoolean();
case 'hyper':
return this.decoder.readHyper();
case 'unsigned_hyper':
return this.decoder.readUnsignedHyper();
case 'float':
return this.decoder.readFloat();
case 'double':
return this.decoder.readDouble();
case 'quadruple':
return this.decoder.readQuadruple();
case 'enum':
return this.readEnum(schema);
case 'opaque':
return this.readOpaque(schema);
case 'vopaque':
return this.readVarlenOpaque(schema);
case 'string':
return this.readString(schema);
case 'array':
return this.readArray(schema);
case 'varray':
return this.readVarlenArray(schema);
case 'struct':
return this.readStruct(schema);
case 'union':
return this.readUnion(schema);
case 'optional':
return this.readOptional(schema);
case 'const':
return undefined;
default:
throw new Error(`Unknown schema type: ${schema.type}`);
}
}
readEnum(schema) {
const value = this.decoder.readEnum();
for (const [name, enumValue] of Object.entries(schema.values)) {
if (enumValue === value) {
return name;
}
}
return value;
}
readOpaque(schema) {
return this.decoder.readOpaque(schema.size);
}
readVarlenOpaque(schema) {
const data = this.decoder.readVarlenOpaque();
if (schema.size !== undefined && data.length > schema.size) {
throw new Error(`Variable-length opaque data size ${data.length} exceeds maximum ${schema.size}`);
}
return data;
}
readString(schema) {
const str = this.decoder.readString();
if (schema.size !== undefined && str.length > schema.size) {
throw new Error(`String length ${str.length} exceeds maximum ${schema.size}`);
}
return str;
}
readArray(schema) {
return this.decoder.readArray(schema.size, () => this.readValue(schema.elements));
}
readVarlenArray(schema) {
const array = this.decoder.readVarlenArray(() => this.readValue(schema.elements));
if (schema.size !== undefined && array.length > schema.size) {
throw new Error(`Variable-length array size ${array.length} exceeds maximum ${schema.size}`);
}
return array;
}
readStruct(schema) {
const struct = {};
for (const [fieldSchema, fieldName] of schema.fields) {
struct[fieldName] = this.readValue(fieldSchema);
}
return struct;
}
readUnion(schema) {
const discriminant = this.decoder.readInt();
for (const [armDiscriminant, armSchema] of schema.arms) {
if (armDiscriminant === discriminant) {
const value = this.readValue(armSchema);
return new XdrUnion_1.XdrUnion(discriminant, value);
}
}
if (schema.default) {
const value = this.readValue(schema.default);
return new XdrUnion_1.XdrUnion(discriminant, value);
}
throw new Error(`No matching union arm for discriminant: ${discriminant}`);
}
readOptional(schema) {
const opted = this.decoder.readBoolean();
if (!opted)
return null;
return this.readValue(schema.element);
}
}
exports.XdrSchemaDecoder = XdrSchemaDecoder;
//# sourceMappingURL=XdrSchemaDecoder.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"XdrSchemaDecoder.js","sourceRoot":"","sources":["../../src/xdr/XdrSchemaDecoder.ts"],"names":[],"mappings":";;;AAAA,4DAAuD;AACvD,6CAAwC;AACxC,yCAAoC;AAoBpC,MAAa,gBAAgB;IAG3B,YAA4B,SAAsC,IAAI,eAAM,EAAE;QAAlD,WAAM,GAAN,MAAM,CAA4C;QAC5E,IAAI,CAAC,OAAO,GAAG,IAAI,uBAAU,CAAC,MAAM,CAAC,CAAC;IACxC,CAAC;IAKM,MAAM,CAAC,IAAgB,EAAE,MAAiB;QAC/C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACxB,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IAKO,SAAS,CAAC,MAAiB;QACjC,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;YAEpB,KAAK,MAAM;gBACT,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YACjC,KAAK,KAAK;gBACR,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YAChC,K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,CAAC;YAC3C,CAAC;QACH,CAAC;QAGD,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC7C,OAAO,IAAI,mBAAQ,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;QAC3C,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,2CAA2C,YAAY,EAAE,CAAC,CAAC;IAC7E,CAAC;IAOO,YAAY,CAAC,MAAyB;QAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;QACzC,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC;QACxB,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC;CACF;AA9LD,4CA8LC"}
+30
View File
@@ -0,0 +1,30 @@
import type { IWriter, IWriterGrowable } from '@jsonjoy.com/buffers/lib';
import type { XdrSchema, XdrEnumSchema, XdrOpaqueSchema, XdrVarlenOpaqueSchema, XdrStringSchema, XdrArraySchema, XdrVarlenArraySchema, XdrStructSchema, XdrUnionSchema, XdrOptionalSchema } from './types';
export declare class XdrSchemaEncoder {
readonly writer: IWriter & IWriterGrowable;
private encoder;
constructor(writer: IWriter & IWriterGrowable);
encode(value: unknown, schema: XdrSchema): Uint8Array;
writeVoid(schema: XdrSchema): void;
writeInt(value: number, schema: XdrSchema): void;
writeUnsignedInt(value: number, schema: XdrSchema): void;
writeBoolean(value: boolean, schema: XdrSchema): void;
writeHyper(value: number | bigint, schema: XdrSchema): void;
writeUnsignedHyper(value: number | bigint, schema: XdrSchema): void;
writeFloat(value: number, schema: XdrSchema): void;
writeDouble(value: number, schema: XdrSchema): void;
writeQuadruple(value: number, schema: XdrSchema): void;
writeEnum(value: string, schema: XdrEnumSchema): void;
writeOpaque(value: Uint8Array, schema: XdrOpaqueSchema): void;
writeVarlenOpaque(value: Uint8Array, schema: XdrVarlenOpaqueSchema): void;
writeString(value: string, schema: XdrStringSchema): void;
writeArray(value: unknown[], schema: XdrArraySchema): void;
writeVarlenArray(value: unknown[], schema: XdrVarlenArraySchema): void;
writeStruct(value: Record<string, unknown>, schema: XdrStructSchema): void;
writeUnion(value: unknown, schema: XdrUnionSchema, discriminant: number | string | boolean): void;
writeOptional(value: unknown, schema: XdrOptionalSchema): void;
writeNumber(value: number, schema: XdrSchema): void;
private writeValue;
private validateSchemaType;
private writeDiscriminant;
}
+278
View File
@@ -0,0 +1,278 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.XdrSchemaEncoder = void 0;
const XdrEncoder_1 = require("./XdrEncoder");
const XdrUnion_1 = require("./XdrUnion");
class XdrSchemaEncoder {
constructor(writer) {
this.writer = writer;
this.encoder = new XdrEncoder_1.XdrEncoder(writer);
}
encode(value, schema) {
this.writer.reset();
this.writeValue(value, schema);
return this.writer.flush();
}
writeVoid(schema) {
this.validateSchemaType(schema, 'void');
this.encoder.writeVoid();
}
writeInt(value, schema) {
this.validateSchemaType(schema, 'int');
if (!Number.isInteger(value) || value < -2147483648 || value > 2147483647) {
throw new Error('Value is not a valid 32-bit signed integer');
}
this.encoder.writeInt(value);
}
writeUnsignedInt(value, schema) {
this.validateSchemaType(schema, 'unsigned_int');
if (!Number.isInteger(value) || value < 0 || value > 4294967295) {
throw new Error('Value is not a valid 32-bit unsigned integer');
}
this.encoder.writeUnsignedInt(value);
}
writeBoolean(value, schema) {
this.validateSchemaType(schema, 'boolean');
this.encoder.writeBoolean(value);
}
writeHyper(value, schema) {
this.validateSchemaType(schema, 'hyper');
this.encoder.writeHyper(value);
}
writeUnsignedHyper(value, schema) {
this.validateSchemaType(schema, 'unsigned_hyper');
if ((typeof value === 'number' && value < 0) || (typeof value === 'bigint' && value < BigInt(0))) {
throw new Error('Value is not a valid unsigned integer');
}
this.encoder.writeUnsignedHyper(value);
}
writeFloat(value, schema) {
this.validateSchemaType(schema, 'float');
this.encoder.writeFloat(value);
}
writeDouble(value, schema) {
this.validateSchemaType(schema, 'double');
this.encoder.writeDouble(value);
}
writeQuadruple(value, schema) {
this.validateSchemaType(schema, 'quadruple');
this.encoder.writeQuadruple(value);
}
writeEnum(value, schema) {
if (schema.type !== 'enum') {
throw new Error('Schema is not an enum schema');
}
if (!(value in schema.values)) {
throw new Error(`Invalid enum value: ${value}. Valid values are: ${Object.keys(schema.values).join(', ')}`);
}
const enumValue = schema.values[value];
if (!Number.isInteger(enumValue)) {
throw new Error(`Enum value ${value} has non-integer assignment: ${enumValue}`);
}
this.encoder.writeInt(enumValue);
}
writeOpaque(value, schema) {
if (schema.type !== 'opaque') {
throw new Error('Schema is not an opaque schema');
}
if (value.length !== schema.size) {
throw new Error(`Opaque data length ${value.length} does not match schema size ${schema.size}`);
}
this.encoder.writeOpaque(value);
}
writeVarlenOpaque(value, schema) {
if (schema.type !== 'vopaque') {
throw new Error('Schema is not a variable-length opaque schema');
}
if (schema.size !== undefined && value.length > schema.size) {
throw new Error(`Opaque data length ${value.length} exceeds maximum size ${schema.size}`);
}
this.encoder.writeVarlenOpaque(value);
}
writeString(value, schema) {
if (schema.type !== 'string') {
throw new Error('Schema is not a string schema');
}
if (schema.size !== undefined && value.length > schema.size) {
throw new Error(`String length ${value.length} exceeds maximum size ${schema.size}`);
}
this.encoder.writeStr(value);
}
writeArray(value, schema) {
if (schema.type !== 'array') {
throw new Error('Schema is not an array schema');
}
if (value.length !== schema.size) {
throw new Error(`Array length ${value.length} does not match schema size ${schema.size}`);
}
for (const item of value) {
this.writeValue(item, schema.elements);
}
}
writeVarlenArray(value, schema) {
if (schema.type !== 'varray') {
throw new Error('Schema is not a variable-length array schema');
}
if (schema.size !== undefined && value.length > schema.size) {
throw new Error(`Array length ${value.length} exceeds maximum size ${schema.size}`);
}
this.encoder.writeUnsignedInt(value.length);
for (const item of value) {
this.writeValue(item, schema.elements);
}
}
writeStruct(value, schema) {
if (schema.type !== 'struct') {
throw new Error('Schema is not a struct schema');
}
for (const [fieldSchema, fieldName] of schema.fields) {
if (!(fieldName in value)) {
throw new Error(`Missing required field: ${fieldName}`);
}
this.writeValue(value[fieldName], fieldSchema);
}
}
writeUnion(value, schema, discriminant) {
if (schema.type !== 'union') {
throw new Error('Schema is not a union schema');
}
const arm = schema.arms.find(([armDiscriminant]) => armDiscriminant === discriminant);
if (!arm) {
if (schema.default) {
this.writeDiscriminant(discriminant);
this.writeValue(value, schema.default);
}
else {
throw new Error(`No matching arm found for discriminant: ${discriminant}`);
}
}
else {
this.writeDiscriminant(discriminant);
this.writeValue(value, arm[1]);
}
}
writeOptional(value, schema) {
if (schema.type !== 'optional') {
throw new Error('Schema is not an optional schema');
}
if (value === null || value === undefined) {
this.encoder.writeBoolean(false);
}
else {
this.encoder.writeBoolean(true);
this.writeValue(value, schema.element);
}
}
writeNumber(value, schema) {
switch (schema.type) {
case 'int':
this.writeInt(value, schema);
break;
case 'unsigned_int':
this.writeUnsignedInt(value, schema);
break;
case 'hyper':
this.writeHyper(value, schema);
break;
case 'unsigned_hyper':
this.writeUnsignedHyper(value, schema);
break;
case 'float':
this.writeFloat(value, schema);
break;
case 'double':
this.writeDouble(value, schema);
break;
case 'quadruple':
this.writeQuadruple(value, schema);
break;
default:
throw new Error(`Schema type ${schema.type} is not a numeric type`);
}
}
writeValue(value, schema) {
switch (schema.type) {
case 'void':
this.encoder.writeVoid();
break;
case 'int':
this.encoder.writeInt(value);
break;
case 'unsigned_int':
this.encoder.writeUnsignedInt(value);
break;
case 'boolean':
this.encoder.writeBoolean(value);
break;
case 'hyper':
this.encoder.writeHyper(value);
break;
case 'unsigned_hyper':
this.encoder.writeUnsignedHyper(value);
break;
case 'float':
this.encoder.writeFloat(value);
break;
case 'double':
this.encoder.writeDouble(value);
break;
case 'quadruple':
this.encoder.writeQuadruple(value);
break;
case 'enum':
this.writeEnum(value, schema);
break;
case 'opaque':
this.writeOpaque(value, schema);
break;
case 'vopaque':
this.writeVarlenOpaque(value, schema);
break;
case 'string':
this.writeString(value, schema);
break;
case 'array':
this.writeArray(value, schema);
break;
case 'varray':
this.writeVarlenArray(value, schema);
break;
case 'struct':
this.writeStruct(value, schema);
break;
case 'union':
if (value instanceof XdrUnion_1.XdrUnion) {
this.writeUnion(value.value, schema, value.discriminant);
}
else {
throw new Error('Union values must be wrapped in XdrUnion class');
}
break;
case 'optional':
this.writeOptional(value, schema);
break;
case 'const':
break;
default:
throw new Error(`Unknown schema type: ${schema.type}`);
}
}
validateSchemaType(schema, expectedType) {
if (schema.type !== expectedType) {
throw new Error(`Expected schema type ${expectedType}, got ${schema.type}`);
}
}
writeDiscriminant(discriminant) {
if (typeof discriminant === 'number') {
this.encoder.writeInt(discriminant);
}
else if (typeof discriminant === 'boolean') {
this.encoder.writeBoolean(discriminant);
}
else {
throw new Error('String discriminants require enum schema context');
}
}
}
exports.XdrSchemaEncoder = XdrSchemaEncoder;
//# sourceMappingURL=XdrSchemaEncoder.js.map
File diff suppressed because one or more lines are too long
+17
View File
@@ -0,0 +1,17 @@
import type { XdrSchema } from './types';
export declare class XdrSchemaValidator {
validateSchema(schema: XdrSchema): boolean;
validateValue(value: unknown, schema: XdrSchema): boolean;
private validateSchemaInternal;
private validateEnumSchema;
private validateOpaqueSchema;
private validateVarlenOpaqueSchema;
private validateStringSchema;
private validateArraySchema;
private validateVarlenArraySchema;
private validateStructSchema;
private validateUnionSchema;
private validateOptionalSchema;
private validateConstantSchema;
private validateValueInternal;
}
+222
View File
@@ -0,0 +1,222 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.XdrSchemaValidator = void 0;
class XdrSchemaValidator {
validateSchema(schema) {
try {
return this.validateSchemaInternal(schema);
}
catch {
return false;
}
}
validateValue(value, schema) {
try {
return this.validateValueInternal(value, schema);
}
catch {
return false;
}
}
validateSchemaInternal(schema) {
if (!schema || typeof schema !== 'object' || !schema.type) {
return false;
}
switch (schema.type) {
case 'void':
case 'int':
case 'unsigned_int':
case 'boolean':
case 'hyper':
case 'unsigned_hyper':
case 'float':
case 'double':
case 'quadruple':
return true;
case 'enum':
return this.validateEnumSchema(schema);
case 'opaque':
return this.validateOpaqueSchema(schema);
case 'vopaque':
return this.validateVarlenOpaqueSchema(schema);
case 'string':
return this.validateStringSchema(schema);
case 'array':
return this.validateArraySchema(schema);
case 'varray':
return this.validateVarlenArraySchema(schema);
case 'struct':
return this.validateStructSchema(schema);
case 'union':
return this.validateUnionSchema(schema);
case 'optional':
return this.validateOptionalSchema(schema);
case 'const':
return this.validateConstantSchema(schema);
default:
return false;
}
}
validateEnumSchema(schema) {
if (!schema.values || typeof schema.values !== 'object') {
return false;
}
const values = Object.values(schema.values);
const uniqueValues = new Set(values);
if (values.length !== uniqueValues.size) {
return false;
}
return values.every((value) => Number.isInteger(value));
}
validateOpaqueSchema(schema) {
return typeof schema.size === 'number' && Number.isInteger(schema.size) && schema.size >= 0;
}
validateVarlenOpaqueSchema(schema) {
return !schema.size || (typeof schema.size === 'number' && Number.isInteger(schema.size) && schema.size >= 0);
}
validateStringSchema(schema) {
return !schema.size || (typeof schema.size === 'number' && Number.isInteger(schema.size) && schema.size >= 0);
}
validateArraySchema(schema) {
if (!schema.elements || typeof schema.size !== 'number' || !Number.isInteger(schema.size) || schema.size < 0) {
return false;
}
return this.validateSchemaInternal(schema.elements);
}
validateVarlenArraySchema(schema) {
if (!schema.elements) {
return false;
}
if (schema.size !== undefined) {
if (typeof schema.size !== 'number' || !Number.isInteger(schema.size) || schema.size < 0) {
return false;
}
}
return this.validateSchemaInternal(schema.elements);
}
validateStructSchema(schema) {
if (!Array.isArray(schema.fields)) {
return false;
}
const fieldNames = new Set();
for (const field of schema.fields) {
if (!Array.isArray(field) || field.length !== 2) {
return false;
}
const [fieldSchema, fieldName] = field;
if (typeof fieldName !== 'string' || fieldName === '') {
return false;
}
if (fieldNames.has(fieldName)) {
return false;
}
fieldNames.add(fieldName);
if (!this.validateSchemaInternal(fieldSchema)) {
return false;
}
}
return true;
}
validateUnionSchema(schema) {
if (!Array.isArray(schema.arms) || schema.arms.length === 0) {
return false;
}
const discriminants = new Set();
for (const arm of schema.arms) {
if (!Array.isArray(arm) || arm.length !== 2) {
return false;
}
const [discriminant, armSchema] = arm;
if (discriminants.has(discriminant)) {
return false;
}
discriminants.add(discriminant);
if (typeof discriminant !== 'number' && typeof discriminant !== 'string' && typeof discriminant !== 'boolean') {
return false;
}
if (!this.validateSchemaInternal(armSchema)) {
return false;
}
}
if (schema.default && !this.validateSchemaInternal(schema.default)) {
return false;
}
return true;
}
validateOptionalSchema(schema) {
if (!schema.element) {
return false;
}
return this.validateSchemaInternal(schema.element);
}
validateConstantSchema(schema) {
if (typeof schema.value !== 'number' || !Number.isInteger(schema.value)) {
return false;
}
return true;
}
validateValueInternal(value, schema) {
switch (schema.type) {
case 'void':
return value === null || value === undefined;
case 'int':
return typeof value === 'number' && Number.isInteger(value) && value >= -2147483648 && value <= 2147483647;
case 'unsigned_int':
return typeof value === 'number' && Number.isInteger(value) && value >= 0 && value <= 4294967295;
case 'boolean':
return typeof value === 'boolean';
case 'hyper':
return (typeof value === 'number' && Number.isInteger(value)) || typeof value === 'bigint';
case 'unsigned_hyper':
return ((typeof value === 'number' && Number.isInteger(value) && value >= 0) ||
(typeof value === 'bigint' && value >= BigInt(0)));
case 'float':
case 'double':
case 'quadruple':
return typeof value === 'number';
case 'enum':
const enumSchema = schema;
return typeof value === 'string' && value in enumSchema.values;
case 'opaque':
const opaqueSchema = schema;
return value instanceof Uint8Array && value.length === opaqueSchema.size;
case 'vopaque':
const vopaqueSchema = schema;
return value instanceof Uint8Array && (!vopaqueSchema.size || value.length <= vopaqueSchema.size);
case 'string':
const stringSchema = schema;
return typeof value === 'string' && (!stringSchema.size || value.length <= stringSchema.size);
case 'array':
const arraySchema = schema;
return (Array.isArray(value) &&
value.length === arraySchema.size &&
value.every((item) => this.validateValueInternal(item, arraySchema.elements)));
case 'varray':
const varraySchema = schema;
return (Array.isArray(value) &&
(!varraySchema.size || value.length <= varraySchema.size) &&
value.every((item) => this.validateValueInternal(item, varraySchema.elements)));
case 'struct':
const structSchema = schema;
if (!value || typeof value !== 'object' || Array.isArray(value)) {
return false;
}
const valueObj = value;
return structSchema.fields.every(([fieldSchema, fieldName]) => fieldName in valueObj && this.validateValueInternal(valueObj[fieldName], fieldSchema));
case 'union':
const unionSchema = schema;
const matchesArm = unionSchema.arms.some(([, armSchema]) => this.validateValueInternal(value, armSchema));
const matchesDefault = unionSchema.default ? this.validateValueInternal(value, unionSchema.default) : false;
return matchesArm || matchesDefault;
case 'optional':
const optionalSchema = schema;
return value === null || value === undefined || this.validateValueInternal(value, optionalSchema.element);
case 'const':
return true;
default:
return false;
}
}
}
exports.XdrSchemaValidator = XdrSchemaValidator;
//# sourceMappingURL=XdrSchemaValidator.js.map
File diff suppressed because one or more lines are too long
+5
View File
@@ -0,0 +1,5 @@
export declare class XdrUnion<T = unknown> {
readonly discriminant: number | string | boolean;
readonly value: T;
constructor(discriminant: number | string | boolean, value: T);
}
+11
View File
@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.XdrUnion = void 0;
class XdrUnion {
constructor(discriminant, value) {
this.discriminant = discriminant;
this.value = value;
}
}
exports.XdrUnion = XdrUnion;
//# sourceMappingURL=XdrUnion.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"XdrUnion.js","sourceRoot":"","sources":["../../src/xdr/XdrUnion.ts"],"names":[],"mappings":";;;AAKA,MAAa,QAAQ;IACnB,YACkB,YAAuC,EACvC,KAAQ;QADR,iBAAY,GAAZ,YAAY,CAA2B;QACvC,UAAK,GAAL,KAAK,CAAG;IACvB,CAAC;CACL;AALD,4BAKC"}
+7
View File
@@ -0,0 +1,7 @@
export * from './types';
export * from './XdrEncoder';
export * from './XdrDecoder';
export * from './XdrSchemaEncoder';
export * from './XdrSchemaDecoder';
export * from './XdrSchemaValidator';
export * from './XdrUnion';
+11
View File
@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("./types"), exports);
tslib_1.__exportStar(require("./XdrEncoder"), exports);
tslib_1.__exportStar(require("./XdrDecoder"), exports);
tslib_1.__exportStar(require("./XdrSchemaEncoder"), exports);
tslib_1.__exportStar(require("./XdrSchemaDecoder"), exports);
tslib_1.__exportStar(require("./XdrSchemaValidator"), exports);
tslib_1.__exportStar(require("./XdrUnion"), exports);
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/xdr/index.ts"],"names":[],"mappings":";;;AAeA,kDAAwB;AACxB,uDAA6B;AAC7B,uDAA6B;AAC7B,6DAAmC;AACnC,6DAAmC;AACnC,+DAAqC;AACrC,qDAA2B"}
+56
View File
@@ -0,0 +1,56 @@
import type { XdrDecoder } from './XdrDecoder';
import type { XdrEncoder } from './XdrEncoder';
export type XdrSchema = XdrPrimitiveSchema | XdrWidePrimitiveSchema | XdrCompositeSchema | XdrOptionalSchema;
export type XdrPrimitiveSchema = XdrVoidSchema | XdrIntSchema | XdrUnsignedIntSchema | XdrEnumSchema | XdrBooleanSchema | XdrHyperSchema | XdrUnsignedHyperSchema | XdrFloatSchema | XdrDoubleSchema | XdrQuadrupleSchema;
export type XdrVoidSchema = XdrBaseSchema<'void'>;
export type XdrIntSchema = XdrBaseSchema<'int'>;
export type XdrUnsignedIntSchema = XdrBaseSchema<'unsigned_int'>;
export interface XdrEnumSchema extends XdrBaseSchema<'enum'> {
values: Record<string, number>;
}
export type XdrBooleanSchema = XdrBaseSchema<'boolean'>;
export type XdrHyperSchema = XdrBaseSchema<'hyper'>;
export type XdrUnsignedHyperSchema = XdrBaseSchema<'unsigned_hyper'>;
export type XdrFloatSchema = XdrBaseSchema<'float'>;
export type XdrDoubleSchema = XdrBaseSchema<'double'>;
export type XdrQuadrupleSchema = XdrBaseSchema<'quadruple'>;
export type XdrWidePrimitiveSchema = XdrOpaqueSchema | XdrVarlenOpaqueSchema | XdrStringSchema;
export interface XdrOpaqueSchema extends XdrBaseSchema<'opaque'> {
size: number;
}
export interface XdrVarlenOpaqueSchema extends XdrBaseSchema<'vopaque'> {
size?: number;
}
export interface XdrStringSchema extends XdrBaseSchema<'string'> {
size?: number;
}
export type XdrCompositeSchema = XdrArraySchema | XdrVarlenArraySchema | XdrStructSchema | XdrUnionSchema | XdrOptionalSchema | XdrConstantSchema;
export interface XdrArraySchema extends XdrBaseSchema<'array'> {
elements: XdrSchema;
size: number;
}
export interface XdrVarlenArraySchema extends XdrBaseSchema<'varray'> {
elements: XdrSchema;
size?: number;
}
export interface XdrStructSchema extends XdrBaseSchema<'struct'> {
fields: [schema: XdrSchema, name: string][];
}
export interface XdrUnionSchema extends XdrBaseSchema<'union'> {
type: 'union';
arms: [discriminant: number | string | boolean, schema: XdrSchema][];
default?: XdrSchema;
}
export interface XdrOptionalSchema extends XdrBaseSchema<'optional'> {
element: XdrSchema;
}
export interface XdrConstantSchema extends XdrBaseSchema<'const'> {
value: number;
}
export interface XdrBaseSchema<Type extends string> {
type: Type;
}
export type XdrTypeDecoder<T extends XdrType> = (xdr: XdrDecoder) => T;
export interface XdrType {
encode(xdr: XdrEncoder): void;
}
+3
View File
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=types.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/xdr/types.ts"],"names":[],"mappings":""}