Buffer.Utils
Getting Started
The Utils component in Buffer serves to, for example, calculate the number of bytes required
or directly convert a number of bytes to Kilobytes, Megabytes, or Gigabytes.
Methods
Getting the required bytes
To get the specific number of bytes, you will need a Schema and a table containing the values.
Note
This function is used in Buffer.Serialize.
I recommend reading that page if you are lost.
Converting bytes
To convert bytes to Kilobytes, etc., the ConvertTo function would be used.
local Buffer = require(somewhere.Buffer)
local Utils = Buffer.Utils
--This will convert the current bytes to Kilobytes
print(Utils.ConvertByte("Kilobytes",1024)) --> this will return 1
--First argument is the convertion and second argument is the bytes
-- Supported convertions: Kilobytes, Megabytes, Gigabytes
GetEquivalentBytesInfoFromNumber
Used in Buffer.WriteAny, this give the exact byte required depending on the number.
@return : {bits : number, bytes : number, @isUnsigned : boolean }
Info
isUnsigned purpose is only for Buffer.WriteAny to detect signed numbers,
you can still use it if you have to do some use case with u/i numbers
GetByteCodeValueFromType
Used in Buffer.WriteStruct. this resolves the byte code identifier associated with a given value.
Determines the most efficient byte representation for a value based on its type and characteristics. This byte code is later used for serialization to encode the value in a compact binary format.
@param value any -- Value to analyze @return number -- Byte code representing the value type