API reference@evolu/common › Buffer

Binary data handling and byte array utilities.

Buffer-based decoding functions intentionally throw errors instead of returning Result. This is a deliberate micro-optimization for Evolu Protocol's hot paths: Result is inexpensive, but returning decoded values directly avoids its success-case allocation, and using Error objects preserves stack traces. In the future, we will try returning Error objects in Result values to measure the real-world performance impact.

Classes

ClassDescription
BufferErrorCustom error for Buffer-related failures like premature end of data. Provides better stack traces for debugging binary protocol issues.

Functions

FunctionDescription
bytesToHexConvert byte array to hex string. Uses built-in function, when available.
bytesToUtf8Converts bytes to string using UTF8 encoding.
concatBytesCopies several Uint8Arrays into one.
createBufferCreates a Buffer for efficient byte operations.
decodeJsonValueDecodes a JsonValue using the MessagePack format.
encodeJsonValueEncodes a JsonValue using the MessagePack format.
hexToBytesConvert hex string to byte array. Uses built-in function, when available.
utf8ToBytesConverts string to bytes using UTF8 encoding.

Interfaces

InterfaceDescription
BufferA Buffer is a dynamic, resizable container for binary data, optimized for scenarios where the final size is unknown. It grows exponentially (doubling its capacity) to minimize memory reallocations and uses subarray for efficient, copy-free data access in methods like unwrap and shift.