Page 4 of 4

Re: Implementing save data

Posted: Tue Aug 17, 2021 5:31 am
by grump
zorg wrote: Tue Aug 17, 2021 3:26 am bitser (and iirc binser as well) kinda arbitrarily defined its tokens to save data in various forms of compression... there's still the missing library that just uses love.data.un/pack to use C types directly without arbitrary tokens. :P
You mean saving the format string along with the data? I mean, you have to use some kind of type identifiers - they are always more or less arbitrary.

pack/unpack is not really usable for general serialization. It is too limited, and its performance is meh. No support for tables or cdata or userdata. You have to build format strings dynamically and they approach the size of the data you wanna serialize.

Re: Implementing save data

Posted: Tue Aug 17, 2021 1:06 pm
by zorg
grump wrote: Tue Aug 17, 2021 5:31 am
zorg wrote: Tue Aug 17, 2021 3:26 am bitser (and iirc binser as well) kinda arbitrarily defined its tokens to save data in various forms of compression... there's still the missing library that just uses love.data.un/pack to use C types directly without arbitrary tokens. :P
You mean saving the format string along with the data? I mean, you have to use some kind of type identifiers - they are always more or less arbitrary.
Okay, but you brought this up with "what's 241?" :P

What i meant by arbitrary is that; stuff like this in bitser:

Code: Select all

if value >= -27 and value <= 100 then
			--small int
			Buffer_write_byte(value + 27)
		elseif value >= -32768 and value <= 32767 then
			--short int
			Buffer_write_byte(250)
			Buffer_write_data("int16_t[1]", 2, value)
		else
			--long int
			Buffer_write_byte(245)
			Buffer_write_data("int32_t[1]", 4, value)
		end
the range [-27,100] is pretty arbitrary; i myself prefer to have a different set of format specifiers and simpler types, like the other two; simple (u)int_16 and (u)int_32.
grump wrote: Tue Aug 17, 2021 5:31 am pack/unpack is not really usable for general serialization. It is too limited, and its performance is meh. No support for tables or cdata or userdata. You have to build format strings dynamically and they approach the size of the data you wanna serialize.
Since i didn't test the performance yet, i'm sad that it is meh in terms of performance.

Re: Implementing save data

Posted: Tue Aug 17, 2021 2:25 pm
by grump
zorg wrote: Tue Aug 17, 2021 1:06 pm Okay, but you brought this up with "what's 241?" :P
Yes, and we mean the same thing. You have to choose arbitrary values; but at the very least assign names to the values and don't litter your code with magic numbers, unless you're golfing for minimal code size. It's bad for maintainability.