CSDS Key-Value Notation parser
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

OCaml 84.4%
Dune 4.9%
Other 10.7%
12 1 0

Clone this repository

https://tangled.org/gazagnaire.org/ocaml-kvn https://tangled.org/did:plc:jhift2vwcxhou52p3sewcrpx/ocaml-kvn
git@git.recoil.org:gazagnaire.org/ocaml-kvn git@git.recoil.org:did:plc:jhift2vwcxhou52p3sewcrpx/ocaml-kvn

For self-hosted knots, clone URLs may differ based on your setup.

Download tar.gz
README.md

kvn#

CCSDS Key-Value Notation parser.

Typed parser for CCSDS Key-Value Notation (KVN), the text format used by OEM, OCM, TDM, ADM, CDM, and other CCSDS navigation data messages. Provides line classification, epoch parsing, block iteration, and low-level parsing primitives.

Installation#

Install with opam:

$ opam install kvn

If opam cannot find the package, it may not yet be released in the public opam-repository. Add the overlay repository, then install it:

$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install kvn

Usage#

let kvn_data =
  "CCSDS_OEM_VERS = 2.0\n\
   META_START\n\
   OBJECT_NAME = ISS\n\
   META_STOP\n"

(* Parse a KVN file line by line *)
let scan () =
  let st = Kvn.of_string kvn_data in
  while not (Kvn.eof st) do
    (match Kvn.next st with
     | Some (_n, line) ->
         (match Kvn.classify line with
          | Kvn.Keyword (k, v) -> Printf.printf "%s = %s\n" k v
          | Kvn.Data d -> Printf.printf "data: %s\n" d
          | Kvn.Comment c -> Printf.printf "# %s\n" c
          | Kvn.Blank -> ())
     | None -> ())
  done

(* Iterate over a metadata block *)
let iter () =
  let st = Kvn.of_string kvn_data in
  Kvn.iter_block ~start:"META_START" ~stop:"META_STOP" st
    ~on_keyword:(fun k v -> Printf.printf "%s = %s\n" k v)
    ~on_data:(fun _n _d -> ())

API Overview#

  • type line -- Keyword of string * string, Data of string, Comment of string, Blank
  • classify -- Classify a raw KVN line
  • parse_epoch -- Parse CCSDS epoch string to Ptime.t
  • type state -- Mutable line-by-line parser state
  • of_string, of_channel -- Create parser from string or channel
  • peek, next, advance, skip_blanks, eof -- Parser navigation
  • iter_block -- Iterate over a delimited block (e.g., META_START/META_STOP)
  • expect_keyword -- Check and consume a specific keyword
  • parse_float, parse_int, parse_floats, split_data -- Value parsing

License#

ISC