-
Notifications
You must be signed in to change notification settings - Fork 321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Union type in C# #59
Comments
In general this will not do what you want. Bond will optimize size of serialized data by omitting fields set to the default value when serializing. This means that you can effectively use a schema with multiple fields like a union from wire format perspective (only the one field that is set will be serialized). However when you store all the fields at the same offset, like in your example, then they will likely all have non-default values and thus will all be serialized. There are also other pitfalls with this approach if the field types are anything other than numeric types. You might actually get invalid value after deserialization. If the |
Thanks Adam Sounds good - I will essentially create a Bond DTO for the wire. A few questions:
|
|
If I use an explict struct (see below) and manually decorate it with the [bond] attributes, will Bond do the right things in terms of de/serialization. In other words, in the snippet below will the populated field (both at offset 0) maintain fidelity across the wire?
Background: I have an efficient in-memory representation of data (the struct below is just one part of that representation). I also need an efficient wire representation of the same data, but not sure whether I need a completely separate struct for Bond or whether I can just 're-use' the existing struct.
The text was updated successfully, but these errors were encountered: