Hi Sean,
yes I know about the __tocbor metamethod, and I know that there are also other alternatives with the org.conman.cbor library, but none has "zero impact".
The simplest proof-of-concept using __tocbor:
function b(data)
local d={data=""> setmetatable(d,{__tocbor=function(self) return cbor.TYPE.BIN(self.data) end})
return d
end
cbor.encode{string1='abc', buffer1=b'abc'}
works, but I have to transform fields in the table via the 'b' function.
I was looking for something that can mark buffers or strings "natively" in Lua (userdata? I'm a bit of a Lua newb), e.g. in pseudocode:
tbl={}
tbl.string1='abc'
tbl.buffer1='abc'
settypehint(tbl.buffer1,'bytes')
cbor.encode(tbl) -- somehow reads the type hint above
so that I can keep the original table content unchanged.
Is there anything closer to that hypothetical settypehint() function in the example above?
Cheers,