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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
use crate;
pub use Version;
pub use Value;
pub use Key;
pub use Row;
pub use *;
/// Splits a byte buffer into segments bounded by start and end markers.
///
/// This function iterates over a byte buffer and extracts all contiguous slices
/// that begin with the `start` byte and end with the `end` byte. Each segment
/// includes both the start and end markers.
///
/// # Type Parameters
/// - `B`: Any type implementing [`AsRef<Vec<u8>>`], allowing use of `Vec<u8>`
/// or references like `&Vec<u8>`.
///
/// # Parameters
/// - `bytes`: The raw byte buffer to segment.
/// - `start`: The byte that marks the beginning of a segment.
/// - `end`: The byte that marks the end of a segment.
///
/// # Returns
/// - A `Vec<Vec<u8>>`, where each inner vector represents a segment including
/// its start and end markers.
///
/// # Notes
/// - Segments that do not start with `start` or do not end with `end` are ignored.
/// - Nested segments are **not supported**; only top-level segments are captured.
/// - If a start marker is found without a matching end marker, it will be ignored.
///
/// # Examples
/// ```rust
/// use yad_core::core::segment;
///
/// let data = vec![0x01, 0x02, 0x03, 0x04, 0x02];
/// let segments = segment(data, &0x01, &0x04);
/// // segments = vec![vec![0x01, 0x02, 0x03, 0x04]]
/// ```
/// Splits a byte buffer into individual key segments using the YAD key markers.
///
/// # Type Parameters
/// - `B`: Any type implementing [`AsRef<Vec<u8>>`].
///
/// # Parameters
/// - `bytes`: The raw byte buffer containing serialized keys.
///
/// # Returns
/// - A vector of byte vectors, each representing a complete key including
/// [`KEY_START`] and [`KEY_END`] markers.
///
/// # Examples
/// ```rust
/// use yad_core::constants::headers::*;
/// use yad_core::core::segment_keys;
///
/// let bytes = vec![KEY_START, 1, KEY_END, KEY_START, 2, KEY_END];
/// let keys = segment_keys(bytes);
/// assert_eq!(keys.len(), 2);
/// ```
/// Splits a byte buffer into individual row segments using the YAD row markers.
///
/// # Type Parameters
/// - `B`: Any type implementing [`AsRef<Vec<u8>>`].
///
/// # Parameters
/// - `bytes`: The raw byte buffer containing serialized rows.
///
/// # Returns
/// - A vector of byte vectors, each representing a complete row including
/// [`ROW_START`] and [`ROW_END`] markers.
///
/// # Examples
/// ```rust
/// use yad_core::constants::headers::*;
/// use yad_core::core::segment_rows;
///
/// let bytes = vec![ROW_START, 1, ROW_END, ROW_START, 2, ROW_END];
/// let rows = segment_rows(bytes);
/// assert_eq!(rows.len(), 2);
/// ```