@pamoja/codec 0.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/LICENSE-MIT +21 -0
  2. package/README.md +74 -0
  3. package/package.json +39 -0
package/LICENSE-MIT ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Anthony Wiedman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # @pamoja/codec
2
+
3
+ CBOR, JSON, and raw codecs behind one trait, delta and varint batch packing, and an f32 quantizer for metered links. One capability of [pamoja](https://github.com/molexxxx/pamoja), one memory-safe Rust core with bindings for TypeScript, Python, and C#.
4
+
5
+ [![API reference](https://raw.githubusercontent.com/molexxxx/pamoja/main/.github/badges/btn-api.svg)](https://pamoja.molex.cloud/docs/reference/node/modules/_pamoja_codec.html)
6
+ [![read the guide](https://raw.githubusercontent.com/molexxxx/pamoja/main/.github/badges/btn-guide.svg)](https://pamoja.molex.cloud/docs/guides/codec.html)
7
+ [![documentation](https://raw.githubusercontent.com/molexxxx/pamoja/main/.github/badges/btn-docs.svg)](https://pamoja.molex.cloud/docs/)
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ npm install @pamoja/codec
13
+ ```
14
+
15
+ This pulls in `@pamoja/native`, the compiled engine. `npm install pamoja` is the whole framework in one package.
16
+
17
+ ## Example
18
+
19
+ The test that runs in CI, spliced here as it ran.
20
+
21
+ From [`bindings/node/guides/codec.ts`](https://github.com/molexxxx/pamoja/blob/main/bindings/node/guides/codec.ts):
22
+
23
+ ```typescript
24
+ import { Quantizer, fromCbor, packSamples, toCbor, unpackSamples } from '@pamoja/codec'
25
+
26
+ // The same reading as JSON and as CBOR. Nothing is lost, and 21.5 rides as a
27
+ // half-precision float, the shortest form RFC 8949 allows for it.
28
+ const reading = { c: 21.5, ok: true }
29
+ const asJson = Buffer.from(JSON.stringify(reading))
30
+ const cbor = toCbor(reading)
31
+ console.log(`json ${asJson.length} bytes`)
32
+ console.log(`cbor ${cbor.length} bytes`)
33
+
34
+ // A gateway that speaks JSON gets it back unchanged, so the compact form is a transport
35
+ // choice rather than a different data model.
36
+ const restored = fromCbor(cbor)
37
+ console.log(`back to json, unchanged: ${JSON.stringify(restored) === JSON.stringify(reading)}`)
38
+
39
+ // A batch of readings packs to a count, then the difference between each sample and the
40
+ // one before it. Successive readings differ by very little, so the differences cost about
41
+ // a byte each where the samples would cost eight.
42
+ const samples = [10, 11, 13, 12, 900]
43
+ const packed = packSamples(samples)
44
+ console.log(`batch ${samples.length} samples in ${packed.length} bytes`)
45
+ console.log(`unpacked ${unpackSamples(packed).join(', ')}`)
46
+
47
+ // Readings that arrive as floats pack the same way once a scale is chosen. Nothing in the
48
+ // bytes records that scale, so the sender and the receiver have to agree on it.
49
+ const quantizer = new Quantizer(100)
50
+ const celsius = [20.0, 20.1, 20.2, 20.3]
51
+ const packedCelsius = quantizer.encode(celsius)
52
+ const recovered = quantizer.decode(packedCelsius)
53
+ console.log(`degrees ${celsius.length} readings in ${packedCelsius.length} bytes`)
54
+ console.log(`recovered ${[...recovered].map((v) => v.toFixed(1)).join(', ')}`)
55
+ ```
56
+
57
+ ## The same capability in every language
58
+
59
+ | Language | Package | Reference |
60
+ | --- | --- | --- |
61
+ | Rust | [`pamoja-codec`](https://crates.io/crates/pamoja-codec) | [reference](https://pamoja.molex.cloud/docs/reference/rust/pamoja_codec/index.html), [docs.rs](https://docs.rs/pamoja-codec) |
62
+ | TypeScript | [`@pamoja/codec`](https://www.npmjs.com/package/@pamoja/codec) | [reference](https://pamoja.molex.cloud/docs/reference/node/modules/_pamoja_codec.html) |
63
+ | Python | [`pamoja-codec`](https://pypi.org/project/pamoja-codec/) | [reference](https://pamoja.molex.cloud/docs/reference/python/pamoja/codec.html) |
64
+ | C# | [`Pamoja.Codec`](https://www.nuget.org/packages/Pamoja.Codec) | [reference](https://pamoja.molex.cloud/docs/reference/dotnet/api/Pamoja.Codec.html) |
65
+
66
+ ## Documentation
67
+
68
+ - [`@pamoja/codec` reference](https://pamoja.molex.cloud/docs/reference/node/modules/_pamoja_codec.html), every class, function, and type this package exports.
69
+ - [The Codecs guide](https://pamoja.molex.cloud/docs/guides/codec.html), with the same example in Rust, Python, and C#.
70
+ - [Every capability](https://pamoja.molex.cloud/docs/), and the [install page](https://pamoja.molex.cloud/docs/install.html).
71
+
72
+ ## License
73
+
74
+ MIT
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@pamoja/codec",
3
+ "version": "0.1.15",
4
+ "description": "CBOR, JSON, and raw codecs behind one trait, delta and varint batch packing, and an f32 quantizer for metered links.",
5
+ "license": "MIT",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/molexxxx/pamoja.git",
12
+ "directory": "bindings/node/packages/codec"
13
+ },
14
+ "homepage": "https://pamoja.molex.cloud/docs/guides/codec.html",
15
+ "keywords": [
16
+ "pamoja",
17
+ "iot",
18
+ "robotics",
19
+ "codec"
20
+ ],
21
+ "main": "dist/index.js",
22
+ "types": "dist/index.d.ts",
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "default": "./dist/index.js"
27
+ }
28
+ },
29
+ "files": [
30
+ "dist/",
31
+ "LICENSE-MIT"
32
+ ],
33
+ "engines": {
34
+ "node": ">= 16"
35
+ },
36
+ "dependencies": {
37
+ "@pamoja/native": "0.1.15"
38
+ }
39
+ }