From 15af5852ac2e2c1e53893a1f4ee9baf5d0c447b6 Mon Sep 17 00:00:00 2001 From: Victor Bombi Date: Fri, 2 Apr 2021 11:53:13 +0200 Subject: [PATCH] allow VLA serialization with t=254 --- bitser.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bitser.lua b/bitser.lua index b76a9d7..86bb10c 100644 --- a/bitser.lua +++ b/bitser.lua @@ -235,6 +235,17 @@ local function write_cdata(value, seen) serialize_value(tostring(ty):sub(7, -2), seen) return end + if tostring(ty):match"%s*%[%?%]" then + -- VLA + Buffer_write_byte(254) + serialize_value(ty, seen) + local len = ffi.sizeof(value) + write_number(len) + local nelem = len/ffi.sizeof(ty,1) + write_number(nelem) + Buffer_write_raw(ffi.string(value,len), len) + return + end -- cdata Buffer_write_byte(252) serialize_value(ty, seen) @@ -388,6 +399,13 @@ local function deserialize_value(seen) local read_into = ffi.typeof('$[1]', ctype)() Buffer_read_raw(read_into, len) return ctype(read_into[0]) + elseif t == 254 then + local ctype = deserialize_value(seen) + local len = deserialize_value(seen) + local nelem = deserialize_value(seen) + local read_into = ffi.typeof(ctype)(nelem) + Buffer_read_raw(read_into, len) + return read_into else error("unsupported serialized type " .. t) end