Integrating with other storage API fail: wrong code example?

Discussion and help for Easy Save 3
Post Reply
User avatar
soulburner
Posts: 4
Joined: Fri Jun 01, 2018 1:24 pm

Integrating with other storage API fail: wrong code example?

Post by soulburner »

I'm trying to follow your example here: https://docs.moodkie.com/easy-save-3/es ... rage-apis/

And doing the following:
public static byte[] Serialize<T>(T o)
{
    ES3File f = new ES3File(false);
    f.Save<T>("data", o);
    return f.LoadRawBytes();
}

public static T Deserialize<T>(byte[] data)
{
    ES3File f = new ES3File(data, false);
    return f.Load<T>("data");
}
And then I use it the following way:
byte[] data = Serialize(t1);
TestClass t2 = Deserialize<TestClass>(data);
The problem is that I get "KeyNotFoundException: Key "data" was not found in this ES3File" exception. I've checked - the "data" (byte array) is correct - the exact the same that came after the "serialize method".

Digging into ES3 code, I've noticed that the "cache" which contains the keys dictionary is inited only when syncWithFile is true.

So, am I doing something wrong? Or is there an error in the ES3 code?
User avatar
Joel
Moodkie Staff
Posts: 4848
Joined: Wed Nov 07, 2012 10:32 pm

Re: Integrating with other storage API fail: wrong code exam

Post by Joel »

Hi there,

Well spotted. It looks like a change we made wasn't pushed to the latest update.

You can fix it by not specifying the syncWithFile parameter in your Deserialize method. i.e.
ES3File f = new ES3File(data);
Note that the syncWithFile parameter will be removed in the next update for methods which also provide the bytes parameter. I've manually updated the example in the docs to represent this.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
User avatar
soulburner
Posts: 4
Joined: Fri Jun 01, 2018 1:24 pm

Re: Integrating with other storage API fail: wrong code exam

Post by soulburner »

Thanks a lot for a quick response!

BTW, we're not integrating ES3 into our game, Graveyard Keeper: https://www.graveyardkeeper.com/
User avatar
Joel
Moodkie Staff
Posts: 4848
Joined: Wed Nov 07, 2012 10:32 pm

Re: Integrating with other storage API fail: wrong code exam

Post by Joel »

I've seen some of the alpha of Graveyard Keeper on Twitch and it looks great, so I'm looking forward to when you finally get it released.

Best of luck with it. It looks like it's going to be a big success!

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
User avatar
soulburner
Posts: 4
Joined: Fri Jun 01, 2018 1:24 pm

Re: Integrating with other storage API fail: wrong code exam

Post by soulburner »

Thanks. I will definately write a positive review for your plugin as soon as I finished with coding ;)
User avatar
soulburner
Posts: 4
Joined: Fri Jun 01, 2018 1:24 pm

Re: Integrating with other storage API fail: wrong code exam

Post by soulburner »

PS: Dropped ES3 for a while because I noticed that inside your serializer is still a JSON. My point was to move from JsonUtility that is extremely large (~25 Mb) for our needs and sometime crashes with out-of-memory to something binary.

Additionaly to that, I noticed that our extremely folded structure (which is serialized fine with Unity's JsonUtility) doesn't serialize that good with your tool. Some classes stays null after deserialize. Tried to figure out why, but didn't find the reason (and don't have much time for that). Dropping EasySave for now, sorry.
User avatar
Joel
Moodkie Staff
Posts: 4848
Joined: Wed Nov 07, 2012 10:32 pm

Re: Integrating with other storage API fail: wrong code exam

Post by Joel »

Hi there,

Sorry to hear that. Not sure why certain things would be serialised as null without being able to see a repro project, though I'm guessing you're probably too busy for that at the moment.

Easy Save 2 (included with Easy Save 3) uses extremely compact and fast binary serialisation, though it does not have automatic serialisation of classes. There's an explanation of integrating it into other storage APIs here.

Also a quick note, there's a feature request for binary serialisation in Easy Save 3 here.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply