Skip to main content

BitBuffer

BitBuffer object.

Functions

is

General
BitBuffer.is(objany) → boolean

Returns whether the passed object is a BitBuffer.

print(BitBuffer.is(BitBuffer.new())) --> true
print(BitBuffer.is(true)) --> false

new

Constructor
BitBuffer.new(
sizeInBitsnumber?--

Initial size of the buffer in bits (defaults to 0)

) → BitBuffer

Creates a new BitBuffer with an initial size of sizeInBits.

local buffer = BitBuffer.new(128)
print(buffer:GetSize()) --> 128

FromString

Constructor
BitBuffer.FromString(inputStrstring) → BitBuffer

Creates a new BitBuffer from a binary string, starting with a size corresponding to number of bits in the input string (8 bits per character), and it's cursor positioned at 0.

local buffer = BitBuffer.FromString("\89")
print(buffer:ReadUInt(8)) --> 89
print(buffer:GetSize()) --> 8

See BitBuffer::ToString

FromBase64

Constructor
BitBuffer.FromBase64(inputStrstring) → BitBuffer

Creates a new BitBuffer from a Base64 string, starting with a size corresponding to the number of bits stored in the input string (6 bits per character), and it's cursor positioned at 0.

local str = base64("\45\180")
local buffer = BitBuffer.FromBase64(str)

print(buffer:ReadUInt(8)) --> 45
print(buffer:ReadUInt(8)) --> 180

See BitBuffer::ToBase64

FromBase91

Constructor
BitBuffer.FromBase91(inputStrstring) → BitBuffer

Creates a new BitBuffer from a Base91 string, starting with a size corresponding to the number of bits stored in the input string, and it's cursor positioned at 0. This is the recommended function to use for DataStores.

local initialBuffer = BitBuffer.new()
initialBuffer:WriteUInt(32, 78)
initialBuffer:WriteString("Hi")

local b91 = initialBuffer:ToBase91()
local newBuffer = BitBuffer.FromBase91(b91)
print(newBuffer:ReadUInt(32)) --> 78
print(newBuffer:ReadString()) --> Hi

See BitBuffer::ToBase91

What is Base91?

Base91 is a way to pack binary data into text, similar to Base64. It is, on average, about 10% more efficient than Base64. Check this page to learn more.

FromBase128

Constructor
BitBuffer.FromBase128(inputStrstring) → BitBuffer

Creates a new BitBuffer from a Base128 string, starting with a size corresponding to the number of bits stored in the input string (7 bits per character), and it's cursor positioned at 0.

local str = base128("\255\12")
local buffer = BitBuffer.FromBase128(str)
print(buffer:ReadUInt(8)) --> 255
print(buffer:ReadUInt(8)) --> 12

See BitBuffer::ToBase128

ResetCursor

General
BitBuffer:ResetCursor() → ()

Resets the position of the cursor.

local buffer = BitBuffer.new()
buffer:WriteUInt(32, 890)
buffer:ResetCursor()

print(buffer:GetCursor()) --> 0

SetCursor

General
BitBuffer:SetCursor(positionnumber) → ()

Sets the position of the cursor to the given position.

local buffer = BitBuffer.new()
buffer:WriteUInt(32, 67)
buffer:WriteUInt(32, 44)

buffer:SetCursor(32)
print(buffer:ReadUInt(32)) --> 44

GetCursor

General
BitBuffer:GetCursor() → number

Returns the position of the cursor.

local buffer = BitBuffer.new()
buffer:WriteUInt(17, 901)
buffer:WriteUInt(4, 2)
print(buffer:GetCursor()) --> 21

ResetBuffer

General
BitBuffer:ResetBuffer() → ()

Clears the buffer, setting its size to zero, and sets its position to 0.

local buffer = BitBuffer.new()
buffer:WriteUInt(32, math.pow(2, 32) - 1)

buffer:ResetBuffer()
print(buffer:GetCursor()) --> 0
print(buffer:ReadUInt(32)) --> 0

GetSize

General
BitBuffer:GetSize() → number

Returns the size of the buffer.

local buffer = BitBuffer.new()
buffer:WriteUInt(18, 618)

print(buffer:GetSize()) --> 18

ToString

Serialization
BitBuffer:ToString() → string

Serializes the buffer into a binary string. You can retrieve the buffer from this string using BitBuffer.FromString.

local buffer = BitBuffer.new()
buffer:WriteUInt(8, 65)
buffer:WriteUInt(8, 66)
buffer:WriteUInt(8, 67)

print(buffer:ToString()) --> ABC

See BitBuffer.FromString

ToBase64

Serialization
BitBuffer:ToBase64() → string

Serializes the buffer into a Base64 string. You can retrieve the buffer from this string using BitBuffer.FromBase64.

local initialBuffer = BitBuffer.new()
initialBuffer:WriteUInt(15, 919)
initialBuffer:WriteString("Hello!")

local b64 = initialBuffer:ToBase64()
local newBuffer = BitBuffer.FromBase64(b64)
print(newBuffer:ReadUInt(15)) --> 919
print(newBuffer:ReadString()) --> Hello!

See BitBuffer.FromBase64

ToBase91

Serialization
BitBuffer:ToBase91() → string

Serializes the buffer into a Base91 string. You can retrieve the buffer from this string using BitBuffer.FromBase91. This is the recommended function to use for DataStores.

local buffer = BitBuffer.new()
buffer:WriteString(playerData.CustomName)
buffer:WriteUInt(8, playerData.Level)
buffer:WriteUInt(16, playerData.Money)

SaveToDataStore(buffer:ToBase91())
local b91 = RetrieveFromDataStore()
local buffer = BitBuffer.FromBase91(b91)

local playerData = {
	CustomName = buffer:ReadString();
	Level = buffer:ReadUInt(8);
	Money = buffer:ReadUInt(16);
}

See BitBuffer.FromBase91

ToBase128

Serialization
BitBuffer:ToBase128() → string

Serializes the buffer into a Base128 string. You can retrieve the buffer from this string using BitBuffer.FromBase128.

return string

WriteUInt

Write
BitBuffer:WriteUInt(
bitWidthnumber,
uintnumber
) → ()

Writes an unsigned integer of bitWidth bits to the buffer. bitWidth must be an integer between 1 and 32. If the input integer uses more bits than bitWidth, it will overflow as expected.

buffer:WriteUInt(32, 560) -- Writes 560 to the buffer
buffer:WriteUInt(3, 9) -- Writes 0b101 (5) because 9 is 0b1101, but `bitWidth` is only 3!

ReadUInt

Read
BitBuffer:ReadUInt(bitWidthnumber) → number

Reads bitWidth bits from the buffer as an unsigned integer. bitWidth must be an integer between 1 and 32.

buffer:WriteUInt(12, 89)
buffer:ResetCursor()
print(buffer:ReadUInt(12)) --> 89

WriteInt

Write
BitBuffer:WriteInt(
bitWidthnumber,
intnumber
) → ()

Writes a signed integer of bitWidth bits using two's complement. bitWidth must be an integer between 1 and 32. Overflow is untested, use at your own risk.

local buffer = BitBuffer.new()
buffer:WriteInt(22, -901) --> Writes -901 to the buffer

ReadInt

Read
BitBuffer:ReadInt(bitWidthnumber) → number

Reads bitWidth bits as a signed integer stored using two's complement. bitWidth must be an integer between 1 and 32.

local buffer = BitBuffer.new()
buffer:WriteInt(15, -78)
buffer:ResetCursor()
print(buffer:ReadInt(15)) --> -78

WriteBool

Write
BitBuffer:WriteBool(valueany) → ()

Writes one bit the buffer: 1 if value is truthy, 0 otherwise.

local buffer = BitBuffer.new()
buffer:WriteBool(true) --> Writes 1
buffer:WriteBool("A") --> Also writes 1
buffer:WriteBool(nil) --> Writes 0

ReadBool

Read
BitBuffer:ReadBool() → boolean

Reads one bit from the buffer and returns a boolean: true if the bit is 1, false if the bit is 0.

local buffer = BitBuffer.new()
buffer:WriteUInt(4, 0b1011)
buffer:ResetCursor()

print(buffer:ReadBool()) --> true
print(buffer:ReadBool()) --> true
print(buffer:ReadBool()) --> false
print(buffer:ReadBool()) --> true

WriteChar

