factorization
This commit is contained in:
parent
98f2058da6
commit
bf337663df
1 changed files with 8 additions and 9 deletions
|
@ -10,7 +10,14 @@ let parse_header reader =
|
|||
| _ -> failwith "Invalid number of fields"
|
||||
;;
|
||||
|
||||
let decode_name_simple reader =
|
||||
let rec parse_question reader =
|
||||
let reader', name_b = decode_name_simple reader in
|
||||
let name = String.to_bytes name_b in
|
||||
match List.init 2 (fun offset -> unpack_short_be reader' (offset * 2)) with
|
||||
| [ type_; class_ ] -> { name; type_; class_ }
|
||||
| _ -> failwith "Invalid number of fields"
|
||||
|
||||
and decode_name_simple reader =
|
||||
let rec read_parts parts pos =
|
||||
let length = int_of_char (Bytes.get reader pos) in
|
||||
if length = 0
|
||||
|
@ -23,11 +30,3 @@ let decode_name_simple reader =
|
|||
let offset, parts = read_parts [] 0 in
|
||||
bytes_forward reader offset, String.concat "." parts
|
||||
;;
|
||||
|
||||
let parse_question reader =
|
||||
let reader', name_b = decode_name_simple reader in
|
||||
let name = String.to_bytes name_b in
|
||||
match List.init 2 (fun offset -> unpack_short_be reader' (offset * 2)) with
|
||||
| [ type_; class_ ] -> { name; type_; class_ }
|
||||
| _ -> failwith "Invalid number of fields"
|
||||
;;
|
||||
|
|
Reference in a new issue