From 1e1ee73fbc1efb7a28788768b890e9e556e9511a Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 5 Jun 2023 21:23:53 +0200 Subject: [PATCH] fix issue with the question to byte --- lib/query.ml | 6 ++++-- lib/utils.ml | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/query.ml b/lib/query.ml index f2f9a21..2b68785 100644 --- a/lib/query.ml +++ b/lib/query.ml @@ -3,7 +3,7 @@ open Utils let header_to_bytes header = new_buffer - header + (2 * get_obj_size header) [ header.id ; header.flags ; header.num_questions @@ -14,7 +14,9 @@ let header_to_bytes header = ;; let question_to_bytes question = - let buffer = new_buffer question [ question.type_; question.class_ ] in + let buffer = + new_buffer (2 * (get_obj_size question - 1)) [ question.type_; question.class_ ] + in Bytes.cat buffer question.name ;; diff --git a/lib/utils.ml b/lib/utils.ml index 771e1a3..369b526 100644 --- a/lib/utils.ml +++ b/lib/utils.ml @@ -11,8 +11,9 @@ let get_bytecode data = String.concat "" result ;; -let new_buffer obj list = - let size = 2 * Obj.size (Obj.repr obj) in +let get_obj_size obj = Obj.size (Obj.repr obj) + +let new_buffer size list = let buffer = Bytes.create size in let verification = List.fold_left