Feature Implementation - AceSerializer-3.0, PairByKeys #581

  • New
  • Patch
  • Pantheon_Neekio created this issue Aug 11, 2021

    Version: AceSerializer-3.0, 5

    Description: Currently, when serializing tables, the serializer follows traditional Lua code by using pairs. This typically doesn't cause any issues, except for when you are attempting to use LibDeflate's Adler32 hashing algorithm to compare two identical tables from two separate clients. Because table pairs are non-deterministic in the order that they process, this causes the resulting serialized strings to not be identical, and thus the hashes of those strings are not identical (even though the contents of the tables are).


    This can be remedied by either including the behavior of pairingByKey by default or by allowing us to pass in a config option.

    I have attached the necessary code below, to show how this behavior could be fixed by default:

    New Function PairByKeys:

    local function PairByKeys(t, f)
       local a = {};
       for n in pairs(t) do table.insert(a, n) end
       table.sort(a, f)
       local i = 0;
       local iter = function()
          i = i + 1
          if a[i] == nil then return nil
          else return a[i], t[a[i]]
       return iter;

    Change Line 86 From: for k, v in pairs(v) do ...
    To: for k,v in PairByKeys(v) do...


  • Pantheon_Neekio added the tags New Patch Aug 11, 2021
  • Pantheon_Neekio edited description Aug 11, 2021
  • Pantheon_Neekio posted a comment Aug 12, 2021

    Btw, If anyone is reading this and having the same issue. I fixed it by implementing the above code changes, and then editing the minor version number in the Serializer file from 5 to 6 (so that my version gets loaded by default, instead of another addons).

  • nevcairiel posted a comment Dec 15, 2021

    table.sort errors on mixed type keys, so if you have a table with string keys as well as number keys, or anything even fancier, you would likely encounter issues.


    As a general solution, much more hardening would have to go in here.

To post a comment, please login or register a new account.