pile-audio refactor
This commit is contained in:
53
crates/pile-audio/src/blocks/cuesheet.rs
Normal file
53
crates/pile-audio/src/blocks/cuesheet.rs
Normal file
@@ -0,0 +1,53 @@
|
||||
use std::fmt::Debug;
|
||||
|
||||
use super::{FlacMetablockDecode, FlacMetablockEncode, FlacMetablockHeader, FlacMetablockType};
|
||||
use crate::{FlacDecodeError, FlacEncodeError};
|
||||
|
||||
/// A cuesheet meta in a flac file
|
||||
pub struct FlacCuesheetBlock {
|
||||
/// The seek table
|
||||
pub data: Vec<u8>,
|
||||
}
|
||||
|
||||
impl Debug for FlacCuesheetBlock {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("FlacAudioFrame")
|
||||
.field("data_len", &self.data.len())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl FlacMetablockDecode for FlacCuesheetBlock {
|
||||
fn decode(data: &[u8]) -> Result<Self, FlacDecodeError> {
|
||||
Ok(Self { data: data.into() })
|
||||
}
|
||||
}
|
||||
|
||||
impl FlacMetablockEncode for FlacCuesheetBlock {
|
||||
#[expect(clippy::expect_used)]
|
||||
fn get_len(&self) -> u32 {
|
||||
self.data
|
||||
.len()
|
||||
.try_into()
|
||||
.expect("cuesheet size does not fit into u32")
|
||||
}
|
||||
|
||||
fn encode(
|
||||
&self,
|
||||
is_last: bool,
|
||||
with_header: bool,
|
||||
target: &mut impl std::io::Write,
|
||||
) -> Result<(), FlacEncodeError> {
|
||||
if with_header {
|
||||
let header = FlacMetablockHeader {
|
||||
block_type: FlacMetablockType::Cuesheet,
|
||||
length: self.get_len(),
|
||||
is_last,
|
||||
};
|
||||
header.encode(target)?;
|
||||
}
|
||||
|
||||
target.write_all(&self.data)?;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user