pub struct Message { /* private fields */ }
Expand description
Container of binary data, which also includes a header. This header is a special collection of data which isn’t used in things like encoding, as it is meant to be a lightweight message with information about the contained data.
Implementations§
Source§impl Message
impl Message
Sourcepub fn new() -> Message
pub fn new() -> Message
Create an empty message.
Examples found in repository?
More examples
3fn main() {
4 let modulation = MFSK::new(16);
5 let channel = Sound::new(&modulation);
6
7 // let time = 20;
8
9 // channel.play(500, time);
10 // channel.play(1000, time);
11 // channel.play(500, time);
12 // channel.play(1000, time);
13 // channel.play(500, time);
14 // channel.play(1000, time);
15 // channel.play(500, time);
16 // channel.play(1000, time);
17
18 let msg = Message::new().data("Hello world!");
19 channel.send(&msg, 100);
20}
3fn main() {
4 let msg = Message::new().data(
5 "Peter Piper picked a peck of pickled peppers
6A peck of pickled peppers Peter Piper picked
7If Peter Piper picked a peck of pickled peppers
8Where's the peck of pickled peppers Peter Piper picked?",
9 );
10
11 let time = 100;
12
13 let fsk256 = MFSK::new(256).base_frequency(100).delta_frequency(30);
14 let channel256 = Sound::new(&fsk256);
15 channel256.export_wav(&msg, "examples/wav_export/audio/256fsk.wav", time);
16
17 let fsk16 = MFSK::new(16).base_frequency(100).delta_frequency(100);
18 let channel16 = Sound::new(&fsk16);
19 channel16.export_wav(&msg, "examples/wav_export/audio/16fsk.wav", time);
20
21 let qam256 = MQAM::new(256, 1000);
22 let channel256 = Sound::new(&qam256);
23 channel256.export_wav(&msg, "examples/wav_export/audio/256qam.wav", time);
24
25 let qam16 = MQAM::new(16, 1000);
26 let channel16 = Sound::new(&qam16);
27 channel16.export_wav(&msg, "examples/wav_export/audio/16qam.wav", time);
28}
Sourcepub fn from_string(data: &str, header: &str) -> Message
pub fn from_string(data: &str, header: &str) -> Message
Create a message from some given data and a header as strings. These are transformed into binary and then stored.
Examples found in repository?
3fn main() {
4 let small_msg = Message::from_string("Hello world!", "HEADER");
5 let encoder = HuffmanCoding::from_message(&small_msg);
6 let small_enc = encoder.encode(&small_msg);
7 let small_dec = encoder.decode(&small_enc, 0);
8 println!("{}", encoder);
9 println!("{} -> DECODED : {}", small_msg, small_dec);
10 println!(
11 "\n=== SIZES ===\n{} b -> ENCODED : {} b -> DECODED : {} b",
12 small_msg.bit_size(),
13 small_enc.bit_size(),
14 small_dec.bit_size()
15 );
16
17 println!("\n\n");
18
19 let msg1 = Message::from_string(
20 "Peter Piper picked a peck of pickled peppers
21 A peck of pickled peppers Peter Piper picked
22 If Peter Piper picked a peck of pickled peppers
23 Where's the peck of pickled peppers Peter Piper picked?",
24 "THIS IS A TEST HEADER",
25 );
26 let encoder1 = HuffmanCoding::from_message(&msg1);
27 let msg1_enc = encoder1.encode(&msg1);
28 let msg1_dec = encoder1.decode(&msg1_enc, 0);
29 println!("{}", encoder);
30 println!("{} -> DECODED : {}", msg1, msg1_dec);
31 println!(
32 "\n=== SIZES ===\n{} b -> ENCODED : {} b -> DECODED : {} b",
33 msg1.bit_size(),
34 msg1_enc.bit_size(),
35 msg1_dec.bit_size()
36 );
37}
Sourcepub fn from_binary(data: &str, header: &str) -> Message
pub fn from_binary(data: &str, header: &str) -> Message
Create a message from some given data and header binaries.
Sourcepub fn data(self, data: &str) -> Message
pub fn data(self, data: &str) -> Message
Set the data of the message.
Examples found in repository?
More examples
3fn main() {
4 let modulation = MFSK::new(16);
5 let channel = Sound::new(&modulation);
6
7 // let time = 20;
8
9 // channel.play(500, time);
10 // channel.play(1000, time);
11 // channel.play(500, time);
12 // channel.play(1000, time);
13 // channel.play(500, time);
14 // channel.play(1000, time);
15 // channel.play(500, time);
16 // channel.play(1000, time);
17
18 let msg = Message::new().data("Hello world!");
19 channel.send(&msg, 100);
20}
3fn main() {
4 let msg = Message::new().data(
5 "Peter Piper picked a peck of pickled peppers
6A peck of pickled peppers Peter Piper picked
7If Peter Piper picked a peck of pickled peppers
8Where's the peck of pickled peppers Peter Piper picked?",
9 );
10
11 let time = 100;
12
13 let fsk256 = MFSK::new(256).base_frequency(100).delta_frequency(30);
14 let channel256 = Sound::new(&fsk256);
15 channel256.export_wav(&msg, "examples/wav_export/audio/256fsk.wav", time);
16
17 let fsk16 = MFSK::new(16).base_frequency(100).delta_frequency(100);
18 let channel16 = Sound::new(&fsk16);
19 channel16.export_wav(&msg, "examples/wav_export/audio/16fsk.wav", time);
20
21 let qam256 = MQAM::new(256, 1000);
22 let channel256 = Sound::new(&qam256);
23 channel256.export_wav(&msg, "examples/wav_export/audio/256qam.wav", time);
24
25 let qam16 = MQAM::new(16, 1000);
26 let channel16 = Sound::new(&qam16);
27 channel16.export_wav(&msg, "examples/wav_export/audio/16qam.wav", time);
28}
Sourcepub fn data_from_binary(self, data: &str) -> Message
pub fn data_from_binary(self, data: &str) -> Message
Set the data of the message as a binary.
Sourcepub fn header_from_binary(self, header: &str) -> Message
pub fn header_from_binary(self, header: &str) -> Message
Set the header of the message as a binary.
Sourcepub fn get_header(&self) -> &str
pub fn get_header(&self) -> &str
Get the header of the message as binary.
Sourcepub fn bit_size(&self) -> u32
pub fn bit_size(&self) -> u32
Get the total amount of bits in the message.
Examples found in repository?
More examples
3fn main() {
4 let small_msg = Message::from_string("Hello world!", "HEADER");
5 let encoder = HuffmanCoding::from_message(&small_msg);
6 let small_enc = encoder.encode(&small_msg);
7 let small_dec = encoder.decode(&small_enc, 0);
8 println!("{}", encoder);
9 println!("{} -> DECODED : {}", small_msg, small_dec);
10 println!(
11 "\n=== SIZES ===\n{} b -> ENCODED : {} b -> DECODED : {} b",
12 small_msg.bit_size(),
13 small_enc.bit_size(),
14 small_dec.bit_size()
15 );
16
17 println!("\n\n");
18
19 let msg1 = Message::from_string(
20 "Peter Piper picked a peck of pickled peppers
21 A peck of pickled peppers Peter Piper picked
22 If Peter Piper picked a peck of pickled peppers
23 Where's the peck of pickled peppers Peter Piper picked?",
24 "THIS IS A TEST HEADER",
25 );
26 let encoder1 = HuffmanCoding::from_message(&msg1);
27 let msg1_enc = encoder1.encode(&msg1);
28 let msg1_dec = encoder1.decode(&msg1_enc, 0);
29 println!("{}", encoder);
30 println!("{} -> DECODED : {}", msg1, msg1_dec);
31 println!(
32 "\n=== SIZES ===\n{} b -> ENCODED : {} b -> DECODED : {} b",
33 msg1.bit_size(),
34 msg1_enc.bit_size(),
35 msg1_dec.bit_size()
36 );
37}
Sourcepub fn header_size(&self) -> u32
pub fn header_size(&self) -> u32
Get the amount of bits in the header part of the message.
Sourcepub fn group_string(message: &String, num: u32) -> Vec<String>
pub fn group_string(message: &String, num: u32) -> Vec<String>
Group a string in packets of a given size.
Sourcepub fn group_data(&self, num: u32) -> Vec<String>
pub fn group_data(&self, num: u32) -> Vec<String>
Group the data in packets of the given size.
Sourcepub fn group_header(&self, num: u32) -> Vec<String>
pub fn group_header(&self, num: u32) -> Vec<String>
Group the header in packets of the given size.
Sourcepub fn as_u8_array(&self) -> Vec<u8> ⓘ
pub fn as_u8_array(&self) -> Vec<u8> ⓘ
Get the message as an array of 8-bit integers.
Sourcepub fn data_as_u8_array(&self) -> Vec<u8> ⓘ
pub fn data_as_u8_array(&self) -> Vec<u8> ⓘ
Get the data as an array of 8-bit integers.
Sourcepub fn header_as_u8_array(&self) -> Vec<u8> ⓘ
pub fn header_as_u8_array(&self) -> Vec<u8> ⓘ
Get the header as an array of 8-bit integers.
Sourcepub fn data_as_binary(&self) -> &str
pub fn data_as_binary(&self) -> &str
Get the data as a binary string.
Sourcepub fn header_as_binary(&self) -> &str
pub fn header_as_binary(&self) -> &str
Get the header as a binary string.
Sourcepub fn data_as_string(&self) -> String
pub fn data_as_string(&self) -> String
Get the data as a decoded string.
Sourcepub fn header_as_string(&self) -> String
pub fn header_as_string(&self) -> String
Get the header as a decoded string.