toe_beans/v4/message/options/opaque.rs
1use serde::{Deserialize, Serialize};
2
3/// An option that contains ambiguous bytes. For example, it might be an id, with no special meaning, sent by the client.
4#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
5pub struct OpaqueOption(Vec<u8>);
6
7impl OpaqueOption {
8 /// Used, when serializing, to add to the byte buffer.
9 #[inline]
10 pub fn extend_into(&self, bytes: &mut Vec<u8>, tag: u8) {
11 bytes.push(tag); // tag
12 bytes.push(self.0.len() as u8); // length
13 bytes.extend_from_slice(&self.0); // value
14 }
15}
16
17impl From<&[u8]> for OpaqueOption {
18 fn from(value: &[u8]) -> Self {
19 Self(value.into())
20 }
21}