pub struct LawEncoder;Implementations§
Source§impl LawEncoder
impl LawEncoder
Sourcepub fn encode(
&self,
input_format: InputFormat,
input_data: &[u8],
output_format: OutputFormat,
output_buffer: &mut [u8],
) -> Result<usize, EncodeError>
pub fn encode( &self, input_format: InputFormat, input_data: &[u8], output_format: OutputFormat, output_buffer: &mut [u8], ) -> Result<usize, EncodeError>
Encodes audio data from one format to another, writing the encoded data into the provided output buffer.
§Parameters:
input_format: AnInputFormatenum specifying the format of the input data.input_data: A slice ofu8representing the audio data to be encoded. This data should conform to the format specified byinput_format.output_format: AnOutputFormatenum specifying the desired format of the output data.output_buffer: A mutable slice ofu8where the encoded data will be stored. The buffer must be large enough to hold the encoded data; otherwise, an error is returned.
§Returns:
- A
Result<usize, EncodeError>indicating the outcome of the encoding operation. On success, it returnsOk(num_bytes), wherenum_bytesis the number of bytes written tooutput_buffer. On failure, it returnsErr(EncodeError), indicating the nature of the error.
§Errors:
EncodeError::OutputBufferTooSmall: This error indicates that the providedoutput_bufferis not large enough to contain the encoded data. The size of the output buffer must be at least half the size of the input data, reflecting the specific encoding algorithm’s requirements.
§Example Usage:
use law_encoder::{InputFormat, OutputFormat, LawEncoder};
let input_data = vec![/* input data bytes */];
let mut output_buffer = vec![0u8; /* appropriate size */ 12];
let encoder = LawEncoder;
match encoder.encode(InputFormat::BigEndian, &input_data, OutputFormat::Alaw, &mut output_buffer) {
Ok(num_bytes) => println!("Encoded {} bytes successfully.", num_bytes),
Err(e) => println!("Encoding failed: {:?}", e),
}§Notes:
- The exact size requirement for
output_buffermay vary depending on the input and output formats. It is generally recommended to allocate the output buffer with at least half the size of the input data to accommodate the encoded data.
Auto Trait Implementations§
impl Freeze for LawEncoder
impl RefUnwindSafe for LawEncoder
impl Send for LawEncoder
impl Sync for LawEncoder
impl Unpin for LawEncoder
impl UnwindSafe for LawEncoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more