buffer
A buffer is an object that represents a fixed-size mutable block of memory. The buffer library provides functions for creation and manipulation of buffer objects, providing all its functions inside the global buffer variable.
Buffer is intended to be used a low-level binary data storage structure, replacing the uses of string.pack() and string.unpack(). Use cases include reading and writing existing binary formats, working with data in a more compact form, serialization to custom binary formats, and general work with native memory types like fixed-length integers and floats.
When passed through Roblox APIs, including sending a buffer through custom events, the identity of the buffer object is not preserved and the target will receive a copy. Similar to other limitations, the same buffer object cannot be used from multiple Actor scripts (Parallel Luau).
Many of the functions accept an offset in bytes from the start of the buffer. Offset of 0 from the start of the buffer memory block accesses the first byte. All offsets, counts and sizes should be non-negative integer numbers. If the bytes that are accessed by any read or write operation are outside the buffer memory, an error is thrown.
The read and write methods that work with integers and floats use little-endian encoding.
Summary
Functions
Creates a buffer.
Creates a buffer from a string.
Converts a buffer to a string.
Returns the size of the buffer in bytes.
Reads a range of bits into an unsigned integer from the buffer based on a specific bitCount integer from 0 to 32, inclusive.
Reads an 8-bit signed integer from the buffer.
Reads an 8-bit unsigned integer from the buffer.
Reads a 16-bit signed integer from the buffer.
Reads a 16-bit unsigned integer from the buffer.
Reads a 32-bit signed integer from the buffer.
Reads a 32-bit unsigned integer from the buffer.
Reads a 32-bit floating-point value from the buffer.
Reads a 64-bit floating-point value from the buffer.
Writes data to the buffer based on a specific bitCount integer from 0 to 32, inclusive.
Writes an 8-bit signed integer to the buffer.
Writes an 8-bit unsigned integer to the buffer.
Writes a 16-bit signed integer to the buffer.
Writes a 16-bit unsigned integer to the buffer.
Writes a 32-bit signed integer to the buffer.
Writes a 32-bit unsigned integer to the buffer.
Writes a 32-bit floating-point value to the buffer.
Writes a 64-bit floating-point value to the buffer.
Reads a string from the buffer.
Writes a string to the buffer.
Copies bytes between buffers.
Sets a region of the buffer memory to some 8-bit unsigned integer value.