Best way to serialize/deserialize data?

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Best way to serialize/deserialize data?

Postby BackRaw » Thu Nov 16, 2017 4:36 am

Hi,

currently I'm using JSON for serializing spawn points in my Ultimate Deathmatch plugin. While this might be OK and doesn't really slow anything down since the files are only loaded on special occasians, they are not really readable and could very safely be saved in a binary format. Other than that the order of the file's contents could be preserved.

Now, my question is which options we have for SP. Converting everything using Pickle/cPickle would cause more code overhead than usage imho. Is there an easier way/library? How about Google's protobufs? Are they included in SP? - I read that word a couple times while looking up something in SP's source files, but I don't know if I could use protobufs in a plugin other than putting its source into a package or something.

Thanks for your answers!

Edit: Protobufs are probably too much overhead as well. But the question remains :)
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Best way to serialize/deserialize data?

Postby L'In20Cible » Thu Nov 16, 2017 4:58 am

BackRaw wrote:Converting everything using Pickle/cPickle would cause more code overhead than usage imho. Is there an easier way/library?

I always liked the simplicity of shelve which does all the pickling for you from a dict-like object. Vector instances also have their own suite so they can be stored as is.
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Re: Best way to serialize/deserialize data?

Postby BackRaw » Thu Nov 16, 2017 5:25 am

L'In20Cible wrote:
BackRaw wrote:Converting everything using Pickle/cPickle would cause more code overhead than usage imho. Is there an easier way/library?

I always liked the simplicity of shelve which does all the pickling for you from a dict-like object. Vector instances also have their own suite so they can be stored as is.

Great! I totally forgot about shelve to be honest. How would I use the vector suit in a plugin?
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Best way to serialize/deserialize data?

Postby L'In20Cible » Thu Nov 16, 2017 5:49 am

BackRaw wrote:
L'In20Cible wrote:How would I use the vector suit in a plugin?
You don't have to do anything, was just pointing out that Vector instances can be pickled as is without conversion on your part:

Syntax: Select all

with shelve.open('spawnpoints') as db:
db['de_dust2'] = [Vector(1, 2, 3), Vector(4, 5, 6)]
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Re: Best way to serialize/deserialize data?

Postby BackRaw » Thu Nov 16, 2017 6:41 am

L'In20Cible wrote:
BackRaw wrote:
L'In20Cible wrote:How would I use the vector suit in a plugin?
You don't have to do anything, was just pointing out that Vector instances can be pickled as is without conversion on your part:

Syntax: Select all

with shelve.open('spawnpoints') as db:
db['de_dust2'] = [Vector(1, 2, 3), Vector(4, 5, 6)]

Oh, alright. Thanks!

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 29 guests