Skip to content

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.

ParameterTypeDescription
lengthintegerBuffer size in bytes

Returns: DataView instance

lua
local buf = DataView.ArrayBuffer(32)

DataView.Wrap(blob)

Wraps an existing binary blob (string) into a DataView.

ParameterTypeDescription
blobstringRaw binary data

Returns: DataView instance

lua
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.

ParameterTypeDescription
offsetintegerByte 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 PairSizeDescription
GetInt8 / SetInt81 byteSigned 8-bit integer
GetUint8 / SetUint81 byteUnsigned 8-bit integer
GetInt16 / SetInt162 bytesSigned 16-bit integer
GetUint16 / SetUint162 bytesUnsigned 16-bit integer
GetInt32 / SetInt324 bytesSigned 32-bit integer
GetUint32 / SetUint324 bytesUnsigned 32-bit integer
GetInt64 / SetInt648 bytesSigned 64-bit integer
GetUint64 / SetUint648 bytesUnsigned 64-bit integer
GetFloat32 / SetFloat324 bytes32-bit float
GetFloat64 / SetFloat648 bytes64-bit float (double)
GetLuaInt / SetLuaIntLua integer (platform-dependent)
GetLuaNum / SetLuaNumLua number (double)

Fixed-Size Methods

MethodDescription
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.

ParameterTypeDescription
textstringString representation of a 64-bit integer

Returns: integer

lua
local hash = bigInt("12345678901234567")

Examples

Read a native output buffer

lua
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

lua
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))    -- 255

Use SubView for offset access

lua
local buf = DataView.ArrayBuffer(64)
local sub = buf:SubView(32)

sub:SetInt32(0, 100) -- writes at byte 32 of the original buffer

Notes

  • DataView and bigInt are exposed as globals (not under the tw namespace).
  • This module is primarily used for interacting with RedM natives that expect or return binary data buffers.
  • All offsets are zero-based byte offsets.

Premium RedM Scripts — Multi-Framework