Struct dle_encoder::DleEncoder [−][src]
Expand description
This struct is used to create a DleEncoder instance. It can also be used to configure the encoder
Fields
escape_stx_etx: boolConfigure whether the encoder uses the escaped or non-escaped mode
escape_cr: boolIt is possible to escape CR characters as well in the escaped mode
add_stx_etx: boolConfigure the encoder to not add STX and ETX characters at the start and end when encoding
Implementations
This method encodes a given byte stream with ASCII based DLE encoding. It returns the number of encoded bytes or a DLE error code.
Arguments
source_stream- The stream to encodedest_stream- Encoded stream will be written here
Examples
use dle_encoder::DleEncoder;
let dle_encoder = DleEncoder::default();
let mut encoding_buffer: [u8; 16] = [0; 16];
let example_array: [u8; 3] = [0, 0x02, 0x10];
let encode_result = dle_encoder.encode(
&example_array, &mut encoding_buffer
);
assert!(encode_result.is_ok());
let encoded_len = encode_result.unwrap();
assert_eq!(encoded_len, 7);
println!("Source buffer: {:?}", example_array);
println!("Encoded stream: {:?}", &encoding_buffer[ .. encoded_len])This method encodes a given byte stream with ASCII based DLE encoding. It explicitely does so in the escaped mode, which is the default mode.
Arguments
source_stream- The stream to encodedest_stream- Encoded stream will be written here
This method encodes a given byte stream with ASCII based DLE encoding. It explicitely does so in the non-escaped mode.
Arguments
source_stream- The stream to encodedest_stream- Encoded stream will be written here
Example
use dle_encoder::DleEncoder;
let dle_encoder = DleEncoder::default();
let mut encoding_buffer: [u8; 16] = [0; 16];
let example_array: [u8; 3] = [0, 0x02, 0x10];
let encode_result = dle_encoder.encode_non_escaped(
&example_array, &mut encoding_buffer
);
assert!(encode_result.is_ok());
let encoded_len = encode_result.unwrap();
assert_eq!(encoded_len, 8);
println!("Source buffer: {:?}", example_array);
println!("Encoded stream: {:?}", &encoding_buffer[ .. encoded_len])This method decodes a given byte stream which was encoded with a ASCII DLE encoder. It explicitely does so in the escaped mode, which is the default mode. It returns the length of the decoded buffer or an error code if there is a decoder failure or the destination stream is too short.
Arguments
source_stream- The stream to decodedest_stream- Decoded stream will be written hereread_len- The number of read bytes in the source stream will be assigned to this variable
Examples
use dle_encoder::DleEncoder;
let dle_encoder = DleEncoder::default();
let mut decoding_buffer: [u8; 16] = [0; 16];
let encoded_array: [u8; 4] = [0x02, 0x10, 0x02 + 0x40, 0x03];
let mut read_len = 0;
let decode_result = dle_encoder.decode(
&encoded_array, &mut decoding_buffer, &mut read_len
);
assert!(decode_result.is_ok());
let decoded_len = decode_result.unwrap();
assert_eq!(decoded_len, 1);
println!("Source buffer: {:?}", encoded_array);
println!("Encoded stream: {:?}", &decoding_buffer[ .. decoded_len])This method decodes a given byte stream which was encoded with a ASCII DLE encoder. It explicitely does so in the escaped mode, which is the default mode. It returns the length of the decoded buffer or an error code if there is a decoder failure or the destination stream is too short.
Arguments
source_stream- The stream to decodedest_stream- Decoded stream will be written hereread_len- The number of read bytes in the source stream will be assigned to this variable
This method decodes a given byte stream which was encoded with a ASCII DLE encoder. It explicitely does so in the non-escaped mode. It returns the length of the decoded buffer or an error code if there is a decoder failure or the destination stream is too short.
Arguments
source_stream- The stream to decodedest_stream- Decoded stream will be written hereread_len- The number of read bytes in the source stream will be assigned to this variable
Examples
use dle_encoder::DleEncoder;
let dle_encoder = DleEncoder::default();
let mut decoding_buffer: [u8; 16] = [0; 16];
let encoded_array: [u8; 6] = [0x10, 0x02, 0x02, 0x03, 0x10, 0x03];
let mut read_len = 0;
let decode_result = dle_encoder.decode_non_escaped(
&encoded_array, &mut decoding_buffer, &mut read_len
);
assert!(decode_result.is_ok());
let decoded_len = decode_result.unwrap();
assert_eq!(decoded_len, 2);
println!("Source buffer: {:?}", encoded_array);
println!("Encoded stream: {:?}", &decoding_buffer[ .. decoded_len])Trait Implementations
Returns the “default value” for a type. Read more
Auto Trait Implementations
impl RefUnwindSafe for DleEncoder
impl Send for DleEncoder
impl Sync for DleEncoder
impl Unpin for DleEncoder
impl UnwindSafe for DleEncoder
Blanket Implementations
Mutably borrows from an owned value. Read more