Declarative CSV codecs
0
fork

Configure Feed

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

Add/update READMEs for all recently updated packages

Created 7 new READMEs: xmlt, dsp, demod, rtlsdr, erasure,
short-ldpc, ccsds (meta-package with full protocol suite table).

Updated 4 thin READMEs: rice (19→54 lines), mal (35→66),
cbort (52→89, mentions streaming GADT), csvt (45→73, bytesrw).

Each has: title, spec reference, quick start example, API overview.

+38 -10
+38 -10
README.md
··· 1 1 # csvt 2 2 3 - Declarative CSV codecs. 3 + Declarative CSV codecs with bytesrw streaming. 4 4 5 - Bidirectional codec system for CSV files, inspired by Jsont's approach to JSON codecs. Define typed codecs for your OCaml types and use them to decode CSV rows and encode values back to CSV. 5 + ## Overview 6 + 7 + Csvt provides bidirectional CSV encoding and decoding using a combinator-based 8 + approach inspired by 9 + [Jsont](https://github.com/dbuenzli/jsont). Define a typed row codec once 10 + and use it for both decoding CSV files into OCaml records and encoding records 11 + back to CSV. Column names are resolved at decode time for O(1) per-row field 12 + access. 13 + 14 + Streaming I/O is built on [bytesrw](https://github.com/dbuenzli/bytesrw): 15 + `decode` reads from a `Bytes.Reader.t` and `encode` writes to a 16 + `Bytes.Writer.t`, so CSV processing composes with other bytesrw-based codecs 17 + in a pipeline. For simple cases, `decode_file`, `decode_string`, and 18 + `fold_file` provide direct access. 6 19 7 20 ## Installation 8 21 ··· 24 37 |> finish 25 38 )) 26 39 40 + (* Decode from a file *) 27 41 let () = 28 42 match Csvt.decode_file point_codec "points.csv" with 29 43 | Ok points -> List.iter (fun p -> Printf.printf "%s\n" p.label) points 30 44 | Error e -> prerr_endline (Csvt.error_to_string e) 45 + 46 + (* Streaming fold without building a list *) 47 + let sum = 48 + Csvt.fold_file point_codec "points.csv" 49 + (fun acc p -> acc +. p.x) 0.0 50 + 51 + (* Encode to a bytesrw writer *) 52 + let () = 53 + let buf = Buffer.create 256 in 54 + let w = Bytesrw.Bytes.Writer.of_buffer buf in 55 + Csvt.encode point_codec points w 31 56 ``` 32 57 33 58 ## API Overview 34 59 35 - - **`type 'a col_codec`** -- Column-level codecs: `string`, `int`, `float`, `bool`, `option`, `nullable_float` 36 - - **`type 'a t`** -- Row-level codecs mapping CSV rows to OCaml records 37 - - **`Row.obj`**, **`Row.col`**, **`Row.finish`** -- Builder for row codecs 38 - - **`resolve`** -- Resolve column names to indices (O(1) per-row decoding) 39 - - **`decode_file`**, **`decode_channel`**, **`decode_string`** -- Decode CSV data 40 - - **`encode_header`**, **`encode_row`** -- Encode values back to CSV 60 + - **Field codecs** -- `string`, `int`, `float`, `bool`, `option`, `nullable_float`, `nullable_int` 61 + - **`col_map`** -- Custom field codec from `dec`/`enc` functions 62 + - **`Row`** module -- Row builder: `obj`, `col`, `finish` 63 + - **`decode_file`**, **`decode_channel`**, **`decode_string`** -- Batch decoding 41 64 - **`fold_file`**, **`fold_channel`** -- Streaming fold over rows 65 + - **`decode`** -- Streaming decode from a bytesrw reader 66 + - **`encode`** -- Streaming encode to a bytesrw writer 67 + - **`get_col`** -- Single-column projection query 68 + - **`update_col`**, **`delete_col`** -- Column-level transforms 69 + - **`col_names`**, **`col_count`** -- Codec introspection 42 70 43 - ## License 71 + ## Licence 44 72 45 - ISC 73 + ISC License. See [LICENSE.md](LICENSE.md) for details.