Skip to content

default

Defined in: .work/repos/edinburgh/src/datapack.ts:31

A byte buffer for efficient reading and writing of primitive values and bit sequences.

The DataPack class provides methods for serializing and deserializing various data types including numbers, strings, bit sequences, and other primitive values to/from byte buffers. It supports both reading and writing operations with automatic buffer management.

new default(data?): DataPack

Defined in: .work/repos/edinburgh/src/datapack.ts:51

Create a new DataPack instance.

number | Uint8Array<ArrayBufferLike>

Optional initial data as Uint8Array or buffer size as number.

DataPack

readPos: number = 0

Defined in: .work/repos/edinburgh/src/datapack.ts:35


writePos: number = 0

Defined in: .work/repos/edinburgh/src/datapack.ts:36


static EOD: symbol

Defined in: .work/repos/edinburgh/src/datapack.ts:38


CustomData: typeof CustomData

Defined in: .work/repos/edinburgh/src/datapack.ts:765

get _buffer(): Uint8Array

Defined in: .work/repos/edinburgh/src/datapack.ts:43

Backward compatibility: Access to the internal buffer

Uint8Array

write(data): DataPack

Defined in: .work/repos/edinburgh/src/datapack.ts:139

Each data item starts with a single byte. The high 3 bits indicate the type. The low 5 bits indicate a size or a subtype, depending on the type.

0: negative integer (byte count encoded as bitwise NOT in lower bits) 1: small integer 0..31 (encoded in lower bits) 2: small integer 32…63 (encoded in lower bits) 3: integer (byte count encoded in lower bits) 4: 0: float64 (8 bytes follow) 1: undefined 2: null 3: true 4: false 5: array start (followed by a items until EOD) 6: object start (followed by key+value pairs until EOD) 7: map start (followed by key+value pairs until EOD) 8: set start (followed by items until EOD) 9: EOD 10: identifier (6 byte positive int follows, represented as a base64 string of length 8) 11: null-terminated string 12: Date/Time (varint with whole seconds since epoch follows) 13: custom type, followed by name string and data value 5: short string (length in lower bits, 0-31) 6: string (byte count of length in lower bits) 7: blob (byte count of length in lower bits)

any

DataPack


read(customConverters?): any

Defined in: .work/repos/edinburgh/src/datapack.ts:231

any


readNumber(): number

Defined in: .work/repos/edinburgh/src/datapack.ts:400

number


readDate(): Date

Defined in: .work/repos/edinburgh/src/datapack.ts:408

Date


readPositiveInt(limit?): number

Defined in: .work/repos/edinburgh/src/datapack.ts:416

number

number


readBoolean(): boolean

Defined in: .work/repos/edinburgh/src/datapack.ts:424

boolean


readUint8Array(): Uint8Array

Defined in: .work/repos/edinburgh/src/datapack.ts:432

Uint8Array


readString(): string

Defined in: .work/repos/edinburgh/src/datapack.ts:440

string


writeIdentifier(id): DataPack

Defined in: .work/repos/edinburgh/src/datapack.ts:448

string | number

DataPack


readIdentifier(): string

Defined in: .work/repos/edinburgh/src/datapack.ts:482

string


readIdentifierNumber(): number

Defined in: .work/repos/edinburgh/src/datapack.ts:495

number


writeOrderedString(str): DataPack

Defined in: .work/repos/edinburgh/src/datapack.ts:516

Like writeString but writes without a length prefix and with a null terminator, for ordered storage. Can be read with read or readString just like any other string.

string

The string to write. May not contain null characters.

DataPack


toUint8Array(copyBuffer?, startPos?, endPos?): Uint8Array

Defined in: .work/repos/edinburgh/src/datapack.ts:529

boolean = true

number = 0

number = ...

Uint8Array


toBuffer(): ArrayBuffer

Defined in: .work/repos/edinburgh/src/datapack.ts:533

ArrayBuffer


clone(copyBuffer, readPos?, writePos?): DataPack

Defined in: .work/repos/edinburgh/src/datapack.ts:537

boolean

number = 0

number = ...

DataPack


