package rpclib

  1. Overview
  2. Docs
A library to deal with RPCs in OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

rpclib-9.0.0.tbz
sha256=ce23eb756c028d9374bd19823296bddb7c237d3f055452d30d1cf7d15216e963
sha512=d4dfd7a9ee1b7996c24819ac1895925af0ad732f117c6e06cd28c215b14aa094dbd045e44d7f84c0eeb7ab807ed970d6879c29d07b02377fcb928325124ba7f6

doc/src/rpclib.internals/internals.ml.html

Source file internals.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
(** Encodes a string using the given translation function that maps a character
    to a string that is its encoded version, if that character needs encoding. *)
let encode translate s =
  let n = String.length s in
  let need_encoding =
    let b = ref false in
    let i = ref 0 in
    while (not !b) && !i < n do
      b := translate s.[!i] <> None;
      incr i
    done;
    !b
  in
  if need_encoding
  then (
    let buf = Buffer.create 0 in
    let m = ref 0 in
    for i = 0 to n - 1 do
      match translate s.[i] with
      | None -> ()
      | Some n ->
        Buffer.add_substring buf s !m (i - !m);
        Buffer.add_string buf n;
        m := i + 1
    done;
    Buffer.add_substring buf s !m (n - !m);
    Buffer.contents buf)
  else s
OCaml

Innovation. Community. Security.