DataView
Side: Client
Binary buffer manipulation for working with RedM natives that require structured binary data. This module exposes two globals: DataView and bigInt().
Constructors
DataView.ArrayBuffer(length)
Creates a new zero-initialized buffer of the given byte length.
| Parameter | Type | Description |
|---|---|---|
length | integer | Buffer size in bytes |
Returns: DataView instance
local buf = DataView.ArrayBuffer(32)DataView.Wrap(blob)
Wraps an existing binary blob (string) into a DataView.
| Parameter | Type | Description |
|---|---|---|
blob | string | Raw binary data |
Returns: DataView instance
local buf = DataView.Wrap(some_binary_data)Methods
:Buffer()
Returns the underlying binary buffer as a string.
Returns: string
:ByteLength()
Returns the total byte length of the buffer.
Returns: integer
:SubView(offset)
Creates a new DataView starting at the given byte offset within the same buffer.
| Parameter | Type | Description |
|---|---|---|
offset | integer | Byte offset from the start |
Returns: DataView instance
Get / Set Methods
All getter and setter methods follow the pattern :Get<Type>(offset) and :Set<Type>(offset, value).
| Method Pair | Size | Description |
|---|---|---|
GetInt8 / SetInt8 | 1 byte | Signed 8-bit integer |
GetUint8 / SetUint8 | 1 byte | Unsigned 8-bit integer |
GetInt16 / SetInt16 | 2 bytes | Signed 16-bit integer |
GetUint16 / SetUint16 | 2 bytes | Unsigned 16-bit integer |
GetInt32 / SetInt32 | 4 bytes | Signed 32-bit integer |
GetUint32 / SetUint32 | 4 bytes | Unsigned 32-bit integer |
GetInt64 / SetInt64 | 8 bytes | Signed 64-bit integer |
GetUint64 / SetUint64 | 8 bytes | Unsigned 64-bit integer |
GetFloat32 / SetFloat32 | 4 bytes | 32-bit float |
GetFloat64 / SetFloat64 | 8 bytes | 64-bit float (double) |
GetLuaInt / SetLuaInt | — | Lua integer (platform-dependent) |
GetLuaNum / SetLuaNum | — | Lua number (double) |
Fixed-Size Methods
| Method | Description |
|---|---|
GetFixedString(offset, length) | Read a fixed-length string from the buffer |
GetFixedInt(offset, length) | Read a fixed-length signed integer |
GetFixedUint(offset, length) | Read a fixed-length unsigned integer |
bigInt(text) -> integer
Global function that converts a string representation of a number to a 64-bit integer. Useful for large hash values and native arguments.
| Parameter | Type | Description |
|---|---|---|
text | string | String representation of a 64-bit integer |
Returns: integer
local hash = bigInt("12345678901234567")Examples
Read a native output buffer
local buf = DataView.ArrayBuffer(8 * 10)
-- Pass buffer to a native that fills it
Citizen.InvokeNative(0xABCD, buf:Buffer(), Citizen.ReturnResultAnyway())
-- Read values from the buffer
local value1 = buf:GetInt32(0)
local value2 = buf:GetFloat32(4)Write and read structured data
local buf = DataView.ArrayBuffer(16)
buf:SetInt32(0, 42)
buf:SetFloat32(4, 3.14)
buf:SetUint8(8, 255)
print(buf:GetInt32(0)) -- 42
print(buf:GetFloat32(4)) -- 3.14
print(buf:GetUint8(8)) -- 255Use SubView for offset access
local buf = DataView.ArrayBuffer(64)
local sub = buf:SubView(32)
sub:SetInt32(0, 100) -- writes at byte 32 of the original bufferNotes
DataViewandbigIntare exposed as globals (not under thetwnamespace).- This module is primarily used for interacting with RedM natives that expect or return binary data buffers.
- All offsets are zero-based byte offsets.

