BondTools.Runtime 1.10.1

dotnet add package BondTools.Runtime --version 1.10.1
                    
NuGet\Install-Package BondTools.Runtime -Version 1.10.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BondTools.Runtime" Version="1.10.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BondTools.Runtime" Version="1.10.1" />
                    
Directory.Packages.props
<PackageReference Include="BondTools.Runtime" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BondTools.Runtime --version 1.10.1
                    
#r "nuget: BondTools.Runtime, 1.10.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package BondTools.Runtime@1.10.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=BondTools.Runtime&version=1.10.1
                    
Install as a Cake Addin
#tool nuget:?package=BondTools.Runtime&version=1.10.1
                    
Install as a Cake Tool

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 wstring and nullable, as in struct Item : Box<wstring>. C# can't annotate a base type, so upstream writes and reads string and plain T there, 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 --structs is 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.10.1 91 11/20/2026
1.10.0 100 11/4/2026
1.9.0 118 10/20/2026
1.8.1 104 10/15/2026
1.8.0 97 10/15/2026
1.7.0 106 10/14/2026
1.6.0 121 10/2/2026