c# - Serialize Struct in Binary, Packed Format -
In order to serial a string in the binary stream (memorystream), there is no such way in Binary that how to represent binary Is the structure is visually excluded (i.e. no padding)?
In C / C ++, you can use the #pragma commands to pack the creator to the compiler, so that there is no padding between the fields. This is useful if you send messages back and forth through two application sockets. With packing disabled, you can simply "send" the contents of the structure on the socket and there is no need to worry about packing each area in a binary buffer separately (if necessary it is also to be embedded) .
Protocol buffer or thrift or something like that unless you use insecure code; Based on my experience I do not recommend the underlying binary serialization of .NET. You can also sort / deserialize with BinaryWriter / BinaryReader (reflection or pre-generated serialization code). For packing, you can control it with the [StructLayout] attribute.
Comments
Post a Comment