diff options
author | Daniil Baturin <daniil@baturin.org> | 2024-11-07 18:02:08 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-07 18:02:08 +0000 |
commit | 196fdd7fdf6dcf751b7364c59e34278bfd0193e3 (patch) | |
tree | cfeff0991481c8281e24cf1698b20a76854059a4 /src/message.ml | |
parent | dd9271b4304c6b1a5a2576821d1b2b8fd3aa6bf5 (diff) | |
parent | 9b90d3cc4da72c13ef4270150e4b547ff03fc813 (diff) | |
download | vyconf-196fdd7fdf6dcf751b7364c59e34278bfd0193e3.tar.gz vyconf-196fdd7fdf6dcf751b7364c59e34278bfd0193e3.zip |
Merge pull request #11 from jestabro/vyconf-minimal
T6718: use the vyconf daemon for validation of set commands
Diffstat (limited to 'src/message.ml')
-rw-r--r-- | src/message.ml | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/message.ml b/src/message.ml index 3629f0d..d4cc374 100644 --- a/src/message.ml +++ b/src/message.ml @@ -3,6 +3,11 @@ Messages are preceded by a length header, four bytes in network order. *) +(** Makes a hex dump of a byte string *) +let hexdump b = + let dump = ref "" in + Bytes.iter (fun c -> dump := Char.code c |> Printf.sprintf "%s %02x" !dump) b; + !dump let read ic = let header = Bytes.create 4 in @@ -12,14 +17,14 @@ let read ic = if length < 0 then failwith (Printf.sprintf "Bad message length: %d" length) else let buffer = Bytes.create length in let%lwt () = Lwt_io.read_into_exactly ic buffer 0 length in - Lwt_log.debug (Util.hexdump buffer |> Printf.sprintf "Read mesage: %s") |> Lwt.ignore_result; + Lwt_log.debug (hexdump buffer |> Printf.sprintf "Read mesage: %s") |> Lwt.ignore_result; Lwt.return buffer let write oc msg = let length = Bytes.length msg in let length' = Int32.of_int length in Lwt_log.debug (Printf.sprintf "Write length: %d\n" length) |> Lwt.ignore_result; - Lwt_log.debug (Util.hexdump msg |> Printf.sprintf "Write message: %s") |> Lwt.ignore_result; + Lwt_log.debug (hexdump msg |> Printf.sprintf "Write message: %s") |> Lwt.ignore_result; if length' < 0l then failwith (Printf.sprintf "Bad message length: %d" length) else let header = Bytes.create 4 in let () = EndianBytes.BigEndian.set_int32 header 0 length' in |