Encoding
lua Code:
LBE:Encode(binary,<optional> addonName,<optional> purpose,<optional> base) OR
LBE:Encode64(binary,<optional> addonName,<optional> purpose)
binary: can be a number (not recommended), a string or a table of boolean values. It will handle the conversion from the table, so you do not need to worry about whether it is a numeric or boolean binary value.
base: 64 or 256. Defaults to 256. If addonName and purpose are provided, this parameter inherits from them and is ignored.
Decoding
The "base256" must be a string or number (not recommended).
lua Code:
LBE:Decode(baseString,<optional> addonName,<optional> purpose,<optional> base) OR
LBE:Decode64(baseString,<optional> addonName,<optional> purpose)
Returns a table of boolean values.
base: 64 or 256. Defaults to 256. If addonName and purpose are provided, this parameter inherits from them and is ignored.
lua Code:
LBE:DecodeToString(baseString,<optional> addonName,<optional> purpose,<optional> base) OR
LBE:DecodeToString64(baseString,<optional> addonName,<optional> purpose)
Returns a string.
Versioning
As your schema changes, you will need to handle the different versions that may be in use.
Note: If you know the data in the old schema will fit inside of the new schema, use ParseTrusted instead of handling this yourself (LBETest includes examples on short and long form version handling).
lua Code:
LBE:ConvertSchema(binary_table,<optional> addonName,<optional> purpose)
This attempts to convert the data from one schema to another.
binary_table: the real, old data
addonName: likely the same, but is the name of the addon from the new schema
purpose: the new schema's purpose
Returns a table or false on failure.
lua Code:
LBE:CloneSchema(<optional> addonName,<optional> purpose)
If you know the old version won't work, this function will make a blank copy of the new schema instead to be used in its place.
Returns a table or false on failure.
Helpers
These are functions that you don't necessarily need but I found useful.
lua Code:
LBE:IsTrue(boolean,<optional> strict) OR IsTrue(boolean,<optional> strict)
IsTrue will take a value and determine if it is true. Unlike Lua's default, it evaluates 0 and empty strings as false. If strict is true, only the most basic forms of boolean "true" will be considered true. For example: 5 or "content" would evaluate as false.
lua Code:
LBE:NumBool(boolean,<optional> strict) OR NumBool(boolean,<optional> strict)
NumBool will take a value (assumed boolean) and return 0 or 1. When combined with doing your boolean checks using IsTrue, it allows saving booleans as a single byte instead of multiple in savedvars, which adds up for addons using a lot of booleans.
lua Code:
LBE:SplitString(inputString,<optional> separator)
LBE:SplitString will take an input string and break it down character by character into a table. If "separator" is used it will be the preferred method of breaking the string. This splitter does not consume any characters unless specified by separator.
lua Code:
LBE:SplitBooleanString(inputString,<optional> separator)
Works like SplitString, except it determines whether the character is true or false and outputs it as a boolean value. Only recommended for parsing binary strings.
lua Code:
LBE:ConcatTables(table1, table2)
Combines two 1D tables, such as combining separate lists of IDs together.
Converts a 1D table into a table of of those indexes, such as turning a list of IDs into a schema.
lua Code:
LBE:CloneSchema(addonName, purpose)
Creates a copy of a schema's table into a new table with all values set to false.
lua Code:
LBE:ConvertSchema(table, addonName, purpose)
Converts a table into a new table that abides by the schema that comes from that addonName/purpose combo.
lua Code:
LBE:MergeTables(originTbl, targetTbl)
Overwrites values in the target table with values in the origin table where they have matching indices.
lua Code:
LBE:FlattenTable(table, addonName, purpose)
Converts the table per its schema into a binary string.