Skip to main content

BufferWriter

A BufferWriter is an abstraction wrapper for buffer objects that provides a convenient way of writing data to buffers.

The internal buffer is automatically resized to fit the data that is being written.

Functions

WriteInt8

BufferWriter:WriteInt8(int8number) → ()

Write a signed 8-bit integer to the buffer.

WriteUInt8

BufferWriter:WriteUInt8(uint8number) → ()

Write an unsigned 8-bit integer to the buffer.

WriteInt16

BufferWriter:WriteInt16(int16number) → ()

Write a signed 16-bit integer to the buffer.

WriteUInt16

BufferWriter:WriteUInt16(uint16number) → ()

Write an unsigned 16-bit integer to the buffer.

WriteInt32

BufferWriter:WriteInt32(int32number) → ()

Write a signed 32-bit integer to the buffer.

WriteUInt32

BufferWriter:WriteUInt32(uint32number) → ()

Write an unsigned 32-bit integer to the buffer.

WriteFloat32

BufferWriter:WriteFloat32(f32number) → ()

Write a 32-bit single-precision float to the buffer.

WriteFloat64

BufferWriter:WriteFloat64(f64number) → ()

Write a 64-bit double-precision float to the buffer.

WriteBool

BufferWriter:WriteBool(boolboolean) → ()

Write a boolean to the buffer.

WriteString

BufferWriter:WriteString(
strstring,
lengthnumber?
) → ()

Write a string to the buffer. An optional length argument can be provided to limit the number of bytes read from the string.

info

An extra 32-bit integer is stored before the string to mark the length of the string. If the length of the string is always known, it is more memory-efficient to use WriteStringRaw.

WriteStringRaw

BufferWriter:WriteStringRaw(
strstring,
lengthnumber?
) → ()

Write a string to the buffer. An optional length argument can be provided to limit the number of bytes read from the string.

info

The length of the string must be known to the reader in order to read this string from the buffer, as the length of the string is not stored in the buffer. For strings of dynamic/unknown length, use WriteString instead.

WriteDataType

BufferWriter:WriteDataType(valueany) → ()

Write a DataType to the buffer.

writer:WriteDataType(CFrame.new(0, 10, 5))

Shrink

BufferWriter:Shrink() → ()

Shrinks the capacity of the buffer to the current data size.

GetSize

BufferWriter:GetSize() → number

Returns the current data size of the buffer. This is not necessarily equal to the capacity of the buffer.

GetCapacity

BufferWriter:GetCapacity() → number

Returns the current capacity of the buffer. This is the length of the internal buffer, which is usually not the same as the length of the stored data.

The buffer capacity automatically grows as data is added.

SetCursor

BufferWriter:SetCursor(positionnumber) → ()

Sets the position of the cursor.

GetCursor

BufferWriter:GetCursor() → number

Gets the position of the cursor.

ResetCursor

BufferWriter:ResetCursor() → ()

Resets the position of the cursor.

GetBuffer

BufferWriter:GetBuffer() → buffer

Returns the buffer object.

ToString

BufferWriter:ToString() → string

Returns the string version of the internal buffer.

