package plebeia

  1. Overview
  2. Docs
Functional storage using Merkle Patricia tree

Install

Dune Dependency

Authors

Maintainers

Sources

plebeia-2.2.0.tar.gz
md5=7191dbbd3057df0a78032b560039bb59
sha512=f09790dfa65a6c8dc0da9618123d93f145c16c3b5be719dad04114bbe95a7e94697cacf2c6fb5b50c14408f864954dbf8d47e5994093623eb77f488bdf5c4205

doc/src/plebeia/data_encoding_tools.ml.html

Source file data_encoding_tools.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
44
45
46
47
48
49
50
51
52
(*****************************************************************************)
(*                                                                           *)
(* Open Source License                                                       *)
(* Copyright (c) 2020 DaiLambda, Inc. <contact@dailambda.jp>                 *)
(*                                                                           *)
(* Permission is hereby granted, free of charge, to any person obtaining a   *)
(* copy of this software and associated documentation files (the "Software"),*)
(* to deal in the Software without restriction, including without limitation *)
(* the rights to use, copy, modify, merge, publish, distribute, sublicense,  *)
(* and/or sell copies of the Software, and to permit persons to whom the     *)
(* Software is furnished to do so, subject to the following conditions:      *)
(*                                                                           *)
(* The above copyright notice and this permission notice shall be included   *)
(* in all copies or substantial portions of the Software.                    *)
(*                                                                           *)
(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)
(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  *)
(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL   *)
(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)
(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING   *)
(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER       *)
(* DEALINGS IN THE SOFTWARE.                                                 *)
(*                                                                           *)
(*****************************************************************************)

open Lwt.Syntax
open Data_encoding

let pp_with_encoding encoding ppf v =
  Json.pp ppf (Data_encoding.Json.construct encoding v)

type reader = { reader : 'a . 'a Data_encoding.t -> (int * 'a) Lwt.t }

let make_reader fd =
  let bytes = Bytes.create 4096 in
  let stream = ref None in
  let rec f read_bytes = function
    | Data_encoding.Binary.Success { result; stream= str; _ } ->
        stream := Some str;
        Lwt.return (read_bytes, result)
    | Await fill ->
        let* read = Lwt_unix.read fd bytes 0 4096 in
        if read = 0 then assert false; (* unexpected eof *)
        f (read_bytes + read) @@ fill (Bytes.sub bytes 0 read)
    | Error e ->
        let* () = Lwt_fmt.eprintf "%a@." Data_encoding.Binary.pp_read_error e in
        assert false
  in
  { reader =
      fun encoding ->
        f 0 @@ Data_encoding.Binary.read_stream ?init:!stream encoding
  }
OCaml

Innovation. Community. Security.