From ae1c021d964a4faf001be227c5382149e3b1f591 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 19 Jun 2023 20:03:07 +0200 Subject: [PATCH] add int (4bytes) unpacker --- lib/utils.ml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/utils.ml b/lib/utils.ml index 6e75aeb..144473c 100644 --- a/lib/utils.ml +++ b/lib/utils.ml @@ -33,4 +33,12 @@ let unpack_short_be data offset = (msb lsl 8) + lsb ;; +let unpack_int_be data offset = + let byte1 = int_of_char (Bytes.get data offset) in + let byte2 = int_of_char (Bytes.get data (offset + 1)) in + let byte3 = int_of_char (Bytes.get data (offset + 2)) in + let byte4 = int_of_char (Bytes.get data (offset + 3)) in + (byte1 lsl 24) lor (byte2 lsl 16) lor (byte3 lsl 8) lor byte4 +;; + let bytes_forward data offset = Bytes.sub data offset (Bytes.length data - offset)