buffer

Show Deprecated

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

Functions

create

Parameters

size: number

Returns

fromstring

Parameters

str: string

Returns

tostring

Parameters

Returns

Parameters

Returns

readi8

Parameters

offset: number

Returns

readu8

Parameters

offset: number

Returns

readi16

Parameters

offset: number

Returns

readu16

Parameters

offset: number

Returns

readi32

Parameters

offset: number

Returns

readu32

Parameters

offset: number

Returns

readf32

Parameters

offset: number

Returns

readf64

Parameters

offset: number

Returns

writei8

void

Parameters

offset: number
value: number

Returns

void

writeu8

void

Parameters

offset: number
value: number

Returns

void

writei16

void

Parameters

offset: number
value: number

Returns

void

writeu16

void

Parameters

offset: number
value: number

Returns

void

writei32

void

Parameters

offset: number
value: number

Returns

void

writeu32

void

Parameters

offset: number
value: number

Returns

void

writef32

void

Parameters

offset: number
value: number

Returns

void

writef64

void

Parameters

offset: number
value: number

Returns

void

readstring

Parameters

offset: number
count: number

Returns

writestring

void

Parameters

offset: number
value: string
count: number

Returns

void

copy

void

Parameters

target: buffer
targetOffset: number
source: buffer
sourceOffset: number
Default Value: 0
count: number

Returns

void

fill

void

Parameters

offset: number
value: number
count: number

Returns

void