Binary serialization / deserialization where you don't control the format
I wrote this:
The purpose of this is binary serialization/deserialization to/from a file format I don't control. It has to exactly match that format. The question is, how would I convert my naïve
Read
and Write
methods into something that would properly implement Serializable
and ISerializable
the idiomatic C# way?1 Reply
This is just the header to a larger file format
.NET Standard 2.0 with PolySharp letting me use more recent language features.
What is the right way to do binary serialization/deserialization of a file format I don't control then?
Is there no standard interface for reading and writing?
A standard interface which marks a type as one that can be binary serialized or deserialized, so that outside code can reference this aspect of the type without knowing more about the type, which is what I thought
ISerializable
was for.
OK, I thought that my Read(Stream stream)
and Write(Stream stream)
methods were supposed to be implementing some standard C# interface, but you're telling me that in reality, it's just the wild west and everyone does their own thing.
Since there are no standards, I'm adding my own: