-
Notifications
You must be signed in to change notification settings - Fork 0
ByteBuffer
ByteBuffers are written in pure Lua, simular to file-objects and store their data in a string. They offer support for booleans, integers, floats, doubles, strings, Colors, Vectors, Angles, Tables, VarInts, has multiple additional features and can read/write at the same time.
- ID:
buffer - Accessed with:
thorium.gbuffer

gbuffer.New(o: table?) -> ByteBuffer
Creates new ByteBuffer

ByteBuffer.New(self: ByteBuffer, this: table?) -> ByteBuffer
Creates new BitBuffer

ByteBuffer.Clear(self: ByteBuffer) -> self: ByteBuffer
Clears buffer, removing all data from it

ByteBuffer.EndOfBuffer(self: ByteBuffer) -> endofbuffer: boolean
Returns whether we are at the end of buffer or not

ByteBuffer.Seek(self: ByteBuffer, seek_to: integer) -> self: ByteBuffer
Seeks (moves pointer) to a position in buffer.
On overflow goes over.

ByteBuffer.Size(self: ByteBuffer) -> size: integer
Get size of buffer

ByteBuffer.Skip(self: ByteBuffer, bytes: integer) -> self: ByteBuffer
Skips some amount of bytes, same as buffer:Seek(buffer:Tell()+bytes)

ByteBuffer.Tell(self: ByteBuffer) -> position: integer
Tell the position of pointer in buffer

ByteBuffer.ReadRAW(self: ByteBuffer, amount: integer) -> data: string
Reads raw data (string) from buffer

ByteBuffer.ReadBool(self: ByteBuffer) -> bool: boolean
Reads a boolean. Reads 1 byte

ByteBuffer.ReadUByte(self: ByteBuffer) -> num: integer
Reads unsigned byte. Reads 1 byte

ByteBuffer.ReadUShort(self: ByteBuffer) -> num: integer
Reads unsigned short. Reads 2 bytes

ByteBuffer.ReadUInt(self: ByteBuffer) -> num: integer
Reads unsigned integer. Reads 4 bytes

ByteBuffer.ReadByte(self: ByteBuffer) -> num: integer
Reads signed byte. Reads 1 byte

ByteBuffer.ReadShort(self: ByteBuffer) -> num: integer
Reads signed short. Reads 2 bytes

ByteBuffer.ReadInt(self: ByteBuffer) -> num: integer
Reads signed integer. Reads 4 bytes

ByteBuffer.ReadVarInt(self: ByteBuffer) -> num: integer
Reads VarInt. Reads variable amount of bytes

ByteBuffer.ReadFloat(self: ByteBuffer) -> x: number
Reads single-precision float. Reads 4 bytes

ByteBuffer.ReadDouble(self: ByteBuffer) -> x: number
Reads double-precision float. Reads 8 bytes

ByteBuffer.ReadStringLP(self: ByteBuffer) -> str: string
Reads length prefixed string. Reads #str + 2 bytes

ByteBuffer.ReadStringNT(self: ByteBuffer) -> str: string
Reads null terminated string. Reads #str + 1 bytes

ByteBuffer.ReadAngle(self: ByteBuffer) -> ang: Angle
Reads angle. Reads 12 bytes

ByteBuffer.ReadColor(self: ByteBuffer) -> clr: Color
Reads color. Reads 4 bytes

ByteBuffer.ReadVector(self: ByteBuffer) -> vec: Vector
Reads vector. Reads 12 bytes

ByteBuffer.ReadTable(self: ByteBuffer) -> tbl: table
Reads table from buffer. Reads variable amount of bytes

ByteBuffer.ReadType(self: ByteBuffer) -> v: any
Attempts to read a variable type. Reads variable amount of bytes

ByteBuffer.WriteRAW(self: ByteBuffer, data: string) -> self: ByteBuffer
Appends raw data (string) to buffer.

ByteBuffer.WriteBool(self: ByteBuffer, bool: boolean) -> self: ByteBuffer
Writes a boolean. Writes 1 byte

ByteBuffer.WriteUByte(self: ByteBuffer, num: integer) -> self: ByteBuffer
Writes unsigned byte. Writes 1 byte

ByteBuffer.WriteUShort(self: ByteBuffer, num: integer) -> self: ByteBuffer
Writes unsigned short. Writes 2 bytes

ByteBuffer.WriteUInt(self: ByteBuffer, num: integer) -> self: ByteBuffer
Writes unsigned integer. Writes 4 bytes

ByteBuffer.WriteByte(self: ByteBuffer, num: integer) -> self: ByteBuffer
Writes signed byte. Writes 1 byte

ByteBuffer.WriteShort(self: ByteBuffer, num: integer) -> self: ByteBuffer
Writes signed short. Writes 2 bytes

ByteBuffer.WriteInt(self: ByteBuffer, num: integer) -> self: ByteBuffer
Writes signed integer. Writes 4 bytes

ByteBuffer.WriteVarInt(self: ByteBuffer, num: integer) -> self: ByteBuffer
Writes VarInt. Writes variable amount of bytes

ByteBuffer.WriteFloat(self: ByteBuffer, x: number) -> self: ByteBuffer
Writes single-precision float. Writes 4 bytes

ByteBuffer.WriteDouble(self: ByteBuffer, x: number) -> self: ByteBuffer
Writes double-precision float. Writes 8 bytes

ByteBuffer.WriteStringLP(self: ByteBuffer, str: string) -> self: ByteBuffer
Writes length prefixed string. Writes #str + 2 bytes

ByteBuffer.WriteStringNT(self: ByteBuffer, str: string) -> self: ByteBuffer
Writes null terminated string. Writes #str + 1 bytes

ByteBuffer.WriteAngle(self: ByteBuffer, ang: Angle) -> self: ByteBuffer
Writes angle. Writes 12 bytes

ByteBuffer.WriteColor(self: ByteBuffer, clr: Color) -> self: ByteBuffer
Writes color. Writes 4 bytes

ByteBuffer.WriteVector(self: ByteBuffer, vec: Vector) -> self: ByteBuffer
Writes vector. Writes 12 bytes

ByteBuffer.WriteTable(self: ByteBuffer, tbl: table) -> self: ByteBuffer
Writes table to buffer. Writes variable amount of bytes

ByteBuffer.WriteType(self: ByteBuffer, v: any) -> self: ByteBuffer
Attempts to write a variable type. Writes variable amount of bytes

ByteBuffer.TYPETABLE_read: table
Tables used by ReadType to read variable types.
Key should be type from TYPE_ enum, and value is a function that takes BitBuffer and returns read value.

ByteBuffer.TYPETABLE_write: table
Tables used by WriteType to write variable types.
Key should be type from TYPE_ enum, and value is a function that takes BitBuffer and value itself.