Move stuff around

This commit is contained in:
Pedro de Oliveira 2022-11-13 03:25:46 +00:00
parent 55560f4f22
commit 48ee1872b8
1 changed files with 72 additions and 72 deletions

View File

@ -168,16 +168,22 @@ pub trait Block: std::fmt::Debug {
// Terminator // Terminator
pub struct Terminator {
block_type: BlockType,
}
impl Terminator {
pub fn new() -> Self {
Self { block_type: BlockType::Terminator }
}
}
impl Block for Terminator { impl Block for Terminator {
fn to_bytes(&self) -> Vec<u8> { fn to_bytes(&self) -> Vec<u8> {
vec![self.block_type as u8] vec![self.block_type as u8]
} }
} }
pub struct Terminator {
block_type: BlockType,
}
impl fmt::Debug for Terminator { impl fmt::Debug for Terminator {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Terminator") f.debug_struct("Terminator")
@ -185,13 +191,27 @@ impl fmt::Debug for Terminator {
} }
} }
impl Terminator { // SoundData
pub fn new() -> Self {
Self { block_type: BlockType::Terminator } pub struct SoundData {
} block_type: BlockType,
pub size: i32,
pub sample_rate: i32,
pub codec: Codec,
pub data: Vec<u8>,
} }
// SoundData impl SoundData {
pub fn new(size: i32, sample_rate: i32, codec: Codec, data: Vec<u8>) -> Self {
Self {
block_type: BlockType::SoundData,
size,
sample_rate,
codec,
data,
}
}
}
impl Block for SoundData { impl Block for SoundData {
fn to_bytes(&self) -> Vec<u8> { fn to_bytes(&self) -> Vec<u8> {
@ -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<u8>,
}
impl fmt::Debug for SoundData { impl fmt::Debug for SoundData {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("SoundData") 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<u8>) -> Self {
Self {
block_type: BlockType::SoundData,
size,
sample_rate,
codec,
data,
}
}
}
// SoundDataContinuation // SoundDataContinuation
impl Block for SoundDataContinuation {
fn to_bytes(&self) -> Vec<u8> {
let mut result: Vec<u8> = vec![self.block_type as u8];
result.extend_from_slice(&self.data);
result
}
}
pub struct SoundDataContinuation { pub struct SoundDataContinuation {
pub block_type: BlockType, pub block_type: BlockType,
pub size: i32, pub size: i32,
pub data: Vec<u8>, pub data: Vec<u8>,
} }
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 { impl SoundDataContinuation {
pub fn new(size: i32, data: Vec<u8>) -> Self { pub fn new(size: i32, data: Vec<u8>) -> Self {
Self { Self {
@ -277,15 +261,24 @@ impl SoundDataContinuation {
} }
} }
// Silence impl Block for SoundDataContinuation {
impl Block for Silence {
fn to_bytes(&self) -> Vec<u8> { fn to_bytes(&self) -> Vec<u8> {
panic!("Not implemented"); let mut result: Vec<u8> = vec![self.block_type as u8];
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)] #[derive(Debug)]
pub struct Silence { pub struct Silence {
pub block_type: BlockType, pub block_type: BlockType,
@ -294,15 +287,15 @@ pub struct Silence {
pub length: i16, pub length: i16,
} }
// Marker impl Block for Silence {
impl Block for Marker {
fn to_bytes(&self) -> Vec<u8> { fn to_bytes(&self) -> Vec<u8> {
panic!("Not implemented"); panic!("Not implemented");
vec![self.block_type as u8] vec![self.block_type as u8]
} }
} }
// Marker
#[derive(Debug)] #[derive(Debug)]
pub struct Marker { pub struct Marker {
block_type: BlockType, block_type: BlockType,
@ -310,8 +303,21 @@ pub struct Marker {
value: i16, value: i16,
} }
impl Block for Marker {
fn to_bytes(&self) -> Vec<u8> {
panic!("Not implemented");
vec![self.block_type as u8]
}
}
// Text // Text
pub struct Text {
pub block_type: BlockType,
pub size: i32,
pub data: Vec<u8>,
}
impl Block for Text { impl Block for Text {
fn to_bytes(&self) -> Vec<u8> { fn to_bytes(&self) -> Vec<u8> {
let size_bytes: [u8; 4] = self.size.to_le_bytes(); 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<u8>,
}
impl fmt::Debug for Text { impl fmt::Debug for Text {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Text") f.debug_struct("Text")
@ -345,13 +345,6 @@ impl fmt::Debug for Text {
// RepeatStart // RepeatStart
impl Block for RepeatStart {
fn to_bytes(&self) -> Vec<u8> {
panic!("Not implemented");
vec![self.block_type as u8]
}
}
#[derive(Debug)] #[derive(Debug)]
pub struct RepeatStart { pub struct RepeatStart {
block_type: BlockType, block_type: BlockType,
@ -359,17 +352,24 @@ pub struct RepeatStart {
repeat: i16, repeat: i16,
} }
impl Block for RepeatStart {
fn to_bytes(&self) -> Vec<u8> {
panic!("Not implemented");
vec![self.block_type as u8]
}
}
// RepeatEnd // RepeatEnd
#[derive(Debug)]
pub struct RepeatEnd {
block_type: BlockType,
size: i32,
}
impl Block for RepeatEnd { impl Block for RepeatEnd {
fn to_bytes(&self) -> Vec<u8> { fn to_bytes(&self) -> Vec<u8> {
panic!("Not implemented"); panic!("Not implemented");
vec![self.block_type as u8] vec![self.block_type as u8]
} }
} }
#[derive(Debug)]
pub struct RepeatEnd {
block_type: BlockType,
size: i32,
}