Skip to main content

rule2sor

Convert OpenSCHC JSON rule files into .sor files (the Set of Rules serialized in CORECONF/CBOR, following the ietf-schc YANG data model).

Usage with uvx

uvx --from git+https://github.com/ltn22/rule2sor rule2sor <rule-file.json>

Or after installation (pip install git+https://github.com/ltn22/rule2sor):

rule2sor <rule-file.json> [-s <sid-file>]... [-o <output.sor>] [-q]

By default the output file has the same name as the input with the .sor extension, and the SID file is the bundled ietf-schc@2026-05-07.sid. -s can be repeated to load several SID files (the bundled one is then not loaded unless given explicitly). With -q only the final message is printed.

If you pass a .sor file instead of a JSON file, rule2sor will read and print its contents (CBOR hex, CBOR diagnostic notation, and decoded RESTCONF JSON) directly to the standard output:

rule2sor <file.sor> [-s <sid-file>]

Example:

rule2sor atmos41.json
# -> atmos41.sor

rule2sor atmos41.sor
# displays the content of atmos41.sor

What it does

This is an extraction of the minimal code from OpenSCHC:

  • gen_rulemanager.py — trimmed RuleManager keeping:
    • Add(): loads a JSON rule file, checks rule integrity (RuleID overlaps, valid FID/MO/CDA, one of compression/fragmentation/no-compression per rule, FP consistent with the order of repeated fields) and fills in missing defaults (FL, FP, DI);
    • Print(): displays the rules as ASCII tables;
    • add_sid_file() / to_coreconf(): serializes the Set of Rules in CORECONF/CBOR using the SID values.
  • gen_parameters.py — constants, YANG_ID mapping (simplified to a direct name-to-YANG-identifier mapping) and adapt_value().
  • ietf-schc@2026-05-07.sid — default SID file.

JSON rule format

See the long docstring at the top of rule2sor/gen_rulemanager.py, which documents the OpenSCHC JSON rule data model (compression and fragmentation).

FID, FL, DI, MO and CDA can be written with the names of the YANG identities without their prefix (ipv6-version, length-bytes(16), down, equal, compute...), looked up in the SID files, or with the old OpenSCHC names (IPV6.VER, length-byte(16), DW, compute-length...). Universal options are written coap.option(11) or UO(coap, 11). See meteo.json for an example.

Metadata

Release files for rule2sor 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rule2sor 0.2.0
File Size Uploaded
rule2sor-0.2.0.tar.gz 48.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rule2sor 0.2.0
File Interpreter ABI Platform
rule2sor-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 72.7 kB

Release files / rule2sor-0.2.0.tar.gz

Download URL rule2sor-0.2.0.tar.gz
Size 48.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d2ef5096a15369462c2d3472c5fb16aaf41ed9f20a3b893a44796883ec2e1868
BLAKE2b-256 checksum
How to use checksums
6c71593ef975d1b22d3ef433c6b6b78a34bc4c54bba6dcbd50933b92672c8d16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.4

Release files / rule2sor-0.2.0-py3-none-any.whl

Download URL rule2sor-0.2.0-py3-none-any.whl
Size 24.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
40c1bdb9974bad080ac1ea5f0bc1a7d765f0e00495782ff9b18703f8ef03fb68
BLAKE2b-256 checksum
How to use checksums
c5072e6a3eef69f1e49f63417313b192a16c7012b86c14db7002bdd84d3c589d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.4

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page