Jørgen Lien Sellæg 4 months ago
parent
commit
10047e31ab
  1. 23
      TradeSkillMaster_AuctionDB/Modules/ChannelSync.lua

23
TradeSkillMaster_AuctionDB/Modules/ChannelSync.lua

@ -27,7 +27,16 @@ local strbyte = string.byte
local libS = LibStub:GetLibrary("AceSerializer-3.0")
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 hash = 0
@ -74,18 +83,22 @@ end
local function EncodePayload(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
encoded = libCE:Encode(libC:CompressLZW(serialized))
encoded = codec:Encode(libC:CompressLZW(serialized))
end
if not encoded then
encoded = libCE:Encode("\001" .. serialized)
encoded = codec:Encode("\001" .. serialized)
end
return encoded
end
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
local decompressed = libC:Decompress(decoded)
if not decompressed then return end

Loading…
Cancel
Save