1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use serde::{Deserialize, Serialize};
/// Variants of option 52 in [MessageOptions](crate::v4::MessageOptions).
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
#[repr(u8)]
pub enum OverloadOptions {
/// The 128 bytes of `Message.file` are used to store additional options.
File,
/// The 64 bytes of `Message.sname` are used to store additional options.
Sname,
/// The 192 bytes of `Message.file` and `Message.sname` are used to store additional options.
Both,
}
impl From<&OverloadOptions> for u8 {
fn from(mtype: &OverloadOptions) -> Self {
match mtype {
OverloadOptions::File => 1,
OverloadOptions::Sname => 2,
OverloadOptions::Both => 3,
}
}
}
impl From<&[u8]> for OverloadOptions {
fn from(value: &[u8]) -> Self {
match value[0] {
1 => OverloadOptions::File,
2 => OverloadOptions::Sname,
3 => OverloadOptions::Both,
_ => OverloadOptions::Both,
}
}
}
impl OverloadOptions {
/// Used, when serializing, to add to the byte buffer.
#[inline]
pub fn extend_into(&self, bytes: &mut Vec<u8>, tag: u8) {
bytes.push(tag); // tag
bytes.push(1); // length
bytes.push(self.into()); // value
}
}