sorcery  marshal.lua at [f4a14cad78]

File test/marshal.lua artifact c7cd728357 part of check-in f4a14cad78


dofile'test/common.lua'
local m = dofile"lib/marshal.lua"
local car_t = m.g.struct {
	brand = m.t.str;
	year = m.t.u16;
}
local pack, unpack = m.transcoder {
	version = m.t.u16;
	name = m.t.str;
	networth = m.t.s32;
	byte = m.t.u8;
	blob = m.t.text;
	taxes = m.g.array(8, m.t.s32);
	mistresses = m.g.array(16, m.t.str);
	maincar = car_t;
	cars = m.g.array(8,car_t);
}

local s = pack {
	version = 0xAAEE;
	name = 'lord wigglesmith';
	networth = -1239201;
	byte = 0xBE;
	blob = [[it was a dark and stormy night]];
	taxes = {12,5123,12,633,-5816235};
	mistresses = {
		'evangeline';
		'clarissa';
		'catherine';
		'fredericka the great';
	};
	maincar = {
		brand = 'ford';
		year = 1234;
	};
	cars = {
		{brand = 'dodge', year = 2596};
		{brand = 'subaru', year = 321};
	};
}
if m.wrong(s) then print(s.exp) os.exit(1) end

print(hexdump(s))

local v = unpack(s)

print(dump(v))