Implementing save data

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Implementing save data

Post 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.
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Implementing save data

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Implementing save data

Post 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.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest