local Packages = script.Parent.Parent.Parent.Packages
local RbxDom = require(Packages.RbxDom)
local Error = require(script.Parent.Error)
local function decodeValue(encodedValue, instanceMap)
local ty, value = next(encodedValue)
if ty == "Ref" then
if value == "00000000000000000000000000000000" then
return true, nil
end
local instance = instanceMap.fromIds[value]
if instance ~= nil then
return true, instance
else
return false, Error.new(Error.RefDidNotExist, {
encodedValue = encodedValue,
})
end
end
local decodeSuccess, decodedValue = RbxDom.EncodedValue.decode(encodedValue)
if not decodeSuccess then
return false,
Error.new(Error.CannotDecodeValue, {
encodedValue = encodedValue,
innerError = decodedValue,
})
end
return true, decodedValue
end
return decodeValue