toe_beans/v4/message/options/
overload_options.rs

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