ogg_pager 0.3.2

This commit is contained in:
Serial 2022-03-05 12:06:38 -05:00
parent 0920cb2cda
commit 0426542f50
No known key found for this signature in database
GPG key ID: DA95198DC17C4568
2 changed files with 11 additions and 11 deletions

View file

@ -1,6 +1,6 @@
[package]
name = "ogg_pager"
version = "0.3.1"
version = "0.3.2"
authors = ["Serial <69764315+Serial-ATA@users.noreply.github.com>"]
edition = "2021"
license = "MIT OR Apache-2.0"

View file

@ -101,10 +101,10 @@ impl Page {
/// See [`segment_table`]
pub fn as_bytes(&self) -> Result<Vec<u8>> {
let mut segment_table = self.segment_table()?;
let mut bytes = Vec::new();
let mut bytes = Vec::with_capacity(27 + segment_table.len() + self.content.len());
bytes.extend(b"OggS");
bytes.push(0);
bytes.push(0); // Version
bytes.extend(self.header_type.to_le_bytes());
bytes.extend(self.abgp.to_le_bytes());
bytes.extend(self.serial.to_le_bytes());
@ -352,19 +352,19 @@ pub fn paginate(packet: &[u8], stream_serial: u32, abgp: u64, flags: u8) -> Vec<
///
/// `length` > [`MAX_CONTENT_SIZE`]
pub fn segment_table(length: usize) -> Result<Vec<u8>> {
match length {
0 => return Ok(vec![1, 0]),
l if l > MAX_CONTENT_SIZE => return Err(PageError::TooMuchData),
_ => {},
};
let mut last_len = (length % 255) as u8;
if last_len == 0 {
last_len = 255;
}
let mut needed = length / 255;
if needed != 255 {
needed += 1
}
if needed > 255 {
return Err(PageError::TooMuchData);
}
let mut needed = (length / 255) + 1;
needed = std::cmp::min(needed, 255);
let mut segments = Vec::with_capacity(needed);