Comments (3)
I updated the code a bit - I can read the value data type as well, but still unable to read actual values:
private void ReadContainer(CompactBinaryReader<Bond.IO.Unsafe.InputBuffer> reader, bool isMap = false)
{
string marker = "Mapped value type: ";
int containerCounter;
BondDataType containerDataType = BondDataType.BT_UNAVAILABLE;
BondDataType valueDataType = BondDataType.BT_UNAVAILABLE;
if (!isMap)
{
reader.ReadContainerBegin(out containerCounter, out containerDataType);
}
else
{
reader.ReadContainerBegin(out containerCounter, out containerDataType, out valueDataType);
}
for (int i = 0; i < containerCounter; i++)
{
this.DecideOnDataType(reader, containerDataType);
}
reader.ReadContainerEnd();
}
How do I read the full mapped value here?
from bond.
Maps are serialized in Compact Binary as contiguous key/value pairs. Your DecideOnDataType
doesn't take a valueDataType
parameter, so my guess is that it doesn't know how to read the value in each map entry's key/value pair.
The .expressions files under cs/test/expressions show the Linq expressions that each transform generates for the schema in the same directory. Those could be useful to consult to figure out how Bond deserializes a given construct. For example, take a look at the code generated to deserialize 60: map<int32, double> _map
. The core loop reads an int32 then a double count times where count is the size that ReadContainerBegin
reported.
.Block(
System.Int32 $Example_result._map_key,
System.Double $Example_result._map_value) {
.Default(System.Void);
.Loop {
.If ($count-- > 0) {
.Block() {
$Example_result._map_key = .Call $reader.ReadInt32();
.Default(System.Void);
$Example_result._map_value = .Call $reader.ReadDouble();
($Example_result._map).Item[$Example_result._map_key] = $Example_result._map_value
}
} .Else {
.Break end { }
}
}
.LabelTarget end:
There's a lot more code there, but it's also handling numeric promotions for both the key and the value as well as skipping unknown fields.
from bond.
Aha - I think I see that the right approach here is that once I read the map key, I also need to read the value sequentially. Here is my implementation for it: https://github.com/OpenSpartan/bond-reader/blob/e5a6b454721e81aa3766a8e0eca55aa0e6b73795/src/BondReader/BondProcessor.cs#L101-L109
It seems, at least on the surface, to work - because the value is a struct, it goes into reading the container again and seems to yield the right values back.
Thank you again for helping look into this @chwarr!
from bond.
Related Issues (20)
- [C#] Support System.Collections.Immutable collections as custom containers
- [C++] How do we deserialize two continuous objects from one bulk of memory? HOT 2
- In C# implementation, how to parse to structs separated by BT_STOP_BASE HOT 2
- [ci] Image cleanup script needs to handle 18.04 images
- [ci] CI image Dockerfile needs to be paramatarized on FROM registry
- This repo is missing important files
- c#: Add ToString() implementations for compiled bond objects HOT 1
- Merge API support for C#? HOT 2
- 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 2
- [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
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.