Chdef 0.0.16

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

Chdef

Channel definitions (CH) and bit-field definitions (BF) for binary frames: read the CSVs, compute the frame layout, encode and decode frames.

A binding over the chdef Rust crate, carrying its native library for linux-x64, win-x64, osx-arm64 and osx-x64dotnet add package Chdef and nothing else.

⚠ Pre-alpha (0.0.x). The API and the CSV rules are still moving; until 0.1.0 lands, patch releases may break either.

Nothing here throws for a bad row. A problem comes back as an Issue beside the value it is about, so a file that is wrong in one cell still loads. Only an unreadable file — bad encoding, an unterminated quote — raises ChdefException.

Every example below is a test in Chdef.Tests/ReadmeTests.cs, and the build fails if this page and that file disagree.

Reading a frame

const string ch =
    "number,bytes,type,name,lsb,offset,unit\n"
    + "1,2,UI,speed,0.5,0,km/h\n"
    + "2,1,BF,status,1,0,\n";
const string bf = "number,bit,name\n2,0,ready\n2,1,fault\n";

using var defs = Definitions.Parse(ch, bf);
Assert.Empty(defs.Issues);

// 0x0040 little-endian is raw 64, which is 32 km/h at lsb 0.5.
var readings = defs.Decode(new byte[] { 0x40, 0x00, 0b01 });

Assert.Equal(32.0, readings[0].Value);
Assert.Equal(new[] { ("ready", true), ("fault", false) },
    readings[1].Bits.Select(b => (b.Name, b.Value)));

Building one

Encode writes the values you give and the defaults of the channels you do not. A channel the definitions mark as derived — a CRC — is filled by Seal, which is a call of its own so that Encode stays a pure function of what you handed it.

const string ch =
    "number,bytes,type,kind,derived,default,name\n"
    + "1,2,UI,const,,0x7E7E,sync\n"
    + "2,2,UI,plain,,,speed\n"
    + "3,2,UI,derived,crc16/x25 1..2,,crc\n";

using var defs = Definitions.Parse(ch);
var frame = defs.Encode([Value.Physical(2, 120)], out var issues);

Assert.Empty(issues);
Assert.Equal(new byte[] { 0x7E, 0x7E }, frame[..2]);
Assert.Equal(new byte[] { 0, 0 }, frame[4..]);

Assert.Empty(defs.Seal(frame));
Assert.NotEqual(new byte[] { 0, 0 }, frame[4..]);
Assert.Empty(defs.DerivedMismatches(frame));

Headers in another language

A column has one canonical name, and every other spelling a header may use is a vocabulary you supply. The one shipped for the Japanese column names has no standing one you build lacks.

using var german = ColumnVocabulary.Create()
    .Ch("Nummer", ChColumn.Number)
    .Ch("Bytes", ChColumn.Bytes)
    .Ch("Bezeichnung", ChColumn.Name);

using var defs = Definitions.Parse("Nummer,Bytes,Bezeichnung\n7,4,Frame\n", null, german);

Assert.Empty(defs.Issues);
Assert.Equal(7u, defs.Channels[0].Number);
Assert.Equal("Frame", defs.Channels[0].Name);

Editing a definition file

Grid is the file as its cells — comment rows, blank rows and unknown columns included — and it writes back in the shape it was read, byte for byte when the file already follows the write rules.

using var grid = Grid.Parse("number,bytes,memo\r\n1,2,first\r\n");

Assert.Equal(new[] { "number", "bytes", "memo" }, grid.Header);
Assert.Equal("first", grid.Cell(0, 2));

grid.SetCell(0, 1, "4");
Assert.Equal("number,bytes,memo\r\n1,4,first\r\n", grid.ToCsv());

An editor wants to mark the cell, not print a sentence about it, so a finding carries the row and the column it is about.

using var grid = Grid.Parse(
    "number,bytes,type,lsb,min,max,default\n1,2,UI,1,0,100,150\n");
var finding = Assert.Single(grid.DefaultsOutOfRange());

Assert.Equal(IssueCode.ValueOutOfRange, finding.Code);
Assert.Equal("default", grid.Header[finding.Col!.Value]);
Assert.Equal("150", grid.Cell(finding.Row!.Value, finding.Col!.Value));

Where to look next

License

MIT OR Apache-2.0.

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.
  • net8.0

    • No dependencies.

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.0.16 85 8/28/2026
0.0.15 90 8/26/2026
0.0.14 99 8/25/2026
0.0.13 95 8/25/2026
0.0.12 85 8/25/2026
0.0.11 93 8/25/2026
0.0.10 91 8/25/2026
0.0.9 91 8/25/2026
0.0.8 93 8/25/2026
0.0.7 95 8/24/2026
0.0.5 86 8/24/2026
0.0.4 85 8/24/2026
0.0.3 99 8/24/2026