boc
boc.tolk standard library file
Module for encoding cells as raw Bag of Cells (BoC) bytes and decoding them back.
The encoded bytes can be written directly with fs.writeBytes or passed to APIs that
expect a binary BoC. Decoding accepts standard single-root BoCs with or without CRC32C
and with or without an index.
Example:
val data = beginCell()
.storeUint(0xDEADBEEF, 32)
.endCell();
val encoded = boc.encode(data, { crc32: true });
fs.writeBytes("data.boc", encoded);
val decoded = boc.decode(fs.readBytes("data.boc")!);
if (decoded != null) {
// decoded! contains the original cell tree
}Definitions
boc
struct bocNamespace for raw Bag of Cells encoding and decoding.
Source codeBocEncodeOptions
struct BocEncodeOptions {
/// Append a four-byte CRC32C checksum to the encoded BoC.
crc32: bool = false
}Options controlling raw BoC encoding.
Source codeboc.encode
fun boc.encode<T>(value: T, options: BocEncodeOptions = {}): sliceEncodes a cell or the unread remainder of a slice as raw BoC bytes.
Returns a snake slice containing the exact binary representation. By default, the BoC
has one root, no index, and no checksum. Set options.crc32 to append CRC32C.
When value is a slice, only its remaining bits and references are encoded. Bits or
references already loaded from the slice are not included.
boc.decode
fun boc.decode(data: slice): cell?Decodes raw BoC bytes into a single root cell.
Returns null when data is not a valid snake byte slice, is not a valid BoC, has an
invalid CRC32C checksum, or contains a number of roots other than one.
Last updated on