Kanonak.Codec 0.6.1

dotnet add package Kanonak.Codec --version 0.6.1
                    
NuGet\Install-Package Kanonak.Codec -Version 0.6.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="Kanonak.Codec" Version="0.6.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Kanonak.Codec" Version="0.6.1" />
                    
Directory.Packages.props
<PackageReference Include="Kanonak.Codec" />
                    
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 Kanonak.Codec --version 0.6.1
                    
#r "nuget: Kanonak.Codec, 0.6.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 Kanonak.Codec@0.6.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=Kanonak.Codec&version=0.6.1
                    
Install as a Cake Addin
#tool nuget:?package=Kanonak.Codec&version=0.6.1
                    
Install as a Cake Tool

Kanonak.Codec (C#)

The generic, ontology-independent codec runtime referenced by Kanonak's generated typed SDKs — the C# port of @kanonak-protocol/codec. It turns typed nodes into Kanonak content addresses and the normalized-JSON wire form, given the per-package CodecSchema that a generated SDK embeds.

It depends on the sibling Kanonak.Canonical port (a local ProjectReference) for the same canonical form + content hash the kanonak hash CLI produces.

What it does

  • Codec.ContentHash(nodes, schema, pkg) → sha256:… — the permanent content address of the package those nodes form. Builds the language-neutral canonical input model and hashes it via Kanonak.Canonical. Byte-identical to kanonak hash of the equivalent authored .kan.yml, including the synthesized rdf:type triples and the package-wrapper subject.
  • Codec.CanonicalForm(nodes, schema, pkg) — the canonical form itself (the {subjects:[…]} JSON), for inspection/debugging.
  • Codec.Serialize(node) / Codec.Deserialize(json, schema) — the normalized-JSON wire form. Open-world assertions outside the type-model round-trip losslessly through $extra (top-level wire fields, collected under $extra on the typed node — [JsonExtensionData] semantics).
  • Codec.TypeMatches(node, classUri, schema) — what a generated type guard asks: is this node (a map or a KanonakNode) an instance of classUri?
  • Codec.EnumMember(schema, reference) → EnumMemberMatch (EnumType, Uri, Member) or null — the enumeration member a {"$ref": …} names.

Reading an earlier compatible version (0.6.1)

A node is typed with the class version its producer resolved; a codec built from a later COMPATIBLE version of the same package still reads it. Deserialize resolves $type by the exact key first, then by the same publisher/package/name at the highest schema version for which Coordinate.IsReadableBy(written, schemaVersion) (Kanonak.Canonical) holds, and the node keeps its WRITTEN $type. A rejection message ends in a bracketed kind: [unknown-type], [newer-version], [other-major] or [other-minor-line]. TypeMatches resolves each of the node's types ($types, else $type) the same way and matches the class itself or any entry of the optional CodecClass.Ancestors (every superclass, by versioned URI; canonicalization never reads it, and a schema without it still parses); unreadable types never match. EnumMember resolves a reference exactly, then to the same member at a version that can read it. Hashing stays EXACT-version only: a node or embedded value whose $type is only compatibly present is rejected with [hash-needs-exact-version], since its predicates would carry the schema's version instead of the producer's.

The YAML / Package wire (toPackage/fromPackage) is out of scope for this port.

Node shape

A node is a plain IReadOnlyDictionary<string, object>: the $-envelope ($type, $id, optional $extra) plus alias-collapsed local-name fields. Field values are CLR primitives (string, bool, numeric), an IReadOnlyList of those, or a reference map ({ "$ref": uri }). $extra is a map keyed by predicate URI.

Project layout

  • src/Kanonak.Codec/ — the library (netstandard2.0), public package Kanonak.Codec. References ../../kanonak-canonical/csharp/src/Kanonak.Canonical.
  • test/Kanonak.Codec.Conformance/ — the conformance runner (net10.0).

Conformance

The runner drives the shared codec vectors (every kanonak-codec/vectors/codec-vectors*.json file: base, embedded, types, enums, compat) and asserts the canonical form, content hash, (structurally compared) Serialize/Deserialize output, and the compatibility contract all match the authoritative expected values.

cd test/Kanonak.Codec.Conformance
dotnet run

All vectors must pass. The basic-case hash is sha256:6ed4e664dbaf7d3331d71af297f48da23994af34d081a86f555cb34706de2913.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
0.6.1 36 10/2/2026
0.6.0 196 9/23/2026
0.5.0 153 8/17/2026
0.4.1 178 8/8/2026
0.4.0 182 7/13/2026
0.3.0 130 7/5/2026
0.2.0 114 7/5/2026
0.1.0 405 6/7/2026