package bson2
Bson format encoding/decoding for Ocaml
Install
Dune Dependency
Authors
Maintainers
Sources
0.0.1.tar.gz
md5=c85d4bff9cd74f10102c54f0c117deac
sha512=66241cc8ab0c012f3f99ac9eb586e2e779ec1477086b39f1518a8b00017086a432f70da1d1b0f3a8f967945e66ede602997abb5a86fa655e198dc27a05a84a0c
Description
Published: 30 Oct 2019
README
Bson2
Bson2 is an Ocaml library for Bson encoding and decoding.
The Bson spec can be found here: Bson.
Modules
Currently, this library supports reading and writing from and to the binary bson format.
Bson2.Binary
contains the Reader
and Writer
modules.
Getting Started
Writing
let document =
let open Bson2.Binary.Writer in
let doc = create 64 in
write_string doc "name" "Stephanos";
write_int32 doc "age" 28l;
write_string doc "email" "stephanos.tsoucas@gmail.com";
write_document_close doc;
to_string doc |> Result.ok_or_failwith
Reading
A reader can be created from either bytes or a channel.
To read a document, call the read_next
function.
open Bson2.Binary
let process reader =
match Reader.read_next reader with
| Field(name, Double f) ->
handle_float name f
| Field(name, String s) ->
handle_string name s
| Field(name, Document_start) -> handle_document_start name
| Document_end -> handle_document_end ()
...
let () =
let chan = Stdio.In_channel.create "foo.txt" in
let reader = Reader.of_channel chan in
process reader
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
On This Page