hdm_am/operations/
config.rs1use crate::wire::OperationCode;
2use serde::{Deserialize, Serialize, Serializer};
3
4use super::{EmptyResponse, Operation};
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8#[repr(u8)]
9pub enum TextAlign {
10 Left = 1,
12 Centered = 2,
14 Right = 3,
16}
17
18impl Serialize for TextAlign {
19 fn serialize<S: Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
20 ser.serialize_u8(*self as u8)
21 }
22}
23
24impl<'de> Deserialize<'de> for TextAlign {
25 fn deserialize<D: serde::Deserializer<'de>>(de: D) -> Result<Self, D::Error> {
26 let code = u8::deserialize(de)?;
27 Ok(match code {
28 1 => Self::Left,
29 2 => Self::Centered,
30 3 => Self::Right,
31 other => {
32 return Err(serde::de::Error::custom(format!(
33 "unknown text alignment {other} (expected 1, 2, or 3)"
34 )));
35 }
36 })
37 }
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
42#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
43pub struct TextLine {
44 #[cfg_attr(feature = "schema", schemars(with = "u8"))]
46 pub align: TextAlign,
47 pub bold: bool,
51 pub fsize: u8,
53 pub text: String,
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
59#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
60pub struct SetupHeaderFooterRequest {
61 #[serde(default)]
63 pub headers: Vec<TextLine>,
64 #[serde(default)]
66 pub footers: Vec<TextLine>,
67}
68
69impl Operation for SetupHeaderFooterRequest {
70 const CODE: OperationCode = OperationCode::SetupHeaderFooter;
71 type Response = EmptyResponse;
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
76#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
77pub struct SetupHeaderLogoRequest {
78 #[serde(rename = "headerLogo")]
83 pub header_logo: String,
84}
85
86impl Operation for SetupHeaderLogoRequest {
87 const CODE: OperationCode = OperationCode::SetupHeaderLogo;
88 type Response = EmptyResponse;
89}