SDNV - Self-Delimiting Numeric Values (RFC 6256)#
Variable-length integer encoding used by LTP (CCSDS 734.1-B-1), Bundle Protocol, and other space protocols. Provides efficient encoding of arbitrary-precision integers with self-delimiting properties.
Supports:
- In-memory encoding/decoding to bytes
- Streaming I/O with bytesrw
Installation#
opam install sdnv will install this library.
Usage#
open Sdnv
(* Encode a value *)
let encoded = encode 300L
(* Decode from bytes *)
match decode encoded 0 with
| Ok (value, consumed) -> Printf.printf "Value: %Ld (%d bytes)\n" value consumed
| Error Truncated -> print_endline "Truncated input"
| Error Overflow -> print_endline "Value too large"
(* Streaming with bytesrw *)
let value = read_exn reader
write writer 42L