fix: decode of the compressed name
This commit is contained in:
parent
b87c8913fe
commit
aa93508881
2 changed files with 14 additions and 3 deletions
|
@ -27,7 +27,9 @@ and decode_name reader =
|
||||||
then 1, parts
|
then 1, parts
|
||||||
else if length land 0b1100_0000 <> 0
|
else if length land 0b1100_0000 <> 0
|
||||||
then (
|
then (
|
||||||
let decoded_name = decode_compressed_name reader length in
|
let decoded_name =
|
||||||
|
decode_compressed_name { reader with pointer = reader.pointer + pos } length
|
||||||
|
in
|
||||||
2, decoded_name :: parts)
|
2, decoded_name :: parts)
|
||||||
else (
|
else (
|
||||||
let part = Bytes.sub_string reader.data (reader.pointer + pos + 1) length in
|
let part = Bytes.sub_string reader.data (reader.pointer + pos + 1) length in
|
||||||
|
@ -38,9 +40,12 @@ and decode_name reader =
|
||||||
String.to_bytes (String.concat "." parts), offset
|
String.to_bytes (String.concat "." parts), offset
|
||||||
|
|
||||||
and decode_compressed_name reader length =
|
and decode_compressed_name reader length =
|
||||||
let pointer =
|
let pointer_bytes =
|
||||||
(length land 0b0011_1111) + int_of_char (Bytes.get reader.data (reader.pointer + 1))
|
Bytes.cat
|
||||||
|
(int_to_bytes (length land 0b0011_1111))
|
||||||
|
(Bytes.sub reader.data (reader.pointer + 1) 1)
|
||||||
in
|
in
|
||||||
|
let pointer = unpack_short_be pointer_bytes 0 in
|
||||||
String.of_bytes (fst (decode_name { reader with pointer }))
|
String.of_bytes (fst (decode_name { reader with pointer }))
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,12 @@ let unpack_short_be data offset =
|
||||||
(msb lsl 8) + lsb
|
(msb lsl 8) + lsb
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
let int_to_bytes n =
|
||||||
|
let byte_array = Bytes.create 1 in
|
||||||
|
Bytes.set byte_array 0 (Char.chr (n land 255));
|
||||||
|
byte_array
|
||||||
|
;;
|
||||||
|
|
||||||
let unpack_int_be data offset =
|
let unpack_int_be data offset =
|
||||||
let byte1 = int_of_char (Bytes.get data offset) in
|
let byte1 = int_of_char (Bytes.get data offset) in
|
||||||
let byte2 = int_of_char (Bytes.get data (offset + 1)) in
|
let byte2 = int_of_char (Bytes.get data (offset + 1)) in
|
||||||
|
|
Reference in a new issue