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.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new default(
data?):DataPack
Defined in: .work/repos/edinburgh/src/datapack.ts:51
Create a new DataPack instance.
Parameters
Section titled “Parameters”number | Uint8Array<ArrayBufferLike>
Optional initial data as Uint8Array or buffer size as number.
Returns
Section titled “Returns”DataPack
Properties
Section titled “Properties”readPos
Section titled “readPos”readPos:
number=0
Defined in: .work/repos/edinburgh/src/datapack.ts:35
writePos
Section titled “writePos”writePos:
number=0
Defined in: .work/repos/edinburgh/src/datapack.ts:36
staticEOD:symbol
Defined in: .work/repos/edinburgh/src/datapack.ts:38
CustomData
Section titled “CustomData”CustomData: typeof
CustomData
Defined in: .work/repos/edinburgh/src/datapack.ts:765
Accessors
Section titled “Accessors”_buffer
Section titled “_buffer”Get Signature
Section titled “Get Signature”get _buffer():
Uint8Array
Defined in: .work/repos/edinburgh/src/datapack.ts:43
Backward compatibility: Access to the internal buffer
Returns
Section titled “Returns”Uint8Array
Methods
Section titled “Methods”write()
Section titled “write()”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)
Parameters
Section titled “Parameters”any
Returns
Section titled “Returns”DataPack
read()
Section titled “read()”read(
customConverters?):any
Defined in: .work/repos/edinburgh/src/datapack.ts:231
Parameters
Section titled “Parameters”customConverters?
Section titled “customConverters?”Returns
Section titled “Returns”any
readNumber()
Section titled “readNumber()”readNumber():
number
Defined in: .work/repos/edinburgh/src/datapack.ts:400
Returns
Section titled “Returns”number
readDate()
Section titled “readDate()”readDate():
Date
Defined in: .work/repos/edinburgh/src/datapack.ts:408
Returns
Section titled “Returns”Date
readPositiveInt()
Section titled “readPositiveInt()”readPositiveInt(
limit?):number
Defined in: .work/repos/edinburgh/src/datapack.ts:416
Parameters
Section titled “Parameters”limit?
Section titled “limit?”number
Returns
Section titled “Returns”number
readBoolean()
Section titled “readBoolean()”readBoolean():
boolean
Defined in: .work/repos/edinburgh/src/datapack.ts:424
Returns
Section titled “Returns”boolean
readUint8Array()
Section titled “readUint8Array()”readUint8Array():
Uint8Array
Defined in: .work/repos/edinburgh/src/datapack.ts:432
Returns
Section titled “Returns”Uint8Array
readString()
Section titled “readString()”readString():
string
Defined in: .work/repos/edinburgh/src/datapack.ts:440
Returns
Section titled “Returns”string
writeIdentifier()
Section titled “writeIdentifier()”writeIdentifier(
id):DataPack
Defined in: .work/repos/edinburgh/src/datapack.ts:448
Parameters
Section titled “Parameters”string | number
Returns
Section titled “Returns”DataPack
readIdentifier()
Section titled “readIdentifier()”readIdentifier():
string
Defined in: .work/repos/edinburgh/src/datapack.ts:482
Returns
Section titled “Returns”string
readIdentifierNumber()
Section titled “readIdentifierNumber()”readIdentifierNumber():
number
Defined in: .work/repos/edinburgh/src/datapack.ts:495
Returns
Section titled “Returns”number
writeOrderedString()
Section titled “writeOrderedString()”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.
Parameters
Section titled “Parameters”string
The string to write. May not contain null characters.
Returns
Section titled “Returns”DataPack
toUint8Array()
Section titled “toUint8Array()”toUint8Array(
copyBuffer?,startPos?,endPos?):Uint8Array
Defined in: .work/repos/edinburgh/src/datapack.ts:529
Parameters
Section titled “Parameters”copyBuffer?
Section titled “copyBuffer?”boolean = true
startPos?
Section titled “startPos?”number = 0
endPos?
Section titled “endPos?”number = ...
Returns
Section titled “Returns”Uint8Array
toBuffer()
Section titled “toBuffer()”toBuffer():
ArrayBuffer
Defined in: .work/repos/edinburgh/src/datapack.ts:533
Returns
Section titled “Returns”ArrayBuffer
clone()
Section titled “clone()”clone(
copyBuffer,readPos?,writePos?):DataPack
Defined in: .work/repos/edinburgh/src/datapack.ts:537
Parameters
Section titled “Parameters”copyBuffer
Section titled “copyBuffer”boolean
readPos?
Section titled “readPos?”number = 0
writePos?
Section titled “writePos?”number = ...
Returns
Section titled “Returns”DataPack
writeCustom()
Section titled “writeCustom()”writeCustom(
name,data):void
Defined in: .work/repos/edinburgh/src/datapack.ts:548
Parameters
Section titled “Parameters”string
any
Returns
Section titled “Returns”void
writeAsObject()
Section titled “writeAsObject()”writeAsObject(
obj):DataPack
Defined in: .work/repos/edinburgh/src/datapack.ts:554
Parameters
Section titled “Parameters”Record<string, any>
Returns
Section titled “Returns”DataPack
writeCollection()
Section titled “writeCollection()”Call Signature
Section titled “Call Signature”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.
Parameters
Section titled “Parameters”"array" | "set"
‘array’ | ‘set’ | ‘object’ | ‘map’
bodyFunc
Section titled “bodyFunc”(addField) => void
Callback function to add items/fields. It accepts a function to add values or key-value pairs (depending on the collection type).
Returns
Section titled “Returns”DataPack
The DataPack instance for chaining.
Example
Section titled “Example”// Writing an arraypack.writeCollection('array', add => { add(1); add(2); add(3);});
// Writing an objectpack.writeCollection('object', (add) => { add('key1', 'value1'); add('key2', 42);});Call Signature
Section titled “Call Signature”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.
Parameters
Section titled “Parameters”"object"
‘array’ | ‘set’ | ‘object’ | ‘map’
bodyFunc
Section titled “bodyFunc”(addField) => void
Callback function to add items/fields. It accepts a function to add values or key-value pairs (depending on the collection type).
Returns
Section titled “Returns”DataPack
The DataPack instance for chaining.
Example
Section titled “Example”// Writing an arraypack.writeCollection('array', add => { add(1); add(2); add(3);});
// Writing an objectpack.writeCollection('object', (add) => { add('key1', 'value1'); add('key2', 42);});Call Signature
Section titled “Call Signature”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.
Parameters
Section titled “Parameters”"map"
‘array’ | ‘set’ | ‘object’ | ‘map’
bodyFunc
Section titled “bodyFunc”(addField) => void
Callback function to add items/fields. It accepts a function to add values or key-value pairs (depending on the collection type).
Returns
Section titled “Returns”DataPack
The DataPack instance for chaining.
Example
Section titled “Example”// Writing an arraypack.writeCollection('array', add => { add(1); add(2); add(3);});
// Writing an objectpack.writeCollection('object', (add) => { add('key1', 'value1'); add('key2', 42);});writeCollectionBoundary()
Section titled “writeCollectionBoundary()”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.
Parameters
Section titled “Parameters”marker
Section titled “marker”"object" | "array" | "set" | "map" | "end"
Returns
Section titled “Returns”DataPack
writeObjectKey()
Section titled “writeObjectKey()”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.
Parameters
Section titled “Parameters”string | number
Returns
Section titled “Returns”void
readCollectionBoundary()
Section titled “readCollectionBoundary()”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.
Parameters
Section titled “Parameters”expected
Section titled “expected”"object" | "array" | "set" | "map" | "end"
Returns
Section titled “Returns”void
increment()
Section titled “increment()”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).
Returns
Section titled “Returns”DataPack
toString()
Section titled “toString()”toString(
extended?,startPos?,endPos?):string
Defined in: .work/repos/edinburgh/src/datapack.ts:661
Parameters
Section titled “Parameters”extended?
Section titled “extended?”boolean = undefined
startPos?
Section titled “startPos?”number = 0
endPos?
Section titled “endPos?”number = ...
Returns
Section titled “Returns”string
readAvailable()
Section titled “readAvailable()”readAvailable():
boolean
Defined in: .work/repos/edinburgh/src/datapack.ts:712
Returns
Section titled “Returns”boolean
generateIdentifier()
Section titled “generateIdentifier()”
staticgenerateIdentifier():string
Defined in: .work/repos/edinburgh/src/datapack.ts:716
Returns
Section titled “Returns”string
createBuffer()
Section titled “createBuffer()”
staticcreateBuffer(…args):ArrayBuffer
Defined in: .work/repos/edinburgh/src/datapack.ts:730
Parameters
Section titled “Parameters”…any
Returns
Section titled “Returns”ArrayBuffer
createUint8Array()
Section titled “createUint8Array()”
staticcreateUint8Array(…args):Uint8Array<ArrayBufferLike>
Defined in: .work/repos/edinburgh/src/datapack.ts:738
Parameters
Section titled “Parameters”…any
Returns
Section titled “Returns”Uint8Array<ArrayBufferLike>