package catapult

  1. Overview
  2. Docs
Tracing system based on the Catapult/TEF format

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.1.1.tar.gz
md5=b706c74e8644967431055dc61f611f37
sha512=2915460b9fdd8a470de1b3bc75fcf58c36d00823588f46082db5099979f96f3bc261a91d4b5c672d2df9493461075fd61df804c1e4e737ee052af280dc6c9a6b

doc/src/catapult.utils/json_out.ml.html

Source file json_out.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

(** Basic output of json values to a buffer *)

let char = Buffer.add_char
let raw_string = Buffer.add_string
let int out i = raw_string out (string_of_int i)
let int64 out i = raw_string out (Int64.to_string i)
let float out f = raw_string out (Printf.sprintf "%.1f" f)
let bool out = function true -> raw_string out "true" | false -> raw_string out "false"
let null oc = raw_string oc "null"

let str_val oc (s:string) =
  char oc '"';
  let encode_char c =
    match c with
    | '"' -> raw_string oc {|\"|}
    | '\\' -> raw_string oc {|\\|}
    | '\n' -> raw_string oc {|\n|}
    | '\b' -> raw_string oc {|\b|}
    | '\r' -> raw_string oc {|\r|}
    | '\t' -> raw_string oc {|\t|}
    | _ when Char.code c <= 0x1f ->
      raw_string oc {|\u00|}; Printf.bprintf oc "%02x" (Char.code c)
    | c -> char oc c
  in
  String.iter encode_char s;
  char oc '"'

let arg oc = function
  | `Int i -> int oc i
  | `String s -> str_val oc s
  | `Bool b -> bool oc b
  | `Float f -> float oc f
  | `Null -> null oc

let char_val oc (c:char) =
  char oc '"';
  char oc c;
  char oc '"'
OCaml

Innovation. Community. Security.