'Microsoft bond c++ runtime deserialization using runtime schema
I could not find anything useful in their docs or examples :( They have docs of how to deserialize schema, and then how to traverse it - that works great. They have also two examples:
- how to use
bond::bonded<void>
with runtime schema to convert binary to json - how to use
bond::bonded<void>
with runtime schema andMapTo
to parse data into some custom ViewStruct
What I need is: to traverse the bond:bonded<void>
to extract fields from it.
In protobuf you have field descriptors (created using FinFieldByName
) and then you use them in runtime methods msg->getString, msg->getInt32
to get the typed value.
Solution 1:[1]
There's nothing built in that allows you to traverse a bonded<void>
and inspect its fields. If you need to do that generically, you'll need to implement a custom transform and then use bond::Apply()
to apply the transform to a bonded<void>
constructed from a reader and a runtime schema. See in particular the transform and access_control examples for how to start writing a transform.
Bond needs this level of indirection compared to Protocol Buffers because Bond supports pluggable encoding protocols. If you know that you will only have to process a specific protocol, you could use that protocol's reader type with the runtime schema to walk the fields in the payload. See Microsoft Bond deserialization without knowing underlying schema for a C# example of the core of this algorithm.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |