Commit 95f36e3d authored by Jaromil's avatar Jaromil
Browse files

zenroom zpack now saves and restores codec

also minor code cleanup
parent 25105ac6
......@@ -96,7 +96,6 @@ H = HASH -- alias
PAIR = ECP2 -- alias
PAIR.ate = ECP2.miller --alias
MPACK = require('zenroom_msgpack')
ZPACK = require('zenroom_zpack')
BENCH = require('zenroom_bench')
MACHINE = require('statemachine')
TIME = require('timetable')
......
......@@ -39,15 +39,18 @@ end)
When("create the zpack of ''", function(src)
empty'zpack'
local source = have(src)
ACK.zpack = ZPACK.encode(source)
local tmp = MPACK.encode( { data = source,
codec = ZEN.CODEC[src] } )
ACK.zpack = compress( O.from_rawlen(tmp, #tmp) )
new_codec('zpack', { zentype = 'element'})
end)
When("create the '' decoded from zpack ''", function(dst, src)
empty(dst)
local pack = have(src)
ZEN.assert(ZEN.CODEC[src].zentype == 'element', "Invalid zpack, not an element: "..src)
ZEN.assert(type(pack) == 'zenroom.octet', "Invalid zpack, not an octet: "..src)
ACK[dst] = ZPACK.decode( pack )
new_codec(dst)
local zpack = have(src)
local tmp = MPACK.decode ( O.to_string( decompress(zpack) ) )
ZEN.assert( tmp.data, "Invalid zpack, data not found: "..src)
ZEN.assert( tmp.codec, "Invalid zpack, codec not found: "..src)
ACK[dst] = tmp.data
ZEN.CODEC[dst] = tmp.codec
end)
--[[
--This file is part of zenroom
--
--Copyright (C) 2022 Dyne.org foundation
--designed, written and maintained by Denis Roio <jaromil@dyne.org>
--
--This program is free software: you can redistribute it and/or modify
--it under the terms of the GNU Affero General Public License v3.0
--
--This program is distributed in the hope that it will be useful,
--but WITHOUT ANY WARRANTY; without even the implied warranty of
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
--GNU Affero General Public License for more details.
--
--Along with this program you should have received a copy of the
--GNU Affero General Public License v3.0
--If not, see http://www.gnu.org/licenses/agpl.txt
--]]
local mpack = MPACK -- require_once'zenroom_msgpack'
local zpack = { }
zpack.encode = function(src)
local tmp = mpack.encode(src)
return compress( O.from_rawlen(tmp, #tmp) )
end
zpack.decode = function(src)
return mpack.decode( O.to_string( decompress(src) ) )
end
return zpack
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment