1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
-- minetest provides its own built-in serializer mechanisms.
-- however, these leave much to be desired: the first works
-- by converting values to *lua source code* and 'deserializes'
-- these values by executing it in a mildly sandboxed env.
-- it's LSON basically. the other serializer is JSON. clearly
-- we need something better. if this was lua 5.3, we'd just
-- use string.pack, but alas, they had to use luajit, which
-- is stuck on an ancient version because it no longer exists.
-- if we built against moonjit, we could use pack, but then
-- that would raise compat issues for other users who might
-- want to use these mods. so we need to write our own.
--
-- good news is, it's very easy to do better than both the
-- minetest people and the clowns at PUC-Rio. (if only we had
-- general purpose bitops, it would be even easier)
local m = {
err = {
unmarshalled = {
exp = 'the bytes passed are not a marshalled data structure';
};
corrupt = {
|
|
|
|
|
|
|
<
|
|
|
|
<
>
|
|
>
>
>
>
>
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
-- minetest provides its own built-in serializer mechanisms. however,
-- these leave much to be desired: the first works by converting
-- values to *lua source code* and 'deserializes' these values by
-- executing it in a mildly sandboxed env. it's LSON basically. the
-- other serializer is JSON. clearly we need something better. if this
-- was lua 5.3, we'd just use string.pack, but alas, they had to use
-- luajit, which is stuck on an ancient version because it no longer
-- exists. if we built against moonjit, we could use pack, but then
-- that would raise compat issues for other users who might want to
-- use these mods. so we need to write our own.
--
-- good news is, it's very easy to do better than both the minetest
-- people and the clowns at PUC-Rio. (if only we had general purpose
-- bitops, it would be even easier)
--
-- WARNING: when storing binary data in minetest metadata stores, the
-- bytes 0x01-0x03 MUST be avoided or they will break the kvstore
-- format and the item/node's metadata will become corrupt. use the
-- lib.str.meta_{,de}armor functions on the output of pack/unpack to
-- safely store and retrieve data structures from meta storage.
local m = {
err = {
unmarshalled = {
exp = 'the bytes passed are not a marshalled data structure';
};
corrupt = {
|