summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2017-12-13 15:28:52 +0100
committerDaniil Baturin <daniil@baturin.org>2017-12-13 15:29:21 +0100
commitcacc8ee6f2ccb43faa971a75d2c4585c8e1a27fc (patch)
treef7a2390758f90307ff5e1982a2f6f3d225a53e78
parent7373e8aea39cec0af507b20a8209bd4697e74674 (diff)
downloadvyconf-cacc8ee6f2ccb43faa971a75d2c4585c8e1a27fc.tar.gz
vyconf-cacc8ee6f2ccb43faa971a75d2c4585c8e1a27fc.zip
Add debug logging of protobuf messages.
-rw-r--r--_oasis2
-rw-r--r--src/message.ml4
-rw-r--r--src/util.ml8
-rw-r--r--src/util.mli2
4 files changed, 14 insertions, 2 deletions
diff --git a/_oasis b/_oasis
index 686f7e0..809d43e 100644
--- a/_oasis
+++ b/_oasis
@@ -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