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
| Class | Description |
|---|---|
| BufferError | Custom error for Buffer-related failures like premature end of data. Provides better stack traces for debugging binary protocol issues. |
Functions
| Function | Description |
|---|---|
| bytesToHex | Convert byte array to hex string. Uses built-in function, when available. |
| bytesToUtf8 | Converts bytes to string using UTF8 encoding. |
| concatBytes | Copies several Uint8Arrays into one. |
| createBuffer | Creates a Buffer for efficient byte operations. |
| decodeJsonValue | Decodes a JsonValue using the MessagePack format. |
| encodeJsonValue | Encodes a JsonValue using the MessagePack format. |
| hexToBytes | Convert hex string to byte array. Uses built-in function, when available. |
| utf8ToBytes | Converts string to bytes using UTF8 encoding. |
Interfaces
| Interface | Description |
|---|---|
| Buffer | A 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. |