diff options
-rw-r--r-- | _oasis | 2 | ||||
-rw-r--r-- | src/message.ml | 4 | ||||
-rw-r--r-- | src/util.ml | 8 | ||||
-rw-r--r-- | src/util.mli | 2 |
4 files changed, 14 insertions, 2 deletions
@@ -22,7 +22,7 @@ Library "vyconf-config" Modules: Vyconf_config InternalModules: Message FindlibParent: vyconf - BuildDepends: toml, fileutils, ppx_deriving.show, batteries + BuildDepends: toml, fileutils, ppx_deriving.show, batteries, vyconf Library "vyconf-client" Path: src diff --git a/src/message.ml b/src/message.ml index 24803fe..3629f0d 100644 --- a/src/message.ml +++ b/src/message.ml @@ -8,14 +8,18 @@ let read ic = let header = Bytes.create 4 in let%lwt () = Lwt_io.read_into_exactly ic header 0 4 in let length = EndianBytes.BigEndian.get_int32 header 0 |> Int32.to_int in + Lwt_log.debug (Printf.sprintf "Read length: %d\n" length) |> Lwt.ignore_result; 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.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; 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 diff --git a/src/util.ml b/src/util.ml index 7f0d681..de85e3e 100644 --- a/src/util.ml +++ b/src/util.ml @@ -1,4 +1,4 @@ -(* Unavoidable module for functions that don't fit anywhere else *) +(** The unavoidable module for functions that don't fit anywhere else *) let find_xml_child name xml = let find_aux e = @@ -23,3 +23,9 @@ let string_of_path path = let absolute_path relative_path = FilePath.make_absolute (Sys.getcwd ()) relative_path + +(** 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 diff --git a/src/util.mli b/src/util.mli index 9f6c3db..68d0094 100644 --- a/src/util.mli +++ b/src/util.mli @@ -3,3 +3,5 @@ val find_xml_child : string -> Xml.xml -> Xml.xml option val string_of_path : string list -> string val absolute_path : FilePath.filename -> FilePath.filename + +val hexdump : bytes -> string |