I’m creating something that has save files. For the most part, it’s just saving objects with 4 values.
- x
- y
- id
- layer
I’ve been saving this as XML for a while, the problem is, the files are starting to get HUGE because I’m saving hundreds to thousands of these objects and XML is kind of bulky for something like this. I tried switching to Json but it was too big as well (I will admit though, better).
My Question
I know a lot of programs save directly using bytes to conserve space. I want to do this. Say I have 300 objects with the properties X, Y, Id, and Layer, how could I save this to file x as bytes and load it later?
I’ve tried reading bytes when I used to make my own servers. I usually ended up getting frustrated and giving up. I’m hoping this isn’t too similar (my gut says otherwise).
EDIT
Oh sorry guys, I forgot to mention, I’m using VB.NET so all .NET answers are acceptable! 🙂
Also, all of these values are integers.
I would use protobuf-net (I would; I’m biased…). It is an open-source .NET serializer, that uses attributes (well, that is optional in v2) to guide it. For example, using C# syntax (purely for my convenience – the engine doesn’t care what language you use):
You can then serialize, for example:
and deserialize:
job done; fast binary output. You probably can get a little tighter by hand-coding all reading/writing manually without any markers etc, but the above will be a lot less maintenane. It’ll also be easy to load into any other platform that has a “protocol buffers” implementation available (which is: most of them).