Giter VIP home page Giter VIP logo

Comments (3)

sapek avatar sapek commented on July 19, 2024

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 Union has numeric fields and is something that you use as a field/element type in larger schema(s) (i.e. you don't serialize Union as a top level object) then you could use type alias facility to get very efficient representation. For example you could define Union as an alias of uint64 and then provide a converter between uint64 and the C# Union struct. BTW, I would suggest trying type aliases using Bond codegen first, even if you want to manually annotate your C# types in your actual project.

from bond.

grant-d avatar grant-d commented on July 19, 2024

Thanks Adam

Sounds good - I will essentially create a Bond DTO for the wire.

A few questions:

  1. Interested in why you recommend idl-first, as opposed to manual-decoration?

  2. Is it faster to use an ArraySegment<> to represent (say) Decimal, or would it be equivalent to use a custom struct such as:

struct BondDecimal
{
    00: required Int32 D0;
    01: required Int32 D1;
    02: required Int32 D2;
    03: required Int32 D3;
}

from bond.

sapek avatar sapek commented on July 19, 2024
  1. The type annotation for complex type aliasing cases can get tricky. The type alias IDL using syntax and the compiler's type alias mapping --using command line option are just easier.
  2. Using blob should be faster and will use less space.

from bond.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.