Source file kinetic_integration.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
53
54
55
56
57
58
59
open Kinetic_tag
open Kinetic_util
type off = int
type len = int
type 'a slice = 'a * off * len
type key = bytes
type version = bytes option
type timeout_ms = int64
module type INTEGRATION = sig
type value
type socket
val create : int -> value
val show : value -> string
val show_socket : socket -> string
val read : socket -> value -> off -> len -> int Lwt.t
val write : socket -> value -> off -> len -> int Lwt.t
val read_bytes : socket -> Bytes.t -> off -> len -> int Lwt.t
val write_bytes : socket -> Bytes.t -> off -> len -> int Lwt.t
val make_sha1 : value -> off -> len -> Tag.t
val make_crc32: value -> off -> len -> Tag.t
end
module BytesIntegration = struct
type value = bytes
type socket = Lwt_ssl.socket
let show_socket socket =
let fd = Lwt_ssl.get_unix_fd socket in
let (fdi:int) = Obj.magic fd in
string_of_int fdi
let create = Bytes.create
let show = trimmed
let read socket = Lwt_ssl.read socket
let write socket = Lwt_ssl.write socket
let read_bytes = read
let write_bytes = write
let make_sha1 v_buff v_off v_len =
let h = Cryptokit.Hash.sha1() in
let () = h # add_substring v_buff v_off v_len in
let hrs = h # result in
let hr = Bytes.of_string hrs in
Tag.Sha1 hr
let make_crc32 _ _ _ = failwith "todo: BytesValue.make_crc32"
end