1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use HashMap;
use crateErrorMessage;
use crate::*;
use *;
/// Deserializes a binary buffer into a [`YAD`] structure.
///
/// # Type Parameters
/// - `V`: A generic type that implements [`AsMut<Vec<u8>>`].
/// This allows flexibility in passing a mutable vector container, such as
/// `Vec<u8>`, `&mut Vec<u8>`, or other types that can yield a mutable reference
/// to a `Vec<u8>`.
///
/// # Parameters
/// - `vec`: A mutable vector of raw bytes (or any wrapper around it) that will be
/// consumed and decoded into a [`YAD`] structure.
/// The function may **mutate** or partially consume this buffer during parsing,
/// depending on the internal deserialization process.
///
/// # Returns
/// - `Ok(YAD)`: A fully reconstructed [`YAD`] instance parsed from the given binary data.
/// - `Err(ErrorMessage)`: An error if the provided binary data is invalid, incomplete,
/// or does not conform to the expected YAD binary format.
///
/// # Errors
/// This function returns [`ErrorMessage`] in cases such as:
/// - The binary sequence is corrupted or truncated.
/// - Unsupported or unknown byte markers are encountered.
/// - Internal inconsistencies prevent constructing a valid [`YAD`] instance.
///
/// # Examples
/// ```rust
/// let bytes: Vec<u8> = vec![/* valid serialized YAD data */];
/// let yad = yad_core::deserialize(bytes)?;
/// // `yad` now contains the reconstructed structure
/// ```
///
/// # Notes
/// - This function assumes that the input follows the **YAD binary specification**.
/// Any deviation or corruption in the binary layout will result in an error.
/// - The provided buffer may be **mutated or emptied** after the operation,
/// depending on how the deserializer consumes bytes.
///
/// # See Also
/// - [`serialize`] for converting a [`YAD`] instance into its binary form.