Write
BitBuffer:WriteChar(charstring) → ()

Writes one ASCII character (one byte) to the buffer. char cannot be an empty string.

local buffer = BitBuffer.new()
buffer:WriteChar("k")
buffer:ResetCursor()
print(buffer:ReadChar()) --> k

ReadChar

Read
BitBuffer:ReadChar() → string

Reads one byte as an ASCII character from the buffer.

local buffer = BitBuffer.new()
buffer:WriteUInt(8, 65)
buffer:ResetCursor()
print(buffer:ReadChar()) --> A

WriteBytes

Write
BitBuffer:WriteBytes(bytesstring) → ()

Writes a stream of bytes to the buffer. if bytes is an empty string, nothing will be written.

local buffer = BitBuffer.new()
buffer:WriteBytes("AD")
buffer:ResetCursor()
print(buffer:ReadUInt(8), buffer:ReadUInt(8)) --> 65 68

See BitBuffer::WriteString

ReadBytes

Read
BitBuffer:ReadBytes(lengthnumber) → string

Reads length bytes as a string from the buffer. if length is 0, nothing will be read and an empty string will be returned.

local buffer = BitBuffer.new()
buffer:WriteUInt(8, 65)
buffer:WriteUInt(8, 67)
print(buffer:ReadBytes(2)) --> AC

See BitBuffer::ReadString

WriteString

Write
BitBuffer:WriteString(strstring) → ()

Writes a string to the buffer.

WriteString will write the length of the string as a 24-bit unsigned integer first, then write the bytes in the string. The length of the string cannot be greater than 2^24 - 1 (16777215).

local buffer = BitBuffer.new()
buffer:WriteString("AB")
buffer:ResetCursor()
print(buffer:ReadUInt(24), buffer:ReadBytes(2)) --> 2 AB

See BitBuffer::WriteBytes

ReadString

Read
BitBuffer:ReadString() → string

Reads a string from the buffer (see BitBuffer::WriteString).

local buffer = BitBuffer.new()
buffer:WriteString("Hello!")
buffer:ResetCursor()
print(buffer:ReadString()) --> Hello!

See BitBuffer:ReadBytes

WriteFloat32

Write
BitBuffer:WriteFloat32(floatnumber) → ()

Writes a single-precision floating point number to the buffer.

local buffer = BitBuffer.new()
buffer:WriteFloat32(892.738)
buffer:ResetCursor()
print(buffer:ReadFloat32()) --> 892.73797607421875

ReadFloat32

Read
BitBuffer:ReadFloat32() → number

Reads a single-precision floating point number from the buffer.

local buffer = BitBuffer.new()
buffer:WriteFloat32(892.738)
buffer:ResetCursor()
print(buffer:ReadFloat32()) --> 892.73797607421875

WriteFloat64

Write
BitBuffer:WriteFloat64(doublenumber) → ()

Writes a double-precision floating point number to the buffer.

local buffer = BitBuffer.new()
buffer:WriteFloat64(-76358128.888202341)
buffer:ResetCursor()
print(buffer:ReadFloat64()) --> -76358128.888202

ReadFloat64

Read
BitBuffer:ReadFloat64() → number

Reads a double-precision floating point number from the buffer.

