Debian Codegraph @

src/lib.rs

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 //! A simple OGG page reader
2
3 mod crcrust-analyzer cargo ogg_pager 0.7.2 crc/;
4 mod errorrust-analyzer cargo ogg_pager 0.7.2 error/;
5 mod headerrust-analyzer cargo ogg_pager 0.7.2 header/;
6 mod packetsrust-analyzer cargo ogg_pager 0.7.2 packets/;
7 mod paginaterust-analyzer cargo ogg_pager 0.7.2 paginate/;
8
9 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#, Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#};
10
11 pub use crcrust-analyzer cargo ogg_pager 0.7.2 crc/::crc32rust-analyzer cargo ogg_pager 0.7.2 crc/crc32().;
12 pub use errorrust-analyzer cargo ogg_pager 0.7.2 error/::{PageErrorrust-analyzer cargo ogg_pager 0.7.2 error/PageError#, Resultrust-analyzer cargo ogg_pager 0.7.2 error/Result#};
13 pub use headerrust-analyzer cargo ogg_pager 0.7.2 header/::{PAGE_HEADER_SIZErust-analyzer cargo ogg_pager 0.7.2 header/PAGE_HEADER_SIZE., PageHeaderrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#};
14 pub use packetsrust-analyzer cargo ogg_pager 0.7.2 packets/::{Packetsrust-analyzer cargo ogg_pager 0.7.2 packets/Packets#, PacketsIterrust-analyzer cargo ogg_pager 0.7.2 packets/PacketsIter#};
15 pub use paginaterust-analyzer cargo ogg_pager 0.7.2 paginate/::paginaterust-analyzer cargo ogg_pager 0.7.2 paginate/paginate().;
16
17 const CONTINUED_PACKETrust-analyzer cargo ogg_pager 0.7.2 CONTINUED_PACKET.: u8 = 0x01;
18 pub(craterust-analyzer cargo ogg_pager 0.7.2 crate/) const MAX_WRITTEN_SEGMENT_COUNTrust-analyzer cargo ogg_pager 0.7.2 MAX_WRITTEN_SEGMENT_COUNT.: usize = 32;
19 pub(craterust-analyzer cargo ogg_pager 0.7.2 crate/) const MAX_WRITTEN_CONTENT_SIZErust-analyzer cargo ogg_pager 0.7.2 MAX_WRITTEN_CONTENT_SIZE.: usize = MAX_WRITTEN_SEGMENT_COUNTrust-analyzer cargo ogg_pager 0.7.2 MAX_WRITTEN_SEGMENT_COUNT. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().255;
20
21 /// The maximum page content size
22 // NOTE: An OGG page can have up to 255 segments, or ~64KB. We cap it at 32 segments, or ~8KB when writing.
23 pub const MAX_CONTENT_SIZErust-analyzer cargo ogg_pager 0.7.2 MAX_CONTENT_SIZE.: usize = MAX_SEGMENT_COUNTrust-analyzer cargo ogg_pager 0.7.2 MAX_SEGMENT_COUNT. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().255;
24 /// The maximum number of segments a page can contain
25 pub const MAX_SEGMENT_COUNTrust-analyzer cargo ogg_pager 0.7.2 MAX_SEGMENT_COUNT.: usize = 255;
26 /// The packet contains the first page of the logical bitstream
27 pub const CONTAINS_FIRST_PAGE_OF_BITSTREAMrust-analyzer cargo ogg_pager 0.7.2 CONTAINS_FIRST_PAGE_OF_BITSTREAM.: u8 = 0x02;
28 /// The packet contains the last page of the logical bitstream
29 pub const CONTAINS_LAST_PAGE_OF_BITSTREAMrust-analyzer cargo ogg_pager 0.7.2 CONTAINS_LAST_PAGE_OF_BITSTREAM.: u8 = 0x04;
30
31 /// An OGG page
32 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
33 pub struct Pagerust-analyzer cargo ogg_pager 0.7.2 Page# {
34 contentrust-analyzer cargo ogg_pager 0.7.2 Page#content.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>,
35 headerrust-analyzer cargo ogg_pager 0.7.2 Page#header.: PageHeaderrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#,
36 /// The position in the stream the page ended
37 pub endrust-analyzer cargo ogg_pager 0.7.2 Page#end.: u64,
38 }
39
40 impl Pagerust-analyzer cargo ogg_pager 0.7.2 Page# {
41 /// Returns a reference to the `Page`'s header
42 pub fn headerrust-analyzer cargo ogg_pager 0.7.2 impl#[Page]header().(&self) -> &PageHeaderrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader# {
43 &self.headerrust-analyzer cargo ogg_pager 0.7.2 Page#header.
44 }
45
46 /// Returns a mutable reference to the `Page`'s header
47 pub fn header_mutrust-analyzer cargo ogg_pager 0.7.2 impl#[Page]header_mut().(&mut self) -> &mut PageHeaderrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader# {
48 &mut self.headerrust-analyzer cargo ogg_pager 0.7.2 Page#header.
49 }
50
51 /// Convert the Page to bytes for writing
52 ///
53 /// NOTE: This will write the checksum as is. It is likely [`Page::gen_crc`] will have
54 /// to be used prior.
55 #[must_use]
56 pub fn as_bytesrust-analyzer cargo ogg_pager 0.7.2 impl#[Page]as_bytes().(&self) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> {
57 let segment_table = &self.headerrust-analyzer cargo ogg_pager 0.7.2 Page#header..segmentsrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#segments.;
58 let num_segments = segment_table.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().();
59 let mut bytes =
60 Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(PAGE_HEADER_SIZErust-analyzer cargo ogg_pager 0.7.2 header/PAGE_HEADER_SIZE. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().num_segments rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().self.headerrust-analyzer cargo ogg_pager 0.7.2 Page#header..content_sizerust-analyzer cargo ogg_pager 0.7.2 header/impl#[PageHeader]content_size().());
61
62 bytes.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<&'a T>`]extend().(b"OggS");
63 bytes.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(0); // Version
64 bytes.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(self.headerrust-analyzer cargo ogg_pager 0.7.2 Page#header..header_type_flagrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#header_type_flag.);
65 bytes.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(self.headerrust-analyzer cargo ogg_pager 0.7.2 Page#header..abgprust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#abgp..to_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]to_le_bytes().());
66 bytes.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(self.headerrust-analyzer cargo ogg_pager 0.7.2 Page#header..stream_serialrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#stream_serial..to_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]to_le_bytes().());
67 bytes.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(self.headerrust-analyzer cargo ogg_pager 0.7.2 Page#header..sequence_numberrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#sequence_number..to_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]to_le_bytes().());
68 bytes.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(self.headerrust-analyzer cargo ogg_pager 0.7.2 Page#header..checksumrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#checksum..to_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]to_le_bytes().());
69 bytes.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(num_segments as u8);
70 bytes.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<&'a T>`]extend().(segment_table);
71 bytes.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<&'a T>`]extend().(self.contentrust-analyzer cargo ogg_pager 0.7.2 Page#content..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().());
72
73 bytes
74 }
75
76 /// Attempts to get a Page from a reader
77 ///
78 /// # Errors
79 ///
80 /// * [`std::io::Error`]
81 /// * [`PageError`]
82 pub fn readrust-analyzer cargo ogg_pager 0.7.2 impl#[Page]read().<V>(data: &mut V) -> Resultrust-analyzer cargo ogg_pager 0.7.2 error/Result#<Selfrust-analyzer cargo ogg_pager 0.7.2 impl#[Page]>
83 where
84 V: Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read# + Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#,
85 {
86 let header = PageHeaderrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#::readrust-analyzer cargo ogg_pager 0.7.2 header/impl#[PageHeader]read().(data)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
87
88 let mut content = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0; header.content_sizerust-analyzer cargo ogg_pager 0.7.2 header/impl#[PageHeader]content_size().()];
89 data.read_exactrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_exact().(&mut content)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
90
91 let end = data.stream_positionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#stream_position().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
92
93 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Pagerust-analyzer cargo ogg_pager 0.7.2 Page# {
94 contentrust-analyzer cargo ogg_pager 0.7.2 Page#content.,
95 headerrust-analyzer cargo ogg_pager 0.7.2 Page#header.,
96 endrust-analyzer cargo ogg_pager 0.7.2 Page#end.,
97 })
98 }
99
100 /// Generates the CRC checksum of the page
101 pub fn gen_crcrust-analyzer cargo ogg_pager 0.7.2 impl#[Page]gen_crc().(&mut self) {
102 // The value is computed over the entire header (with the CRC field in the header set to zero) and then continued over the page
103 self.headerrust-analyzer cargo ogg_pager 0.7.2 Page#header..checksumrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#checksum. = 0;
104 self.headerrust-analyzer cargo ogg_pager 0.7.2 Page#header..checksumrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#checksum. = crcrust-analyzer cargo ogg_pager 0.7.2 crc/::crc32rust-analyzer cargo ogg_pager 0.7.2 crc/crc32().(&self.as_bytesrust-analyzer cargo ogg_pager 0.7.2 impl#[Page]as_bytes().());
105 }
106
107 /// Returns the page's content
108 pub fn contentrust-analyzer cargo ogg_pager 0.7.2 impl#[Page]content().(&self) -> &[u8] {
109 self.contentrust-analyzer cargo ogg_pager 0.7.2 Page#content..as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().()
110 }
111
112 /// Consumes the page and returns its content
113 #[must_use]
114 pub fn take_contentrust-analyzer cargo ogg_pager 0.7.2 impl#[Page]take_content().(self) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> {
115 self.contentrust-analyzer cargo ogg_pager 0.7.2 Page#content.
116 }
117 }
118
119 #[cfg(test)]
120 mod testsrust-analyzer cargo ogg_pager 0.7.2 tests/ {
121 use craterust-analyzer cargo ogg_pager 0.7.2 crate/::{Pagerust-analyzer cargo ogg_pager 0.7.2 Page#, PageHeaderrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#, paginaterust-analyzer cargo ogg_pager 0.7.2 paginate/};
122 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Cursorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/Cursor#;
123
124 pub fn segment_tablerust-analyzer cargo ogg_pager 0.7.2 tests/segment_table().(length: usize) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> {
125 if length rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 {
126 return vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![1, 0];
127 }
128
129 let last_len = (length rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().255) as u8;
130 let needed = (length rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().255) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1;
131
132 let mut segments = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(needed);
133
134 for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#needed {
135 if i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().needed {
136 segments.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(255);
137 } else {
138 segments.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(last_len);
139 }
140 }
141
142 segments
143 }
144
145 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
•146 #[ignore = "missing test file"]
147 fn opus_ident_headerrust-analyzer cargo ogg_pager 0.7.2 tests/opus_ident_header().() {
148 let expected = Pagerust-analyzer cargo ogg_pager 0.7.2 Page# {
149 contentrust-analyzer cargo ogg_pager 0.7.2 Page#content.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
150 0x4F, 0x70, 0x75, 0x73, 0x48, 0x65, 0x61, 0x64, 0x01, 0x02, 0x38, 0x01, 0x80, 0xBB,
151 0, 0, 0, 0, 0,
152 ],
153 headerrust-analyzer cargo ogg_pager 0.7.2 Page#header.: PageHeaderrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader# {
154 startrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#start.: 0,
155 header_type_flagrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#header_type_flag.: 2,
156 abgprust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#abgp.: 0,
157 stream_serialrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#stream_serial.: 1_759_377_061,
158 sequence_numberrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#sequence_number.: 0,
159 segmentsrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#segments.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![19],
160 checksumrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#checksum.: 3_579_522_525,
161 },
162 endrust-analyzer cargo ogg_pager 0.7.2 Page#end.: 47,
163 };
164
165 let content = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read().("test_assets/opus_ident_header.page").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
166
167 let page = Pagerust-analyzer cargo ogg_pager 0.7.2 Page#::readrust-analyzer cargo ogg_pager 0.7.2 impl#[Page]read().(&mut Cursorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/Cursor#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]new().(content)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
168
169 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, page);
170 }
171
172 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
•173 #[ignore = "missing test file"]
174 fn paginate_largerust-analyzer cargo ogg_pager 0.7.2 tests/paginate_large().() {
175 let packet = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read().("test_assets/large_comment_packet.page").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
176
177 let pages = paginaterust-analyzer cargo ogg_pager 0.7.2 paginate/paginate().([packet.as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().()], 1234, 0, 0).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
178
179 let len = pages.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().();
180
181 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(len, 130);
182 let last_page_content = pages.lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().contentrust-analyzer cargo ogg_pager 0.7.2 impl#[Page]content().();
183
184 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
185 last_page_content.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() %rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). 255,
186 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().segment_tablerust-analyzer cargo ogg_pager 0.7.2 tests/segment_table().(last_page_content.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()).lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().() as usize
187 );
188
189 for (i, page) in pages.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
190 let header = page.headerrust-analyzer cargo ogg_pager 0.7.2 impl#[Page]header().();
191
192 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.stream_serialrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#stream_serial., 1234);
193
194 if i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().len {
195 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.abgprust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#abgp., 0);
196 } else {
197 // -1
198 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.abgprust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#abgp., u64::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]MAX.);
199 }
200
201 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.sequence_numberrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#sequence_number., i as u32);
202
203 if i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 {
204 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.header_type_flagrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#header_type_flag., 0);
205 } else {
206 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.header_type_flagrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#header_type_flag., 1);
207 }
208
209 if i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().len {
210 let segments = &header.segmentsrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#segments.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#header.segmentsrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#segments..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().;
211 for s in &segments[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#segments.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). {
212 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().s, 255);
213 }
214
215 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(segments.lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&171));
216 } else {
217 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.segmentsrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#segments., vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![255; superrust-analyzer cargo ogg_pager 0.7.2 crate/::MAX_WRITTEN_SEGMENT_COUNTrust-analyzer cargo ogg_pager 0.7.2 MAX_WRITTEN_SEGMENT_COUNT.]);
218 }
219 }
220 }
221
222 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
223 fn paginate_large_perfectly_divisiblerust-analyzer cargo ogg_pager 0.7.2 tests/paginate_large_perfectly_divisible().() {
224 // Create 20 max-size pages.
225 // This means we will need to make another page with a single zero segment table.
226 const PAGES_TO_WRITErust-analyzer cargo ogg_pager 0.7.2 tests/PAGES_TO_WRITE.: usize = 20;
227 const PACKET_SIZErust-analyzer cargo ogg_pager 0.7.2 tests/PACKET_SIZE.: usize = (superrust-analyzer cargo ogg_pager 0.7.2 crate/::MAX_WRITTEN_SEGMENT_COUNTrust-analyzer cargo ogg_pager 0.7.2 MAX_WRITTEN_SEGMENT_COUNT. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().255) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().PAGES_TO_WRITErust-analyzer cargo ogg_pager 0.7.2 tests/PAGES_TO_WRITE.;
228
229 let packet = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0; PACKET_SIZErust-analyzer cargo ogg_pager 0.7.2 tests/PACKET_SIZE.];
230
231 let pages = paginaterust-analyzer cargo ogg_pager 0.7.2 paginate/paginate().([packet.as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().()], 1234, 0, 0).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
232
233 let len = pages.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().();
234 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(len, PAGES_TO_WRITErust-analyzer cargo ogg_pager 0.7.2 tests/PAGES_TO_WRITE. +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). 1);
235
236 for (i, page) in pages.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
237 if i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().len {
238 break;
239 }
240
241 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(page.headerrust-analyzer cargo ogg_pager 0.7.2 Page#header..segmentsrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#segments..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]all().(|c| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().c == 255));
242 }
243
244 let last = pages.lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
245 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(last.headerrust-analyzer cargo ogg_pager 0.7.2 Page#header..segmentsrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#segments..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1);
246 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().last.headerrust-analyzer cargo ogg_pager 0.7.2 Page#header..segmentsrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#segments..firstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]first().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), 0);
247
248 let mut total_size = 0;
249 for page in pages {
250 total_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().page
251 .headerrust-analyzer cargo ogg_pager 0.7.2 Page#header.
252 .segmentsrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#segments.
253 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
254 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|&b| usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u8>`]from().(b))
255 .sumrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#sum().::<usize>();
256 }
257
258 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(total_size, PACKET_SIZErust-analyzer cargo ogg_pager 0.7.2 tests/PACKET_SIZE.);
259 }
260
261 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
262 fn paginate_perfectly_divisible_terminaterust-analyzer cargo ogg_pager 0.7.2 tests/paginate_perfectly_divisible_terminate().() {
263 // Our segment table will have 17 max-size segments, it should be terminated with a 0 to
264 // indicate the end of our packet.
265 const SEGMENTSrust-analyzer cargo ogg_pager 0.7.2 tests/SEGMENTS.: usize = 17;
266 const PACKET_SIZErust-analyzer cargo ogg_pager 0.7.2 tests/PACKET_SIZE.: usize = SEGMENTSrust-analyzer cargo ogg_pager 0.7.2 tests/SEGMENTS. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().255;
267
268 let packet = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0; PACKET_SIZErust-analyzer cargo ogg_pager 0.7.2 tests/PACKET_SIZE.];
269
270 let pages = paginaterust-analyzer cargo ogg_pager 0.7.2 paginate/paginate().([packet.as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().()], 1234, 0, 0).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
271
272 let len = pages.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().();
273 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(len, 1);
274
275 let page = &pages[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().;
276
277 // + 1 for the terminating 0
278 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(page.headerrust-analyzer cargo ogg_pager 0.7.2 Page#header..segmentsrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#segments..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), SEGMENTSrust-analyzer cargo ogg_pager 0.7.2 tests/SEGMENTS. +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). 1);
279
280 let correct_number_of_segments = page
281 .headerrust-analyzer cargo ogg_pager 0.7.2 Page#header.
282 .segmentsrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#segments.
283 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
284 .takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(SEGMENTSrust-analyzer cargo ogg_pager 0.7.2 tests/SEGMENTS.)
285 .allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#all().(|&b| b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().255);
286 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(correct_number_of_segments);
287
288 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().page.headerrust-analyzer cargo ogg_pager 0.7.2 Page#header..segmentsrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#segments..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), 0);
289 }
290 }