Appearance
AceSerializer-3.0
AceSerializer-3.0 can serialize any variable (except functions or userdata) into a string format that can be sent over the addon communication channel.
AceSerializer was designed to keep all data intact, especially very large numbers or floating point numbers, and table structures. The only caveat currently is, that multiple references to the same table will be send individually.
Usage
Mix it in when creating your addon object:
lua
MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon", "AceSerializer-3.0")Serialize any values into a string:
lua
local MyVal1 = 23
local MyVal2 = "some text"
local MyVal3 = { "foo", 42, "bar" }
local serializedData = MyAddon:Serialize(MyVal1, MyVal2, MyVal3)Deserialize. The first return is a success boolean; on success the original values follow, on failure an error message:
lua
local success, v1, v2, v3 = MyAddon:Deserialize(serializedData)
if not success then
-- handle error (v1 is the error message)
endCombine with AceComm-3.0 to send structured data between clients.
API Reference
Embed
method#
lua
AceSerializer:Embed(target)Copies AceSerializer's methods onto target so you can call them on it directly. See The :Embed method.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
target | table | The target object to embed AceSerializer into. |
Returns
| Type | Description |
|---|---|
table | The target object. |
Serialize
method#
lua
AceSerializer:Serialize(...)Serialize the data passed into the function.
Takes a list of values (strings, numbers, booleans, nils, tables) and returns it in serialized form (a string). May throw errors on invalid data types.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
... | any | List of values to serialize (strings, numbers, booleans, nils, tables). |
Returns
| Type | Description |
|---|---|
string | The data in its serialized form. |
Deserialize
method#
lua
AceSerializer:Deserialize(str)Deserializes the data into its original values.
Accepts serialized data, ignoring all control characters and whitespace.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
str | string | The serialized data (from :Serialize). |
Returns
| Type | Description |
|---|---|
boolean | success: true on success, false on failure. |
any | ...: On success, the deserialized list of values; on failure, the error message (string). |
Example
lua
local ok, value = self:Deserialize(payload)
if ok then
-- use value
end