Files
pile/crates/pile-audio/src/blocks/cuesheet.rs
rm-dr 4b41467cc2
Some checks failed
CI / Typos (push) Successful in 17s
CI / Clippy (push) Has been cancelled
CI / Build and test (push) Has been cancelled
pile-audio refactor
2026-02-21 19:14:52 -08:00

54 lines
1.2 KiB
Rust

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(());
}
}