Show raw api
{
    "functions": [
        {
            "name": "WriteInt8",
            "desc": "Write a signed 8-bit integer to the buffer.",
            "params": [
                {
                    "name": "int8",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 61,
                "path": "modules/buffer-util/BufferWriter.luau"
            }
        },
        {
            "name": "WriteUInt8",
            "desc": "Write an unsigned 8-bit integer to the buffer.",
            "params": [
                {
                    "name": "uint8",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 70,
                "path": "modules/buffer-util/BufferWriter.luau"
            }
        },
        {
            "name": "WriteInt16",
            "desc": "Write a signed 16-bit integer to the buffer.",
            "params": [
                {
                    "name": "int16",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 79,
                "path": "modules/buffer-util/BufferWriter.luau"
            }
        },
        {
            "name": "WriteUInt16",
            "desc": "Write an unsigned 16-bit integer to the buffer.",
            "params": [
                {
                    "name": "uint16",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 88,
                "path": "modules/buffer-util/BufferWriter.luau"
            }
        },
        {
            "name": "WriteInt32",
            "desc": "Write a signed 32-bit integer to the buffer.",
            "params": [
                {
                    "name": "int32",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 97,
                "path": "modules/buffer-util/BufferWriter.luau"
            }
        },
        {
            "name": "WriteUInt32",
            "desc": "Write an unsigned 32-bit integer to the buffer.",
            "params": [
                {
                    "name": "uint32",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 106,
                "path": "modules/buffer-util/BufferWriter.luau"
            }
        },
        {
            "name": "WriteFloat32",
            "desc": "Write a 32-bit single-precision float to the buffer.",
            "params": [
                {
                    "name": "f32",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 115,
                "path": "modules/buffer-util/BufferWriter.luau"
            }
        },
        {
            "name": "WriteFloat64",
            "desc": "Write a 64-bit double-precision float to the buffer.",
            "params": [
                {
                    "name": "f64",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 124,
                "path": "modules/buffer-util/BufferWriter.luau"
            }
        },
        {
            "name": "WriteBool",
            "desc": "Write a boolean to the buffer.",
            "params": [
                {
                    "name": "bool",
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 133,
                "path": "modules/buffer-util/BufferWriter.luau"
            }
        },
        {
            "name": "WriteString",
            "desc": "Write a string to the buffer. An optional `length` argument can\nbe provided to limit the number of bytes read from the string.\n\n:::info\nAn extra 32-bit integer is stored before the string to mark the\nlength of the string. If the length of the string is always\nknown, it is more memory-efficient to use `WriteStringRaw`.",
            "params": [
                {
                    "name": "str",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "length",
                    "desc": "",
                    "lua_type": "number?"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 146,
                "path": "modules/buffer-util/BufferWriter.luau"
            }
        },
        {
            "name": "WriteStringRaw",
            "desc": "Write a string to the buffer. An optional `length` argument can\nbe provided to limit the number of bytes read from the string.\n\n:::info\nThe length of the string must be known to the reader in order to\nread this string from the buffer, as the length of the string is\nnot stored in the buffer. For strings of dynamic/unknown length,\nuse `WriteString` instead.",
            "params": [
                {
                    "name": "str",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "length",
                    "desc": "",
                    "lua_type": "number?"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 165,
                "path": "modules/buffer-util/BufferWriter.luau"
            }
        },
        {
            "name": "WriteDataType",
            "desc": "Write a DataType to the buffer.\n\n```lua\nwriter:WriteDataType(CFrame.new(0, 10, 5))\n```",
            "params": [
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 179,
                "path": "modules/buffer-util/BufferWriter.luau"
            }
        },
        {
            "name": "Shrink",
            "desc": "Shrinks the capacity of the buffer to the current data size.",
            "params": [],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 191,
                "path": "modules/buffer-util/BufferWriter.luau"
            }
        },
        {
            "name": "GetSize",
            "desc": "Returns the current data size of the buffer. This is _not_ necessarily\nequal to the capacity of the buffer.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 208,
                "path": "modules/buffer-util/BufferWriter.luau"
            }
        },
        {
            "name": "GetCapacity",
            "desc": "Returns the current capacity of the buffer. This is the length of the\ninternal buffer, which is usually not the same as the length of the stored\ndata.\n\nThe buffer capacity automatically grows as data is added.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 219,
                "path": "modules/buffer-util/BufferWriter.luau"
            }
        },
        {
            "name": "SetCursor",
            "desc": "Sets the position of the cursor.",
            "params": [
                {
                    "name": "position",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 226,
                "path": "modules/buffer-util/BufferWriter.luau"
            }
        },
        {
            "name": "GetCursor",
            "desc": "Gets the position of the cursor.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 238,
                "path": "modules/buffer-util/BufferWriter.luau"
            }
        },
        {
            "name": "ResetCursor",
            "desc": "Resets the position of the cursor.",
            "params": [],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 245,
                "path": "modules/buffer-util/BufferWriter.luau"
            }
        },
        {
            "name": "GetBuffer",
            "desc": "Returns the `buffer` object.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "buffer\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 252,
                "path": "modules/buffer-util/BufferWriter.luau"
            }
        },
        {
            "name": "ToString",
            "desc": "Returns the string version of the internal buffer.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 259,
                "path": "modules/buffer-util/BufferWriter.luau"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "BufferWriter",
    "desc": "A BufferWriter is an abstraction wrapper for `buffer` objects\nthat provides a convenient way of writing data to buffers.\n\nThe internal buffer is automatically resized to fit the data\nthat is being written.",
    "source": {
        "line": 17,
        "path": "modules/buffer-util/BufferWriter.luau"
    }
}