package protocell
A Protobuf plugin for OCaml
Install
Dune Dependency
Authors
Maintainers
Sources
protocell-1.0.0.tbz
sha256=8296a7b386ad3ceb5e815374e8e4aa608d618869988b6f89b354c46225582fa8
sha512=7e3c758ac59b3a52aa523e1939103e8b4ad6adf8801df0a4bb1f947650e6f626c83ae7c55f1d114bbb652114fd46e88a7ed4835079ba70eaeb137220aefc3189
doc/src/protocell.runtime/byte_input.ml.html
Source file byte_input.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
open Base type t = { bytes : string; byte_count : int; position : int ref; } type error = [`Not_enough_bytes] let create bytes = {bytes; byte_count = String.length bytes; position = ref 0} let has_more_bytes {byte_count; position; _} = !position < byte_count let read_byte ({bytes; position; _} as stream) = match has_more_bytes stream with | true -> let result = bytes.[!position] in Int.incr position; Ok result | false -> Error `Not_enough_bytes let read_bytes {bytes; byte_count; position} count = match !position + count <= byte_count with | true -> let pos = !position in position := !position + count; Ok (String.sub bytes ~pos ~len:count) | false -> Error `Not_enough_bytes let read_while ({position; byte_count; bytes; _} as stream) condition = match has_more_bytes stream with | true -> let rec find_limit from = match from < byte_count with | true -> ( match condition bytes.[from] with | true -> find_limit (Int.succ from) | false -> from) | false -> from in let from_pos = !position in let to_pos = find_limit from_pos in position := to_pos; String.sub bytes ~pos:from_pos ~len:(to_pos - from_pos) | false -> ""
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>