local buffer = BitBuffer.new()
buffer:WriteFloat64(-76358128.888202341)
buffer:ResetCursor()
print(buffer:ReadFloat64()) --> -76358128.888202
Show raw api
{
    "functions": [
        {
            "name": "is",
            "desc": "Returns whether the passed object is a BitBuffer.\n\n```lua\nprint(BitBuffer.is(BitBuffer.new())) --> true\nprint(BitBuffer.is(true)) --> false\n```",
            "params": [
                {
                    "name": "obj",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "tags": [
                "General"
            ],
            "source": {
                "line": 204,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "new",
            "desc": "Creates a new BitBuffer with an initial size of `sizeInBits`.\n\n```lua\nlocal buffer = BitBuffer.new(128)\nprint(buffer:GetSize()) --> 128\n```",
            "params": [
                {
                    "name": "sizeInBits",
                    "desc": "Initial size of the buffer in bits (defaults to 0)",
                    "lua_type": "number?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "BitBuffer"
                }
            ],
            "function_type": "static",
            "tags": [
                "Constructor"
            ],
            "source": {
                "line": 220,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "FromString",
            "desc": "Creates a new BitBuffer from a binary string, starting with a size corresponding to number of bits in the input string (8 bits per character), and it's cursor positioned at 0.\n\n```lua\nlocal buffer = BitBuffer.FromString(\"\\89\")\nprint(buffer:ReadUInt(8)) --> 89\nprint(buffer:GetSize()) --> 8\n```\n\nSee [BitBuffer::ToString](#ToString)",
            "params": [
                {
                    "name": "inputStr",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "BitBuffer"
                }
            ],
            "function_type": "static",
            "tags": [
                "Constructor"
            ],
            "source": {
                "line": 244,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "FromBase64",
            "desc": "Creates a new BitBuffer from a Base64 string, starting with a size corresponding to the number of bits stored in the input string (6 bits per character), and it's cursor positioned at 0.\n\n```lua\nlocal str = base64(\"\\45\\180\")\nlocal buffer = BitBuffer.FromBase64(str)\n\nprint(buffer:ReadUInt(8)) --> 45\nprint(buffer:ReadUInt(8)) --> 180\n```\n\nSee [BitBuffer::ToBase64](#ToBase64)",
            "params": [
                {
                    "name": "inputStr",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "BitBuffer"
                }
            ],
            "function_type": "static",
            "tags": [
                "Constructor"
            ],
            "source": {
                "line": 284,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "FromBase91",
            "desc": "Creates a new BitBuffer from a Base91 string, starting with a size corresponding to the number of bits stored in the input string, and it's cursor positioned at 0.\n**This is the recommended function to use for DataStores.**\n\n```lua\nlocal initialBuffer = BitBuffer.new()\ninitialBuffer:WriteUInt(32, 78)\ninitialBuffer:WriteString(\"Hi\")\n\nlocal b91 = initialBuffer:ToBase91()\nlocal newBuffer = BitBuffer.FromBase91(b91)\nprint(newBuffer:ReadUInt(32)) --> 78\nprint(newBuffer:ReadString()) --> Hi\n```\n\nSee [BitBuffer::ToBase91](#ToBase91)\n\n:::info What is Base91?\nBase91 is a way to pack binary data into text, similar to Base64. It is, on average, about 10% more efficient than Base64. Check [this page](http://base91.sourceforge.net) to learn more.\n:::",
            "params": [
                {
                    "name": "inputStr",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "BitBuffer"
                }
            ],
            "function_type": "static",
            "tags": [
                "Constructor"
            ],
            "source": {
                "line": 379,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "FromBase128",
            "desc": "Creates a new BitBuffer from a Base128 string, starting with a size corresponding to the number of bits stored in the input string (7 bits per character), and it's cursor positioned at 0.\n\n```lua\nlocal str = base128(\"\\255\\12\")\nlocal buffer = BitBuffer.FromBase128(str)\nprint(buffer:ReadUInt(8)) --> 255\nprint(buffer:ReadUInt(8)) --> 12\n```\n\nSee [BitBuffer::ToBase128](#ToBase128)",
            "params": [
                {
                    "name": "inputStr",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "BitBuffer"
                }
            ],
            "function_type": "static",
            "tags": [
                "Constructor"
            ],
            "source": {
                "line": 446,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "ResetCursor",
            "desc": "Resets the position of the cursor.\n\n```lua\nlocal buffer = BitBuffer.new()\nbuffer:WriteUInt(32, 890)\nbuffer:ResetCursor()\n\nprint(buffer:GetCursor()) --> 0\n```",
            "params": [],
            "returns": [],
            "function_type": "method",
            "tags": [
                "General"
            ],
            "source": {
                "line": 509,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "SetCursor",
            "desc": "Sets the position of the cursor to the given position.\n\n```lua\nlocal buffer = BitBuffer.new()\nbuffer:WriteUInt(32, 67)\nbuffer:WriteUInt(32, 44)\n\nbuffer:SetCursor(32)\nprint(buffer:ReadUInt(32)) --> 44\n```",
            "params": [
                {
                    "name": "position",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [],
            "function_type": "method",
            "tags": [
                "General"
            ],
            "source": {
                "line": 528,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "GetCursor",
            "desc": "Returns the position of the cursor.\n\n```lua\nlocal buffer = BitBuffer.new()\nbuffer:WriteUInt(17, 901)\nbuffer:WriteUInt(4, 2)\nprint(buffer:GetCursor()) --> 21\n```",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "method",
            "tags": [
                "General"
            ],
            "source": {
                "line": 549,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "ResetBuffer",
            "desc": "Clears the buffer, setting its size to zero, and sets its position to 0.\n\n```lua\nlocal buffer = BitBuffer.new()\nbuffer:WriteUInt(32, math.pow(2, 32) - 1)\n\nbuffer:ResetBuffer()\nprint(buffer:GetCursor()) --> 0\nprint(buffer:ReadUInt(32)) --> 0\n```",
            "params": [],
            "returns": [],
            "function_type": "method",
            "tags": [
                "General"
            ],
            "source": {
                "line": 566,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "GetSize",
            "desc": "Returns the size of the buffer.\n\n```lua\nlocal buffer = BitBuffer.new()\nbuffer:WriteUInt(18, 618)\n\nprint(buffer:GetSize()) --> 18\n```",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "method",
            "tags": [
                "General"
            ],
            "source": {
                "line": 585,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "ToString",
            "desc": "Serializes the buffer into a binary string.\nYou can retrieve the buffer from this string using [BitBuffer.FromString](#FromString).\n\n```lua\nlocal buffer = BitBuffer.new()\nbuffer:WriteUInt(8, 65)\nbuffer:WriteUInt(8, 66)\nbuffer:WriteUInt(8, 67)\n\nprint(buffer:ToString()) --> ABC\n```\n\nSee [BitBuffer.FromString](#FromString)",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "function_type": "method",
            "tags": [
                "Serialization"
            ],
            "source": {
                "line": 606,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "ToBase64",
            "desc": "Serializes the buffer into a Base64 string.\nYou can retrieve the buffer from this string using [BitBuffer.FromBase64](#FromBase64).\n\n```lua\nlocal initialBuffer = BitBuffer.new()\ninitialBuffer:WriteUInt(15, 919)\ninitialBuffer:WriteString(\"Hello!\")\n\nlocal b64 = initialBuffer:ToBase64()\nlocal newBuffer = BitBuffer.FromBase64(b64)\nprint(newBuffer:ReadUInt(15)) --> 919\nprint(newBuffer:ReadString()) --> Hello!\n```\nSee [BitBuffer.FromBase64](#FromBase64)",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "function_type": "method",
            "tags": [
                "Serialization"
            ],
            "source": {
                "line": 637,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "ToBase91",
            "desc": "Serializes the buffer into a Base91 string.\nYou can retrieve the buffer from this string using [BitBuffer.FromBase91](#FromBase91).\n**This is the recommended function to use for DataStores.**\n\n```lua\nlocal buffer = BitBuffer.new()\nbuffer:WriteString(playerData.CustomName)\nbuffer:WriteUInt(8, playerData.Level)\nbuffer:WriteUInt(16, playerData.Money)\n\nSaveToDataStore(buffer:ToBase91())\n```\n```lua\nlocal b91 = RetrieveFromDataStore()\nlocal buffer = BitBuffer.FromBase91(b91)\n\nlocal playerData = {\n\tCustomName = buffer:ReadString();\n\tLevel = buffer:ReadUInt(8);\n\tMoney = buffer:ReadUInt(16);\n}\n```\n\nSee [BitBuffer.FromBase91](#FromBase91)",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "function_type": "method",
            "tags": [
                "Serialization"
            ],
            "source": {
                "line": 699,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "ToBase128",
            "desc": "Serializes the buffer into a Base128 string.\nYou can retrieve the buffer from this string using [BitBuffer.FromBase128](#FromBase128).\n\nreturn string",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string\n"
                }
            ],
            "function_type": "method",
            "tags": [
                "Serialization"
            ],
            "source": {
                "line": 754,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "WriteUInt",
            "desc": "Writes an unsigned integer of `bitWidth` bits to the buffer.\n`bitWidth` must be an integer between 1 and 32.\nIf the input integer uses more bits than `bitWidth`, it will overflow as expected.\n\n```lua\nbuffer:WriteUInt(32, 560) -- Writes 560 to the buffer\nbuffer:WriteUInt(3, 9) -- Writes 0b101 (5) because 9 is 0b1101, but `bitWidth` is only 3!\n```",
            "params": [
                {
                    "name": "bitWidth",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "uint",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [],
            "function_type": "method",
            "tags": [
                "Write"
            ],
            "source": {
                "line": 794,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "ReadUInt",
            "desc": "Reads `bitWidth` bits from the buffer as an unsigned integer.\n`bitWidth` must be an integer between 1 and 32.\n\n```lua\nbuffer:WriteUInt(12, 89)\nbuffer:ResetCursor()\nprint(buffer:ReadUInt(12)) --> 89\n```",
            "params": [
                {
                    "name": "bitWidth",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "method",
            "tags": [
                "Read"
            ],
            "source": {
                "line": 820,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "WriteInt",
            "desc": "Writes a signed integer of `bitWidth` bits using [two's complement](https://en.wikipedia.org/wiki/Two%27s_complement).\n`bitWidth` must be an integer between 1 and 32.\nOverflow is **untested**, use at your own risk.\n\n```lua\nlocal buffer = BitBuffer.new()\nbuffer:WriteInt(22, -901) --> Writes -901 to the buffer\n```",
            "params": [
                {
                    "name": "bitWidth",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "int",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [],
            "function_type": "method",
            "tags": [
                "Write"
            ],
            "source": {
                "line": 844,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "ReadInt",
            "desc": "Reads `bitWidth` bits as a signed integer stored using [two's complement](https://en.wikipedia.org/wiki/Two%27s_complement).\n`bitWidth` must be an integer between 1 and 32.\n\n```lua\nlocal buffer = BitBuffer.new()\nbuffer:WriteInt(15, -78)\nbuffer:ResetCursor()\nprint(buffer:ReadInt(15)) --> -78\n```",
            "params": [
                {
                    "name": "bitWidth",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "method",
            "tags": [
                "Read"
            ],
            "source": {
                "line": 871,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "WriteBool",
            "desc": "Writes one bit the buffer: 1 if `value` is truthy, 0 otherwise.\n\n```lua\nlocal buffer = BitBuffer.new()\nbuffer:WriteBool(true) --> Writes 1\nbuffer:WriteBool(\"A\") --> Also writes 1\nbuffer:WriteBool(nil) --> Writes 0\n```",
            "params": [
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [],
            "function_type": "method",
            "tags": [
                "Write"
            ],
            "source": {
                "line": 896,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "ReadBool",
            "desc": "Reads one bit from the buffer and returns a boolean: true if the bit is 1, false if the bit is 0.\n\n```lua\nlocal buffer = BitBuffer.new()\nbuffer:WriteUInt(4, 0b1011)\nbuffer:ResetCursor()\n\nprint(buffer:ReadBool()) --> true\nprint(buffer:ReadBool()) --> true\nprint(buffer:ReadBool()) --> false\nprint(buffer:ReadBool()) --> true\n```",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "method",
            "tags": [
                "Read"
            ],
            "source": {
                "line": 921,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "WriteChar",
            "desc": "Writes one ASCII character (one byte) to the buffer.\n`char` cannot be an empty string.\n\n```lua\nlocal buffer = BitBuffer.new()\nbuffer:WriteChar(\"k\")\nbuffer:ResetCursor()\nprint(buffer:ReadChar()) --> k\n```",
            "params": [
                {
                    "name": "char",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [],
            "function_type": "method",
            "tags": [
                "Write"
            ],
            "source": {
                "line": 939,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "ReadChar",
            "desc": "Reads one byte as an ASCII character from the buffer.\n\n```lua\nlocal buffer = BitBuffer.new()\nbuffer:WriteUInt(8, 65)\nbuffer:ResetCursor()\nprint(buffer:ReadChar()) --> A\n```",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "function_type": "method",
            "tags": [
                "Read"
            ],
            "source": {
                "line": 962,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "WriteBytes",
            "desc": "Writes a stream of bytes to the buffer.\nif `bytes` is an empty string, nothing will be written.\n\n```lua\nlocal buffer = BitBuffer.new()\nbuffer:WriteBytes(\"AD\")\nbuffer:ResetCursor()\nprint(buffer:ReadUInt(8), buffer:ReadUInt(8)) --> 65 68\n```\n\nSee [BitBuffer::WriteString](#WriteString)",
            "params": [
                {
                    "name": "bytes",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [],
            "function_type": "method",
            "tags": [
                "Write"
            ],
            "source": {
                "line": 981,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "ReadBytes",
            "desc": "Reads `length` bytes as a string from the buffer.\nif `length` is 0, nothing will be read and an empty string will be returned.\n\n```lua\nlocal buffer = BitBuffer.new()\nbuffer:WriteUInt(8, 65)\nbuffer:WriteUInt(8, 67)\nprint(buffer:ReadBytes(2)) --> AC\n```\n\nSee [BitBuffer::ReadString](#ReadString)",
            "params": [
                {
                    "name": "length",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "function_type": "method",
            "tags": [
                "Read"
            ],
            "source": {
                "line": 1021,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "WriteString",
            "desc": "Writes a string to the buffer.\n\nWriteString will write the length of the string as a 24-bit unsigned integer first, then write the bytes in the string.\nThe length of the string cannot be greater than `2^24 - 1 (16777215)`.\n\n```lua\nlocal buffer = BitBuffer.new()\nbuffer:WriteString(\"AB\")\nbuffer:ResetCursor()\nprint(buffer:ReadUInt(24), buffer:ReadBytes(2)) --> 2 AB\n```\n\nSee [BitBuffer::WriteBytes](#WriteBytes)",
            "params": [
                {
                    "name": "str",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [],
            "function_type": "method",
            "tags": [
                "Write"
            ],
            "source": {
                "line": 1068,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "ReadString",
            "desc": "Reads a string from the buffer (see [BitBuffer::WriteString](#WriteString)).\n\n```lua\nlocal buffer = BitBuffer.new()\nbuffer:WriteString(\"Hello!\")\nbuffer:ResetCursor()\nprint(buffer:ReadString()) --> Hello!\n```\n\nSee [BitBuffer:ReadBytes](#ReadBytes)",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "function_type": "method",
            "tags": [
                "Read"
            ],
            "source": {
                "line": 1096,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "WriteFloat32",
            "desc": "Writes a single-precision floating point number to the buffer.\n\n```lua\nlocal buffer = BitBuffer.new()\nbuffer:WriteFloat32(892.738)\nbuffer:ResetCursor()\nprint(buffer:ReadFloat32()) --> 892.73797607421875\n```",
            "params": [
                {
                    "name": "float",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [],
            "function_type": "method",
            "tags": [
                "Write"
            ],
            "source": {
                "line": 1120,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "ReadFloat32",
            "desc": "Reads a single-precision floating point number from the buffer.\n\n```lua\nlocal buffer = BitBuffer.new()\nbuffer:WriteFloat32(892.738)\nbuffer:ResetCursor()\nprint(buffer:ReadFloat32()) --> 892.73797607421875\n```",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "method",
            "tags": [
                "Read"
            ],
            "source": {
                "line": 1155,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "WriteFloat64",
            "desc": "Writes a double-precision floating point number to the buffer.\n\n```lua\nlocal buffer = BitBuffer.new()\nbuffer:WriteFloat64(-76358128.888202341)\nbuffer:ResetCursor()\nprint(buffer:ReadFloat64()) --> -76358128.888202\n```",
            "params": [
                {
                    "name": "double",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [],
            "function_type": "method",
            "tags": [
                "Write"
            ],
            "source": {
                "line": 1187,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        },
        {
            "name": "ReadFloat64",
            "desc": "Reads a double-precision floating point number from the buffer.\n\n```lua\nlocal buffer = BitBuffer.new()\nbuffer:WriteFloat64(-76358128.888202341)\nbuffer:ResetCursor()\nprint(buffer:ReadFloat64()) --> -76358128.888202\n```",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "method",
            "tags": [
                "Read"
            ],
            "source": {
                "line": 1210,
                "path": "src/bitbuffer/src/BitBuffer.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "BitBuffer",
    "desc": "BitBuffer object.",
    "source": {
        "line": 185,
        "path": "src/bitbuffer/src/BitBuffer.lua"
    }
}