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