File: test_json.ml

package info (click to toggle)
ocaml-angstrom 0.16.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,088 kB
  • sloc: ml: 2,012; makefile: 20; sh: 3
file content (19 lines) | stat: -rw-r--r-- 555 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
let read f =
  try
    let ic = open_in_bin f in
    let n = in_channel_length ic in
    let s = Bytes.create n in
    really_input ic s 0 n;
    close_in ic;
    let b = Bigstringaf.create n in
    Bigstringaf.blit_from_bytes s ~src_off:0 b ~dst_off:0 ~len:n;
    b
  with e ->
    failwith (Printf.sprintf "Cannot read content of %s.\n%s" f (Printexc.to_string e))
;;

let () =
  let twitter_big = read Sys.argv.(1) in
  match Angstrom.(parse_bigstring ~consume:Consume.Prefix RFC7159.json twitter_big) with
  | Ok _ -> ()
  | Error err -> failwith err