Struct dle_encoder::DleEncoder[][src]

pub struct DleEncoder {
    pub escape_stx_etx: bool,
    pub escape_cr: bool,
    pub add_stx_etx: bool,
}
Expand description

This struct is used to create a DleEncoder instance. It can also be used to configure the encoder

Fields

escape_stx_etx: bool

Configure whether the encoder uses the escaped or non-escaped mode

escape_cr: bool

It is possible to escape CR characters as well in the escaped mode

add_stx_etx: bool

Configure 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 encode
  • dest_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 encode
  • dest_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 encode
  • dest_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 decode
  • dest_stream - Decoded stream will be written here
  • read_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 decode
  • dest_stream - Decoded stream will be written here
  • read_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 decode
  • dest_stream - Decoded stream will be written here
  • read_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 a copy of the value. Read more

Performs copy-assignment from source. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.