1use serde::{Deserialize, Serialize};
2
3use crate::commands::macros::{
4 impl_deserialize_from_empty_map_and_into_unit, impl_serialize_as_empty_map,
5};
6
7#[derive(Clone, Debug, Serialize, Eq, PartialEq)]
9pub struct ReadSetting<'a> {
10 pub name: &'a str,
12 #[serde(skip_serializing_if = "Option::is_none")]
14 pub max_size: Option<u32>,
15}
16
17#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
19pub struct ReadSettingResponse {
20 pub val: Vec<u8>,
24 pub max_size: Option<u32>,
28}
29
30#[derive(Clone, Debug, Serialize, Eq, PartialEq)]
32pub struct WriteSetting<'a, 'b> {
33 pub name: &'a str,
35 #[serde(with = "serde_bytes")]
37 pub val: &'b [u8],
38}
39
40#[derive(Clone, Default, Debug, Eq, PartialEq)]
42pub struct WriteSettingResponse;
43impl_deserialize_from_empty_map_and_into_unit!(WriteSettingResponse);
44
45#[derive(Clone, Debug, Serialize, Eq, PartialEq)]
47pub struct DeleteSetting<'a> {
48 pub name: &'a str,
50}
51
52#[derive(Clone, Default, Debug, Eq, PartialEq)]
54pub struct DeleteSettingResponse;
55impl_deserialize_from_empty_map_and_into_unit!(DeleteSettingResponse);
56
57#[derive(Clone, Debug, Eq, PartialEq)]
59pub struct CommitSettings;
60impl_serialize_as_empty_map!(CommitSettings);
61
62#[derive(Clone, Default, Debug, Eq, PartialEq)]
64pub struct CommitSettingsResponse;
65impl_deserialize_from_empty_map_and_into_unit!(CommitSettingsResponse);
66
67#[derive(Clone, Debug, Eq, PartialEq)]
69pub struct LoadSettings;
70impl_serialize_as_empty_map!(LoadSettings);
71
72#[derive(Clone, Default, Debug, Eq, PartialEq)]
74pub struct LoadSettingsResponse;
75impl_deserialize_from_empty_map_and_into_unit!(LoadSettingsResponse);
76
77#[derive(Clone, Debug, Serialize, Eq, PartialEq)]
79pub struct SaveSettings<'a> {
80 #[serde(skip_serializing_if = "Option::is_none")]
82 pub name: Option<&'a str>,
83}
84
85#[derive(Clone, Default, Debug, Eq, PartialEq)]
87pub struct SaveSettingsResponse;
88impl_deserialize_from_empty_map_and_into_unit!(SaveSettingsResponse);
89
90#[cfg(test)]
91mod tests {
92 use super::super::macros::command_encode_decode_test;
93 use super::*;
94 use ciborium::cbor;
95
96 command_encode_decode_test! {
97 read_setting,
98 (0, 3, 0),
99 ReadSetting {
100 name: "foo/bar",
101 max_size: None
102 },
103 cbor!({
104 "name" => "foo/bar",
105 }),
106 cbor!({
107 "val" => ciborium::Value::Bytes(vec![1,2,3,4,5]),
108 }),
109 ReadSettingResponse{
110 val: vec![1,2,3,4,5],
111 max_size: None,
112 },
113 }
114 command_encode_decode_test! {
115 read_setting_with_max_size,
116 (0, 3, 0),
117 ReadSetting {
118 name: "foo/bar",
119 max_size: Some(42),
120 },
121 cbor!({
122 "name" => "foo/bar",
123 "max_size" => 42,
124 }),
125 cbor!({
126 "val" => ciborium::Value::Bytes(vec![1,2,3,4,5]),
127 "max_size" => 36,
128 }),
129 ReadSettingResponse{
130 val: vec![1,2,3,4,5],
131 max_size: Some(36),
132 },
133 }
134
135 command_encode_decode_test! {
136 write_setting,
137 (2, 3, 0),
138 WriteSetting {
139 name: "foo",
140 val: &[1,2,3,4,5],
141 },
142 cbor!({
143 "name" => "foo",
144 "val" => ciborium::Value::Bytes(vec![1,2,3,4,5]),
145 }),
146 cbor!({}),
147 WriteSettingResponse,
148 }
149
150 command_encode_decode_test! {
151 delete_setting,
152 (2, 3, 1),
153 DeleteSetting {
154 name: "bar",
155 },
156 cbor!({
157 "name" => "bar",
158 }),
159 cbor!({}),
160 DeleteSettingResponse,
161 }
162
163 command_encode_decode_test! {
164 commit_settings,
165 (2, 3, 2),
166 CommitSettings,
167 cbor!({}),
168 cbor!({}),
169 CommitSettingsResponse,
170 }
171
172 command_encode_decode_test! {
173 load_settings,
174 (0, 3, 3),
175 LoadSettings,
176 cbor!({}),
177 cbor!({}),
178 LoadSettingsResponse,
179 }
180
181 command_encode_decode_test! {
182 save_settings,
183 (2, 3, 3),
184 SaveSettings{
185 name: None,
186 },
187 cbor!({}),
188 cbor!({}),
189 SaveSettingsResponse,
190 }
191
192 command_encode_decode_test! {
193 save_settings_with_name,
194 (2, 3, 3),
195 SaveSettings{
196 name: Some("foo"),
197 },
198 cbor!({
199 "name" => "foo",
200 }),
201 cbor!({}),
202 SaveSettingsResponse,
203 }
204}