Skip to content

Commit fc3b98a

Browse files
committed
Add documentation
1 parent ecd6388 commit fc3b98a

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Add `law-encoder` to your `Cargo.toml`:
1616

1717
```toml
1818
[dependencies]
19-
law_encoding = "0.1.0"
19+
law_encoder = "0.1.0"
2020
```
2121

2222
### Usage

src/lib.rs

+27
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,33 @@ pub mod formats;
1010
pub struct LawEncoder;
1111

1212
impl LawEncoder {
13+
///Encodes audio data from one format to another, writing the encoded data into the provided output buffer.
14+
///
15+
///#### Parameters:
16+
///
17+
///- `input_format`: An `InputFormat` enum specifying the format of the input data.
18+
///- `input_data`: A slice of `u8` representing the audio data to be encoded. This data should conform to the format specified by `input_format`.
19+
///- `output_format`: An `OutputFormat` enum specifying the desired format of the output data.
20+
///- `output_buffer`: A mutable slice of `u8` where the encoded data will be stored. The buffer must be large enough to hold the encoded data; otherwise, an error is returned.
21+
///#### Returns:
22+
///- A `Result<usize, EncodeError>` indicating the outcome of the encoding operation. On success, it returns `Ok(num_bytes)`, where `num_bytes` is the number of bytes written to `output_buffer`. On failure, it returns `Err(EncodeError)`, indicating the nature of the error.
23+
///#### Errors:
24+
///- `EncodeError::OutputBufferTooSmall`: This error indicates that the provided `output_buffer` is 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.
25+
///#### Example Usage:
26+
///```rust
27+
///use law_encoder::{InputFormat, OutputFormat, LawEncoder};
28+
///let input_data = vec![/* input data bytes */];
29+
///let mut output_buffer = vec![0u8; /* appropriate size */ 12];
30+
///let encoder = LawEncoder;
31+
///match encoder.encode(InputFormat::BigEndian, &input_data, OutputFormat::Alaw, &mut output_buffer) {
32+
/// Ok(num_bytes) => println!("Encoded {} bytes successfully.", num_bytes),
33+
/// Err(e) => println!("Encoding failed: {:?}", e),
34+
///}
35+
///```
36+
///
37+
///#### Notes:
38+
///
39+
///- The exact size requirement for `output_buffer` may 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.
1340
pub fn encode(
1441
&self,
1542
input_format: InputFormat,

0 commit comments

Comments
 (0)