package catapult

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

Install

Dune Dependency

Authors

Maintainers

Sources

v0.2.tar.gz
md5=c732cce9430be74e8136cf87d6d8f9e5
sha512=2c221b86950a5ef81a41358b929633acc9d2b600aef8192a2b978b3b16dfc6237c79457db39f3beb95750d732674c977bc0547dde75bdfdf2fb378d192d37c48

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
40
41
42
43
(** 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.