Comments (3)
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.
Thanks Adam
Sounds good - I will essentially create a Bond DTO for the wire.
A few questions:
-
Interested in why you recommend idl-first, as opposed to manual-decoration?
-
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.
- 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. - Using
blob
should be faster and will use less space.
from bond.
Related Issues (20)
- Bond generated headers don't work for clang in c++20 HOT 2
- Include enums in Bond runtime schema HOT 1
- cmake/Config.cmake looks for the EOLed Python-2.7 HOT 1
- Deserialization/serialization under Linux is 7x-10x slower than Windows HOT 2
- [C#] gbc.exe: Exec format error inside mcr.microsoft.com/dotnet/sdk:latest docker image. HOT 3
- "openFile: does not exist (No such file or directory)" on Linux HOT 3
- [C#] Deserializing bond-like strings into dynamic type HOT 2
- Linux build error - ghc: panic! HOT 4
- Support dotnet trimming HOT 5
- Target `netstandard2.0` for c# HOT 1
- C++: GCC: Double/Float comparison warning HOT 2
- Is this project still being maintained? HOT 2
- emit #nullable enable pragma in generated C# code
- bond on aarch64 is failing with unsupported LLVM
- [msvc][cpplatest] bond failed to build with msvc option /std:c++latest due to error C2027 and error C2061
- Upgrade to Stack lts-22.12 for aarch64 support
- Simple usage example for python HOT 1
- Is it possible to use Python bindings without Boost? HOT 1
- Compilation failed with msvc version 14.39.33519
- Following HLint suggestions?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bond.