Skip to content

BitBuffer

Nak edited this page Sep 19, 2022 · 20 revisions

BitBuffers are written in pure Lua, similar to file-objects and store their data in a 32-bit number-array. They offer up to 80x the speed of regular file I/O operations, supports non-byte integers, Float, Double, has multiple additional features and can read/write at the same time.

Returns Functions Description
BitBuffer NikNaks.BitBuffer( String? /Table? data, Bool? little_endian) Creates a new BitBuffer.
Can be given a Data-String or -Table with 32bit numbers.
little_endian is true by default.
BitBuffer NikNaks.BitBuffer.OpenFile( String fileName, String? gamePath, Bool? lzma, Bool? little_endian ) Same as file.Open, but returns it as a bitbuffer.
little_endian is true by default.
Number NikNaks.BitBuffer.StringToInt( String str ) Takes a string of 1-4 charectors and converts it into a Little-Endian int
String NikNaks.BitBuffer.IntToString( Number int ) Takes an Little-Endian number and converts it into a 4 char-string

Bitbuffer Functions:

Returns Functions Description
Number BitBuffer:Tell() Returns the size of the BitBuffer
self BitBuffer:Seek( Number num ) Sets the pointer to the given position in bits.
self BitBuffer:Skip( Number int ) Skips the pointer the given bits forward.
Bool BitBuffer:Clear() Removes all data from the buffer.
Bool BitBuffer:EndOfData() Returns true if we've reached the end of the buffer.
Bool BitBuffer:IsLittleEndian() Returns true if the buffer is little endian.
Bool BitBuffer:IsBigEndian() Returns true if the buffer is big endian.
self BitBuffer:SetLittleEndian() Sets the buffer to little endian.
self BitBuffer:SetBigEndian() Sets the buffer to big endian.
BitBuffer:Debug() Prints the data to the console.

Bitbuffer Bits:

Returns Functions Description
self BitBuffer:WriteUInt( Number int,Number bits ) Writes an unsigned int
Number BitBuffer:ReadUInt( Number bits ) Reads an unsigned int
self BitBuffer:WriteInt( Number int,Number bits ) Writes a signed int
Number BitBuffer:ReadInt( Number bits ) Reads a signed int

Bitbuffer Integers:

Returns Functions Description
self BitBuffer:WriteLong( Number num ) Writes a 4 byte number ( -2147483648 to 2147483647 )
Number BitBuffer:ReadLong() Reads a 4 byte number ( -2147483648 to 2147483647 )
self BitBuffer:WriteShort( Number num ) Writes a 2 byte number ( -32768 to 32767 )
Number BitBuffer:ReadShort() Reads an 2 byte number ( -32768 to 32767 )
self BitBuffer:WriteSignedByte( Number byte ) Writes a signed byte ( -128 to 127 )
Number BitBuffer:ReadSignedByte() Reads a signed byte ( -128 to 127 )
self BitBuffer:WriteULong( Number num ) Writes an unsigned 4 byte number ( 0 to 4294967295 )
Number BitBuffer:ReadULong() Reads an unsigned 4 byte number ( 0 to 4294967295 )
self BitBuffer:WriteUShort( Number num ) Writes an unsigned 2 byte number ( 0 to 65535 )
Number BitBuffer:ReadUShort() Reads an unsigned 2 byte number ( 0 to 65535 )
self BitBuffer:WriteByte( Number byte ) Writes a byte ( 0 to 255 )
Number BitBuffer:ReadByte() Reads a byte ( 0 to 255 )
self BitBuffer:WriteNibble( Number num ) Writes a 4 bit unsigned number ( 0 to 15 )
Number BitBuffer:ReadNibble() Reads a 4 bit unsigned number ( 0 to 15 )
self BitBuffer:WriteSnort( Number num ) Writes a 2 bit unsigned number ( 0 to 3 )
Number BitBuffer:ReadSnort() Reads a 2 bit unsigned number ( 0 to 3 )

BitBuffer Floats/Doubles:

Returns Functions Description
self BitBuffer:WriteFloat( Number num ) Writes an IEEE 754 float
Number BitBuffer:ReadFloat() Reads an IEEE 754 float
self BitBuffer:WriteDouble( Number num ) Writes an IEEE 754 double
Number BitBuffer:ReadDouble() Reads an IEEE 754 double

BitBuffer Types:

Returns Functions Description
self BitBuffer:WriteBoolean( Bool bool ) Writes a boolean
Bool BitBuffer:ReadBoolean() Reads a boolean
self BitBuffer:WriteVector( Vector vector ) Writes a vector
Vector BitBuffer:ReadVector() Reads a vector
self BitBuffer:WriteString( String str ) Writes a string. Max string length: 65535
String BitBuffer:ReadString() Reads a string. Max string length: 65535
self BitBuffer:WriteAngle( Angle angle ) Writes an angle
Angle BitBuffer:ReadAngle() Reads an angle
self BitBuffer:WriteColor( Color color ) Writes a 32bit color
Color BitBuffer:ReadColor() Reads a 32bit color
self BitBuffer:WriteTable( Table tab ) Writes a table
Table BitBuffer:ReadTable() Reads a table
self BitBuffer:WriteType( any obj ) Writes a type using a byte as TYPE_ID.
any BitBuffer:ReadType() Reads a type using a byte as TYPE_ID.
self BitBuffer:WriteStringNull( String str ) Writes a string using a nullbyte at the end. Note: Will remove all nullbytes given.
String BitBuffer:ReadStringNull( Number? maxLength ) Reads a string using a nullbyte at the end. Note: ReadStringNull is a bit slower than ReadString.

BitBuffer Net functions:

Returns Functions Description
BitBuffer NikNaks.BitBuffer.FromNet( Number bits ) Reads the bits from net library and returns it as a BitBuffer.
Number NikNaks.BitBuffer.ToNet( BitBuffer buffer ) Writes the BitBuffer to the net library and returns the amount of bits it wrote.
self BitBuffer:ReadFromNet( Number bits ) Reads the bits from net library and returns self.
Number BitBuffer:WriteToNet() Writes the BitBuffer to the net library and returns the amount of bits it wrote.

Nik Naks Wiki


Features:

Clone this wiki locally