Skip to content

Commit

Permalink
Add can_encode function to validate encodable values
Browse files Browse the repository at this point in the history
  • Loading branch information
Srlion committed Dec 18, 2024
1 parent 018e666 commit 1c544e4
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions sfs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,19 @@ do
--
end

local function can_encode(val)
local t = type(val)
if t == "table" then
for k, v in pairs(val) do
if not can_encode(k) or not can_encode(v) then
return false
end
end
return true
end
return encoders[t] ~= nil
end

return {
TYPES = TYPES,

Expand Down Expand Up @@ -1181,6 +1194,8 @@ return {
decoders[id] = decoder
end,

can_encode = can_encode,

chars = chars,
VERSION = "4.0.0"
}

0 comments on commit 1c544e4

Please sign in to comment.