diff options
author | Daniil Baturin <daniil@baturin.org> | 2017-12-13 15:28:52 +0100 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2017-12-13 15:29:21 +0100 |
commit | cacc8ee6f2ccb43faa971a75d2c4585c8e1a27fc (patch) | |
tree | f7a2390758f90307ff5e1982a2f6f3d225a53e78 /src | |
parent | 7373e8aea39cec0af507b20a8209bd4697e74674 (diff) | |
download | vyconf-cacc8ee6f2ccb43faa971a75d2c4585c8e1a27fc.tar.gz vyconf-cacc8ee6f2ccb43faa971a75d2c4585c8e1a27fc.zip |
Add debug logging of protobuf messages.
Diffstat (limited to 'src')
-rw-r--r-- | src/message.ml | 4 | ||||
-rw-r--r-- | src/util.ml | 8 | ||||
-rw-r--r-- | src/util.mli | 2 |
3 files changed, 13 insertions, 1 deletions
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 |