sorcery  encode.lua at [032f54d1d5]

File test/encode.lua artifact 765ecd04d6 part of check-in 032f54d1d5


dofile'test/common.lua'
local m = dofile'lib/marshal.lua'
local s = dofile'lib/str.lua'
local ench_t = m.g.struct {
	id = m.t.str;
	slot = m.t.u8;
	boost = m.t.u8;
	reliability = m.t.u8;
}
local pack, unpack = m.transcoder {
	spells = m.g.array(8, ench_t);
	energy = m.t.u16;
}

local packed = pack{
	energy = 1550;
	spells = {
		{ slot = 0; boost = 15; reliability = 100; id = 'dowse' };
		{ slot = 1; boost = 3; reliability = 0; id = 'e' };
	};
}

print('\x1b[1munarmored\x1b[m\n' .. hexdump(packed))
print('\x1b[1marmored\x1b[m\n' .. hexdump(s.meta_armor(packed)))
print('\x1b[1marmored (struct mode)\x1b[m\n' .. hexdump(s.meta_armor(packed,true)))
print('\x1b[1mdearmored\x1b[m\n' .. hexdump(s.meta_dearmor(s.meta_armor(packed))))
print('\x1b[1mdearmored (struct mode)\x1b[m\n' .. hexdump(s.meta_dearmor(s.meta_armor(packed,true),true)))

test('dearmor(armor(x)) == x',s.meta_dearmor(s.meta_armor(packed)) == packed)
test('struct_dearmor(struct_armor(x)) == x',s.meta_dearmor(s.meta_armor(packed,true),true) == packed)
test('struct_dearmor("string") == "string"',s.meta_dearmor('string',true) == 'string')
report()