diff --git a/src/voc.rs b/src/voc.rs index 6390d0f..64ab1ee 100644 --- a/src/voc.rs +++ b/src/voc.rs @@ -168,16 +168,22 @@ pub trait Block: std::fmt::Debug { // Terminator +pub struct Terminator { + block_type: BlockType, +} + +impl Terminator { + pub fn new() -> Self { + Self { block_type: BlockType::Terminator } + } +} + impl Block for Terminator { fn to_bytes(&self) -> Vec { vec![self.block_type as u8] } } -pub struct Terminator { - block_type: BlockType, -} - impl fmt::Debug for Terminator { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Terminator") @@ -185,13 +191,27 @@ impl fmt::Debug for Terminator { } } -impl Terminator { - pub fn new() -> Self { - Self { block_type: BlockType::Terminator } - } +// SoundData + +pub struct SoundData { + block_type: BlockType, + pub size: i32, + pub sample_rate: i32, + pub codec: Codec, + pub data: Vec, } -// SoundData +impl SoundData { + pub fn new(size: i32, sample_rate: i32, codec: Codec, data: Vec) -> Self { + Self { + block_type: BlockType::SoundData, + size, + sample_rate, + codec, + data, + } + } +} impl Block for SoundData { fn to_bytes(&self) -> Vec { @@ -213,14 +233,6 @@ impl Block for SoundData { } } -pub struct SoundData { - block_type: BlockType, - pub size: i32, - pub sample_rate: i32, - pub codec: Codec, - pub data: Vec, -} - impl fmt::Debug for SoundData { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("SoundData") @@ -231,42 +243,14 @@ impl fmt::Debug for SoundData { } } -impl SoundData { - pub fn new(size: i32, sample_rate: i32, codec: Codec, data: Vec) -> Self { - Self { - block_type: BlockType::SoundData, - size, - sample_rate, - codec, - data, - } - } -} - // SoundDataContinuation -impl Block for SoundDataContinuation { - fn to_bytes(&self) -> Vec { - let mut result: Vec = vec![self.block_type as u8]; - result.extend_from_slice(&self.data); - result - } -} - pub struct SoundDataContinuation { pub block_type: BlockType, pub size: i32, pub data: Vec, } -impl fmt::Debug for SoundDataContinuation { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("SoundDataContinuation") - .field("size", &self.size) - .finish() - } -} - impl SoundDataContinuation { pub fn new(size: i32, data: Vec) -> Self { Self { @@ -277,15 +261,24 @@ impl SoundDataContinuation { } } -// Silence - -impl Block for Silence { +impl Block for SoundDataContinuation { fn to_bytes(&self) -> Vec { - panic!("Not implemented"); - vec![self.block_type as u8] + let mut result: Vec = vec![self.block_type as u8]; + result.extend_from_slice(&self.data); + result } } +impl fmt::Debug for SoundDataContinuation { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("SoundDataContinuation") + .field("size", &self.size) + .finish() + } +} + +// Silence + #[derive(Debug)] pub struct Silence { pub block_type: BlockType, @@ -294,15 +287,15 @@ pub struct Silence { pub length: i16, } -// Marker - -impl Block for Marker { +impl Block for Silence { fn to_bytes(&self) -> Vec { panic!("Not implemented"); vec![self.block_type as u8] } } +// Marker + #[derive(Debug)] pub struct Marker { block_type: BlockType, @@ -310,8 +303,21 @@ pub struct Marker { value: i16, } +impl Block for Marker { + fn to_bytes(&self) -> Vec { + panic!("Not implemented"); + vec![self.block_type as u8] + } +} + // Text +pub struct Text { + pub block_type: BlockType, + pub size: i32, + pub data: Vec, +} + impl Block for Text { fn to_bytes(&self) -> Vec { let size_bytes: [u8; 4] = self.size.to_le_bytes(); @@ -329,12 +335,6 @@ impl Block for Text { } } -pub struct Text { - pub block_type: BlockType, - pub size: i32, - pub data: Vec, -} - impl fmt::Debug for Text { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Text") @@ -345,13 +345,6 @@ impl fmt::Debug for Text { // RepeatStart -impl Block for RepeatStart { - fn to_bytes(&self) -> Vec { - panic!("Not implemented"); - vec![self.block_type as u8] - } -} - #[derive(Debug)] pub struct RepeatStart { block_type: BlockType, @@ -359,17 +352,24 @@ pub struct RepeatStart { repeat: i16, } +impl Block for RepeatStart { + fn to_bytes(&self) -> Vec { + panic!("Not implemented"); + vec![self.block_type as u8] + } +} + // RepeatEnd +#[derive(Debug)] +pub struct RepeatEnd { + block_type: BlockType, + size: i32, +} + impl Block for RepeatEnd { fn to_bytes(&self) -> Vec { panic!("Not implemented"); vec![self.block_type as u8] } } - -#[derive(Debug)] -pub struct RepeatEnd { - block_type: BlockType, - size: i32, -}