BondTools.Runtime
1.10.1
dotnet add package BondTools.Runtime --version 1.10.1
NuGet\Install-Package BondTools.Runtime -Version 1.10.1
<PackageReference Include="BondTools.Runtime" Version="1.10.1" />
<PackageVersion Include="BondTools.Runtime" Version="1.10.1" />
<PackageReference Include="BondTools.Runtime" />
paket add BondTools.Runtime --version 1.10.1
#r "nuget: BondTools.Runtime, 1.10.1"
#:package BondTools.Runtime@1.10.1
#addin nuget:?package=BondTools.Runtime&version=1.10.1
#tool nuget:?package=BondTools.Runtime&version=1.10.1
BondTools.Runtime
Serialization for C# generated by bond generate csharp --serialization, compatible with Bond's Compact Binary (v1) protocol. Generated code writes and reads fields directly: no reflection and no runtime code generation, so it works with trimming and NativeAOT. It writes the bytes upstream Bond writes, and reads any payload, valid or not, as upstream Bond reads it, apart from a few differences.
byte[] bytes = order.Serialize(); // also Serialize(IBufferWriter<byte>) and Serialize(Stream)
Order copy = Order.Deserialize(bytes); // also ReadOnlySequence<byte> and Stream
Reusing instances
Deserialize(bytes, into) reads into an existing instance, as Bond merges: the payload's fields replace the instance's, directly typed nested structs are read into the instance's own, and container elements are appended. With --clear, clearing first reads it as a new instance would while retaining built-in collections and directly typed nested structs generated from the same schema file. Imported, nullable, generic, custom-mapped, and blob values may still be replaced or allocated:
order.Clear();
Order.Deserialize(bytes, into: order);
Structs
--structs generates C# structs instead of classes, so nested structs and the elements of containers are stored inline rather than allocated one by one: reading vector<Point> into a cleared instance allocates nothing. Their members are public fields, so nested structs are assigned in place, as in order.customer.name = "Ada", and written without copies. C# structs can't inherit, so schemas with bases fail to generate, nor contain themselves other than in a container, as in nullable<Node> next, which the compiler rejects. Structs are values, so Deserialize(bytes, into) returns the instance it read into:
order.Clear();
order = Order.Deserialize(bytes, into: order);
A field of a type parameter holds default(T) until it is assigned or read, as with upstream, so it lacks the constructor's defaults: assign it before writing a value of a generic struct with a struct type argument. So does a bonded<T> whose struct can contain it again, as in struct Node { 0: bonded<Node> next; }, as with classes. A struct can't be the type argument of a generic struct that takes it as nullable, as in nullable<T>, since a struct can't be null, unless its parameter is a T : value. With --equality, nor can a bonded<T> of a struct, which Equals() can't deserialize without its type: one passed from C# is compared by reference.
Generic structs
A generic struct takes a codec for each type parameter:
var codec = BondCodec.Struct<Order>();
byte[] bytes = page.Serialize(codec);
Page<Order> copy = Page<Order>.Deserialize(bytes, codec);
BondCodec has a codec for every Bond type, such as BondCodec.WString and BondCodec.Vector(BondCodec.Int32).
bonded<T>
A bonded<T> field reads as a BondedPayload<T>: the struct's bytes, deserialized by Deserialize() and written back unchanged, including fields T does not know. Values such as new Bond.Bonded<T>(value) are written by T's codec, and other implementations of IBonded<T>, such as a Bonded<Derived>, as upstream Bond writes them.
Custom type mappings
Values of custom-mapped types are converted by the BondTypeAliasConverter class in their struct's namespace, as with upstream Bond: Convert(value, default(BondType)) before writing and Convert(value, default(MappedType)) after reading.
Differences from upstream
Where upstream Bond breaks the schema, BondTools.Runtime follows it:
- A base struct's type arguments keep
wstringandnullable, as instruct Item : Box<wstring>. C# can't annotate a base type, so upstream writes and readsstringand plainTthere, and throws on a null element. new Bond.Bonded<T>(value)is written as the schema says. Upstream writes it as the CLR type, with the same loss in T's type arguments.- A
bonded<T>field must have the struct wire type. Upstream reads whatever follows as a struct. - A missing required field is always rejected. Upstream misses it when the field just before the gap is one it skipped, such as an unknown one.
- A
nullable<T>of a struct generated with--structsis written and read. Upstream throws on a nullable C# struct.
And it reads deeper payloads. Both reject a payload nested more than 64 levels deep, but upstream counts each container, nullable and bonded value as a level too, so it rejects valid payloads with as few as 33 structs nested in containers.
Performance
Against upstream Bond: benchmarks.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Bond.Core.CSharp (>= 13.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.