Fix bluon:len

This commit is contained in:
Lars Mueller 2021-05-08 21:02:12 +02:00
parent e28ee76d7d
commit f6a3f31c13

@ -95,9 +95,14 @@ local function is_map_key(key, list_len)
end end
function len(self, object) function len(self, object)
if object == nil then
return 0
end
if constants[object] then if constants[object] then
return 1 return 1
end end
local object_ids = {}
local current_id = 0
local _type = type(object) local _type = type(object)
if _type == "number" then if _type == "number" then
if object ~= object then if object ~= object then
@ -126,7 +131,6 @@ function len(self, object)
if _type == "table" then if _type == "table" then
if next(object) == nil then if next(object) == nil then
-- empty {} table -- empty {} table
byte(type_ranges.string + 1)
return 1 return 1
end end
local list_len = #object local list_len = #object
@ -138,14 +142,14 @@ function len(self, object)
end end
local table_len = 1 + uint_len(list_len) + uint_len(kv_len) local table_len = 1 + uint_len(list_len) + uint_len(kv_len)
for index = 1, list_len do for index = 1, list_len do
table_len = table_len + len(self, object[index]) table_len = table_len + self:len(object[index])
end end
for key, value in pairs(object) do for key, value in pairs(object) do
if is_map_key(key, list_len) then if is_map_key(key, list_len) then
table_len = table_len + len(self, key) + len(self, value) table_len = table_len + self:len(key) + self:len(value)
end end
end end
return len return kv_len + table_len
end end
return self.aux_len(object) return self.aux_len(object)
end end