Debian Codegraph @

src/header.rs

raw symbols SCIP
1 use craterust-analyzer cargo ogg_pager 0.7.2 crate/::{PageErrorrust-analyzer cargo ogg_pager 0.7.2 error/PageError#, Resultrust-analyzer cargo ogg_pager 0.7.2 error/Result#};
2
3 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#};
4
5 use byteorderrust-analyzer cargo byteorder 1.5.0 crate/::{LittleEndianrust-analyzer cargo byteorder 1.5.0 LittleEndian#, ReadBytesExtrust-analyzer cargo byteorder 1.5.0 io/ReadBytesExt#};
6
7 /// The size of an OGG page header
8 pub const PAGE_HEADER_SIZErust-analyzer cargo ogg_pager 0.7.2 header/PAGE_HEADER_SIZE.: usize = 27;
9
10 /// An OGG page header
11 #[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:)]
12 pub struct PageHeaderrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader# {
13 /// The position in the stream the page started at
14 pub startrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#start.: u64,
15 pub(craterust-analyzer cargo ogg_pager 0.7.2 crate/) header_type_flagrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#header_type_flag.: u8,
16 /// The page's absolute granule position
17 pub abgprust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#abgp.: u64,
18 /// The page's stream serial number
19 pub stream_serialrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#stream_serial.: u32,
20 /// The page's sequence number
21 pub sequence_numberrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#sequence_number.: u32,
22 pub(craterust-analyzer cargo ogg_pager 0.7.2 crate/) 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#<u8>,
23 pub(craterust-analyzer cargo ogg_pager 0.7.2 crate/) checksumrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#checksum.: u32,
24 }
25
26 impl PageHeaderrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader# {
27 /// Creates a new `PageHeader`
28 #[must_use]
29 pub const fn newrust-analyzer cargo ogg_pager 0.7.2 header/impl#[PageHeader]new().(
30 header_type_flag: u8,
31 abgp: u64,
32 stream_serial: u32,
33 sequence_number: u32,
34 ) -> Selfrust-analyzer cargo ogg_pager 0.7.2 header/impl#[PageHeader] {
35 Selfrust-analyzer cargo ogg_pager 0.7.2 header/impl#[PageHeader] {
36 startrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#start.: 0,
37 header_type_flagrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#header_type_flag.,
38 abgprust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#abgp.,
39 stream_serialrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#stream_serial.,
40 sequence_numberrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#sequence_number.,
41 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().(),
42 checksumrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#checksum.: 0,
43 }
44 }
45
46 /// Reads a `PageHeader` from a reader
47 ///
48 /// # Errors
49 ///
50 /// * [`PageError::MissingMagic`]
51 /// * [`PageError::InvalidVersion`]
52 /// * [`PageError::BadSegmentCount`]
53 /// * Reader does not have enough data
54 pub fn readrust-analyzer cargo ogg_pager 0.7.2 header/impl#[PageHeader]read().<R>(data: &mut R) -> Resultrust-analyzer cargo ogg_pager 0.7.2 error/Result#<Selfrust-analyzer cargo ogg_pager 0.7.2 header/impl#[PageHeader]>
55 where
56 R: 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#,
57 {
58 let start = 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().;
59
60 let mut sig = [0; 4];
61 data.read_exactrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_exact().(&mut sig)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
62
63 if &sig rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().b"OggS" {
64 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(PageErrorrust-analyzer cargo ogg_pager 0.7.2 error/PageError#::MissingMagicrust-analyzer cargo ogg_pager 0.7.2 error/PageError#MissingMagic#);
65 }
66
67 // Version, always 0
68 let version = data.read_u8rust-analyzer cargo byteorder 1.5.0 io/ReadBytesExt#read_u8().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
69
70 if version 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 {
71 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(PageErrorrust-analyzer cargo ogg_pager 0.7.2 error/PageError#::InvalidVersionrust-analyzer cargo ogg_pager 0.7.2 error/PageError#InvalidVersion#);
72 }
73
74 let header_type_flag = data.read_u8rust-analyzer cargo byteorder 1.5.0 io/ReadBytesExt#read_u8().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
75
76 let abgp = data.read_u64rust-analyzer cargo byteorder 1.5.0 io/ReadBytesExt#read_u64().::<LittleEndianrust-analyzer cargo byteorder 1.5.0 LittleEndian#>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
77 let stream_serial = data.read_u32rust-analyzer cargo byteorder 1.5.0 io/ReadBytesExt#read_u32().::<LittleEndianrust-analyzer cargo byteorder 1.5.0 LittleEndian#>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
78 let sequence_number = data.read_u32rust-analyzer cargo byteorder 1.5.0 io/ReadBytesExt#read_u32().::<LittleEndianrust-analyzer cargo byteorder 1.5.0 LittleEndian#>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
79 let checksum = data.read_u32rust-analyzer cargo byteorder 1.5.0 io/ReadBytesExt#read_u32().::<LittleEndianrust-analyzer cargo byteorder 1.5.0 LittleEndian#>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
80
81 let segments = data.read_u8rust-analyzer cargo byteorder 1.5.0 io/ReadBytesExt#read_u8().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
82
83 if segments rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]lt().1 {
84 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(PageErrorrust-analyzer cargo ogg_pager 0.7.2 error/PageError#::BadSegmentCountrust-analyzer cargo ogg_pager 0.7.2 error/PageError#BadSegmentCount#);
85 }
86
87 let mut segment_table = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0; segments as usize];
88 data.read_exactrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_exact().(&mut segment_table)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
89
90 let header = Selfrust-analyzer cargo ogg_pager 0.7.2 header/impl#[PageHeader] {
91 startrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#start.,
92 header_type_flagrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#header_type_flag.,
93 abgprust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#abgp.,
94 stream_serialrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#stream_serial.,
95 sequence_numberrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#sequence_number.,
96 segmentsrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#segments.: segment_table,
97 checksumrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#checksum.,
98 };
99
100 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(header)
101 }
102
103 /// Returns the size of the page content, excluding the header
104 pub fn content_sizerust-analyzer cargo ogg_pager 0.7.2 header/impl#[PageHeader]content_size().(&self) -> usize {
105 self.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().().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)).sumrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#sum().::<usize>()
106 }
107
108 /// Returns the page's header type flag
109 pub fn header_type_flagrust-analyzer cargo ogg_pager 0.7.2 header/impl#[PageHeader]header_type_flag().(&self) -> u8 {
110 self.header_type_flagrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#header_type_flag.
111 }
112
113 /// Returns the page's checksum
114 pub fn checksumrust-analyzer cargo ogg_pager 0.7.2 header/impl#[PageHeader]checksum().(&self) -> u32 {
115 self.checksumrust-analyzer cargo ogg_pager 0.7.2 header/PageHeader#checksum.
116 }
117 }