|
|
|
@ -27,7 +27,16 @@ local strbyte = string.byte |
|
|
|
|
|
|
|
|
|
|
|
local libS = LibStub:GetLibrary("AceSerializer-3.0") |
|
|
|
local libS = LibStub:GetLibrary("AceSerializer-3.0") |
|
|
|
local libC = LibStub:GetLibrary("LibCompress") |
|
|
|
local libC = LibStub:GetLibrary("LibCompress") |
|
|
|
local libCE = libC:GetChatEncodeTable("", "\031") |
|
|
|
local libCE |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local function GetCodec() |
|
|
|
|
|
|
|
if libCE then return libCE end |
|
|
|
|
|
|
|
libCE = libC:GetChatEncodeTable("", "\031") |
|
|
|
|
|
|
|
if not libCE then |
|
|
|
|
|
|
|
libCE = libC:GetChatEncodeTable() |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
return libCE |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
local function HashString(str) |
|
|
|
local function HashString(str) |
|
|
|
local hash = 0 |
|
|
|
local hash = 0 |
|
|
|
@ -74,18 +83,22 @@ end |
|
|
|
|
|
|
|
|
|
|
|
local function EncodePayload(payload) |
|
|
|
local function EncodePayload(payload) |
|
|
|
local serialized = libS:Serialize(payload) |
|
|
|
local serialized = libS:Serialize(payload) |
|
|
|
local encoded = libCE:Encode(libC:CompressHuffman(serialized)) |
|
|
|
local codec = GetCodec() |
|
|
|
|
|
|
|
if not codec then return end |
|
|
|
|
|
|
|
local encoded = codec:Encode(libC:CompressHuffman(serialized)) |
|
|
|
if not encoded then |
|
|
|
if not encoded then |
|
|
|
encoded = libCE:Encode(libC:CompressLZW(serialized)) |
|
|
|
encoded = codec:Encode(libC:CompressLZW(serialized)) |
|
|
|
end |
|
|
|
end |
|
|
|
if not encoded then |
|
|
|
if not encoded then |
|
|
|
encoded = libCE:Encode("\001" .. serialized) |
|
|
|
encoded = codec:Encode("\001" .. serialized) |
|
|
|
end |
|
|
|
end |
|
|
|
return encoded |
|
|
|
return encoded |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
local function DecodePayload(encoded) |
|
|
|
local function DecodePayload(encoded) |
|
|
|
local decoded = libCE:Decode(encoded) |
|
|
|
local codec = GetCodec() |
|
|
|
|
|
|
|
if not codec then return end |
|
|
|
|
|
|
|
local decoded = codec:Decode(encoded) |
|
|
|
if not decoded then return end |
|
|
|
if not decoded then return end |
|
|
|
local decompressed = libC:Decompress(decoded) |
|
|
|
local decompressed = libC:Decompress(decoded) |
|
|
|
if not decompressed then return end |
|
|
|
if not decompressed then return end |
|
|
|
|