| 1 | use craterust-analyzer cargo ogg_pager 0.7.2 crate/::errorrust-analyzer cargo ogg_pager 0.7.2 error/::Resultrust-analyzer cargo ogg_pager 0.7.2 error/Result#; |
| 2 | use craterust-analyzer cargo ogg_pager 0.7.2 crate/::{ |
| 3 | CONTAINS_FIRST_PAGE_OF_BITSTREAMrust-analyzer cargo ogg_pager 0.7.2 CONTAINS_FIRST_PAGE_OF_BITSTREAM., CONTAINS_LAST_PAGE_OF_BITSTREAMrust-analyzer cargo ogg_pager 0.7.2 CONTAINS_LAST_PAGE_OF_BITSTREAM., CONTINUED_PACKETrust-analyzer cargo ogg_pager 0.7.2 CONTINUED_PACKET., |
| 4 | MAX_WRITTEN_CONTENT_SIZErust-analyzer cargo ogg_pager 0.7.2 MAX_WRITTEN_CONTENT_SIZE., MAX_WRITTEN_SEGMENT_COUNTrust-analyzer cargo ogg_pager 0.7.2 MAX_WRITTEN_SEGMENT_COUNT., Pagerust-analyzer cargo ogg_pager 0.7.2 Page#, PageHeaderrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#, |
| 5 | }; |
| 6 | |
| 7 | 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#; |
| 8 | |
| 9 | struct PaginateContextrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext# { |
| 10 | pagesrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#pages.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Pagerust-analyzer cargo ogg_pager 0.7.2 Page#>, |
| 11 | abgprust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#abgp.: u64, |
| 12 | stream_serialrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#stream_serial.: u32, |
| 13 | header_flagsrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#header_flags.: u8, |
| 14 | flagsrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#flags.: PaginateContextFlagsrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContextFlags#, |
| 15 | posrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#pos.: u64, |
| 16 | idxrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#idx.: usize, |
| 17 | remaining_page_sizerust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#remaining_page_size.: usize, |
| 18 | current_packet_lenrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#current_packet_len.: usize, |
| 19 | last_segment_sizerust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#last_segment_size.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u8>, |
| 20 | } |
| 21 | |
| 22 | impl PaginateContextrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext# { |
| 23 | fn newrust-analyzer cargo ogg_pager 0.7.2 paginate/impl#[PaginateContext]new().(abgp: u64, stream_serial: u32, header_flags: u8) -> Selfrust-analyzer cargo ogg_pager 0.7.2 paginate/impl#[PaginateContext] { |
| 24 | Selfrust-analyzer cargo ogg_pager 0.7.2 paginate/impl#[PaginateContext] { |
| 25 | pagesrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#pages.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(), |
| 26 | abgprust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#abgp., |
| 27 | stream_serialrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#stream_serial., |
| 28 | header_flagsrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#header_flags., |
| 29 | flagsrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#flags.: PaginateContextFlagsrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContextFlags# { |
| 30 | first_pagerust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContextFlags#first_page.: true, |
| 31 | fresh_packetrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContextFlags#fresh_packet.: true, |
| 32 | packet_finished_on_pagerust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContextFlags#packet_finished_on_page.: false, |
| 33 | }, |
| 34 | posrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#pos.: 0, |
| 35 | idxrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#idx.: 0, |
| 36 | remaining_page_sizerust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#remaining_page_size.: MAX_WRITTEN_CONTENT_SIZErust-analyzer cargo ogg_pager 0.7.2 MAX_WRITTEN_CONTENT_SIZE., |
| 37 | current_packet_lenrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#current_packet_len.: 0, |
| 38 | last_segment_sizerust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#last_segment_size.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | fn fresh_packetrust-analyzer cargo ogg_pager 0.7.2 paginate/impl#[PaginateContext]fresh_packet().(&mut self, packet: &[u8]) { |
| 43 | self.flagsrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#flags..fresh_packetrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContextFlags#fresh_packet. = true; |
| 44 | self.posrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#pos. = 0; |
| 45 | |
| 46 | self.current_packet_lenrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#current_packet_len. = packet.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(); |
| 47 | self.last_segment_sizerust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#last_segment_size. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((packet.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().%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); |
| 48 | } |
| 49 | |
| 50 | fn flush_pagerust-analyzer cargo ogg_pager 0.7.2 paginate/impl#[PaginateContext]flush_page().(&mut self, content: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) { |
| 51 | let mut header = PageHeaderrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader# { |
| 52 | startrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#start.: self.posrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#pos., |
| 53 | header_type_flagrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#header_type_flag.: { |
| 54 | if self.flagsrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#flags..first_pagerust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContextFlags#first_page. |
| 55 | && self.header_flagsrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#header_flags. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().CONTAINS_FIRST_PAGE_OF_BITSTREAMrust-analyzer cargo ogg_pager 0.7.2 CONTAINS_FIRST_PAGE_OF_BITSTREAM. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().0 |
| 56 | { |
| 57 | CONTAINS_FIRST_PAGE_OF_BITSTREAMrust-analyzer cargo ogg_pager 0.7.2 CONTAINS_FIRST_PAGE_OF_BITSTREAM. |
| 58 | } else if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.flagsrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#flags..fresh_packetrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContextFlags#fresh_packet. { |
| 59 | // A packet from the previous page continues onto this page |
| 60 | CONTINUED_PACKETrust-analyzer cargo ogg_pager 0.7.2 CONTINUED_PACKET. |
| 61 | } else { |
| 62 | 0 |
| 63 | } |
| 64 | }, |
| 65 | abgprust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#abgp.: 0, |
| 66 | stream_serialrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#stream_serial.: self.stream_serialrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#stream_serial., |
| 67 | sequence_numberrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#sequence_number.: self.idxrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#idx. as u32, |
| 68 | segmentsrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#segments.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(), |
| 69 | // Calculated later |
| 70 | checksumrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#checksum.: 0, |
| 71 | }; |
| 72 | |
| 73 | let content = corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/take().(content); |
| 74 | let content_len = content.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 75 | self.posrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<Self>`]add_assign().content_len as u64; |
| 76 | |
| 77 | // Determine how many *full* segments our page content takes up. |
| 78 | // Anything < 255 will be covered by `last_segment_size` |
| 79 | let full_segments_occupied = content_len 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; |
| 80 | |
| 81 | // Moving on to a new packet |
| 82 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(self.posrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#pos. <= self.current_packet_lenrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#current_packet_len. as u64); |
| 83 | |
| 84 | if self.flagsrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#flags..packet_finished_on_pagerust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContextFlags#packet_finished_on_page. { |
| 85 | header.abgprust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#abgp. = self.abgprust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#abgp.; |
| 86 | } else { |
| 87 | // A special value of '-1' (in two's complement) indicates that no packets |
| 88 | // finish on this page. |
| 89 | header.abgprust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#abgp. = 1_u64.wrapping_negrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]wrapping_neg().() |
| 90 | } |
| 91 | |
| 92 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(full_segments_occupied <= MAX_WRITTEN_SEGMENT_COUNTrust-analyzer cargo ogg_pager 0.7.2 MAX_WRITTEN_SEGMENT_COUNT.); |
| 93 | 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; full_segments_occupied]; |
| 94 | |
| 95 | if full_segments_occupied rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().MAX_WRITTEN_SEGMENT_COUNTrust-analyzer cargo ogg_pager 0.7.2 MAX_WRITTEN_SEGMENT_COUNT. { |
| 96 | // End of the packet |
| 97 | let last_segment_size = self |
| 98 | .last_segment_sizerust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#last_segment_size. |
| 99 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("fresh packet should be indicated at this point"); |
| 100 | header.segmentsrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#segments..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(last_segment_size); |
| 101 | } |
| 102 | |
| 103 | self.pagesrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#pages..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Pagerust-analyzer cargo ogg_pager 0.7.2 Page# { |
| 104 | contentrust-analyzer cargo ogg_pager 0.7.2 Page#content., |
| 105 | headerrust-analyzer cargo ogg_pager 0.7.2 Page#header., |
| 106 | endrust-analyzer cargo ogg_pager 0.7.2 Page#end.: self.posrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#pos., |
| 107 | }); |
| 108 | |
| 109 | self.idxrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#idx. 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().1; |
| 110 | self.flagsrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#flags..packet_finished_on_pagerust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContextFlags#packet_finished_on_page. = false; |
| 111 | self.remaining_page_sizerust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#remaining_page_size. = MAX_WRITTEN_CONTENT_SIZErust-analyzer cargo ogg_pager 0.7.2 MAX_WRITTEN_CONTENT_SIZE.; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | struct PaginateContextFlagsrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContextFlags# { |
| 116 | first_pagerust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContextFlags#first_page.: bool, |
| 117 | fresh_packetrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContextFlags#fresh_packet.: bool, |
| 118 | packet_finished_on_pagerust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContextFlags#packet_finished_on_page.: bool, |
| 119 | } |
| 120 | |
| 121 | /// Create pages from a list of packets |
| 122 | /// |
| 123 | /// # Errors |
| 124 | /// |
| 125 | /// * Unable to read packet content |
| 126 | /// |
| 127 | /// # Example |
| 128 | /// |
| 129 | /// ```rust,ignore |
| 130 | /// use ogg_pager::paginate; |
| 131 | /// |
| 132 | /// // Creating the comment header |
| 133 | /// let comment_header_packet = vec![...]; |
| 134 | /// let stream_serial_number = 2784419176; |
| 135 | /// |
| 136 | /// let pages = paginate(&comment_header_packet, stream_serial_number, 0, 0); |
| 137 | /// ``` |
| 138 | pub fn paginaterust-analyzer cargo ogg_pager 0.7.2 paginate/paginate().<'a, I>(packets: I, stream_serial: u32, abgp: u64, flags: u8) -> Resultrust-analyzer cargo ogg_pager 0.7.2 error/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Pagerust-analyzer cargo ogg_pager 0.7.2 Page#>> |
| 139 | where |
| 140 | I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = &'a [u8]> + 'a, |
| 141 | { |
| 142 | let mut ctx = PaginateContextrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#::newrust-analyzer cargo ogg_pager 0.7.2 paginate/impl#[PaginateContext]new().(abgp, stream_serial, flags); |
| 143 | |
| 144 | for packet in packets { |
| 145 | ctx.fresh_packetrust-analyzer cargo ogg_pager 0.7.2 paginate/impl#[PaginateContext]fresh_packet().(packet); |
| 146 | paginate_packetrust-analyzer cargo ogg_pager 0.7.2 paginate/paginate_packet().(&mut ctx, packet)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 147 | } |
| 148 | |
| 149 | if flags rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().CONTAINS_LAST_PAGE_OF_BITSTREAMrust-analyzer cargo ogg_pager 0.7.2 CONTAINS_LAST_PAGE_OF_BITSTREAM. 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().0x04 |
| 150 | && let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(last) = ctx.pagesrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#pages..last_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last_mut().() |
| 151 | { |
| 152 | last.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. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign().CONTAINS_LAST_PAGE_OF_BITSTREAMrust-analyzer cargo ogg_pager 0.7.2 CONTAINS_LAST_PAGE_OF_BITSTREAM.; |
| 153 | } |
| 154 | |
| 155 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ctx.pagesrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#pages.) |
| 156 | } |
| 157 | |
| 158 | fn paginate_packetrust-analyzer cargo ogg_pager 0.7.2 paginate/paginate_packet().(ctx: &mut PaginateContextrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#, packet: &[u8]) -> Resultrust-analyzer cargo ogg_pager 0.7.2 error/Result#<()> { |
| 159 | let mut page_content = 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().(MAX_WRITTEN_CONTENT_SIZErust-analyzer cargo ogg_pager 0.7.2 MAX_WRITTEN_CONTENT_SIZE.); |
| 160 | let mut packet = packet; |
| 161 | loop { |
| 162 | if packet.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { |
| 163 | break; |
| 164 | } |
| 165 | |
| 166 | let bytes_read = packet |
| 167 | .takerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#take().(ctx.remaining_page_sizerust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#remaining_page_size. as u64) |
| 168 | .read_to_endrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_to_end().(&mut page_content)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 169 | ctx.remaining_page_sizerust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#remaining_page_size. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().bytes_read; |
| 170 | |
| 171 | packet = &packet[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().bytes_read..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 172 | |
| 173 | if bytes_read rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().MAX_WRITTEN_CONTENT_SIZErust-analyzer cargo ogg_pager 0.7.2 MAX_WRITTEN_CONTENT_SIZE. && packet.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { |
| 174 | ctx.flagsrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#flags..packet_finished_on_pagerust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContextFlags#packet_finished_on_page. = true; |
| 175 | } |
| 176 | |
| 177 | if ctx.remaining_page_sizerust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#remaining_page_size. 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 || packet.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { |
| 178 | ctx.flush_pagerust-analyzer cargo ogg_pager 0.7.2 paginate/impl#[PaginateContext]flush_page().(&mut page_content); |
| 179 | } |
| 180 | |
| 181 | ctx.flagsrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#flags..first_pagerust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContextFlags#first_page. = false; |
| 182 | ctx.flagsrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#flags..fresh_packetrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContextFlags#fresh_packet. = false; |
| 183 | } |
| 184 | |
| 185 | // Flush any content leftover |
| 186 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().page_content.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 187 | ctx.flush_pagerust-analyzer cargo ogg_pager 0.7.2 paginate/impl#[PaginateContext]flush_page().(&mut page_content); |
| 188 | } |
| 189 | |
| 190 | // After all packet bytes are consumed, check for nil page condition |
| 191 | // If the packet length is a multiple of 255 * MAX_WRITTEN_SEGMENT_COUNT, we need a nil page |
| 192 | |
| 193 | // A 'nil' page just means it is zero-length. This is used when our packet is perfectly |
| 194 | // divisible by `255 * MAX_SEGMENT_COUNT`. We need a zero-sized segment to mark the end of our |
| 195 | // packet across page boundaries. |
| 196 | // |
| 197 | // Very rare circumstance, but still possible. |
| 198 | // |
| 199 | // From <https://xiph.org/ogg/doc/framing.html>: |
| 200 | // "Note also that a 'nil' (zero length) packet is not an error; it consists of nothing more than a lacing value of zero in the header." |
| 201 | if ctx.current_packet_lenrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#current_packet_len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().0 |
| 202 | && ctx |
| 203 | .current_packet_lenrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#current_packet_len. |
| 204 | .is_multiple_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]is_multiple_of().(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().MAX_WRITTEN_SEGMENT_COUNTrust-analyzer cargo ogg_pager 0.7.2 MAX_WRITTEN_SEGMENT_COUNT.) |
| 205 | { |
| 206 | ctx.flagsrust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContext#flags..packet_finished_on_pagerust-analyzer cargo ogg_pager 0.7.2 paginate/PaginateContextFlags#packet_finished_on_page. = true; |
| 207 | let mut nil_content = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 208 | ctx.flush_pagerust-analyzer cargo ogg_pager 0.7.2 paginate/impl#[PaginateContext]flush_page().(&mut nil_content); |
| 209 | } |
| 210 | |
| 211 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 212 | } |