Pamoja.Codec
0.1.17
dotnet add package Pamoja.Codec --version 0.1.17
NuGet\Install-Package Pamoja.Codec -Version 0.1.17
<PackageReference Include="Pamoja.Codec" Version="0.1.17" />
<PackageVersion Include="Pamoja.Codec" Version="0.1.17" />
<PackageReference Include="Pamoja.Codec" />
paket add Pamoja.Codec --version 0.1.17
#r "nuget: Pamoja.Codec, 0.1.17"
#:package Pamoja.Codec@0.1.17
#addin nuget:?package=Pamoja.Codec&version=0.1.17
#tool nuget:?package=Pamoja.Codec&version=0.1.17
Pamoja.Codec
CBOR, JSON, and raw codecs behind one trait, delta and varint batch packing, and an f32 quantizer for metered links. One capability of pamoja, one memory-safe Rust core with bindings for TypeScript, Python, and C#.
Install
dotnet add package Pamoja.Codec
using Pamoja.Codec;
This pulls in Pamoja.Native, the compiled engine. dotnet add package Pamoja is the whole framework in one package.
Example
The guide project's example, spliced here as it ran in CI.
From bindings/dotnet/samples/Pamoja.Guides/CodecGuide.cs:
// The same reading as JSON and as CBOR. Nothing is lost, and 21.5 rides as a
// half-precision float, the shortest form RFC 8949 allows for it.
byte[] asJson = Encoding.UTF8.GetBytes("{\"c\":21.5,\"ok\":true}");
byte[] cbor = Codec.JsonToCbor(asJson);
Console.WriteLine($"json {asJson.Length} bytes");
Console.WriteLine($"cbor {cbor.Length} bytes");
// A gateway that speaks JSON gets it back unchanged, so the compact form is a
// transport choice rather than a different data model.
byte[] restored = Codec.CborToJson(cbor);
Console.WriteLine($"back to json, unchanged: {restored.SequenceEqual(asJson)}");
// A batch of readings packs to a count, then the difference between each sample
// and the one before it. Successive readings differ by very little, so the
// differences cost about a byte each where the samples would cost eight.
long[] samples = [10, 11, 13, 12, 900];
byte[] packed = Codec.PackSamples(samples);
Console.WriteLine($"batch {samples.Length} samples in {packed.Length} bytes");
Console.WriteLine($"unpacked {string.Join(", ", Codec.UnpackSamples(packed))}");
// Readings that arrive as floats pack the same way once a scale is chosen. Nothing
// in the bytes records that scale, so sender and receiver have to agree on it.
var quantizer = new Quantizer(100.0f);
float[] celsius = [20.0f, 20.1f, 20.2f, 20.3f];
byte[] packedCelsius = quantizer.Encode(celsius);
float[] recovered = quantizer.Decode(packedCelsius);
Console.WriteLine($"degrees {celsius.Length} readings in {packedCelsius.Length} bytes");
Console.WriteLine($"recovered {string.Join(", ", recovered.Select(v => v.ToString("F1")))}");
The same capability in every language
| Language | Package | Reference |
|---|---|---|
| Rust | pamoja-codec |
reference, docs.rs, install |
| TypeScript | @pamoja/codec |
reference, install |
| Python | pamoja-codec |
reference, install |
| C# | Pamoja.Codec |
reference, install |
Documentation
Pamoja.Codecreference, every type in this namespace.- The Codecs guide, with the same example in Rust, TypeScript, and Python.
- Every capability, and the install page.
License
MIT
| 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
- Pamoja.Native (>= 0.1.17)
NuGet packages (9)
Showing the top 5 NuGet packages that depend on Pamoja.Codec:
| Package | Downloads |
|---|---|
|
Pamoja.Audit
A tamper-evident, hash-chained log; altering, reordering, or dropping a record breaks verification. |
|
|
Pamoja.Modbus
Modbus RTU requests and replies with CRC-16/MODBUS for RS485 field devices. |
|
|
Pamoja.Serial
SLIP and COBS byte stuffing with streaming decoders, so a UART byte stream carries discrete packets. |
|
|
Pamoja.Sync
Offline-first queues: in memory, and a crash-safe on-disk queue that survives power loss. |
|
|
Pamoja.Bus
An in-memory typed publish and subscribe event bus. |
GitHub repositories
This package is not used by any popular GitHub repositories.