Kanonak.Codec
0.6.1
dotnet add package Kanonak.Codec --version 0.6.1
NuGet\Install-Package Kanonak.Codec -Version 0.6.1
<PackageReference Include="Kanonak.Codec" Version="0.6.1" />
<PackageVersion Include="Kanonak.Codec" Version="0.6.1" />
<PackageReference Include="Kanonak.Codec" />
paket add Kanonak.Codec --version 0.6.1
#r "nuget: Kanonak.Codec, 0.6.1"
#:package Kanonak.Codec@0.6.1
#addin nuget:?package=Kanonak.Codec&version=0.6.1
#tool nuget:?package=Kanonak.Codec&version=0.6.1
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 viaKanonak.Canonical. Byte-identical tokanonak hashof the equivalent authored.kan.yml, including the synthesizedrdf:typetriples 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$extraon the typed node —[JsonExtensionData]semantics).Codec.TypeMatches(node, classUri, schema)— what a generated type guard asks: is this node (a map or aKanonakNode) an instance ofclassUri?Codec.EnumMember(schema, reference)→EnumMemberMatch(EnumType,Uri,Member) ornull— 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 packageKanonak.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 | Versions 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. |
-
.NETStandard 2.0
- Kanonak.Canonical (>= 0.2.2)
- System.Text.Json (>= 8.0.5)
-
net8.0
- Kanonak.Canonical (>= 0.2.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.