writeCustom(name, data): void

Defined in: .work/repos/edinburgh/src/datapack.ts:548

string

any

void


writeAsObject(obj): DataPack

Defined in: .work/repos/edinburgh/src/datapack.ts:554

Record<string, any>

DataPack


writeCollection(type, bodyFunc): DataPack

Defined in: .work/repos/edinburgh/src/datapack.ts:584

Write a collection (array, set, object, or map) using a callback to add items/fields.

"array" | "set"

‘array’ | ‘set’ | ‘object’ | ‘map’

(addField) => void

Callback function to add items/fields. It accepts a function to add values or key-value pairs (depending on the collection type).

DataPack

The DataPack instance for chaining.

// Writing an array
pack.writeCollection('array', add => {
add(1);
add(2);
add(3);
});
// Writing an object
pack.writeCollection('object', (add) => {
add('key1', 'value1');
add('key2', 42);
});

writeCollection(type, bodyFunc): DataPack

Defined in: .work/repos/edinburgh/src/datapack.ts:585

Write a collection (array, set, object, or map) using a callback to add items/fields.

"object"

‘array’ | ‘set’ | ‘object’ | ‘map’

(addField) => void

Callback function to add items/fields. It accepts a function to add values or key-value pairs (depending on the collection type).

DataPack

The DataPack instance for chaining.

// Writing an array
pack.writeCollection('array', add => {
add(1);
add(2);
add(3);
});
// Writing an object
pack.writeCollection('object', (add) => {
add('key1', 'value1');
add('key2', 42);
});

writeCollection(type, bodyFunc): DataPack

Defined in: .work/repos/edinburgh/src/datapack.ts:586

Write a collection (array, set, object, or map) using a callback to add items/fields.

"map"

‘array’ | ‘set’ | ‘object’ | ‘map’

(addField) => void

Callback function to add items/fields. It accepts a function to add values or key-value pairs (depending on the collection type).

DataPack

The DataPack instance for chaining.

// Writing an array
pack.writeCollection('array', add => {
add(1);
add(2);
add(3);
});
// Writing an object
pack.writeCollection('object', (add) => {
add('key1', 'value1');
add('key2', 42);
});

writeCollectionBoundary(marker): DataPack

Defined in: .work/repos/edinburgh/src/datapack.ts:609

Write a collection boundary marker (start or end) for arrays, sets, objects, or maps. This is a low-level method for advanced use cases. Use writeCollection (or just write) if possible.

"object" | "array" | "set" | "map" | "end"

DataPack


writeObjectKey(key): void

Defined in: .work/repos/edinburgh/src/datapack.ts:620

Writes either a string or a number, converting strings to numbers if they represent javascript-safe integers. This is useful for writing object keys, which are always strings but may be more compactly represented as numbers.

string | number

void


readCollectionBoundary(expected): void

Defined in: .work/repos/edinburgh/src/datapack.ts:634

Read and consume a collection boundary marker, validating it matches the expected type.

"object" | "array" | "set" | "map" | "end"

void


increment(): DataPack

Defined in: .work/repos/edinburgh/src/datapack.ts:648

Increment the last byte of the buffer. If it was already 255 set it to 0 and increment the previous byte, and so on. If all bytes were 255, return undefined. This is useful for creating an exclusive end key for range scans. This may result in a DataPack instance that cannot be parsed (or represented by toString).

DataPack


toString(extended?, startPos?, endPos?): string

Defined in: .work/repos/edinburgh/src/datapack.ts:661

boolean = undefined

number = 0

number = ...

string


readAvailable(): boolean

Defined in: .work/repos/edinburgh/src/datapack.ts:712

boolean


static generateIdentifier(): string

Defined in: .work/repos/edinburgh/src/datapack.ts:716

string


static createBuffer(…args): ArrayBuffer

Defined in: .work/repos/edinburgh/src/datapack.ts:730

any

ArrayBuffer


static createUint8Array(…args): Uint8Array<ArrayBufferLike>

Defined in: .work/repos/edinburgh/src/datapack.ts:738

any

Uint8Array<ArrayBufferLike>