You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd really like to use MemoryPack for the purpose of serializing/deserializing game state to/from a save, but I need an option to also save/read a human-readable format. While MessagePack would get me both the binary and the JSON option, MessagePack cannot serialize private fields, which is very unfortunate, as I'm trying to replace the existing Json.NET serialization without rewriting a large portion of codebase.
TypeScript code generation would probably cover my use case, as I could deserialize a binary save in JavaScript and then easily dump it into JSON, but unfortunately, TypeScript generation is missing a lot of things, including struct serialization, and, as far as I can tell, Unity objects serialization.
I'm thinking about modifying MemoryPack generator to also (optionally?) generate classes that read and write JSON. Would you be willing to accept a PR adding such feature, and if you do, do you have any advice how to best approach this task? Currently, I'm thinking about:
Creating MemoryPackJsonWriter/MemoryPackJsonReader classes to handle low-level tasks as MemoryPackWriter/Reader does. If it was just for my own project, I'd probably use Newtonsoft's JsonWriter/Reader for actual writing, but I guess such dependency is a bit too much for MessagePack proper, so I'd have to write my own Writer/Reader class, or maybe pilfer one from MessagePack.
Adding SerializeJson/DeserializeJson methods to IMemoryPackFormatter and its implementations (we'll probably be unable to serialize SOME fields well - like various raw memory representations, but I guess we can fake it by serializing a Base64-encoded string, and most users won't need this anyway, including me). This is quite a bit of work, because each case should be handled with care.
Adding a set of methods for generating JSON serializers to MemoryPack.Generator, in a separate source file (MemoryPackGenerator.EmitterJson), with entry point GenerateJson. This is the main body of work, I think.
Calling GenerateJson at the same point where Generate is called, if option to generate JSON serializers is specified (I think it should be enabled by default for Unity, because Unity cannot pass options into generators)
Other than that, I think MemberMeta has all the necessary information to make writing and reading JSON a possibility (mostly, member names and types).
So, what do you think?
The text was updated successfully, but these errors were encountered:
I'd really like to use MemoryPack for the purpose of serializing/deserializing game state to/from a save, but I need an option to also save/read a human-readable format. While MessagePack would get me both the binary and the JSON option, MessagePack cannot serialize private fields, which is very unfortunate, as I'm trying to replace the existing Json.NET serialization without rewriting a large portion of codebase.
TypeScript code generation would probably cover my use case, as I could deserialize a binary save in JavaScript and then easily dump it into JSON, but unfortunately, TypeScript generation is missing a lot of things, including struct serialization, and, as far as I can tell, Unity objects serialization.
I'm thinking about modifying MemoryPack generator to also (optionally?) generate classes that read and write JSON. Would you be willing to accept a PR adding such feature, and if you do, do you have any advice how to best approach this task? Currently, I'm thinking about:
Creating MemoryPackJsonWriter/MemoryPackJsonReader classes to handle low-level tasks as MemoryPackWriter/Reader does. If it was just for my own project, I'd probably use Newtonsoft's JsonWriter/Reader for actual writing, but I guess such dependency is a bit too much for MessagePack proper, so I'd have to write my own Writer/Reader class, or maybe pilfer one from MessagePack.
Adding SerializeJson/DeserializeJson methods to IMemoryPackFormatter and its implementations (we'll probably be unable to serialize SOME fields well - like various raw memory representations, but I guess we can fake it by serializing a Base64-encoded string, and most users won't need this anyway, including me). This is quite a bit of work, because each case should be handled with care.
Adding a set of methods for generating JSON serializers to MemoryPack.Generator, in a separate source file (MemoryPackGenerator.EmitterJson), with entry point GenerateJson. This is the main body of work, I think.
Calling GenerateJson at the same point where Generate is called, if option to generate JSON serializers is specified (I think it should be enabled by default for Unity, because Unity cannot pass options into generators)
Other than that, I think MemberMeta has all the necessary information to make writing and reading JSON a possibility (mostly, member names and types).
So, what do you think?
The text was updated successfully, but these errors were encountered: