• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 // @generated rust packets from uci_packets.pdl
15 
16 #![allow(clippy::all)]
17 #![allow(non_upper_case_globals)]
18 #![allow(non_camel_case_types)]
19 #![allow(non_snake_case)]
20 #![allow(unused)]
21 #![allow(missing_docs)]
22 
23 use bytes::{BufMut, Bytes, BytesMut};
24 use num_derive::{FromPrimitive, ToPrimitive};
25 use num_traits::{FromPrimitive, ToPrimitive};
26 use std::convert::{TryFrom, TryInto};
27 use std::fmt;
28 use std::sync::Arc;
29 use thiserror::Error;
30 
31 type Result<T> = std::result::Result<T, Error>;
32 
33 #[derive(Debug, Error)]
34 pub enum Error {
35     #[error("Packet parsing failed")]
36     InvalidPacketError,
37     #[error("{field} was {value:x}, which is not known")]
38     ConstraintOutOfBounds { field: String, value: u64 },
39     #[error("when parsing {obj}.{field} needed length of {wanted} but got {got}")]
40     InvalidLengthError {
41         obj: String,
42         field: String,
43         wanted: usize,
44         got: usize,
45     },
46     #[error("Due to size restrictions a struct could not be parsed.")]
47     ImpossibleStructError,
48     #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")]
49     InvalidEnumValueError {
50         obj: String,
51         field: String,
52         value: u64,
53         type_: String,
54     },
55 }
56 
57 #[derive(Debug, Error)]
58 #[error("{0}")]
59 pub struct TryFromError(&'static str);
60 
61 pub trait Packet {
to_bytes(self) -> Bytes62     fn to_bytes(self) -> Bytes;
to_vec(self) -> Vec<u8>63     fn to_vec(self) -> Vec<u8>;
64 }
65 
66 #[derive(FromPrimitive, ToPrimitive, Debug, Hash, Eq, PartialEq, Clone, Copy)]
67 #[repr(u64)]
68 pub enum PacketBoundaryFlag {
69     Complete = 0x0,
70     NotComplete = 0x1,
71 }
72 impl fmt::Display for PacketBoundaryFlag {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result73     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
74         match self {
75             PacketBoundaryFlag::Complete => write!(f, "{:#04X} (COMPLETE)", self.to_u8().unwrap()),
76             PacketBoundaryFlag::NotComplete => {
77                 write!(f, "{:#04X} (NOT_COMPLETE)", self.to_u8().unwrap())
78             }
79         }
80     }
81 }
82 
83 #[derive(FromPrimitive, ToPrimitive, Debug, Hash, Eq, PartialEq, Clone, Copy)]
84 #[repr(u64)]
85 pub enum GroupId {
86     Core = 0x0,
87     SessionConfig = 0x1,
88     RangingSessionControl = 0x2,
89     DataControl = 0x3,
90     VendorReservedA = 0xa,
91     VendorReservedB = 0xb,
92     VendorAndroid = 0xc,
93     Test = 0xd,
94     VendorReservedE = 0xe,
95     VendorReservedF = 0xf,
96 }
97 impl fmt::Display for GroupId {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result98     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
99         match self {
100             GroupId::Core => write!(f, "{:#04X} (CORE)", self.to_u8().unwrap()),
101             GroupId::SessionConfig => write!(f, "{:#04X} (SESSION_CONFIG)", self.to_u8().unwrap()),
102             GroupId::RangingSessionControl => write!(
103                 f,
104                 "{:#04X} (RANGING_SESSION_CONTROL)",
105                 self.to_u8().unwrap()
106             ),
107             GroupId::DataControl => write!(f, "{:#04X} (DATA_CONTROL)", self.to_u8().unwrap()),
108             GroupId::VendorReservedA => {
109                 write!(f, "{:#04X} (VENDOR_RESERVED_A)", self.to_u8().unwrap())
110             }
111             GroupId::VendorReservedB => {
112                 write!(f, "{:#04X} (VENDOR_RESERVED_B)", self.to_u8().unwrap())
113             }
114             GroupId::VendorAndroid => write!(f, "{:#04X} (VENDOR_ANDROID)", self.to_u8().unwrap()),
115             GroupId::Test => write!(f, "{:#04X} (TEST)", self.to_u8().unwrap()),
116             GroupId::VendorReservedE => {
117                 write!(f, "{:#04X} (VENDOR_RESERVED_E)", self.to_u8().unwrap())
118             }
119             GroupId::VendorReservedF => {
120                 write!(f, "{:#04X} (VENDOR_RESERVED_F)", self.to_u8().unwrap())
121             }
122         }
123     }
124 }
125 
126 #[derive(FromPrimitive, ToPrimitive, Debug, Hash, Eq, PartialEq, Clone, Copy)]
127 #[repr(u64)]
128 pub enum CoreOpCode {
129     CoreDeviceReset = 0x0,
130     CoreDeviceStatusNtf = 0x1,
131     CoreGetDeviceInfo = 0x2,
132     CoreGetCapsInfo = 0x3,
133     CoreSetConfig = 0x4,
134     CoreGetConfig = 0x5,
135     CoreDeviceSuspend = 0x6,
136     CoreGenericErrorNtf = 0x7,
137 }
138 impl fmt::Display for CoreOpCode {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result139     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
140         match self {
141             CoreOpCode::CoreDeviceReset => {
142                 write!(f, "{:#04X} (CORE_DEVICE_RESET)", self.to_u8().unwrap())
143             }
144             CoreOpCode::CoreDeviceStatusNtf => {
145                 write!(f, "{:#04X} (CORE_DEVICE_STATUS_NTF)", self.to_u8().unwrap())
146             }
147             CoreOpCode::CoreGetDeviceInfo => {
148                 write!(f, "{:#04X} (CORE_GET_DEVICE_INFO)", self.to_u8().unwrap())
149             }
150             CoreOpCode::CoreGetCapsInfo => {
151                 write!(f, "{:#04X} (CORE_GET_CAPS_INFO)", self.to_u8().unwrap())
152             }
153             CoreOpCode::CoreSetConfig => {
154                 write!(f, "{:#04X} (CORE_SET_CONFIG)", self.to_u8().unwrap())
155             }
156             CoreOpCode::CoreGetConfig => {
157                 write!(f, "{:#04X} (CORE_GET_CONFIG)", self.to_u8().unwrap())
158             }
159             CoreOpCode::CoreDeviceSuspend => {
160                 write!(f, "{:#04X} (CORE_DEVICE_SUSPEND)", self.to_u8().unwrap())
161             }
162             CoreOpCode::CoreGenericErrorNtf => {
163                 write!(f, "{:#04X} (CORE_GENERIC_ERROR_NTF)", self.to_u8().unwrap())
164             }
165         }
166     }
167 }
168 
169 #[derive(FromPrimitive, ToPrimitive, Debug, Hash, Eq, PartialEq, Clone, Copy)]
170 #[repr(u64)]
171 pub enum SessionOpCode {
172     SessionInit = 0x0,
173     SessionDeinit = 0x1,
174     SessionStatusNtf = 0x2,
175     SessionSetAppConfig = 0x3,
176     SessionGetAppConfig = 0x4,
177     SessionGetCount = 0x5,
178     SessionGetState = 0x6,
179     SessionUpdateControllerMulticastList = 0x7,
180 }
181 impl fmt::Display for SessionOpCode {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result182     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
183         match self {
184             SessionOpCode::SessionInit => {
185                 write!(f, "{:#04X} (SESSION_INIT)", self.to_u8().unwrap())
186             }
187             SessionOpCode::SessionDeinit => {
188                 write!(f, "{:#04X} (SESSION_DEINIT)", self.to_u8().unwrap())
189             }
190             SessionOpCode::SessionStatusNtf => {
191                 write!(f, "{:#04X} (SESSION_STATUS_NTF)", self.to_u8().unwrap())
192             }
193             SessionOpCode::SessionSetAppConfig => {
194                 write!(f, "{:#04X} (SESSION_SET_APP_CONFIG)", self.to_u8().unwrap())
195             }
196             SessionOpCode::SessionGetAppConfig => {
197                 write!(f, "{:#04X} (SESSION_GET_APP_CONFIG)", self.to_u8().unwrap())
198             }
199             SessionOpCode::SessionGetCount => {
200                 write!(f, "{:#04X} (SESSION_GET_COUNT)", self.to_u8().unwrap())
201             }
202             SessionOpCode::SessionGetState => {
203                 write!(f, "{:#04X} (SESSION_GET_STATE)", self.to_u8().unwrap())
204             }
205             SessionOpCode::SessionUpdateControllerMulticastList => write!(
206                 f,
207                 "{:#04X} (SESSION_UPDATE_CONTROLLER_MULTICAST_LIST)",
208                 self.to_u8().unwrap()
209             ),
210         }
211     }
212 }
213 
214 #[derive(FromPrimitive, ToPrimitive, Debug, Hash, Eq, PartialEq, Clone, Copy)]
215 #[repr(u64)]
216 pub enum RangeOpCode {
217     RangeStart = 0x0,
218     RangeStop = 0x1,
219     RangeIntervalUpdateReq = 0x2,
220     RangeGetRangingCount = 0x3,
221 }
222 impl fmt::Display for RangeOpCode {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result223     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
224         match self {
225             RangeOpCode::RangeStart => write!(f, "{:#04X} (RANGE_START)", self.to_u8().unwrap()),
226             RangeOpCode::RangeStop => write!(f, "{:#04X} (RANGE_STOP)", self.to_u8().unwrap()),
227             RangeOpCode::RangeIntervalUpdateReq => write!(
228                 f,
229                 "{:#04X} (RANGE_INTERVAL_UPDATE_REQ)",
230                 self.to_u8().unwrap()
231             ),
232             RangeOpCode::RangeGetRangingCount => write!(
233                 f,
234                 "{:#04X} (RANGE_GET_RANGING_COUNT)",
235                 self.to_u8().unwrap()
236             ),
237         }
238     }
239 }
240 
241 #[derive(FromPrimitive, ToPrimitive, Debug, Hash, Eq, PartialEq, Clone, Copy)]
242 #[repr(u64)]
243 pub enum AppDataOpCode {
244     AppDataTx = 0x0,
245     AppDataRx = 0x1,
246 }
247 impl fmt::Display for AppDataOpCode {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result248     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
249         match self {
250             AppDataOpCode::AppDataTx => write!(f, "{:#04X} (APP_DATA_TX)", self.to_u8().unwrap()),
251             AppDataOpCode::AppDataRx => write!(f, "{:#04X} (APP_DATA_RX)", self.to_u8().unwrap()),
252         }
253     }
254 }
255 
256 #[derive(FromPrimitive, ToPrimitive, Debug, Hash, Eq, PartialEq, Clone, Copy)]
257 #[repr(u64)]
258 pub enum PicaOpCode {
259     PicaInitDevice = 0x0,
260     PicaSetDevicePosition = 0x1,
261     PicaCreateBeacon = 0x2,
262     PicaSetBeaconPosition = 0x3,
263     PicaDestroyBeacon = 0x4,
264 }
265 impl fmt::Display for PicaOpCode {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result266     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
267         match self {
268             PicaOpCode::PicaInitDevice => {
269                 write!(f, "{:#04X} (PICA_INIT_DEVICE)", self.to_u8().unwrap())
270             }
271             PicaOpCode::PicaSetDevicePosition => write!(
272                 f,
273                 "{:#04X} (PICA_SET_DEVICE_POSITION)",
274                 self.to_u8().unwrap()
275             ),
276             PicaOpCode::PicaCreateBeacon => {
277                 write!(f, "{:#04X} (PICA_CREATE_BEACON)", self.to_u8().unwrap())
278             }
279             PicaOpCode::PicaSetBeaconPosition => write!(
280                 f,
281                 "{:#04X} (PICA_SET_BEACON_POSITION)",
282                 self.to_u8().unwrap()
283             ),
284             PicaOpCode::PicaDestroyBeacon => {
285                 write!(f, "{:#04X} (PICA_DESTROY_BEACON)", self.to_u8().unwrap())
286             }
287         }
288     }
289 }
290 
291 #[derive(FromPrimitive, ToPrimitive, Debug, Hash, Eq, PartialEq, Clone, Copy)]
292 #[repr(u64)]
293 pub enum AndroidOpCode {
294     AndroidGetPowerStats = 0x0,
295     AndroidSetCountryCode = 0x1,
296 }
297 impl fmt::Display for AndroidOpCode {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result298     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
299         match self {
300             AndroidOpCode::AndroidGetPowerStats => write!(
301                 f,
302                 "{:#04X} (ANDROID_GET_POWER_STATS)",
303                 self.to_u8().unwrap()
304             ),
305             AndroidOpCode::AndroidSetCountryCode => write!(
306                 f,
307                 "{:#04X} (ANDROID_SET_COUNTRY_CODE)",
308                 self.to_u8().unwrap()
309             ),
310         }
311     }
312 }
313 
314 #[derive(FromPrimitive, ToPrimitive, Debug, Hash, Eq, PartialEq, Clone, Copy)]
315 #[repr(u64)]
316 pub enum StatusCode {
317     UciStatusOk = 0x0,
318     UciStatusRejected = 0x1,
319     UciStatusFailed = 0x2,
320     UciStatusSyntaxError = 0x3,
321     UciStatusInvalidParam = 0x4,
322     UciStatusInvalidRange = 0x5,
323     UciStatusInvalidMsgSize = 0x6,
324     UciStatusUnknownGid = 0x7,
325     UciStatusUnknownOid = 0x8,
326     UciStatusReadOnly = 0x9,
327     UciStatusCommandRetry = 0xa,
328     UciStatusSessionNotExist = 0x11,
329     UciStatusSessionDuplicate = 0x12,
330     UciStatusSessionActive = 0x13,
331     UciStatusMaxSessionsExceeded = 0x14,
332     UciStatusSessionNotConfigured = 0x15,
333     UciStatusActiveSessionOngoing = 0x16,
334     UciStatusMulticastListFull = 0x17,
335     UciStatusAddressNotFound = 0x18,
336     UciStatusAddressAlreadyPresent = 0x19,
337     UciStatusRangingTxFailed = 0x20,
338     UciStatusRangingRxTimeout = 0x21,
339     UciStatusRangingRxPhyDecFailed = 0x22,
340     UciStatusRangingRxPhyToaFailed = 0x23,
341     UciStatusRangingRxPhyStsFailed = 0x24,
342     UciStatusRangingRxMacDecFailed = 0x25,
343     UciStatusRangingRxMacIeDecFailed = 0x26,
344     UciStatusRangingRxMacIeMissing = 0x27,
345     UciStatusDataMaxTxPsduSizeExceeded = 0x30,
346     UciStatusDataRxCrcError = 0x31,
347     UciStatusErrorCccSeBusy = 0x50,
348     UciStatusErrorCccLifecycle = 0x51,
349 }
350 impl fmt::Display for StatusCode {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result351     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
352         match self {
353             StatusCode::UciStatusOk => write!(f, "{:#04X} (UCI_STATUS_OK)", self.to_u8().unwrap()),
354             StatusCode::UciStatusRejected => {
355                 write!(f, "{:#04X} (UCI_STATUS_REJECTED)", self.to_u8().unwrap())
356             }
357             StatusCode::UciStatusFailed => {
358                 write!(f, "{:#04X} (UCI_STATUS_FAILED)", self.to_u8().unwrap())
359             }
360             StatusCode::UciStatusSyntaxError => write!(
361                 f,
362                 "{:#04X} (UCI_STATUS_SYNTAX_ERROR)",
363                 self.to_u8().unwrap()
364             ),
365             StatusCode::UciStatusInvalidParam => write!(
366                 f,
367                 "{:#04X} (UCI_STATUS_INVALID_PARAM)",
368                 self.to_u8().unwrap()
369             ),
370             StatusCode::UciStatusInvalidRange => write!(
371                 f,
372                 "{:#04X} (UCI_STATUS_INVALID_RANGE)",
373                 self.to_u8().unwrap()
374             ),
375             StatusCode::UciStatusInvalidMsgSize => write!(
376                 f,
377                 "{:#04X} (UCI_STATUS_INVALID_MSG_SIZE)",
378                 self.to_u8().unwrap()
379             ),
380             StatusCode::UciStatusUnknownGid => {
381                 write!(f, "{:#04X} (UCI_STATUS_UNKNOWN_GID)", self.to_u8().unwrap())
382             }
383             StatusCode::UciStatusUnknownOid => {
384                 write!(f, "{:#04X} (UCI_STATUS_UNKNOWN_OID)", self.to_u8().unwrap())
385             }
386             StatusCode::UciStatusReadOnly => {
387                 write!(f, "{:#04X} (UCI_STATUS_READ_ONLY)", self.to_u8().unwrap())
388             }
389             StatusCode::UciStatusCommandRetry => write!(
390                 f,
391                 "{:#04X} (UCI_STATUS_COMMAND_RETRY)",
392                 self.to_u8().unwrap()
393             ),
394             StatusCode::UciStatusSessionNotExist => write!(
395                 f,
396                 "{:#04X} (UCI_STATUS_SESSION_NOT_EXIST)",
397                 self.to_u8().unwrap()
398             ),
399             StatusCode::UciStatusSessionDuplicate => write!(
400                 f,
401                 "{:#04X} (UCI_STATUS_SESSION_DUPLICATE)",
402                 self.to_u8().unwrap()
403             ),
404             StatusCode::UciStatusSessionActive => write!(
405                 f,
406                 "{:#04X} (UCI_STATUS_SESSION_ACTIVE)",
407                 self.to_u8().unwrap()
408             ),
409             StatusCode::UciStatusMaxSessionsExceeded => write!(
410                 f,
411                 "{:#04X} (UCI_STATUS_MAX_SESSIONS_EXCEEDED)",
412                 self.to_u8().unwrap()
413             ),
414             StatusCode::UciStatusSessionNotConfigured => write!(
415                 f,
416                 "{:#04X} (UCI_STATUS_SESSION_NOT_CONFIGURED)",
417                 self.to_u8().unwrap()
418             ),
419             StatusCode::UciStatusActiveSessionOngoing => write!(
420                 f,
421                 "{:#04X} (UCI_STATUS_ACTIVE_SESSION_ONGOING)",
422                 self.to_u8().unwrap()
423             ),
424             StatusCode::UciStatusMulticastListFull => write!(
425                 f,
426                 "{:#04X} (UCI_STATUS_MULTICAST_LIST_FULL)",
427                 self.to_u8().unwrap()
428             ),
429             StatusCode::UciStatusAddressNotFound => write!(
430                 f,
431                 "{:#04X} (UCI_STATUS_ADDRESS_NOT_FOUND)",
432                 self.to_u8().unwrap()
433             ),
434             StatusCode::UciStatusAddressAlreadyPresent => write!(
435                 f,
436                 "{:#04X} (UCI_STATUS_ADDRESS_ALREADY_PRESENT)",
437                 self.to_u8().unwrap()
438             ),
439             StatusCode::UciStatusRangingTxFailed => write!(
440                 f,
441                 "{:#04X} (UCI_STATUS_RANGING_TX_FAILED)",
442                 self.to_u8().unwrap()
443             ),
444             StatusCode::UciStatusRangingRxTimeout => write!(
445                 f,
446                 "{:#04X} (UCI_STATUS_RANGING_RX_TIMEOUT)",
447                 self.to_u8().unwrap()
448             ),
449             StatusCode::UciStatusRangingRxPhyDecFailed => write!(
450                 f,
451                 "{:#04X} (UCI_STATUS_RANGING_RX_PHY_DEC_FAILED)",
452                 self.to_u8().unwrap()
453             ),
454             StatusCode::UciStatusRangingRxPhyToaFailed => write!(
455                 f,
456                 "{:#04X} (UCI_STATUS_RANGING_RX_PHY_TOA_FAILED)",
457                 self.to_u8().unwrap()
458             ),
459             StatusCode::UciStatusRangingRxPhyStsFailed => write!(
460                 f,
461                 "{:#04X} (UCI_STATUS_RANGING_RX_PHY_STS_FAILED)",
462                 self.to_u8().unwrap()
463             ),
464             StatusCode::UciStatusRangingRxMacDecFailed => write!(
465                 f,
466                 "{:#04X} (UCI_STATUS_RANGING_RX_MAC_DEC_FAILED)",
467                 self.to_u8().unwrap()
468             ),
469             StatusCode::UciStatusRangingRxMacIeDecFailed => write!(
470                 f,
471                 "{:#04X} (UCI_STATUS_RANGING_RX_MAC_IE_DEC_FAILED)",
472                 self.to_u8().unwrap()
473             ),
474             StatusCode::UciStatusRangingRxMacIeMissing => write!(
475                 f,
476                 "{:#04X} (UCI_STATUS_RANGING_RX_MAC_IE_MISSING)",
477                 self.to_u8().unwrap()
478             ),
479             StatusCode::UciStatusDataMaxTxPsduSizeExceeded => write!(
480                 f,
481                 "{:#04X} (UCI_STATUS_DATA_MAX_TX_PSDU_SIZE_EXCEEDED)",
482                 self.to_u8().unwrap()
483             ),
484             StatusCode::UciStatusDataRxCrcError => write!(
485                 f,
486                 "{:#04X} (UCI_STATUS_DATA_RX_CRC_ERROR)",
487                 self.to_u8().unwrap()
488             ),
489             StatusCode::UciStatusErrorCccSeBusy => write!(
490                 f,
491                 "{:#04X} (UCI_STATUS_ERROR_CCC_SE_BUSY)",
492                 self.to_u8().unwrap()
493             ),
494             StatusCode::UciStatusErrorCccLifecycle => write!(
495                 f,
496                 "{:#04X} (UCI_STATUS_ERROR_CCC_LIFECYCLE)",
497                 self.to_u8().unwrap()
498             ),
499         }
500     }
501 }
502 
503 #[derive(FromPrimitive, ToPrimitive, Debug, Hash, Eq, PartialEq, Clone, Copy)]
504 #[repr(u64)]
505 pub enum ResetConfig {
506     UwbsReset = 0x0,
507 }
508 impl fmt::Display for ResetConfig {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result509     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
510         match self {
511             ResetConfig::UwbsReset => write!(f, "{:#04X} (UWBS_RESET)", self.to_u8().unwrap()),
512         }
513     }
514 }
515 
516 #[derive(FromPrimitive, ToPrimitive, Debug, Hash, Eq, PartialEq, Clone, Copy)]
517 #[repr(u64)]
518 pub enum DeviceConfigId {
519     DeviceState = 0x0,
520     LowPowerMode = 0x1,
521 }
522 impl fmt::Display for DeviceConfigId {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result523     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
524         match self {
525             DeviceConfigId::DeviceState => {
526                 write!(f, "{:#04X} (DEVICE_STATE)", self.to_u8().unwrap())
527             }
528             DeviceConfigId::LowPowerMode => {
529                 write!(f, "{:#04X} (LOW_POWER_MODE)", self.to_u8().unwrap())
530             }
531         }
532     }
533 }
534 
535 #[derive(FromPrimitive, ToPrimitive, Debug, Hash, Eq, PartialEq, Clone, Copy)]
536 #[repr(u64)]
537 pub enum AppConfigTlvType {
538     DeviceType = 0x0,
539     RangingRoundUsage = 0x1,
540     StsConfig = 0x2,
541     MultiNodeMode = 0x3,
542     ChannelNumber = 0x4,
543     NoOfControlee = 0x5,
544     DeviceMacAddress = 0x6,
545     DstMacAddress = 0x7,
546     SlotDuration = 0x8,
547     RangingInterval = 0x9,
548     StsIndex = 0xa,
549     MacFcsType = 0xb,
550     RangingRoundControl = 0xc,
551     AoaResultReq = 0xd,
552     RngDataNtf = 0xe,
553     RngDataNtfProximityNear = 0xf,
554     RngDataNtfProximityFar = 0x10,
555     DeviceRole = 0x11,
556     RframeConfig = 0x12,
557     PreambleCodeIndex = 0x14,
558     SfdId = 0x15,
559     PsduDataRate = 0x16,
560     PreambleDuration = 0x17,
561     RangingTimeStruct = 0x1a,
562     SlotsPerRr = 0x1b,
563     TxAdaptivePayloadPower = 0x1c,
564     ResponderSlotIndex = 0x1e,
565     PrfMode = 0x1f,
566     ScheduledMode = 0x22,
567     KeyRotation = 0x23,
568     KeyRotationRate = 0x24,
569     SessionPriority = 0x25,
570     MacAddressMode = 0x26,
571     VendorId = 0x27,
572     StaticStsIv = 0x28,
573     NumberOfStsSegments = 0x29,
574     MaxRrRetry = 0x2a,
575     UwbInitiationTime = 0x2b,
576     HoppingMode = 0x2c,
577     BlockStrideLength = 0x2d,
578     ResultReportConfig = 0x2e,
579     InBandTerminationAttemptCount = 0x2f,
580     SubSessionId = 0x30,
581     BprfPhrDataRate = 0x31,
582     MaxNumberOfMeasurements = 0x32,
583     StsLength = 0x35,
584     CccHopModeKey = 0xa0,
585     CccUwbTime0 = 0xa1,
586     CccRangingProtocolVer = 0xa3,
587     CccUwbConfigId = 0xa4,
588     CccPulseshapeCombo = 0xa5,
589     CccUrskTtl = 0xa6,
590     NbOfRangeMeasurements = 0xe3,
591     NbOfAzimuthMeasurements = 0xe4,
592     NbOfElevationMeasurements = 0xe5,
593 }
594 impl fmt::Display for AppConfigTlvType {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result595     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
596         match self {
597             AppConfigTlvType::DeviceType => {
598                 write!(f, "{:#04X} (DEVICE_TYPE)", self.to_u8().unwrap())
599             }
600             AppConfigTlvType::RangingRoundUsage => {
601                 write!(f, "{:#04X} (RANGING_ROUND_USAGE)", self.to_u8().unwrap())
602             }
603             AppConfigTlvType::StsConfig => write!(f, "{:#04X} (STS_CONFIG)", self.to_u8().unwrap()),
604             AppConfigTlvType::MultiNodeMode => {
605                 write!(f, "{:#04X} (MULTI_NODE_MODE)", self.to_u8().unwrap())
606             }
607             AppConfigTlvType::ChannelNumber => {
608                 write!(f, "{:#04X} (CHANNEL_NUMBER)", self.to_u8().unwrap())
609             }
610             AppConfigTlvType::NoOfControlee => {
611                 write!(f, "{:#04X} (NO_OF_CONTROLEE)", self.to_u8().unwrap())
612             }
613             AppConfigTlvType::DeviceMacAddress => {
614                 write!(f, "{:#04X} (DEVICE_MAC_ADDRESS)", self.to_u8().unwrap())
615             }
616             AppConfigTlvType::DstMacAddress => {
617                 write!(f, "{:#04X} (DST_MAC_ADDRESS)", self.to_u8().unwrap())
618             }
619             AppConfigTlvType::SlotDuration => {
620                 write!(f, "{:#04X} (SLOT_DURATION)", self.to_u8().unwrap())
621             }
622             AppConfigTlvType::RangingInterval => {
623                 write!(f, "{:#04X} (RANGING_INTERVAL)", self.to_u8().unwrap())
624             }
625             AppConfigTlvType::StsIndex => write!(f, "{:#04X} (STS_INDEX)", self.to_u8().unwrap()),
626             AppConfigTlvType::MacFcsType => {
627                 write!(f, "{:#04X} (MAC_FCS_TYPE)", self.to_u8().unwrap())
628             }
629             AppConfigTlvType::RangingRoundControl => {
630                 write!(f, "{:#04X} (RANGING_ROUND_CONTROL)", self.to_u8().unwrap())
631             }
632             AppConfigTlvType::AoaResultReq => {
633                 write!(f, "{:#04X} (AOA_RESULT_REQ)", self.to_u8().unwrap())
634             }
635             AppConfigTlvType::RngDataNtf => {
636                 write!(f, "{:#04X} (RNG_DATA_NTF)", self.to_u8().unwrap())
637             }
638             AppConfigTlvType::RngDataNtfProximityNear => write!(
639                 f,
640                 "{:#04X} (RNG_DATA_NTF_PROXIMITY_NEAR)",
641                 self.to_u8().unwrap()
642             ),
643             AppConfigTlvType::RngDataNtfProximityFar => write!(
644                 f,
645                 "{:#04X} (RNG_DATA_NTF_PROXIMITY_FAR)",
646                 self.to_u8().unwrap()
647             ),
648             AppConfigTlvType::DeviceRole => {
649                 write!(f, "{:#04X} (DEVICE_ROLE)", self.to_u8().unwrap())
650             }
651             AppConfigTlvType::RframeConfig => {
652                 write!(f, "{:#04X} (RFRAME_CONFIG)", self.to_u8().unwrap())
653             }
654             AppConfigTlvType::PreambleCodeIndex => {
655                 write!(f, "{:#04X} (PREAMBLE_CODE_INDEX)", self.to_u8().unwrap())
656             }
657             AppConfigTlvType::SfdId => write!(f, "{:#04X} (SFD_ID)", self.to_u8().unwrap()),
658             AppConfigTlvType::PsduDataRate => {
659                 write!(f, "{:#04X} (PSDU_DATA_RATE)", self.to_u8().unwrap())
660             }
661             AppConfigTlvType::PreambleDuration => {
662                 write!(f, "{:#04X} (PREAMBLE_DURATION)", self.to_u8().unwrap())
663             }
664             AppConfigTlvType::RangingTimeStruct => {
665                 write!(f, "{:#04X} (RANGING_TIME_STRUCT)", self.to_u8().unwrap())
666             }
667             AppConfigTlvType::SlotsPerRr => {
668                 write!(f, "{:#04X} (SLOTS_PER_RR)", self.to_u8().unwrap())
669             }
670             AppConfigTlvType::TxAdaptivePayloadPower => write!(
671                 f,
672                 "{:#04X} (TX_ADAPTIVE_PAYLOAD_POWER)",
673                 self.to_u8().unwrap()
674             ),
675             AppConfigTlvType::ResponderSlotIndex => {
676                 write!(f, "{:#04X} (RESPONDER_SLOT_INDEX)", self.to_u8().unwrap())
677             }
678             AppConfigTlvType::PrfMode => write!(f, "{:#04X} (PRF_MODE)", self.to_u8().unwrap()),
679             AppConfigTlvType::ScheduledMode => {
680                 write!(f, "{:#04X} (SCHEDULED_MODE)", self.to_u8().unwrap())
681             }
682             AppConfigTlvType::KeyRotation => {
683                 write!(f, "{:#04X} (KEY_ROTATION)", self.to_u8().unwrap())
684             }
685             AppConfigTlvType::KeyRotationRate => {
686                 write!(f, "{:#04X} (KEY_ROTATION_RATE)", self.to_u8().unwrap())
687             }
688             AppConfigTlvType::SessionPriority => {
689                 write!(f, "{:#04X} (SESSION_PRIORITY)", self.to_u8().unwrap())
690             }
691             AppConfigTlvType::MacAddressMode => {
692                 write!(f, "{:#04X} (MAC_ADDRESS_MODE)", self.to_u8().unwrap())
693             }
694             AppConfigTlvType::VendorId => write!(f, "{:#04X} (VENDOR_ID)", self.to_u8().unwrap()),
695             AppConfigTlvType::StaticStsIv => {
696                 write!(f, "{:#04X} (STATIC_STS_IV)", self.to_u8().unwrap())
697             }
698             AppConfigTlvType::NumberOfStsSegments => {
699                 write!(f, "{:#04X} (NUMBER_OF_STS_SEGMENTS)", self.to_u8().unwrap())
700             }
701             AppConfigTlvType::MaxRrRetry => {
702                 write!(f, "{:#04X} (MAX_RR_RETRY)", self.to_u8().unwrap())
703             }
704             AppConfigTlvType::UwbInitiationTime => {
705                 write!(f, "{:#04X} (UWB_INITIATION_TIME)", self.to_u8().unwrap())
706             }
707             AppConfigTlvType::HoppingMode => {
708                 write!(f, "{:#04X} (HOPPING_MODE)", self.to_u8().unwrap())
709             }
710             AppConfigTlvType::BlockStrideLength => {
711                 write!(f, "{:#04X} (BLOCK_STRIDE_LENGTH)", self.to_u8().unwrap())
712             }
713             AppConfigTlvType::ResultReportConfig => {
714                 write!(f, "{:#04X} (RESULT_REPORT_CONFIG)", self.to_u8().unwrap())
715             }
716             AppConfigTlvType::InBandTerminationAttemptCount => write!(
717                 f,
718                 "{:#04X} (IN_BAND_TERMINATION_ATTEMPT_COUNT)",
719                 self.to_u8().unwrap()
720             ),
721             AppConfigTlvType::SubSessionId => {
722                 write!(f, "{:#04X} (SUB_SESSION_ID)", self.to_u8().unwrap())
723             }
724             AppConfigTlvType::BprfPhrDataRate => {
725                 write!(f, "{:#04X} (BPRF_PHR_DATA_RATE)", self.to_u8().unwrap())
726             }
727             AppConfigTlvType::MaxNumberOfMeasurements => write!(
728                 f,
729                 "{:#04X} (MAX_NUMBER_OF_MEASUREMENTS)",
730                 self.to_u8().unwrap()
731             ),
732             AppConfigTlvType::StsLength => write!(f, "{:#04X} (STS_LENGTH)", self.to_u8().unwrap()),
733             AppConfigTlvType::CccHopModeKey => {
734                 write!(f, "{:#04X} (CCC_HOP_MODE_KEY)", self.to_u8().unwrap())
735             }
736             AppConfigTlvType::CccUwbTime0 => {
737                 write!(f, "{:#04X} (CCC_UWB_TIME0)", self.to_u8().unwrap())
738             }
739             AppConfigTlvType::CccRangingProtocolVer => write!(
740                 f,
741                 "{:#04X} (CCC_RANGING_PROTOCOL_VER)",
742                 self.to_u8().unwrap()
743             ),
744             AppConfigTlvType::CccUwbConfigId => {
745                 write!(f, "{:#04X} (CCC_UWB_CONFIG_ID)", self.to_u8().unwrap())
746             }
747             AppConfigTlvType::CccPulseshapeCombo => {
748                 write!(f, "{:#04X} (CCC_PULSESHAPE_COMBO)", self.to_u8().unwrap())
749             }
750             AppConfigTlvType::CccUrskTtl => {
751                 write!(f, "{:#04X} (CCC_URSK_TTL)", self.to_u8().unwrap())
752             }
753             AppConfigTlvType::NbOfRangeMeasurements => write!(
754                 f,
755                 "{:#04X} (NB_OF_RANGE_MEASUREMENTS)",
756                 self.to_u8().unwrap()
757             ),
758             AppConfigTlvType::NbOfAzimuthMeasurements => write!(
759                 f,
760                 "{:#04X} (NB_OF_AZIMUTH_MEASUREMENTS)",
761                 self.to_u8().unwrap()
762             ),
763             AppConfigTlvType::NbOfElevationMeasurements => write!(
764                 f,
765                 "{:#04X} (NB_OF_ELEVATION_MEASUREMENTS)",
766                 self.to_u8().unwrap()
767             ),
768         }
769     }
770 }
771 
772 #[derive(FromPrimitive, ToPrimitive, Debug, Hash, Eq, PartialEq, Clone, Copy)]
773 #[repr(u64)]
774 pub enum CapTlvType {
775     SupportedFiraPhyVersionRange = 0x0,
776     SupportedFiraMacVersionRange = 0x1,
777     SupportedDeviceRoles = 0x2,
778     SupportedRangingMethod = 0x3,
779     SupportedStsConfig = 0x4,
780     SupportedMultiNodeModes = 0x5,
781     SupportedRangingTimeStruct = 0x6,
782     SupportedScheduledMode = 0x7,
783     SupportedHoppingMode = 0x8,
784     SupportedBlockStriding = 0x9,
785     SupportedUwbInitiationTime = 0xa,
786     SupportedChannels = 0xb,
787     SupportedRframeConfig = 0xc,
788     SupportedCcConstraintLength = 0xd,
789     SupportedBprfParameterSets = 0xe,
790     SupportedHprfParameterSets = 0xf,
791     SupportedAoa = 0x10,
792     SupportedExtendedMacAddress = 0x11,
793     CccSupportedChapsPerSlot = 0xa0,
794     CccSupportedSyncCodes = 0xa1,
795     CccSupportedHoppingConfigModesAndSequences = 0xa2,
796     CccSupportedChannels = 0xa3,
797     CccSupportedVersions = 0xa4,
798     CccSupportedUwbConfigs = 0xa5,
799     CccSupportedPulseShapeCombos = 0xa6,
800     CccSupportedRanMultiplier = 0xa7,
801     SupportedPowerStats = 0xc0,
802     SupportedAoaResultReqAntennaInterleaving = 0xe3,
803 }
804 impl fmt::Display for CapTlvType {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result805     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
806         match self {
807             CapTlvType::SupportedFiraPhyVersionRange => write!(
808                 f,
809                 "{:#04X} (SUPPORTED_FIRA_PHY_VERSION_RANGE)",
810                 self.to_u8().unwrap()
811             ),
812             CapTlvType::SupportedFiraMacVersionRange => write!(
813                 f,
814                 "{:#04X} (SUPPORTED_FIRA_MAC_VERSION_RANGE)",
815                 self.to_u8().unwrap()
816             ),
817             CapTlvType::SupportedDeviceRoles => {
818                 write!(f, "{:#04X} (SUPPORTED_DEVICE_ROLES)", self.to_u8().unwrap())
819             }
820             CapTlvType::SupportedRangingMethod => write!(
821                 f,
822                 "{:#04X} (SUPPORTED_RANGING_METHOD)",
823                 self.to_u8().unwrap()
824             ),
825             CapTlvType::SupportedStsConfig => {
826                 write!(f, "{:#04X} (SUPPORTED_STS_CONFIG)", self.to_u8().unwrap())
827             }
828             CapTlvType::SupportedMultiNodeModes => write!(
829                 f,
830                 "{:#04X} (SUPPORTED_MULTI_NODE_MODES)",
831                 self.to_u8().unwrap()
832             ),
833             CapTlvType::SupportedRangingTimeStruct => write!(
834                 f,
835                 "{:#04X} (SUPPORTED_RANGING_TIME_STRUCT)",
836                 self.to_u8().unwrap()
837             ),
838             CapTlvType::SupportedScheduledMode => write!(
839                 f,
840                 "{:#04X} (SUPPORTED_SCHEDULED_MODE)",
841                 self.to_u8().unwrap()
842             ),
843             CapTlvType::SupportedHoppingMode => {
844                 write!(f, "{:#04X} (SUPPORTED_HOPPING_MODE)", self.to_u8().unwrap())
845             }
846             CapTlvType::SupportedBlockStriding => write!(
847                 f,
848                 "{:#04X} (SUPPORTED_BLOCK_STRIDING)",
849                 self.to_u8().unwrap()
850             ),
851             CapTlvType::SupportedUwbInitiationTime => write!(
852                 f,
853                 "{:#04X} (SUPPORTED_UWB_INITIATION_TIME)",
854                 self.to_u8().unwrap()
855             ),
856             CapTlvType::SupportedChannels => {
857                 write!(f, "{:#04X} (SUPPORTED_CHANNELS)", self.to_u8().unwrap())
858             }
859             CapTlvType::SupportedRframeConfig => write!(
860                 f,
861                 "{:#04X} (SUPPORTED_RFRAME_CONFIG)",
862                 self.to_u8().unwrap()
863             ),
864             CapTlvType::SupportedCcConstraintLength => write!(
865                 f,
866                 "{:#04X} (SUPPORTED_CC_CONSTRAINT_LENGTH)",
867                 self.to_u8().unwrap()
868             ),
869             CapTlvType::SupportedBprfParameterSets => write!(
870                 f,
871                 "{:#04X} (SUPPORTED_BPRF_PARAMETER_SETS)",
872                 self.to_u8().unwrap()
873             ),
874             CapTlvType::SupportedHprfParameterSets => write!(
875                 f,
876                 "{:#04X} (SUPPORTED_HPRF_PARAMETER_SETS)",
877                 self.to_u8().unwrap()
878             ),
879             CapTlvType::SupportedAoa => write!(f, "{:#04X} (SUPPORTED_AOA)", self.to_u8().unwrap()),
880             CapTlvType::SupportedExtendedMacAddress => write!(
881                 f,
882                 "{:#04X} (SUPPORTED_EXTENDED_MAC_ADDRESS)",
883                 self.to_u8().unwrap()
884             ),
885             CapTlvType::CccSupportedChapsPerSlot => write!(
886                 f,
887                 "{:#04X} (CCC_SUPPORTED_CHAPS_PER_SLOT)",
888                 self.to_u8().unwrap()
889             ),
890             CapTlvType::CccSupportedSyncCodes => write!(
891                 f,
892                 "{:#04X} (CCC_SUPPORTED_SYNC_CODES)",
893                 self.to_u8().unwrap()
894             ),
895             CapTlvType::CccSupportedHoppingConfigModesAndSequences => write!(
896                 f,
897                 "{:#04X} (CCC_SUPPORTED_HOPPING_CONFIG_MODES_AND_SEQUENCES)",
898                 self.to_u8().unwrap()
899             ),
900             CapTlvType::CccSupportedChannels => {
901                 write!(f, "{:#04X} (CCC_SUPPORTED_CHANNELS)", self.to_u8().unwrap())
902             }
903             CapTlvType::CccSupportedVersions => {
904                 write!(f, "{:#04X} (CCC_SUPPORTED_VERSIONS)", self.to_u8().unwrap())
905             }
906             CapTlvType::CccSupportedUwbConfigs => write!(
907                 f,
908                 "{:#04X} (CCC_SUPPORTED_UWB_CONFIGS)",
909                 self.to_u8().unwrap()
910             ),
911             CapTlvType::CccSupportedPulseShapeCombos => write!(
912                 f,
913                 "{:#04X} (CCC_SUPPORTED_PULSE_SHAPE_COMBOS)",
914                 self.to_u8().unwrap()
915             ),
916             CapTlvType::CccSupportedRanMultiplier => write!(
917                 f,
918                 "{:#04X} (CCC_SUPPORTED_RAN_MULTIPLIER)",
919                 self.to_u8().unwrap()
920             ),
921             CapTlvType::SupportedPowerStats => {
922                 write!(f, "{:#04X} (SUPPORTED_POWER_STATS)", self.to_u8().unwrap())
923             }
924             CapTlvType::SupportedAoaResultReqAntennaInterleaving => write!(
925                 f,
926                 "{:#04X} (SUPPORTED_AOA_RESULT_REQ_ANTENNA_INTERLEAVING)",
927                 self.to_u8().unwrap()
928             ),
929         }
930     }
931 }
932 
933 #[derive(FromPrimitive, ToPrimitive, Debug, Hash, Eq, PartialEq, Clone, Copy)]
934 #[repr(u64)]
935 pub enum AoaResultReqType {
936     AoaDisable = 0x0,
937     AoaEnable = 0x1,
938     AoaEnableAzimuth = 0x2,
939     AoaEnableElevation = 0x3,
940     AoaEnableInterleaved = 0xf0,
941 }
942 impl fmt::Display for AoaResultReqType {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result943     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
944         match self {
945             AoaResultReqType::AoaDisable => {
946                 write!(f, "{:#04X} (AOA_DISABLE)", self.to_u8().unwrap())
947             }
948             AoaResultReqType::AoaEnable => write!(f, "{:#04X} (AOA_ENABLE)", self.to_u8().unwrap()),
949             AoaResultReqType::AoaEnableAzimuth => {
950                 write!(f, "{:#04X} (AOA_ENABLE_AZIMUTH)", self.to_u8().unwrap())
951             }
952             AoaResultReqType::AoaEnableElevation => {
953                 write!(f, "{:#04X} (AOA_ENABLE_ELEVATION)", self.to_u8().unwrap())
954             }
955             AoaResultReqType::AoaEnableInterleaved => {
956                 write!(f, "{:#04X} (AOA_ENABLE_INTERLEAVED)", self.to_u8().unwrap())
957             }
958         }
959     }
960 }
961 
962 #[derive(FromPrimitive, ToPrimitive, Debug, Hash, Eq, PartialEq, Clone, Copy)]
963 #[repr(u64)]
964 pub enum DeviceState {
965     DeviceStateReady = 0x1,
966     DeviceStateActive = 0x2,
967     DeviceStateError = 0xff,
968 }
969 impl fmt::Display for DeviceState {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result970     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
971         match self {
972             DeviceState::DeviceStateReady => {
973                 write!(f, "{:#04X} (DEVICE_STATE_READY)", self.to_u8().unwrap())
974             }
975             DeviceState::DeviceStateActive => {
976                 write!(f, "{:#04X} (DEVICE_STATE_ACTIVE)", self.to_u8().unwrap())
977             }
978             DeviceState::DeviceStateError => {
979                 write!(f, "{:#04X} (DEVICE_STATE_ERROR)", self.to_u8().unwrap())
980             }
981         }
982     }
983 }
984 
985 #[derive(FromPrimitive, ToPrimitive, Debug, Hash, Eq, PartialEq, Clone, Copy)]
986 #[repr(u64)]
987 pub enum SessionState {
988     SessionStateInit = 0x0,
989     SessionStateDeinit = 0x1,
990     SessionStateActive = 0x2,
991     SessionStateIdle = 0x3,
992 }
993 impl fmt::Display for SessionState {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result994     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
995         match self {
996             SessionState::SessionStateInit => {
997                 write!(f, "{:#04X} (SESSION_STATE_INIT)", self.to_u8().unwrap())
998             }
999             SessionState::SessionStateDeinit => {
1000                 write!(f, "{:#04X} (SESSION_STATE_DEINIT)", self.to_u8().unwrap())
1001             }
1002             SessionState::SessionStateActive => {
1003                 write!(f, "{:#04X} (SESSION_STATE_ACTIVE)", self.to_u8().unwrap())
1004             }
1005             SessionState::SessionStateIdle => {
1006                 write!(f, "{:#04X} (SESSION_STATE_IDLE)", self.to_u8().unwrap())
1007             }
1008         }
1009     }
1010 }
1011 
1012 #[derive(FromPrimitive, ToPrimitive, Debug, Hash, Eq, PartialEq, Clone, Copy)]
1013 #[repr(u64)]
1014 pub enum ReasonCode {
1015     StateChangeWithSessionManagementCommands = 0x0,
1016     MaxRangingRoundRetryCountReached = 0x1,
1017     MaxNumberOfMeasurementsReached = 0x2,
1018     ErrorSlotLengthNotSupported = 0x20,
1019     ErrorInsufficientSlotsPerRr = 0x21,
1020     ErrorMacAddressModeNotSupported = 0x22,
1021     ErrorInvalidRangingInterval = 0x23,
1022     ErrorInvalidStsConfig = 0x24,
1023     ErrorInvalidRframeConfig = 0x25,
1024 }
1025 impl fmt::Display for ReasonCode {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result1026     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1027         match self {
1028             ReasonCode::StateChangeWithSessionManagementCommands => write!(
1029                 f,
1030                 "{:#04X} (STATE_CHANGE_WITH_SESSION_MANAGEMENT_COMMANDS)",
1031                 self.to_u8().unwrap()
1032             ),
1033             ReasonCode::MaxRangingRoundRetryCountReached => write!(
1034                 f,
1035                 "{:#04X} (MAX_RANGING_ROUND_RETRY_COUNT_REACHED)",
1036                 self.to_u8().unwrap()
1037             ),
1038             ReasonCode::MaxNumberOfMeasurementsReached => write!(
1039                 f,
1040                 "{:#04X} (MAX_NUMBER_OF_MEASUREMENTS_REACHED)",
1041                 self.to_u8().unwrap()
1042             ),
1043             ReasonCode::ErrorSlotLengthNotSupported => write!(
1044                 f,
1045                 "{:#04X} (ERROR_SLOT_LENGTH_NOT_SUPPORTED)",
1046                 self.to_u8().unwrap()
1047             ),
1048             ReasonCode::ErrorInsufficientSlotsPerRr => write!(
1049                 f,
1050                 "{:#04X} (ERROR_INSUFFICIENT_SLOTS_PER_RR)",
1051                 self.to_u8().unwrap()
1052             ),
1053             ReasonCode::ErrorMacAddressModeNotSupported => write!(
1054                 f,
1055                 "{:#04X} (ERROR_MAC_ADDRESS_MODE_NOT_SUPPORTED)",
1056                 self.to_u8().unwrap()
1057             ),
1058             ReasonCode::ErrorInvalidRangingInterval => write!(
1059                 f,
1060                 "{:#04X} (ERROR_INVALID_RANGING_INTERVAL)",
1061                 self.to_u8().unwrap()
1062             ),
1063             ReasonCode::ErrorInvalidStsConfig => write!(
1064                 f,
1065                 "{:#04X} (ERROR_INVALID_STS_CONFIG)",
1066                 self.to_u8().unwrap()
1067             ),
1068             ReasonCode::ErrorInvalidRframeConfig => write!(
1069                 f,
1070                 "{:#04X} (ERROR_INVALID_RFRAME_CONFIG)",
1071                 self.to_u8().unwrap()
1072             ),
1073         }
1074     }
1075 }
1076 
1077 #[derive(FromPrimitive, ToPrimitive, Debug, Hash, Eq, PartialEq, Clone, Copy)]
1078 #[repr(u64)]
1079 pub enum MulticastUpdateStatusCode {
1080     StatusOkMulticastListUpdate = 0x0,
1081     StatusErrorMulticastListFull = 0x1,
1082     StatusErrorKeyFetchFail = 0x2,
1083     StatusErrorSubSessionIdNotFound = 0x3,
1084 }
1085 impl fmt::Display for MulticastUpdateStatusCode {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result1086     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1087         match self {
1088             MulticastUpdateStatusCode::StatusOkMulticastListUpdate => write!(
1089                 f,
1090                 "{:#04X} (STATUS_OK_MULTICAST_LIST_UPDATE)",
1091                 self.to_u8().unwrap()
1092             ),
1093             MulticastUpdateStatusCode::StatusErrorMulticastListFull => write!(
1094                 f,
1095                 "{:#04X} (STATUS_ERROR_MULTICAST_LIST_FULL)",
1096                 self.to_u8().unwrap()
1097             ),
1098             MulticastUpdateStatusCode::StatusErrorKeyFetchFail => write!(
1099                 f,
1100                 "{:#04X} (STATUS_ERROR_KEY_FETCH_FAIL)",
1101                 self.to_u8().unwrap()
1102             ),
1103             MulticastUpdateStatusCode::StatusErrorSubSessionIdNotFound => write!(
1104                 f,
1105                 "{:#04X} (STATUS_ERROR_SUB_SESSION_ID_NOT_FOUND)",
1106                 self.to_u8().unwrap()
1107             ),
1108         }
1109     }
1110 }
1111 
1112 #[derive(FromPrimitive, ToPrimitive, Debug, Hash, Eq, PartialEq, Clone, Copy)]
1113 #[repr(u64)]
1114 pub enum MacAddressIndicator {
1115     ShortAddress = 0x0,
1116     ExtendedAddress = 0x1,
1117 }
1118 impl fmt::Display for MacAddressIndicator {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result1119     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1120         match self {
1121             MacAddressIndicator::ShortAddress => {
1122                 write!(f, "{:#04X} (SHORT_ADDRESS)", self.to_u8().unwrap())
1123             }
1124             MacAddressIndicator::ExtendedAddress => {
1125                 write!(f, "{:#04X} (EXTENDED_ADDRESS)", self.to_u8().unwrap())
1126             }
1127         }
1128     }
1129 }
1130 
1131 #[derive(FromPrimitive, ToPrimitive, Debug, Hash, Eq, PartialEq, Clone, Copy)]
1132 #[repr(u64)]
1133 pub enum SessionType {
1134     FiraRangingSession = 0x0,
1135     FiraDataTransfer = 0x1,
1136     Ccc = 0xa0,
1137 }
1138 impl fmt::Display for SessionType {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result1139     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1140         match self {
1141             SessionType::FiraRangingSession => {
1142                 write!(f, "{:#04X} (FIRA_RANGING_SESSION)", self.to_u8().unwrap())
1143             }
1144             SessionType::FiraDataTransfer => {
1145                 write!(f, "{:#04X} (FIRA_DATA_TRANSFER)", self.to_u8().unwrap())
1146             }
1147             SessionType::Ccc => write!(f, "{:#04X} (CCC)", self.to_u8().unwrap()),
1148         }
1149     }
1150 }
1151 
1152 #[derive(FromPrimitive, ToPrimitive, Debug, Hash, Eq, PartialEq, Clone, Copy)]
1153 #[repr(u64)]
1154 pub enum MessageType {
1155     Command = 0x1,
1156     Response = 0x2,
1157     Notification = 0x3,
1158 }
1159 impl fmt::Display for MessageType {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result1160     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1161         match self {
1162             MessageType::Command => write!(f, "{:#04X} (COMMAND)", self.to_u8().unwrap()),
1163             MessageType::Response => write!(f, "{:#04X} (RESPONSE)", self.to_u8().unwrap()),
1164             MessageType::Notification => write!(f, "{:#04X} (NOTIFICATION)", self.to_u8().unwrap()),
1165         }
1166     }
1167 }
1168 
1169 #[derive(FromPrimitive, ToPrimitive, Debug, Hash, Eq, PartialEq, Clone, Copy)]
1170 #[repr(u64)]
1171 pub enum RangingMeasurementType {
1172     OneWay = 0x0,
1173     TwoWay = 0x1,
1174 }
1175 impl fmt::Display for RangingMeasurementType {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result1176     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1177         match self {
1178             RangingMeasurementType::OneWay => write!(f, "{:#04X} (ONE_WAY)", self.to_u8().unwrap()),
1179             RangingMeasurementType::TwoWay => write!(f, "{:#04X} (TWO_WAY)", self.to_u8().unwrap()),
1180         }
1181     }
1182 }
1183 
1184 #[derive(Debug, Clone, PartialEq)]
1185 pub struct CapTlv {
1186     pub t: CapTlvType,
1187     pub v: Vec<u8>,
1188 }
1189 impl CapTlv {
conforms(bytes: &[u8]) -> bool1190     fn conforms(bytes: &[u8]) -> bool {
1191         if bytes.len() < 2 {
1192             return false;
1193         }
1194         true
1195     }
parse(bytes: &[u8]) -> Result<Self>1196     pub fn parse(bytes: &[u8]) -> Result<Self> {
1197         if bytes.len() < 1 {
1198             return Err(Error::InvalidLengthError {
1199                 obj: "CapTlv".to_string(),
1200                 field: "t".to_string(),
1201                 wanted: 1,
1202                 got: bytes.len(),
1203             });
1204         }
1205         let t = u8::from_le_bytes([bytes[0]]);
1206         let t = CapTlvType::from_u8(t).ok_or_else(|| Error::InvalidEnumValueError {
1207             obj: "CapTlv".to_string(),
1208             field: "t".to_string(),
1209             value: t as u64,
1210             type_: "CapTlvType".to_string(),
1211         })?;
1212         if bytes.len() < 2 {
1213             return Err(Error::InvalidLengthError {
1214                 obj: "CapTlv".to_string(),
1215                 field: "v_count".to_string(),
1216                 wanted: 2,
1217                 got: bytes.len(),
1218             });
1219         }
1220         let v_count = u8::from_le_bytes([bytes[1]]);
1221         let want_ = 2 + ((v_count as usize) * 1);
1222         if bytes.len() < want_ {
1223             return Err(Error::InvalidLengthError {
1224                 obj: "CapTlv".to_string(),
1225                 field: "v".to_string(),
1226                 wanted: want_,
1227                 got: bytes.len(),
1228             });
1229         }
1230         let v: Vec<u8> = bytes[2..2 + ((v_count as usize) * 1)]
1231             .to_vec()
1232             .chunks_exact(1)
1233             .into_iter()
1234             .map(|i| u8::from_le_bytes([i[0]]))
1235             .collect();
1236         Ok(Self { t, v })
1237     }
write_to(&self, buffer: &mut [u8])1238     fn write_to(&self, buffer: &mut [u8]) {
1239         let t = self.t.to_u8().unwrap();
1240         buffer[0..1].copy_from_slice(&t.to_le_bytes()[0..1]);
1241         buffer[1..2].copy_from_slice(&(self.v.len() as u8).to_le_bytes());
1242         for (i, e) in self.v.iter().enumerate() {
1243             buffer[2 + i..2 + i + 1].copy_from_slice(&e.to_le_bytes())
1244         }
1245     }
get_total_size(&self) -> usize1246     fn get_total_size(&self) -> usize {
1247         let ret = 0;
1248         let ret = ret + 2;
1249         let ret = ret + (self.v.len() * ((/* Bits: */8 + /* Dynamic: */ 0) / 8));
1250         ret
1251     }
1252 }
1253 
1254 #[derive(Debug, Clone, PartialEq)]
1255 pub struct DeviceParameter {
1256     pub id: u8,
1257     pub value: Vec<u8>,
1258 }
1259 impl DeviceParameter {
conforms(bytes: &[u8]) -> bool1260     fn conforms(bytes: &[u8]) -> bool {
1261         if bytes.len() < 2 {
1262             return false;
1263         }
1264         true
1265     }
parse(bytes: &[u8]) -> Result<Self>1266     pub fn parse(bytes: &[u8]) -> Result<Self> {
1267         if bytes.len() < 1 {
1268             return Err(Error::InvalidLengthError {
1269                 obj: "DeviceParameter".to_string(),
1270                 field: "id".to_string(),
1271                 wanted: 1,
1272                 got: bytes.len(),
1273             });
1274         }
1275         let id = u8::from_le_bytes([bytes[0]]);
1276         if bytes.len() < 2 {
1277             return Err(Error::InvalidLengthError {
1278                 obj: "DeviceParameter".to_string(),
1279                 field: "value_count".to_string(),
1280                 wanted: 2,
1281                 got: bytes.len(),
1282             });
1283         }
1284         let value_count = u8::from_le_bytes([bytes[1]]);
1285         let want_ = 2 + ((value_count as usize) * 1);
1286         if bytes.len() < want_ {
1287             return Err(Error::InvalidLengthError {
1288                 obj: "DeviceParameter".to_string(),
1289                 field: "value".to_string(),
1290                 wanted: want_,
1291                 got: bytes.len(),
1292             });
1293         }
1294         let value: Vec<u8> = bytes[2..2 + ((value_count as usize) * 1)]
1295             .to_vec()
1296             .chunks_exact(1)
1297             .into_iter()
1298             .map(|i| u8::from_le_bytes([i[0]]))
1299             .collect();
1300         Ok(Self { id, value })
1301     }
write_to(&self, buffer: &mut [u8])1302     fn write_to(&self, buffer: &mut [u8]) {
1303         let id = self.id;
1304         buffer[0..1].copy_from_slice(&id.to_le_bytes()[0..1]);
1305         buffer[1..2].copy_from_slice(&(self.value.len() as u8).to_le_bytes());
1306         for (i, e) in self.value.iter().enumerate() {
1307             buffer[2 + i..2 + i + 1].copy_from_slice(&e.to_le_bytes())
1308         }
1309     }
get_total_size(&self) -> usize1310     fn get_total_size(&self) -> usize {
1311         let ret = 0;
1312         let ret = ret + 2;
1313         let ret = ret + (self.value.len() * ((/* Bits: */8 + /* Dynamic: */ 0) / 8));
1314         ret
1315     }
1316 }
1317 
1318 #[derive(Debug, Clone, PartialEq)]
1319 pub struct DeviceConfigStatus {
1320     pub parameter_id: u8,
1321     pub status: StatusCode,
1322 }
1323 impl DeviceConfigStatus {
conforms(bytes: &[u8]) -> bool1324     fn conforms(bytes: &[u8]) -> bool {
1325         if bytes.len() < 2 {
1326             return false;
1327         }
1328         true
1329     }
parse(bytes: &[u8]) -> Result<Self>1330     pub fn parse(bytes: &[u8]) -> Result<Self> {
1331         if bytes.len() < 1 {
1332             return Err(Error::InvalidLengthError {
1333                 obj: "DeviceConfigStatus".to_string(),
1334                 field: "parameter_id".to_string(),
1335                 wanted: 1,
1336                 got: bytes.len(),
1337             });
1338         }
1339         let parameter_id = u8::from_le_bytes([bytes[0]]);
1340         if bytes.len() < 2 {
1341             return Err(Error::InvalidLengthError {
1342                 obj: "DeviceConfigStatus".to_string(),
1343                 field: "status".to_string(),
1344                 wanted: 2,
1345                 got: bytes.len(),
1346             });
1347         }
1348         let status = u8::from_le_bytes([bytes[1]]);
1349         let status = StatusCode::from_u8(status).ok_or_else(|| Error::InvalidEnumValueError {
1350             obj: "DeviceConfigStatus".to_string(),
1351             field: "status".to_string(),
1352             value: status as u64,
1353             type_: "StatusCode".to_string(),
1354         })?;
1355         Ok(Self {
1356             parameter_id,
1357             status,
1358         })
1359     }
write_to(&self, buffer: &mut [u8])1360     fn write_to(&self, buffer: &mut [u8]) {
1361         let parameter_id = self.parameter_id;
1362         buffer[0..1].copy_from_slice(&parameter_id.to_le_bytes()[0..1]);
1363         let status = self.status.to_u8().unwrap();
1364         buffer[1..2].copy_from_slice(&status.to_le_bytes()[0..1]);
1365     }
get_total_size(&self) -> usize1366     fn get_total_size(&self) -> usize {
1367         let ret = 0;
1368         let ret = ret + 2;
1369         ret
1370     }
1371 }
1372 
1373 #[derive(Debug, Clone, PartialEq)]
1374 pub struct AppConfigParameter {
1375     pub id: u8,
1376     pub value: Vec<u8>,
1377 }
1378 impl AppConfigParameter {
conforms(bytes: &[u8]) -> bool1379     fn conforms(bytes: &[u8]) -> bool {
1380         if bytes.len() < 2 {
1381             return false;
1382         }
1383         true
1384     }
parse(bytes: &[u8]) -> Result<Self>1385     pub fn parse(bytes: &[u8]) -> Result<Self> {
1386         if bytes.len() < 1 {
1387             return Err(Error::InvalidLengthError {
1388                 obj: "AppConfigParameter".to_string(),
1389                 field: "id".to_string(),
1390                 wanted: 1,
1391                 got: bytes.len(),
1392             });
1393         }
1394         let id = u8::from_le_bytes([bytes[0]]);
1395         if bytes.len() < 2 {
1396             return Err(Error::InvalidLengthError {
1397                 obj: "AppConfigParameter".to_string(),
1398                 field: "value_count".to_string(),
1399                 wanted: 2,
1400                 got: bytes.len(),
1401             });
1402         }
1403         let value_count = u8::from_le_bytes([bytes[1]]);
1404         let want_ = 2 + ((value_count as usize) * 1);
1405         if bytes.len() < want_ {
1406             return Err(Error::InvalidLengthError {
1407                 obj: "AppConfigParameter".to_string(),
1408                 field: "value".to_string(),
1409                 wanted: want_,
1410                 got: bytes.len(),
1411             });
1412         }
1413         let value: Vec<u8> = bytes[2..2 + ((value_count as usize) * 1)]
1414             .to_vec()
1415             .chunks_exact(1)
1416             .into_iter()
1417             .map(|i| u8::from_le_bytes([i[0]]))
1418             .collect();
1419         Ok(Self { id, value })
1420     }
write_to(&self, buffer: &mut [u8])1421     fn write_to(&self, buffer: &mut [u8]) {
1422         let id = self.id;
1423         buffer[0..1].copy_from_slice(&id.to_le_bytes()[0..1]);
1424         buffer[1..2].copy_from_slice(&(self.value.len() as u8).to_le_bytes());
1425         for (i, e) in self.value.iter().enumerate() {
1426             buffer[2 + i..2 + i + 1].copy_from_slice(&e.to_le_bytes())
1427         }
1428     }
get_total_size(&self) -> usize1429     fn get_total_size(&self) -> usize {
1430         let ret = 0;
1431         let ret = ret + 2;
1432         let ret = ret + (self.value.len() * ((/* Bits: */8 + /* Dynamic: */ 0) / 8));
1433         ret
1434     }
1435 }
1436 
1437 #[derive(Debug, Clone, PartialEq)]
1438 pub struct AppConfigStatus {
1439     pub config_id: u8,
1440     pub status: StatusCode,
1441 }
1442 impl AppConfigStatus {
conforms(bytes: &[u8]) -> bool1443     fn conforms(bytes: &[u8]) -> bool {
1444         if bytes.len() < 2 {
1445             return false;
1446         }
1447         true
1448     }
parse(bytes: &[u8]) -> Result<Self>1449     pub fn parse(bytes: &[u8]) -> Result<Self> {
1450         if bytes.len() < 1 {
1451             return Err(Error::InvalidLengthError {
1452                 obj: "AppConfigStatus".to_string(),
1453                 field: "config_id".to_string(),
1454                 wanted: 1,
1455                 got: bytes.len(),
1456             });
1457         }
1458         let config_id = u8::from_le_bytes([bytes[0]]);
1459         if bytes.len() < 2 {
1460             return Err(Error::InvalidLengthError {
1461                 obj: "AppConfigStatus".to_string(),
1462                 field: "status".to_string(),
1463                 wanted: 2,
1464                 got: bytes.len(),
1465             });
1466         }
1467         let status = u8::from_le_bytes([bytes[1]]);
1468         let status = StatusCode::from_u8(status).ok_or_else(|| Error::InvalidEnumValueError {
1469             obj: "AppConfigStatus".to_string(),
1470             field: "status".to_string(),
1471             value: status as u64,
1472             type_: "StatusCode".to_string(),
1473         })?;
1474         Ok(Self { config_id, status })
1475     }
write_to(&self, buffer: &mut [u8])1476     fn write_to(&self, buffer: &mut [u8]) {
1477         let config_id = self.config_id;
1478         buffer[0..1].copy_from_slice(&config_id.to_le_bytes()[0..1]);
1479         let status = self.status.to_u8().unwrap();
1480         buffer[1..2].copy_from_slice(&status.to_le_bytes()[0..1]);
1481     }
get_total_size(&self) -> usize1482     fn get_total_size(&self) -> usize {
1483         let ret = 0;
1484         let ret = ret + 2;
1485         ret
1486     }
1487 }
1488 
1489 #[derive(Debug, Clone, PartialEq)]
1490 pub struct Controlee {
1491     pub short_address: u16,
1492     pub subsession_id: u32,
1493 }
1494 impl Controlee {
conforms(bytes: &[u8]) -> bool1495     fn conforms(bytes: &[u8]) -> bool {
1496         if bytes.len() < 6 {
1497             return false;
1498         }
1499         true
1500     }
parse(bytes: &[u8]) -> Result<Self>1501     pub fn parse(bytes: &[u8]) -> Result<Self> {
1502         if bytes.len() < 2 {
1503             return Err(Error::InvalidLengthError {
1504                 obj: "Controlee".to_string(),
1505                 field: "short_address".to_string(),
1506                 wanted: 2,
1507                 got: bytes.len(),
1508             });
1509         }
1510         let short_address = u16::from_le_bytes([bytes[0], bytes[1]]);
1511         if bytes.len() < 6 {
1512             return Err(Error::InvalidLengthError {
1513                 obj: "Controlee".to_string(),
1514                 field: "subsession_id".to_string(),
1515                 wanted: 6,
1516                 got: bytes.len(),
1517             });
1518         }
1519         let subsession_id = u32::from_le_bytes([bytes[2], bytes[3], bytes[4], bytes[5]]);
1520         Ok(Self {
1521             short_address,
1522             subsession_id,
1523         })
1524     }
write_to(&self, buffer: &mut [u8])1525     fn write_to(&self, buffer: &mut [u8]) {
1526         let short_address = self.short_address;
1527         buffer[0..2].copy_from_slice(&short_address.to_le_bytes()[0..2]);
1528         let subsession_id = self.subsession_id;
1529         buffer[2..6].copy_from_slice(&subsession_id.to_le_bytes()[0..4]);
1530     }
get_total_size(&self) -> usize1531     fn get_total_size(&self) -> usize {
1532         let ret = 0;
1533         let ret = ret + 6;
1534         ret
1535     }
1536 }
1537 
1538 #[derive(Debug, Clone, PartialEq)]
1539 pub struct ControleeStatus {
1540     pub mac_address: u16,
1541     pub subsession_id: u32,
1542     pub status: u8,
1543 }
1544 impl ControleeStatus {
conforms(bytes: &[u8]) -> bool1545     fn conforms(bytes: &[u8]) -> bool {
1546         if bytes.len() < 7 {
1547             return false;
1548         }
1549         true
1550     }
parse(bytes: &[u8]) -> Result<Self>1551     pub fn parse(bytes: &[u8]) -> Result<Self> {
1552         if bytes.len() < 2 {
1553             return Err(Error::InvalidLengthError {
1554                 obj: "ControleeStatus".to_string(),
1555                 field: "mac_address".to_string(),
1556                 wanted: 2,
1557                 got: bytes.len(),
1558             });
1559         }
1560         let mac_address = u16::from_le_bytes([bytes[0], bytes[1]]);
1561         if bytes.len() < 6 {
1562             return Err(Error::InvalidLengthError {
1563                 obj: "ControleeStatus".to_string(),
1564                 field: "subsession_id".to_string(),
1565                 wanted: 6,
1566                 got: bytes.len(),
1567             });
1568         }
1569         let subsession_id = u32::from_le_bytes([bytes[2], bytes[3], bytes[4], bytes[5]]);
1570         if bytes.len() < 7 {
1571             return Err(Error::InvalidLengthError {
1572                 obj: "ControleeStatus".to_string(),
1573                 field: "status".to_string(),
1574                 wanted: 7,
1575                 got: bytes.len(),
1576             });
1577         }
1578         let status = u8::from_le_bytes([bytes[6]]);
1579         Ok(Self {
1580             mac_address,
1581             subsession_id,
1582             status,
1583         })
1584     }
write_to(&self, buffer: &mut [u8])1585     fn write_to(&self, buffer: &mut [u8]) {
1586         let mac_address = self.mac_address;
1587         buffer[0..2].copy_from_slice(&mac_address.to_le_bytes()[0..2]);
1588         let subsession_id = self.subsession_id;
1589         buffer[2..6].copy_from_slice(&subsession_id.to_le_bytes()[0..4]);
1590         let status = self.status;
1591         buffer[6..7].copy_from_slice(&status.to_le_bytes()[0..1]);
1592     }
get_total_size(&self) -> usize1593     fn get_total_size(&self) -> usize {
1594         let ret = 0;
1595         let ret = ret + 7;
1596         ret
1597     }
1598 }
1599 
1600 #[derive(Debug, Clone, PartialEq)]
1601 pub struct ShortAddressTwoWayRangingMeasurement {
1602     pub mac_address: u16,
1603     pub status: StatusCode,
1604     pub nlos: u8,
1605     pub distance: u16,
1606     pub aoa_azimuth: u16,
1607     pub aoa_azimuth_fom: u8,
1608     pub aoa_elevation: u16,
1609     pub aoa_elevation_fom: u8,
1610     pub aoa_destination_azimuth: u16,
1611     pub aoa_destination_azimuth_fom: u8,
1612     pub aoa_destination_elevation: u16,
1613     pub aoa_destination_elevation_fom: u8,
1614     pub slot_index: u8,
1615 }
1616 impl ShortAddressTwoWayRangingMeasurement {
conforms(bytes: &[u8]) -> bool1617     fn conforms(bytes: &[u8]) -> bool {
1618         if bytes.len() < 31 {
1619             return false;
1620         }
1621         true
1622     }
parse(bytes: &[u8]) -> Result<Self>1623     pub fn parse(bytes: &[u8]) -> Result<Self> {
1624         if bytes.len() < 2 {
1625             return Err(Error::InvalidLengthError {
1626                 obj: "ShortAddressTwoWayRangingMeasurement".to_string(),
1627                 field: "mac_address".to_string(),
1628                 wanted: 2,
1629                 got: bytes.len(),
1630             });
1631         }
1632         let mac_address = u16::from_le_bytes([bytes[0], bytes[1]]);
1633         if bytes.len() < 3 {
1634             return Err(Error::InvalidLengthError {
1635                 obj: "ShortAddressTwoWayRangingMeasurement".to_string(),
1636                 field: "status".to_string(),
1637                 wanted: 3,
1638                 got: bytes.len(),
1639             });
1640         }
1641         let status = u8::from_le_bytes([bytes[2]]);
1642         let status = StatusCode::from_u8(status).ok_or_else(|| Error::InvalidEnumValueError {
1643             obj: "ShortAddressTwoWayRangingMeasurement".to_string(),
1644             field: "status".to_string(),
1645             value: status as u64,
1646             type_: "StatusCode".to_string(),
1647         })?;
1648         if bytes.len() < 4 {
1649             return Err(Error::InvalidLengthError {
1650                 obj: "ShortAddressTwoWayRangingMeasurement".to_string(),
1651                 field: "nlos".to_string(),
1652                 wanted: 4,
1653                 got: bytes.len(),
1654             });
1655         }
1656         let nlos = u8::from_le_bytes([bytes[3]]);
1657         if bytes.len() < 6 {
1658             return Err(Error::InvalidLengthError {
1659                 obj: "ShortAddressTwoWayRangingMeasurement".to_string(),
1660                 field: "distance".to_string(),
1661                 wanted: 6,
1662                 got: bytes.len(),
1663             });
1664         }
1665         let distance = u16::from_le_bytes([bytes[4], bytes[5]]);
1666         if bytes.len() < 8 {
1667             return Err(Error::InvalidLengthError {
1668                 obj: "ShortAddressTwoWayRangingMeasurement".to_string(),
1669                 field: "aoa_azimuth".to_string(),
1670                 wanted: 8,
1671                 got: bytes.len(),
1672             });
1673         }
1674         let aoa_azimuth = u16::from_le_bytes([bytes[6], bytes[7]]);
1675         if bytes.len() < 9 {
1676             return Err(Error::InvalidLengthError {
1677                 obj: "ShortAddressTwoWayRangingMeasurement".to_string(),
1678                 field: "aoa_azimuth_fom".to_string(),
1679                 wanted: 9,
1680                 got: bytes.len(),
1681             });
1682         }
1683         let aoa_azimuth_fom = u8::from_le_bytes([bytes[8]]);
1684         if bytes.len() < 11 {
1685             return Err(Error::InvalidLengthError {
1686                 obj: "ShortAddressTwoWayRangingMeasurement".to_string(),
1687                 field: "aoa_elevation".to_string(),
1688                 wanted: 11,
1689                 got: bytes.len(),
1690             });
1691         }
1692         let aoa_elevation = u16::from_le_bytes([bytes[9], bytes[10]]);
1693         if bytes.len() < 12 {
1694             return Err(Error::InvalidLengthError {
1695                 obj: "ShortAddressTwoWayRangingMeasurement".to_string(),
1696                 field: "aoa_elevation_fom".to_string(),
1697                 wanted: 12,
1698                 got: bytes.len(),
1699             });
1700         }
1701         let aoa_elevation_fom = u8::from_le_bytes([bytes[11]]);
1702         if bytes.len() < 14 {
1703             return Err(Error::InvalidLengthError {
1704                 obj: "ShortAddressTwoWayRangingMeasurement".to_string(),
1705                 field: "aoa_destination_azimuth".to_string(),
1706                 wanted: 14,
1707                 got: bytes.len(),
1708             });
1709         }
1710         let aoa_destination_azimuth = u16::from_le_bytes([bytes[12], bytes[13]]);
1711         if bytes.len() < 15 {
1712             return Err(Error::InvalidLengthError {
1713                 obj: "ShortAddressTwoWayRangingMeasurement".to_string(),
1714                 field: "aoa_destination_azimuth_fom".to_string(),
1715                 wanted: 15,
1716                 got: bytes.len(),
1717             });
1718         }
1719         let aoa_destination_azimuth_fom = u8::from_le_bytes([bytes[14]]);
1720         if bytes.len() < 17 {
1721             return Err(Error::InvalidLengthError {
1722                 obj: "ShortAddressTwoWayRangingMeasurement".to_string(),
1723                 field: "aoa_destination_elevation".to_string(),
1724                 wanted: 17,
1725                 got: bytes.len(),
1726             });
1727         }
1728         let aoa_destination_elevation = u16::from_le_bytes([bytes[15], bytes[16]]);
1729         if bytes.len() < 18 {
1730             return Err(Error::InvalidLengthError {
1731                 obj: "ShortAddressTwoWayRangingMeasurement".to_string(),
1732                 field: "aoa_destination_elevation_fom".to_string(),
1733                 wanted: 18,
1734                 got: bytes.len(),
1735             });
1736         }
1737         let aoa_destination_elevation_fom = u8::from_le_bytes([bytes[17]]);
1738         if bytes.len() < 19 {
1739             return Err(Error::InvalidLengthError {
1740                 obj: "ShortAddressTwoWayRangingMeasurement".to_string(),
1741                 field: "slot_index".to_string(),
1742                 wanted: 19,
1743                 got: bytes.len(),
1744             });
1745         }
1746         let slot_index = u8::from_le_bytes([bytes[18]]);
1747         Ok(Self {
1748             mac_address,
1749             status,
1750             nlos,
1751             distance,
1752             aoa_azimuth,
1753             aoa_azimuth_fom,
1754             aoa_elevation,
1755             aoa_elevation_fom,
1756             aoa_destination_azimuth,
1757             aoa_destination_azimuth_fom,
1758             aoa_destination_elevation,
1759             aoa_destination_elevation_fom,
1760             slot_index,
1761         })
1762     }
write_to(&self, buffer: &mut [u8])1763     fn write_to(&self, buffer: &mut [u8]) {
1764         let mac_address = self.mac_address;
1765         buffer[0..2].copy_from_slice(&mac_address.to_le_bytes()[0..2]);
1766         let status = self.status.to_u8().unwrap();
1767         buffer[2..3].copy_from_slice(&status.to_le_bytes()[0..1]);
1768         let nlos = self.nlos;
1769         buffer[3..4].copy_from_slice(&nlos.to_le_bytes()[0..1]);
1770         let distance = self.distance;
1771         buffer[4..6].copy_from_slice(&distance.to_le_bytes()[0..2]);
1772         let aoa_azimuth = self.aoa_azimuth;
1773         buffer[6..8].copy_from_slice(&aoa_azimuth.to_le_bytes()[0..2]);
1774         let aoa_azimuth_fom = self.aoa_azimuth_fom;
1775         buffer[8..9].copy_from_slice(&aoa_azimuth_fom.to_le_bytes()[0..1]);
1776         let aoa_elevation = self.aoa_elevation;
1777         buffer[9..11].copy_from_slice(&aoa_elevation.to_le_bytes()[0..2]);
1778         let aoa_elevation_fom = self.aoa_elevation_fom;
1779         buffer[11..12].copy_from_slice(&aoa_elevation_fom.to_le_bytes()[0..1]);
1780         let aoa_destination_azimuth = self.aoa_destination_azimuth;
1781         buffer[12..14].copy_from_slice(&aoa_destination_azimuth.to_le_bytes()[0..2]);
1782         let aoa_destination_azimuth_fom = self.aoa_destination_azimuth_fom;
1783         buffer[14..15].copy_from_slice(&aoa_destination_azimuth_fom.to_le_bytes()[0..1]);
1784         let aoa_destination_elevation = self.aoa_destination_elevation;
1785         buffer[15..17].copy_from_slice(&aoa_destination_elevation.to_le_bytes()[0..2]);
1786         let aoa_destination_elevation_fom = self.aoa_destination_elevation_fom;
1787         buffer[17..18].copy_from_slice(&aoa_destination_elevation_fom.to_le_bytes()[0..1]);
1788         let slot_index = self.slot_index;
1789         buffer[18..19].copy_from_slice(&slot_index.to_le_bytes()[0..1]);
1790     }
get_total_size(&self) -> usize1791     fn get_total_size(&self) -> usize {
1792         let ret = 0;
1793         let ret = ret + 31;
1794         ret
1795     }
1796 }
1797 
1798 #[derive(Debug, Clone, PartialEq)]
1799 pub struct ExtendedAddressTwoWayRangingMeasurement {
1800     pub mac_address: u64,
1801     pub status: StatusCode,
1802     pub nlos: u8,
1803     pub distance: u16,
1804     pub aoa_azimuth: u16,
1805     pub aoa_azimuth_fom: u8,
1806     pub aoa_elevation: u16,
1807     pub aoa_elevation_fom: u8,
1808     pub aoa_destination_azimuth: u16,
1809     pub aoa_destination_azimuth_fom: u8,
1810     pub aoa_destination_elevation: u16,
1811     pub aoa_destination_elevation_fom: u8,
1812     pub slot_index: u8,
1813 }
1814 impl ExtendedAddressTwoWayRangingMeasurement {
conforms(bytes: &[u8]) -> bool1815     fn conforms(bytes: &[u8]) -> bool {
1816         if bytes.len() < 31 {
1817             return false;
1818         }
1819         true
1820     }
parse(bytes: &[u8]) -> Result<Self>1821     pub fn parse(bytes: &[u8]) -> Result<Self> {
1822         if bytes.len() < 8 {
1823             return Err(Error::InvalidLengthError {
1824                 obj: "ExtendedAddressTwoWayRangingMeasurement".to_string(),
1825                 field: "mac_address".to_string(),
1826                 wanted: 8,
1827                 got: bytes.len(),
1828             });
1829         }
1830         let mac_address = u64::from_le_bytes([
1831             bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7],
1832         ]);
1833         if bytes.len() < 9 {
1834             return Err(Error::InvalidLengthError {
1835                 obj: "ExtendedAddressTwoWayRangingMeasurement".to_string(),
1836                 field: "status".to_string(),
1837                 wanted: 9,
1838                 got: bytes.len(),
1839             });
1840         }
1841         let status = u8::from_le_bytes([bytes[8]]);
1842         let status = StatusCode::from_u8(status).ok_or_else(|| Error::InvalidEnumValueError {
1843             obj: "ExtendedAddressTwoWayRangingMeasurement".to_string(),
1844             field: "status".to_string(),
1845             value: status as u64,
1846             type_: "StatusCode".to_string(),
1847         })?;
1848         if bytes.len() < 10 {
1849             return Err(Error::InvalidLengthError {
1850                 obj: "ExtendedAddressTwoWayRangingMeasurement".to_string(),
1851                 field: "nlos".to_string(),
1852                 wanted: 10,
1853                 got: bytes.len(),
1854             });
1855         }
1856         let nlos = u8::from_le_bytes([bytes[9]]);
1857         if bytes.len() < 12 {
1858             return Err(Error::InvalidLengthError {
1859                 obj: "ExtendedAddressTwoWayRangingMeasurement".to_string(),
1860                 field: "distance".to_string(),
1861                 wanted: 12,
1862                 got: bytes.len(),
1863             });
1864         }
1865         let distance = u16::from_le_bytes([bytes[10], bytes[11]]);
1866         if bytes.len() < 14 {
1867             return Err(Error::InvalidLengthError {
1868                 obj: "ExtendedAddressTwoWayRangingMeasurement".to_string(),
1869                 field: "aoa_azimuth".to_string(),
1870                 wanted: 14,
1871                 got: bytes.len(),
1872             });
1873         }
1874         let aoa_azimuth = u16::from_le_bytes([bytes[12], bytes[13]]);
1875         if bytes.len() < 15 {
1876             return Err(Error::InvalidLengthError {
1877                 obj: "ExtendedAddressTwoWayRangingMeasurement".to_string(),
1878                 field: "aoa_azimuth_fom".to_string(),
1879                 wanted: 15,
1880                 got: bytes.len(),
1881             });
1882         }
1883         let aoa_azimuth_fom = u8::from_le_bytes([bytes[14]]);
1884         if bytes.len() < 17 {
1885             return Err(Error::InvalidLengthError {
1886                 obj: "ExtendedAddressTwoWayRangingMeasurement".to_string(),
1887                 field: "aoa_elevation".to_string(),
1888                 wanted: 17,
1889                 got: bytes.len(),
1890             });
1891         }
1892         let aoa_elevation = u16::from_le_bytes([bytes[15], bytes[16]]);
1893         if bytes.len() < 18 {
1894             return Err(Error::InvalidLengthError {
1895                 obj: "ExtendedAddressTwoWayRangingMeasurement".to_string(),
1896                 field: "aoa_elevation_fom".to_string(),
1897                 wanted: 18,
1898                 got: bytes.len(),
1899             });
1900         }
1901         let aoa_elevation_fom = u8::from_le_bytes([bytes[17]]);
1902         if bytes.len() < 20 {
1903             return Err(Error::InvalidLengthError {
1904                 obj: "ExtendedAddressTwoWayRangingMeasurement".to_string(),
1905                 field: "aoa_destination_azimuth".to_string(),
1906                 wanted: 20,
1907                 got: bytes.len(),
1908             });
1909         }
1910         let aoa_destination_azimuth = u16::from_le_bytes([bytes[18], bytes[19]]);
1911         if bytes.len() < 21 {
1912             return Err(Error::InvalidLengthError {
1913                 obj: "ExtendedAddressTwoWayRangingMeasurement".to_string(),
1914                 field: "aoa_destination_azimuth_fom".to_string(),
1915                 wanted: 21,
1916                 got: bytes.len(),
1917             });
1918         }
1919         let aoa_destination_azimuth_fom = u8::from_le_bytes([bytes[20]]);
1920         if bytes.len() < 23 {
1921             return Err(Error::InvalidLengthError {
1922                 obj: "ExtendedAddressTwoWayRangingMeasurement".to_string(),
1923                 field: "aoa_destination_elevation".to_string(),
1924                 wanted: 23,
1925                 got: bytes.len(),
1926             });
1927         }
1928         let aoa_destination_elevation = u16::from_le_bytes([bytes[21], bytes[22]]);
1929         if bytes.len() < 24 {
1930             return Err(Error::InvalidLengthError {
1931                 obj: "ExtendedAddressTwoWayRangingMeasurement".to_string(),
1932                 field: "aoa_destination_elevation_fom".to_string(),
1933                 wanted: 24,
1934                 got: bytes.len(),
1935             });
1936         }
1937         let aoa_destination_elevation_fom = u8::from_le_bytes([bytes[23]]);
1938         if bytes.len() < 25 {
1939             return Err(Error::InvalidLengthError {
1940                 obj: "ExtendedAddressTwoWayRangingMeasurement".to_string(),
1941                 field: "slot_index".to_string(),
1942                 wanted: 25,
1943                 got: bytes.len(),
1944             });
1945         }
1946         let slot_index = u8::from_le_bytes([bytes[24]]);
1947         Ok(Self {
1948             mac_address,
1949             status,
1950             nlos,
1951             distance,
1952             aoa_azimuth,
1953             aoa_azimuth_fom,
1954             aoa_elevation,
1955             aoa_elevation_fom,
1956             aoa_destination_azimuth,
1957             aoa_destination_azimuth_fom,
1958             aoa_destination_elevation,
1959             aoa_destination_elevation_fom,
1960             slot_index,
1961         })
1962     }
write_to(&self, buffer: &mut [u8])1963     fn write_to(&self, buffer: &mut [u8]) {
1964         let mac_address = self.mac_address;
1965         buffer[0..8].copy_from_slice(&mac_address.to_le_bytes()[0..8]);
1966         let status = self.status.to_u8().unwrap();
1967         buffer[8..9].copy_from_slice(&status.to_le_bytes()[0..1]);
1968         let nlos = self.nlos;
1969         buffer[9..10].copy_from_slice(&nlos.to_le_bytes()[0..1]);
1970         let distance = self.distance;
1971         buffer[10..12].copy_from_slice(&distance.to_le_bytes()[0..2]);
1972         let aoa_azimuth = self.aoa_azimuth;
1973         buffer[12..14].copy_from_slice(&aoa_azimuth.to_le_bytes()[0..2]);
1974         let aoa_azimuth_fom = self.aoa_azimuth_fom;
1975         buffer[14..15].copy_from_slice(&aoa_azimuth_fom.to_le_bytes()[0..1]);
1976         let aoa_elevation = self.aoa_elevation;
1977         buffer[15..17].copy_from_slice(&aoa_elevation.to_le_bytes()[0..2]);
1978         let aoa_elevation_fom = self.aoa_elevation_fom;
1979         buffer[17..18].copy_from_slice(&aoa_elevation_fom.to_le_bytes()[0..1]);
1980         let aoa_destination_azimuth = self.aoa_destination_azimuth;
1981         buffer[18..20].copy_from_slice(&aoa_destination_azimuth.to_le_bytes()[0..2]);
1982         let aoa_destination_azimuth_fom = self.aoa_destination_azimuth_fom;
1983         buffer[20..21].copy_from_slice(&aoa_destination_azimuth_fom.to_le_bytes()[0..1]);
1984         let aoa_destination_elevation = self.aoa_destination_elevation;
1985         buffer[21..23].copy_from_slice(&aoa_destination_elevation.to_le_bytes()[0..2]);
1986         let aoa_destination_elevation_fom = self.aoa_destination_elevation_fom;
1987         buffer[23..24].copy_from_slice(&aoa_destination_elevation_fom.to_le_bytes()[0..1]);
1988         let slot_index = self.slot_index;
1989         buffer[24..25].copy_from_slice(&slot_index.to_le_bytes()[0..1]);
1990     }
get_total_size(&self) -> usize1991     fn get_total_size(&self) -> usize {
1992         let ret = 0;
1993         let ret = ret + 31;
1994         ret
1995     }
1996 }
1997 
1998 #[derive(Debug, Clone, PartialEq)]
1999 pub struct PicaPosition {
2000     pub x: u16,
2001     pub y: u16,
2002     pub z: u16,
2003     pub yaw: u16,
2004     pub pitch: u8,
2005     pub roll: u16,
2006 }
2007 impl PicaPosition {
conforms(bytes: &[u8]) -> bool2008     fn conforms(bytes: &[u8]) -> bool {
2009         if bytes.len() < 11 {
2010             return false;
2011         }
2012         true
2013     }
parse(bytes: &[u8]) -> Result<Self>2014     pub fn parse(bytes: &[u8]) -> Result<Self> {
2015         if bytes.len() < 2 {
2016             return Err(Error::InvalidLengthError {
2017                 obj: "PicaPosition".to_string(),
2018                 field: "x".to_string(),
2019                 wanted: 2,
2020                 got: bytes.len(),
2021             });
2022         }
2023         let x = u16::from_le_bytes([bytes[0], bytes[1]]);
2024         if bytes.len() < 4 {
2025             return Err(Error::InvalidLengthError {
2026                 obj: "PicaPosition".to_string(),
2027                 field: "y".to_string(),
2028                 wanted: 4,
2029                 got: bytes.len(),
2030             });
2031         }
2032         let y = u16::from_le_bytes([bytes[2], bytes[3]]);
2033         if bytes.len() < 6 {
2034             return Err(Error::InvalidLengthError {
2035                 obj: "PicaPosition".to_string(),
2036                 field: "z".to_string(),
2037                 wanted: 6,
2038                 got: bytes.len(),
2039             });
2040         }
2041         let z = u16::from_le_bytes([bytes[4], bytes[5]]);
2042         if bytes.len() < 8 {
2043             return Err(Error::InvalidLengthError {
2044                 obj: "PicaPosition".to_string(),
2045                 field: "yaw".to_string(),
2046                 wanted: 8,
2047                 got: bytes.len(),
2048             });
2049         }
2050         let yaw = u16::from_le_bytes([bytes[6], bytes[7]]);
2051         if bytes.len() < 9 {
2052             return Err(Error::InvalidLengthError {
2053                 obj: "PicaPosition".to_string(),
2054                 field: "pitch".to_string(),
2055                 wanted: 9,
2056                 got: bytes.len(),
2057             });
2058         }
2059         let pitch = u8::from_le_bytes([bytes[8]]);
2060         if bytes.len() < 11 {
2061             return Err(Error::InvalidLengthError {
2062                 obj: "PicaPosition".to_string(),
2063                 field: "roll".to_string(),
2064                 wanted: 11,
2065                 got: bytes.len(),
2066             });
2067         }
2068         let roll = u16::from_le_bytes([bytes[9], bytes[10]]);
2069         Ok(Self {
2070             x,
2071             y,
2072             z,
2073             yaw,
2074             pitch,
2075             roll,
2076         })
2077     }
write_to(&self, buffer: &mut [u8])2078     fn write_to(&self, buffer: &mut [u8]) {
2079         let x = self.x;
2080         buffer[0..2].copy_from_slice(&x.to_le_bytes()[0..2]);
2081         let y = self.y;
2082         buffer[2..4].copy_from_slice(&y.to_le_bytes()[0..2]);
2083         let z = self.z;
2084         buffer[4..6].copy_from_slice(&z.to_le_bytes()[0..2]);
2085         let yaw = self.yaw;
2086         buffer[6..8].copy_from_slice(&yaw.to_le_bytes()[0..2]);
2087         let pitch = self.pitch;
2088         buffer[8..9].copy_from_slice(&pitch.to_le_bytes()[0..1]);
2089         let roll = self.roll;
2090         buffer[9..11].copy_from_slice(&roll.to_le_bytes()[0..2]);
2091     }
get_total_size(&self) -> usize2092     fn get_total_size(&self) -> usize {
2093         let ret = 0;
2094         let ret = ret + 11;
2095         ret
2096     }
2097 }
2098 
2099 #[derive(Debug, Clone, PartialEq)]
2100 pub struct PowerStats {
2101     pub status: StatusCode,
2102     pub idle_time_ms: u32,
2103     pub tx_time_ms: u32,
2104     pub rx_time_ms: u32,
2105     pub total_wake_count: u32,
2106 }
2107 impl PowerStats {
conforms(bytes: &[u8]) -> bool2108     fn conforms(bytes: &[u8]) -> bool {
2109         if bytes.len() < 17 {
2110             return false;
2111         }
2112         true
2113     }
parse(bytes: &[u8]) -> Result<Self>2114     pub fn parse(bytes: &[u8]) -> Result<Self> {
2115         if bytes.len() < 1 {
2116             return Err(Error::InvalidLengthError {
2117                 obj: "PowerStats".to_string(),
2118                 field: "status".to_string(),
2119                 wanted: 1,
2120                 got: bytes.len(),
2121             });
2122         }
2123         let status = u8::from_le_bytes([bytes[0]]);
2124         let status = StatusCode::from_u8(status).ok_or_else(|| Error::InvalidEnumValueError {
2125             obj: "PowerStats".to_string(),
2126             field: "status".to_string(),
2127             value: status as u64,
2128             type_: "StatusCode".to_string(),
2129         })?;
2130         if bytes.len() < 5 {
2131             return Err(Error::InvalidLengthError {
2132                 obj: "PowerStats".to_string(),
2133                 field: "idle_time_ms".to_string(),
2134                 wanted: 5,
2135                 got: bytes.len(),
2136             });
2137         }
2138         let idle_time_ms = u32::from_le_bytes([bytes[1], bytes[2], bytes[3], bytes[4]]);
2139         if bytes.len() < 9 {
2140             return Err(Error::InvalidLengthError {
2141                 obj: "PowerStats".to_string(),
2142                 field: "tx_time_ms".to_string(),
2143                 wanted: 9,
2144                 got: bytes.len(),
2145             });
2146         }
2147         let tx_time_ms = u32::from_le_bytes([bytes[5], bytes[6], bytes[7], bytes[8]]);
2148         if bytes.len() < 13 {
2149             return Err(Error::InvalidLengthError {
2150                 obj: "PowerStats".to_string(),
2151                 field: "rx_time_ms".to_string(),
2152                 wanted: 13,
2153                 got: bytes.len(),
2154             });
2155         }
2156         let rx_time_ms = u32::from_le_bytes([bytes[9], bytes[10], bytes[11], bytes[12]]);
2157         if bytes.len() < 17 {
2158             return Err(Error::InvalidLengthError {
2159                 obj: "PowerStats".to_string(),
2160                 field: "total_wake_count".to_string(),
2161                 wanted: 17,
2162                 got: bytes.len(),
2163             });
2164         }
2165         let total_wake_count = u32::from_le_bytes([bytes[13], bytes[14], bytes[15], bytes[16]]);
2166         Ok(Self {
2167             status,
2168             idle_time_ms,
2169             tx_time_ms,
2170             rx_time_ms,
2171             total_wake_count,
2172         })
2173     }
write_to(&self, buffer: &mut [u8])2174     fn write_to(&self, buffer: &mut [u8]) {
2175         let status = self.status.to_u8().unwrap();
2176         buffer[0..1].copy_from_slice(&status.to_le_bytes()[0..1]);
2177         let idle_time_ms = self.idle_time_ms;
2178         buffer[1..5].copy_from_slice(&idle_time_ms.to_le_bytes()[0..4]);
2179         let tx_time_ms = self.tx_time_ms;
2180         buffer[5..9].copy_from_slice(&tx_time_ms.to_le_bytes()[0..4]);
2181         let rx_time_ms = self.rx_time_ms;
2182         buffer[9..13].copy_from_slice(&rx_time_ms.to_le_bytes()[0..4]);
2183         let total_wake_count = self.total_wake_count;
2184         buffer[13..17].copy_from_slice(&total_wake_count.to_le_bytes()[0..4]);
2185     }
get_total_size(&self) -> usize2186     fn get_total_size(&self) -> usize {
2187         let ret = 0;
2188         let ret = ret + 17;
2189         ret
2190     }
2191 }
2192 
2193 #[derive(Debug)]
2194 enum UciPacketDataChild {
2195     UciCommand(Arc<UciCommandData>),
2196     UciResponse(Arc<UciResponseData>),
2197     UciNotification(Arc<UciNotificationData>),
2198     Payload(Bytes),
2199     None,
2200 }
2201 impl UciPacketDataChild {
get_total_size(&self) -> usize2202     fn get_total_size(&self) -> usize {
2203         match self {
2204             UciPacketDataChild::UciCommand(value) => value.get_total_size(),
2205             UciPacketDataChild::UciResponse(value) => value.get_total_size(),
2206             UciPacketDataChild::UciNotification(value) => value.get_total_size(),
2207             UciPacketDataChild::Payload(p) => p.len(),
2208             UciPacketDataChild::None => 0,
2209         }
2210     }
2211 }
2212 #[derive(Debug)]
2213 pub enum UciPacketChild {
2214     UciCommand(UciCommandPacket),
2215     UciResponse(UciResponsePacket),
2216     UciNotification(UciNotificationPacket),
2217     Payload(Bytes),
2218     None,
2219 }
2220 #[derive(Debug)]
2221 struct UciPacketData {
2222     group_id: GroupId,
2223     packet_boundary_flag: PacketBoundaryFlag,
2224     message_type: MessageType,
2225     opcode: u8,
2226     child: UciPacketDataChild,
2227 }
2228 #[derive(Debug, Clone)]
2229 pub struct UciPacketPacket {
2230     uci_packet: Arc<UciPacketData>,
2231 }
2232 #[derive(Debug)]
2233 pub struct UciPacketBuilder {
2234     pub group_id: GroupId,
2235     pub packet_boundary_flag: PacketBoundaryFlag,
2236     pub message_type: MessageType,
2237     pub opcode: u8,
2238     pub payload: Option<Bytes>,
2239 }
2240 impl UciPacketData {
conforms(bytes: &[u8]) -> bool2241     fn conforms(bytes: &[u8]) -> bool {
2242         if bytes.len() < 4 {
2243             return false;
2244         }
2245         true
2246     }
parse(bytes: &[u8]) -> Result<Self>2247     fn parse(bytes: &[u8]) -> Result<Self> {
2248         let group_id = u8::from_le_bytes([bytes[0]]);
2249         let group_id = group_id & 0xf;
2250         let group_id = GroupId::from_u8(group_id).ok_or_else(|| Error::InvalidEnumValueError {
2251             obj: "UciPacket".to_string(),
2252             field: "group_id".to_string(),
2253             value: group_id as u64,
2254             type_: "GroupId".to_string(),
2255         })?;
2256         let packet_boundary_flag = u8::from_le_bytes([bytes[0]]);
2257         let packet_boundary_flag = packet_boundary_flag >> 4;
2258         let packet_boundary_flag = packet_boundary_flag & 0x1;
2259         let packet_boundary_flag =
2260             PacketBoundaryFlag::from_u8(packet_boundary_flag).ok_or_else(|| {
2261                 Error::InvalidEnumValueError {
2262                     obj: "UciPacket".to_string(),
2263                     field: "packet_boundary_flag".to_string(),
2264                     value: packet_boundary_flag as u64,
2265                     type_: "PacketBoundaryFlag".to_string(),
2266                 }
2267             })?;
2268         let message_type = u8::from_le_bytes([bytes[0]]);
2269         let message_type = message_type >> 5;
2270         let message_type = message_type & 0x7;
2271         let message_type =
2272             MessageType::from_u8(message_type).ok_or_else(|| Error::InvalidEnumValueError {
2273                 obj: "UciPacket".to_string(),
2274                 field: "message_type".to_string(),
2275                 value: message_type as u64,
2276                 type_: "MessageType".to_string(),
2277             })?;
2278         let opcode = u8::from_le_bytes([bytes[1]]);
2279         let opcode = opcode & 0x3f;
2280         if bytes.len() < 4 {
2281             return Err(Error::InvalidLengthError {
2282                 obj: "UciPacket".to_string(),
2283                 field: "payload_size".to_string(),
2284                 wanted: 4,
2285                 got: bytes.len(),
2286             });
2287         }
2288         let payload_size = u8::from_le_bytes([bytes[3]]);
2289         let want_ = 4 + (payload_size as usize);
2290         if bytes.len() < want_ {
2291             return Err(Error::InvalidLengthError {
2292                 obj: "UciPacket".to_string(),
2293                 field: "payload".to_string(),
2294                 wanted: want_,
2295                 got: bytes.len(),
2296             });
2297         }
2298         let payload: Vec<u8> = bytes[4..(4 + payload_size as usize)].into();
2299         let child = match (packet_boundary_flag, message_type) {
2300             (PacketBoundaryFlag::Complete, MessageType::Command)
2301                 if UciCommandData::conforms(&bytes[..]) =>
2302             {
2303                 UciPacketDataChild::UciCommand(Arc::new(UciCommandData::parse(
2304                     &bytes[..],
2305                     group_id,
2306                     opcode,
2307                 )?))
2308             }
2309             (PacketBoundaryFlag::Complete, MessageType::Response)
2310                 if UciResponseData::conforms(&bytes[..]) =>
2311             {
2312                 UciPacketDataChild::UciResponse(Arc::new(UciResponseData::parse(
2313                     &bytes[..],
2314                     group_id,
2315                     opcode,
2316                 )?))
2317             }
2318             (PacketBoundaryFlag::Complete, MessageType::Notification)
2319                 if UciNotificationData::conforms(&bytes[..]) =>
2320             {
2321                 UciPacketDataChild::UciNotification(Arc::new(UciNotificationData::parse(
2322                     &bytes[..],
2323                     group_id,
2324                     opcode,
2325                 )?))
2326             }
2327             (_, _) => return Err(Error::InvalidPacketError),
2328         };
2329         Ok(Self {
2330             group_id,
2331             packet_boundary_flag,
2332             message_type,
2333             opcode,
2334             child,
2335         })
2336     }
write_to(&self, buffer: &mut BytesMut)2337     fn write_to(&self, buffer: &mut BytesMut) {
2338         let group_id = self.group_id.to_u8().unwrap();
2339         let group_id = group_id & 0xf;
2340         buffer[0..1].copy_from_slice(&group_id.to_le_bytes()[0..1]);
2341         let packet_boundary_flag = self.packet_boundary_flag.to_u8().unwrap();
2342         let packet_boundary_flag = packet_boundary_flag & 0x1;
2343         let packet_boundary_flag = (packet_boundary_flag << 4) | ((buffer[0] as u8) & 0xf);
2344         buffer[0..1].copy_from_slice(&packet_boundary_flag.to_le_bytes()[0..1]);
2345         let message_type = self.message_type.to_u8().unwrap();
2346         let message_type = message_type & 0x7;
2347         let message_type = (message_type << 5) | ((buffer[0] as u8) & 0x1f);
2348         buffer[0..1].copy_from_slice(&message_type.to_le_bytes()[0..1]);
2349         let opcode = self.opcode;
2350         let opcode = opcode & 0x3f;
2351         buffer[1..2].copy_from_slice(&opcode.to_le_bytes()[0..1]);
2352         let payload_size =
2353             u8::try_from(self.child.get_total_size()).expect("payload size did not fit");
2354         buffer[3..4].copy_from_slice(&payload_size.to_le_bytes()[0..1]);
2355         match &self.child {
2356             UciPacketDataChild::UciCommand(value) => value.write_to(buffer),
2357             UciPacketDataChild::UciResponse(value) => value.write_to(buffer),
2358             UciPacketDataChild::UciNotification(value) => value.write_to(buffer),
2359             UciPacketDataChild::Payload(p) => buffer[4..].copy_from_slice(&p[..]),
2360             UciPacketDataChild::None => {}
2361         }
2362     }
get_total_size(&self) -> usize2363     fn get_total_size(&self) -> usize {
2364         self.get_size() + self.child.get_total_size()
2365     }
get_size(&self) -> usize2366     fn get_size(&self) -> usize {
2367         let ret = 0;
2368         let ret = ret + 4;
2369         ret
2370     }
2371 }
2372 impl Packet for UciPacketPacket {
to_bytes(self) -> Bytes2373     fn to_bytes(self) -> Bytes {
2374         let mut buffer = BytesMut::new();
2375         buffer.resize(self.uci_packet.get_total_size(), 0);
2376         self.uci_packet.write_to(&mut buffer);
2377         buffer.freeze()
2378     }
to_vec(self) -> Vec<u8>2379     fn to_vec(self) -> Vec<u8> {
2380         self.to_bytes().to_vec()
2381     }
2382 }
2383 impl From<UciPacketPacket> for Bytes {
from(packet: UciPacketPacket) -> Self2384     fn from(packet: UciPacketPacket) -> Self {
2385         packet.to_bytes()
2386     }
2387 }
2388 impl From<UciPacketPacket> for Vec<u8> {
from(packet: UciPacketPacket) -> Self2389     fn from(packet: UciPacketPacket) -> Self {
2390         packet.to_vec()
2391     }
2392 }
2393 impl UciPacketPacket {
parse(bytes: &[u8]) -> Result<Self>2394     pub fn parse(bytes: &[u8]) -> Result<Self> {
2395         Ok(Self::new(Arc::new(UciPacketData::parse(bytes)?)).unwrap())
2396     }
specialize(&self) -> UciPacketChild2397     pub fn specialize(&self) -> UciPacketChild {
2398         match &self.uci_packet.child {
2399             UciPacketDataChild::UciCommand(_) => {
2400                 UciPacketChild::UciCommand(UciCommandPacket::new(self.uci_packet.clone()).unwrap())
2401             }
2402             UciPacketDataChild::UciResponse(_) => UciPacketChild::UciResponse(
2403                 UciResponsePacket::new(self.uci_packet.clone()).unwrap(),
2404             ),
2405             UciPacketDataChild::UciNotification(_) => UciPacketChild::UciNotification(
2406                 UciNotificationPacket::new(self.uci_packet.clone()).unwrap(),
2407             ),
2408             UciPacketDataChild::Payload(p) => UciPacketChild::Payload(p.clone()),
2409             UciPacketDataChild::None => UciPacketChild::None,
2410         }
2411     }
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>2412     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
2413         let uci_packet = root;
2414         Ok(Self { uci_packet })
2415     }
get_group_id(&self) -> GroupId2416     pub fn get_group_id(&self) -> GroupId {
2417         self.uci_packet.as_ref().group_id
2418     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag2419     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
2420         self.uci_packet.as_ref().packet_boundary_flag
2421     }
get_message_type(&self) -> MessageType2422     pub fn get_message_type(&self) -> MessageType {
2423         self.uci_packet.as_ref().message_type
2424     }
get_opcode(&self) -> u82425     pub fn get_opcode(&self) -> u8 {
2426         self.uci_packet.as_ref().opcode
2427     }
2428 }
2429 impl UciPacketBuilder {
build(self) -> UciPacketPacket2430     pub fn build(self) -> UciPacketPacket {
2431         let uci_packet = Arc::new(UciPacketData {
2432             group_id: self.group_id,
2433             packet_boundary_flag: self.packet_boundary_flag,
2434             message_type: self.message_type,
2435             opcode: self.opcode,
2436             child: match self.payload {
2437                 None => UciPacketDataChild::None,
2438                 Some(bytes) => UciPacketDataChild::Payload(bytes),
2439             },
2440         });
2441         UciPacketPacket::new(uci_packet).unwrap()
2442     }
2443 }
2444 
2445 #[derive(Debug)]
2446 enum UciCommandDataChild {
2447     CoreCommand(Arc<CoreCommandData>),
2448     SessionCommand(Arc<SessionCommandData>),
2449     RangingCommand(Arc<RangingCommandData>),
2450     AndroidCommand(Arc<AndroidCommandData>),
2451     UciVendor_A_Command(Arc<UciVendor_A_CommandData>),
2452     UciVendor_B_Command(Arc<UciVendor_B_CommandData>),
2453     UciVendor_E_Command(Arc<UciVendor_E_CommandData>),
2454     UciVendor_F_Command(Arc<UciVendor_F_CommandData>),
2455     Payload(Bytes),
2456     None,
2457 }
2458 impl UciCommandDataChild {
get_total_size(&self) -> usize2459     fn get_total_size(&self) -> usize {
2460         match self {
2461             UciCommandDataChild::CoreCommand(value) => value.get_total_size(),
2462             UciCommandDataChild::SessionCommand(value) => value.get_total_size(),
2463             UciCommandDataChild::RangingCommand(value) => value.get_total_size(),
2464             UciCommandDataChild::AndroidCommand(value) => value.get_total_size(),
2465             UciCommandDataChild::UciVendor_A_Command(value) => value.get_total_size(),
2466             UciCommandDataChild::UciVendor_B_Command(value) => value.get_total_size(),
2467             UciCommandDataChild::UciVendor_E_Command(value) => value.get_total_size(),
2468             UciCommandDataChild::UciVendor_F_Command(value) => value.get_total_size(),
2469             UciCommandDataChild::Payload(p) => p.len(),
2470             UciCommandDataChild::None => 0,
2471         }
2472     }
2473 }
2474 #[derive(Debug)]
2475 pub enum UciCommandChild {
2476     CoreCommand(CoreCommandPacket),
2477     SessionCommand(SessionCommandPacket),
2478     RangingCommand(RangingCommandPacket),
2479     AndroidCommand(AndroidCommandPacket),
2480     UciVendor_A_Command(UciVendor_A_CommandPacket),
2481     UciVendor_B_Command(UciVendor_B_CommandPacket),
2482     UciVendor_E_Command(UciVendor_E_CommandPacket),
2483     UciVendor_F_Command(UciVendor_F_CommandPacket),
2484     Payload(Bytes),
2485     None,
2486 }
2487 #[derive(Debug)]
2488 struct UciCommandData {
2489     child: UciCommandDataChild,
2490 }
2491 #[derive(Debug, Clone)]
2492 pub struct UciCommandPacket {
2493     uci_packet: Arc<UciPacketData>,
2494     uci_command: Arc<UciCommandData>,
2495 }
2496 #[derive(Debug)]
2497 pub struct UciCommandBuilder {
2498     pub group_id: GroupId,
2499     pub opcode: u8,
2500     pub payload: Option<Bytes>,
2501 }
2502 impl UciCommandData {
conforms(bytes: &[u8]) -> bool2503     fn conforms(bytes: &[u8]) -> bool {
2504         if bytes.len() < 4 {
2505             return false;
2506         }
2507         true
2508     }
parse(bytes: &[u8], group_id: GroupId, opcode: u8) -> Result<Self>2509     fn parse(bytes: &[u8], group_id: GroupId, opcode: u8) -> Result<Self> {
2510         let payload: Vec<u8> = bytes[4..].into();
2511         let child = match (group_id) {
2512             (GroupId::Core) if CoreCommandData::conforms(&bytes[..]) => {
2513                 UciCommandDataChild::CoreCommand(Arc::new(CoreCommandData::parse(
2514                     &bytes[..],
2515                     opcode,
2516                 )?))
2517             }
2518             (GroupId::SessionConfig) if SessionCommandData::conforms(&bytes[..]) => {
2519                 UciCommandDataChild::SessionCommand(Arc::new(SessionCommandData::parse(
2520                     &bytes[..],
2521                     opcode,
2522                 )?))
2523             }
2524             (GroupId::RangingSessionControl) if RangingCommandData::conforms(&bytes[..]) => {
2525                 UciCommandDataChild::RangingCommand(Arc::new(RangingCommandData::parse(
2526                     &bytes[..],
2527                     opcode,
2528                 )?))
2529             }
2530             (GroupId::VendorAndroid) if AndroidCommandData::conforms(&bytes[..]) => {
2531                 UciCommandDataChild::AndroidCommand(Arc::new(AndroidCommandData::parse(
2532                     &bytes[..],
2533                     opcode,
2534                 )?))
2535             }
2536             (GroupId::VendorReservedA) if UciVendor_A_CommandData::conforms(&bytes[..]) => {
2537                 UciCommandDataChild::UciVendor_A_Command(Arc::new(UciVendor_A_CommandData::parse(
2538                     &bytes[..],
2539                 )?))
2540             }
2541             (GroupId::VendorReservedB) if UciVendor_B_CommandData::conforms(&bytes[..]) => {
2542                 UciCommandDataChild::UciVendor_B_Command(Arc::new(UciVendor_B_CommandData::parse(
2543                     &bytes[..],
2544                 )?))
2545             }
2546             (GroupId::VendorReservedE) if UciVendor_E_CommandData::conforms(&bytes[..]) => {
2547                 UciCommandDataChild::UciVendor_E_Command(Arc::new(UciVendor_E_CommandData::parse(
2548                     &bytes[..],
2549                 )?))
2550             }
2551             (GroupId::VendorReservedF) if UciVendor_F_CommandData::conforms(&bytes[..]) => {
2552                 UciCommandDataChild::UciVendor_F_Command(Arc::new(UciVendor_F_CommandData::parse(
2553                     &bytes[..],
2554                 )?))
2555             }
2556             (_) => return Err(Error::InvalidPacketError),
2557         };
2558         Ok(Self { child })
2559     }
write_to(&self, buffer: &mut BytesMut)2560     fn write_to(&self, buffer: &mut BytesMut) {
2561         match &self.child {
2562             UciCommandDataChild::CoreCommand(value) => value.write_to(buffer),
2563             UciCommandDataChild::SessionCommand(value) => value.write_to(buffer),
2564             UciCommandDataChild::RangingCommand(value) => value.write_to(buffer),
2565             UciCommandDataChild::AndroidCommand(value) => value.write_to(buffer),
2566             UciCommandDataChild::UciVendor_A_Command(value) => value.write_to(buffer),
2567             UciCommandDataChild::UciVendor_B_Command(value) => value.write_to(buffer),
2568             UciCommandDataChild::UciVendor_E_Command(value) => value.write_to(buffer),
2569             UciCommandDataChild::UciVendor_F_Command(value) => value.write_to(buffer),
2570             UciCommandDataChild::Payload(p) => buffer[4..].copy_from_slice(&p[..]),
2571             UciCommandDataChild::None => {}
2572         }
2573     }
get_total_size(&self) -> usize2574     fn get_total_size(&self) -> usize {
2575         self.get_size() + self.child.get_total_size()
2576     }
get_size(&self) -> usize2577     fn get_size(&self) -> usize {
2578         let ret = 0;
2579         ret
2580     }
2581 }
2582 impl Packet for UciCommandPacket {
to_bytes(self) -> Bytes2583     fn to_bytes(self) -> Bytes {
2584         let mut buffer = BytesMut::new();
2585         buffer.resize(self.uci_packet.get_total_size(), 0);
2586         self.uci_packet.write_to(&mut buffer);
2587         buffer.freeze()
2588     }
to_vec(self) -> Vec<u8>2589     fn to_vec(self) -> Vec<u8> {
2590         self.to_bytes().to_vec()
2591     }
2592 }
2593 impl From<UciCommandPacket> for Bytes {
from(packet: UciCommandPacket) -> Self2594     fn from(packet: UciCommandPacket) -> Self {
2595         packet.to_bytes()
2596     }
2597 }
2598 impl From<UciCommandPacket> for Vec<u8> {
from(packet: UciCommandPacket) -> Self2599     fn from(packet: UciCommandPacket) -> Self {
2600         packet.to_vec()
2601     }
2602 }
2603 impl TryFrom<UciPacketPacket> for UciCommandPacket {
2604     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>2605     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
2606         Self::new(value.uci_packet).map_err(TryFromError)
2607     }
2608 }
2609 impl UciCommandPacket {
specialize(&self) -> UciCommandChild2610     pub fn specialize(&self) -> UciCommandChild {
2611         match &self.uci_command.child {
2612             UciCommandDataChild::CoreCommand(_) => UciCommandChild::CoreCommand(
2613                 CoreCommandPacket::new(self.uci_packet.clone()).unwrap(),
2614             ),
2615             UciCommandDataChild::SessionCommand(_) => UciCommandChild::SessionCommand(
2616                 SessionCommandPacket::new(self.uci_packet.clone()).unwrap(),
2617             ),
2618             UciCommandDataChild::RangingCommand(_) => UciCommandChild::RangingCommand(
2619                 RangingCommandPacket::new(self.uci_packet.clone()).unwrap(),
2620             ),
2621             UciCommandDataChild::AndroidCommand(_) => UciCommandChild::AndroidCommand(
2622                 AndroidCommandPacket::new(self.uci_packet.clone()).unwrap(),
2623             ),
2624             UciCommandDataChild::UciVendor_A_Command(_) => UciCommandChild::UciVendor_A_Command(
2625                 UciVendor_A_CommandPacket::new(self.uci_packet.clone()).unwrap(),
2626             ),
2627             UciCommandDataChild::UciVendor_B_Command(_) => UciCommandChild::UciVendor_B_Command(
2628                 UciVendor_B_CommandPacket::new(self.uci_packet.clone()).unwrap(),
2629             ),
2630             UciCommandDataChild::UciVendor_E_Command(_) => UciCommandChild::UciVendor_E_Command(
2631                 UciVendor_E_CommandPacket::new(self.uci_packet.clone()).unwrap(),
2632             ),
2633             UciCommandDataChild::UciVendor_F_Command(_) => UciCommandChild::UciVendor_F_Command(
2634                 UciVendor_F_CommandPacket::new(self.uci_packet.clone()).unwrap(),
2635             ),
2636             UciCommandDataChild::Payload(p) => UciCommandChild::Payload(p.clone()),
2637             UciCommandDataChild::None => UciCommandChild::None,
2638         }
2639     }
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>2640     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
2641         let uci_packet = root;
2642         let uci_command = match &uci_packet.child {
2643             UciPacketDataChild::UciCommand(value) => (*value).clone(),
2644             _ => return Err("inconsistent state - child was not UciCommand"),
2645         };
2646         Ok(Self {
2647             uci_packet,
2648             uci_command,
2649         })
2650     }
get_group_id(&self) -> GroupId2651     pub fn get_group_id(&self) -> GroupId {
2652         self.uci_packet.as_ref().group_id
2653     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag2654     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
2655         self.uci_packet.as_ref().packet_boundary_flag
2656     }
get_message_type(&self) -> MessageType2657     pub fn get_message_type(&self) -> MessageType {
2658         self.uci_packet.as_ref().message_type
2659     }
get_opcode(&self) -> u82660     pub fn get_opcode(&self) -> u8 {
2661         self.uci_packet.as_ref().opcode
2662     }
2663 }
2664 impl Into<UciPacketPacket> for UciCommandPacket {
into(self) -> UciPacketPacket2665     fn into(self) -> UciPacketPacket {
2666         UciPacketPacket::new(self.uci_packet).unwrap()
2667     }
2668 }
2669 impl UciCommandBuilder {
build(self) -> UciCommandPacket2670     pub fn build(self) -> UciCommandPacket {
2671         let uci_command = Arc::new(UciCommandData {
2672             child: match self.payload {
2673                 None => UciCommandDataChild::None,
2674                 Some(bytes) => UciCommandDataChild::Payload(bytes),
2675             },
2676         });
2677         let uci_packet = Arc::new(UciPacketData {
2678             group_id: self.group_id,
2679             packet_boundary_flag: PacketBoundaryFlag::Complete,
2680             message_type: MessageType::Command,
2681             opcode: self.opcode,
2682             child: UciPacketDataChild::UciCommand(uci_command),
2683         });
2684         UciCommandPacket::new(uci_packet).unwrap()
2685     }
2686 }
2687 impl Into<UciPacketPacket> for UciCommandBuilder {
into(self) -> UciPacketPacket2688     fn into(self) -> UciPacketPacket {
2689         self.build().into()
2690     }
2691 }
2692 
2693 #[derive(Debug)]
2694 enum UciResponseDataChild {
2695     CoreResponse(Arc<CoreResponseData>),
2696     SessionResponse(Arc<SessionResponseData>),
2697     RangingResponse(Arc<RangingResponseData>),
2698     AndroidResponse(Arc<AndroidResponseData>),
2699     UciVendor_A_Response(Arc<UciVendor_A_ResponseData>),
2700     UciVendor_B_Response(Arc<UciVendor_B_ResponseData>),
2701     UciVendor_E_Response(Arc<UciVendor_E_ResponseData>),
2702     UciVendor_F_Response(Arc<UciVendor_F_ResponseData>),
2703     Payload(Bytes),
2704     None,
2705 }
2706 impl UciResponseDataChild {
get_total_size(&self) -> usize2707     fn get_total_size(&self) -> usize {
2708         match self {
2709             UciResponseDataChild::CoreResponse(value) => value.get_total_size(),
2710             UciResponseDataChild::SessionResponse(value) => value.get_total_size(),
2711             UciResponseDataChild::RangingResponse(value) => value.get_total_size(),
2712             UciResponseDataChild::AndroidResponse(value) => value.get_total_size(),
2713             UciResponseDataChild::UciVendor_A_Response(value) => value.get_total_size(),
2714             UciResponseDataChild::UciVendor_B_Response(value) => value.get_total_size(),
2715             UciResponseDataChild::UciVendor_E_Response(value) => value.get_total_size(),
2716             UciResponseDataChild::UciVendor_F_Response(value) => value.get_total_size(),
2717             UciResponseDataChild::Payload(p) => p.len(),
2718             UciResponseDataChild::None => 0,
2719         }
2720     }
2721 }
2722 #[derive(Debug)]
2723 pub enum UciResponseChild {
2724     CoreResponse(CoreResponsePacket),
2725     SessionResponse(SessionResponsePacket),
2726     RangingResponse(RangingResponsePacket),
2727     AndroidResponse(AndroidResponsePacket),
2728     UciVendor_A_Response(UciVendor_A_ResponsePacket),
2729     UciVendor_B_Response(UciVendor_B_ResponsePacket),
2730     UciVendor_E_Response(UciVendor_E_ResponsePacket),
2731     UciVendor_F_Response(UciVendor_F_ResponsePacket),
2732     Payload(Bytes),
2733     None,
2734 }
2735 #[derive(Debug)]
2736 struct UciResponseData {
2737     child: UciResponseDataChild,
2738 }
2739 #[derive(Debug, Clone)]
2740 pub struct UciResponsePacket {
2741     uci_packet: Arc<UciPacketData>,
2742     uci_response: Arc<UciResponseData>,
2743 }
2744 #[derive(Debug)]
2745 pub struct UciResponseBuilder {
2746     pub group_id: GroupId,
2747     pub opcode: u8,
2748     pub payload: Option<Bytes>,
2749 }
2750 impl UciResponseData {
conforms(bytes: &[u8]) -> bool2751     fn conforms(bytes: &[u8]) -> bool {
2752         if bytes.len() < 4 {
2753             return false;
2754         }
2755         true
2756     }
parse(bytes: &[u8], group_id: GroupId, opcode: u8) -> Result<Self>2757     fn parse(bytes: &[u8], group_id: GroupId, opcode: u8) -> Result<Self> {
2758         let payload: Vec<u8> = bytes[4..].into();
2759         let child = match (group_id) {
2760             (GroupId::Core) if CoreResponseData::conforms(&bytes[..]) => {
2761                 UciResponseDataChild::CoreResponse(Arc::new(CoreResponseData::parse(
2762                     &bytes[..],
2763                     opcode,
2764                 )?))
2765             }
2766             (GroupId::SessionConfig) if SessionResponseData::conforms(&bytes[..]) => {
2767                 UciResponseDataChild::SessionResponse(Arc::new(SessionResponseData::parse(
2768                     &bytes[..],
2769                     opcode,
2770                 )?))
2771             }
2772             (GroupId::RangingSessionControl) if RangingResponseData::conforms(&bytes[..]) => {
2773                 UciResponseDataChild::RangingResponse(Arc::new(RangingResponseData::parse(
2774                     &bytes[..],
2775                     opcode,
2776                 )?))
2777             }
2778             (GroupId::VendorAndroid) if AndroidResponseData::conforms(&bytes[..]) => {
2779                 UciResponseDataChild::AndroidResponse(Arc::new(AndroidResponseData::parse(
2780                     &bytes[..],
2781                     opcode,
2782                 )?))
2783             }
2784             (GroupId::VendorReservedA) if UciVendor_A_ResponseData::conforms(&bytes[..]) => {
2785                 UciResponseDataChild::UciVendor_A_Response(Arc::new(
2786                     UciVendor_A_ResponseData::parse(&bytes[..])?,
2787                 ))
2788             }
2789             (GroupId::VendorReservedB) if UciVendor_B_ResponseData::conforms(&bytes[..]) => {
2790                 UciResponseDataChild::UciVendor_B_Response(Arc::new(
2791                     UciVendor_B_ResponseData::parse(&bytes[..])?,
2792                 ))
2793             }
2794             (GroupId::VendorReservedE) if UciVendor_E_ResponseData::conforms(&bytes[..]) => {
2795                 UciResponseDataChild::UciVendor_E_Response(Arc::new(
2796                     UciVendor_E_ResponseData::parse(&bytes[..])?,
2797                 ))
2798             }
2799             (GroupId::VendorReservedF) if UciVendor_F_ResponseData::conforms(&bytes[..]) => {
2800                 UciResponseDataChild::UciVendor_F_Response(Arc::new(
2801                     UciVendor_F_ResponseData::parse(&bytes[..])?,
2802                 ))
2803             }
2804             (_) => return Err(Error::InvalidPacketError),
2805         };
2806         Ok(Self { child })
2807     }
write_to(&self, buffer: &mut BytesMut)2808     fn write_to(&self, buffer: &mut BytesMut) {
2809         match &self.child {
2810             UciResponseDataChild::CoreResponse(value) => value.write_to(buffer),
2811             UciResponseDataChild::SessionResponse(value) => value.write_to(buffer),
2812             UciResponseDataChild::RangingResponse(value) => value.write_to(buffer),
2813             UciResponseDataChild::AndroidResponse(value) => value.write_to(buffer),
2814             UciResponseDataChild::UciVendor_A_Response(value) => value.write_to(buffer),
2815             UciResponseDataChild::UciVendor_B_Response(value) => value.write_to(buffer),
2816             UciResponseDataChild::UciVendor_E_Response(value) => value.write_to(buffer),
2817             UciResponseDataChild::UciVendor_F_Response(value) => value.write_to(buffer),
2818             UciResponseDataChild::Payload(p) => buffer[4..].copy_from_slice(&p[..]),
2819             UciResponseDataChild::None => {}
2820         }
2821     }
get_total_size(&self) -> usize2822     fn get_total_size(&self) -> usize {
2823         self.get_size() + self.child.get_total_size()
2824     }
get_size(&self) -> usize2825     fn get_size(&self) -> usize {
2826         let ret = 0;
2827         ret
2828     }
2829 }
2830 impl Packet for UciResponsePacket {
to_bytes(self) -> Bytes2831     fn to_bytes(self) -> Bytes {
2832         let mut buffer = BytesMut::new();
2833         buffer.resize(self.uci_packet.get_total_size(), 0);
2834         self.uci_packet.write_to(&mut buffer);
2835         buffer.freeze()
2836     }
to_vec(self) -> Vec<u8>2837     fn to_vec(self) -> Vec<u8> {
2838         self.to_bytes().to_vec()
2839     }
2840 }
2841 impl From<UciResponsePacket> for Bytes {
from(packet: UciResponsePacket) -> Self2842     fn from(packet: UciResponsePacket) -> Self {
2843         packet.to_bytes()
2844     }
2845 }
2846 impl From<UciResponsePacket> for Vec<u8> {
from(packet: UciResponsePacket) -> Self2847     fn from(packet: UciResponsePacket) -> Self {
2848         packet.to_vec()
2849     }
2850 }
2851 impl TryFrom<UciPacketPacket> for UciResponsePacket {
2852     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>2853     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
2854         Self::new(value.uci_packet).map_err(TryFromError)
2855     }
2856 }
2857 impl UciResponsePacket {
specialize(&self) -> UciResponseChild2858     pub fn specialize(&self) -> UciResponseChild {
2859         match &self.uci_response.child {
2860             UciResponseDataChild::CoreResponse(_) => UciResponseChild::CoreResponse(
2861                 CoreResponsePacket::new(self.uci_packet.clone()).unwrap(),
2862             ),
2863             UciResponseDataChild::SessionResponse(_) => UciResponseChild::SessionResponse(
2864                 SessionResponsePacket::new(self.uci_packet.clone()).unwrap(),
2865             ),
2866             UciResponseDataChild::RangingResponse(_) => UciResponseChild::RangingResponse(
2867                 RangingResponsePacket::new(self.uci_packet.clone()).unwrap(),
2868             ),
2869             UciResponseDataChild::AndroidResponse(_) => UciResponseChild::AndroidResponse(
2870                 AndroidResponsePacket::new(self.uci_packet.clone()).unwrap(),
2871             ),
2872             UciResponseDataChild::UciVendor_A_Response(_) => {
2873                 UciResponseChild::UciVendor_A_Response(
2874                     UciVendor_A_ResponsePacket::new(self.uci_packet.clone()).unwrap(),
2875                 )
2876             }
2877             UciResponseDataChild::UciVendor_B_Response(_) => {
2878                 UciResponseChild::UciVendor_B_Response(
2879                     UciVendor_B_ResponsePacket::new(self.uci_packet.clone()).unwrap(),
2880                 )
2881             }
2882             UciResponseDataChild::UciVendor_E_Response(_) => {
2883                 UciResponseChild::UciVendor_E_Response(
2884                     UciVendor_E_ResponsePacket::new(self.uci_packet.clone()).unwrap(),
2885                 )
2886             }
2887             UciResponseDataChild::UciVendor_F_Response(_) => {
2888                 UciResponseChild::UciVendor_F_Response(
2889                     UciVendor_F_ResponsePacket::new(self.uci_packet.clone()).unwrap(),
2890                 )
2891             }
2892             UciResponseDataChild::Payload(p) => UciResponseChild::Payload(p.clone()),
2893             UciResponseDataChild::None => UciResponseChild::None,
2894         }
2895     }
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>2896     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
2897         let uci_packet = root;
2898         let uci_response = match &uci_packet.child {
2899             UciPacketDataChild::UciResponse(value) => (*value).clone(),
2900             _ => return Err("inconsistent state - child was not UciResponse"),
2901         };
2902         Ok(Self {
2903             uci_packet,
2904             uci_response,
2905         })
2906     }
get_group_id(&self) -> GroupId2907     pub fn get_group_id(&self) -> GroupId {
2908         self.uci_packet.as_ref().group_id
2909     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag2910     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
2911         self.uci_packet.as_ref().packet_boundary_flag
2912     }
get_message_type(&self) -> MessageType2913     pub fn get_message_type(&self) -> MessageType {
2914         self.uci_packet.as_ref().message_type
2915     }
get_opcode(&self) -> u82916     pub fn get_opcode(&self) -> u8 {
2917         self.uci_packet.as_ref().opcode
2918     }
2919 }
2920 impl Into<UciPacketPacket> for UciResponsePacket {
into(self) -> UciPacketPacket2921     fn into(self) -> UciPacketPacket {
2922         UciPacketPacket::new(self.uci_packet).unwrap()
2923     }
2924 }
2925 impl UciResponseBuilder {
build(self) -> UciResponsePacket2926     pub fn build(self) -> UciResponsePacket {
2927         let uci_response = Arc::new(UciResponseData {
2928             child: match self.payload {
2929                 None => UciResponseDataChild::None,
2930                 Some(bytes) => UciResponseDataChild::Payload(bytes),
2931             },
2932         });
2933         let uci_packet = Arc::new(UciPacketData {
2934             group_id: self.group_id,
2935             packet_boundary_flag: PacketBoundaryFlag::Complete,
2936             message_type: MessageType::Response,
2937             opcode: self.opcode,
2938             child: UciPacketDataChild::UciResponse(uci_response),
2939         });
2940         UciResponsePacket::new(uci_packet).unwrap()
2941     }
2942 }
2943 impl Into<UciPacketPacket> for UciResponseBuilder {
into(self) -> UciPacketPacket2944     fn into(self) -> UciPacketPacket {
2945         self.build().into()
2946     }
2947 }
2948 
2949 #[derive(Debug)]
2950 enum UciNotificationDataChild {
2951     CoreNotification(Arc<CoreNotificationData>),
2952     SessionNotification(Arc<SessionNotificationData>),
2953     RangingNotification(Arc<RangingNotificationData>),
2954     AndroidNotification(Arc<AndroidNotificationData>),
2955     UciVendor_A_Notification(Arc<UciVendor_A_NotificationData>),
2956     UciVendor_B_Notification(Arc<UciVendor_B_NotificationData>),
2957     UciVendor_E_Notification(Arc<UciVendor_E_NotificationData>),
2958     UciVendor_F_Notification(Arc<UciVendor_F_NotificationData>),
2959     Payload(Bytes),
2960     None,
2961 }
2962 impl UciNotificationDataChild {
get_total_size(&self) -> usize2963     fn get_total_size(&self) -> usize {
2964         match self {
2965             UciNotificationDataChild::CoreNotification(value) => value.get_total_size(),
2966             UciNotificationDataChild::SessionNotification(value) => value.get_total_size(),
2967             UciNotificationDataChild::RangingNotification(value) => value.get_total_size(),
2968             UciNotificationDataChild::AndroidNotification(value) => value.get_total_size(),
2969             UciNotificationDataChild::UciVendor_A_Notification(value) => value.get_total_size(),
2970             UciNotificationDataChild::UciVendor_B_Notification(value) => value.get_total_size(),
2971             UciNotificationDataChild::UciVendor_E_Notification(value) => value.get_total_size(),
2972             UciNotificationDataChild::UciVendor_F_Notification(value) => value.get_total_size(),
2973             UciNotificationDataChild::Payload(p) => p.len(),
2974             UciNotificationDataChild::None => 0,
2975         }
2976     }
2977 }
2978 #[derive(Debug)]
2979 pub enum UciNotificationChild {
2980     CoreNotification(CoreNotificationPacket),
2981     SessionNotification(SessionNotificationPacket),
2982     RangingNotification(RangingNotificationPacket),
2983     AndroidNotification(AndroidNotificationPacket),
2984     UciVendor_A_Notification(UciVendor_A_NotificationPacket),
2985     UciVendor_B_Notification(UciVendor_B_NotificationPacket),
2986     UciVendor_E_Notification(UciVendor_E_NotificationPacket),
2987     UciVendor_F_Notification(UciVendor_F_NotificationPacket),
2988     Payload(Bytes),
2989     None,
2990 }
2991 #[derive(Debug)]
2992 struct UciNotificationData {
2993     child: UciNotificationDataChild,
2994 }
2995 #[derive(Debug, Clone)]
2996 pub struct UciNotificationPacket {
2997     uci_packet: Arc<UciPacketData>,
2998     uci_notification: Arc<UciNotificationData>,
2999 }
3000 #[derive(Debug)]
3001 pub struct UciNotificationBuilder {
3002     pub group_id: GroupId,
3003     pub opcode: u8,
3004     pub payload: Option<Bytes>,
3005 }
3006 impl UciNotificationData {
conforms(bytes: &[u8]) -> bool3007     fn conforms(bytes: &[u8]) -> bool {
3008         if bytes.len() < 4 {
3009             return false;
3010         }
3011         true
3012     }
parse(bytes: &[u8], group_id: GroupId, opcode: u8) -> Result<Self>3013     fn parse(bytes: &[u8], group_id: GroupId, opcode: u8) -> Result<Self> {
3014         let payload: Vec<u8> = bytes[4..].into();
3015         let child = match (group_id) {
3016             (GroupId::Core) if CoreNotificationData::conforms(&bytes[..]) => {
3017                 UciNotificationDataChild::CoreNotification(Arc::new(CoreNotificationData::parse(
3018                     &bytes[..],
3019                     opcode,
3020                 )?))
3021             }
3022             (GroupId::SessionConfig) if SessionNotificationData::conforms(&bytes[..]) => {
3023                 UciNotificationDataChild::SessionNotification(Arc::new(
3024                     SessionNotificationData::parse(&bytes[..], opcode)?,
3025                 ))
3026             }
3027             (GroupId::RangingSessionControl) if RangingNotificationData::conforms(&bytes[..]) => {
3028                 UciNotificationDataChild::RangingNotification(Arc::new(
3029                     RangingNotificationData::parse(&bytes[..], opcode)?,
3030                 ))
3031             }
3032             (GroupId::VendorAndroid) if AndroidNotificationData::conforms(&bytes[..]) => {
3033                 UciNotificationDataChild::AndroidNotification(Arc::new(
3034                     AndroidNotificationData::parse(&bytes[..])?,
3035                 ))
3036             }
3037             (GroupId::VendorReservedA) if UciVendor_A_NotificationData::conforms(&bytes[..]) => {
3038                 UciNotificationDataChild::UciVendor_A_Notification(Arc::new(
3039                     UciVendor_A_NotificationData::parse(&bytes[..])?,
3040                 ))
3041             }
3042             (GroupId::VendorReservedB) if UciVendor_B_NotificationData::conforms(&bytes[..]) => {
3043                 UciNotificationDataChild::UciVendor_B_Notification(Arc::new(
3044                     UciVendor_B_NotificationData::parse(&bytes[..])?,
3045                 ))
3046             }
3047             (GroupId::VendorReservedE) if UciVendor_E_NotificationData::conforms(&bytes[..]) => {
3048                 UciNotificationDataChild::UciVendor_E_Notification(Arc::new(
3049                     UciVendor_E_NotificationData::parse(&bytes[..])?,
3050                 ))
3051             }
3052             (GroupId::VendorReservedF) if UciVendor_F_NotificationData::conforms(&bytes[..]) => {
3053                 UciNotificationDataChild::UciVendor_F_Notification(Arc::new(
3054                     UciVendor_F_NotificationData::parse(&bytes[..])?,
3055                 ))
3056             }
3057             (_) => return Err(Error::InvalidPacketError),
3058         };
3059         Ok(Self { child })
3060     }
write_to(&self, buffer: &mut BytesMut)3061     fn write_to(&self, buffer: &mut BytesMut) {
3062         match &self.child {
3063             UciNotificationDataChild::CoreNotification(value) => value.write_to(buffer),
3064             UciNotificationDataChild::SessionNotification(value) => value.write_to(buffer),
3065             UciNotificationDataChild::RangingNotification(value) => value.write_to(buffer),
3066             UciNotificationDataChild::AndroidNotification(value) => value.write_to(buffer),
3067             UciNotificationDataChild::UciVendor_A_Notification(value) => value.write_to(buffer),
3068             UciNotificationDataChild::UciVendor_B_Notification(value) => value.write_to(buffer),
3069             UciNotificationDataChild::UciVendor_E_Notification(value) => value.write_to(buffer),
3070             UciNotificationDataChild::UciVendor_F_Notification(value) => value.write_to(buffer),
3071             UciNotificationDataChild::Payload(p) => buffer[4..].copy_from_slice(&p[..]),
3072             UciNotificationDataChild::None => {}
3073         }
3074     }
get_total_size(&self) -> usize3075     fn get_total_size(&self) -> usize {
3076         self.get_size() + self.child.get_total_size()
3077     }
get_size(&self) -> usize3078     fn get_size(&self) -> usize {
3079         let ret = 0;
3080         ret
3081     }
3082 }
3083 impl Packet for UciNotificationPacket {
to_bytes(self) -> Bytes3084     fn to_bytes(self) -> Bytes {
3085         let mut buffer = BytesMut::new();
3086         buffer.resize(self.uci_packet.get_total_size(), 0);
3087         self.uci_packet.write_to(&mut buffer);
3088         buffer.freeze()
3089     }
to_vec(self) -> Vec<u8>3090     fn to_vec(self) -> Vec<u8> {
3091         self.to_bytes().to_vec()
3092     }
3093 }
3094 impl From<UciNotificationPacket> for Bytes {
from(packet: UciNotificationPacket) -> Self3095     fn from(packet: UciNotificationPacket) -> Self {
3096         packet.to_bytes()
3097     }
3098 }
3099 impl From<UciNotificationPacket> for Vec<u8> {
from(packet: UciNotificationPacket) -> Self3100     fn from(packet: UciNotificationPacket) -> Self {
3101         packet.to_vec()
3102     }
3103 }
3104 impl TryFrom<UciPacketPacket> for UciNotificationPacket {
3105     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>3106     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
3107         Self::new(value.uci_packet).map_err(TryFromError)
3108     }
3109 }
3110 impl UciNotificationPacket {
specialize(&self) -> UciNotificationChild3111     pub fn specialize(&self) -> UciNotificationChild {
3112         match &self.uci_notification.child {
3113             UciNotificationDataChild::CoreNotification(_) => {
3114                 UciNotificationChild::CoreNotification(
3115                     CoreNotificationPacket::new(self.uci_packet.clone()).unwrap(),
3116                 )
3117             }
3118             UciNotificationDataChild::SessionNotification(_) => {
3119                 UciNotificationChild::SessionNotification(
3120                     SessionNotificationPacket::new(self.uci_packet.clone()).unwrap(),
3121                 )
3122             }
3123             UciNotificationDataChild::RangingNotification(_) => {
3124                 UciNotificationChild::RangingNotification(
3125                     RangingNotificationPacket::new(self.uci_packet.clone()).unwrap(),
3126                 )
3127             }
3128             UciNotificationDataChild::AndroidNotification(_) => {
3129                 UciNotificationChild::AndroidNotification(
3130                     AndroidNotificationPacket::new(self.uci_packet.clone()).unwrap(),
3131                 )
3132             }
3133             UciNotificationDataChild::UciVendor_A_Notification(_) => {
3134                 UciNotificationChild::UciVendor_A_Notification(
3135                     UciVendor_A_NotificationPacket::new(self.uci_packet.clone()).unwrap(),
3136                 )
3137             }
3138             UciNotificationDataChild::UciVendor_B_Notification(_) => {
3139                 UciNotificationChild::UciVendor_B_Notification(
3140                     UciVendor_B_NotificationPacket::new(self.uci_packet.clone()).unwrap(),
3141                 )
3142             }
3143             UciNotificationDataChild::UciVendor_E_Notification(_) => {
3144                 UciNotificationChild::UciVendor_E_Notification(
3145                     UciVendor_E_NotificationPacket::new(self.uci_packet.clone()).unwrap(),
3146                 )
3147             }
3148             UciNotificationDataChild::UciVendor_F_Notification(_) => {
3149                 UciNotificationChild::UciVendor_F_Notification(
3150                     UciVendor_F_NotificationPacket::new(self.uci_packet.clone()).unwrap(),
3151                 )
3152             }
3153             UciNotificationDataChild::Payload(p) => UciNotificationChild::Payload(p.clone()),
3154             UciNotificationDataChild::None => UciNotificationChild::None,
3155         }
3156     }
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>3157     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
3158         let uci_packet = root;
3159         let uci_notification = match &uci_packet.child {
3160             UciPacketDataChild::UciNotification(value) => (*value).clone(),
3161             _ => return Err("inconsistent state - child was not UciNotification"),
3162         };
3163         Ok(Self {
3164             uci_packet,
3165             uci_notification,
3166         })
3167     }
get_group_id(&self) -> GroupId3168     pub fn get_group_id(&self) -> GroupId {
3169         self.uci_packet.as_ref().group_id
3170     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag3171     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
3172         self.uci_packet.as_ref().packet_boundary_flag
3173     }
get_message_type(&self) -> MessageType3174     pub fn get_message_type(&self) -> MessageType {
3175         self.uci_packet.as_ref().message_type
3176     }
get_opcode(&self) -> u83177     pub fn get_opcode(&self) -> u8 {
3178         self.uci_packet.as_ref().opcode
3179     }
3180 }
3181 impl Into<UciPacketPacket> for UciNotificationPacket {
into(self) -> UciPacketPacket3182     fn into(self) -> UciPacketPacket {
3183         UciPacketPacket::new(self.uci_packet).unwrap()
3184     }
3185 }
3186 impl UciNotificationBuilder {
build(self) -> UciNotificationPacket3187     pub fn build(self) -> UciNotificationPacket {
3188         let uci_notification = Arc::new(UciNotificationData {
3189             child: match self.payload {
3190                 None => UciNotificationDataChild::None,
3191                 Some(bytes) => UciNotificationDataChild::Payload(bytes),
3192             },
3193         });
3194         let uci_packet = Arc::new(UciPacketData {
3195             group_id: self.group_id,
3196             packet_boundary_flag: PacketBoundaryFlag::Complete,
3197             message_type: MessageType::Notification,
3198             opcode: self.opcode,
3199             child: UciPacketDataChild::UciNotification(uci_notification),
3200         });
3201         UciNotificationPacket::new(uci_packet).unwrap()
3202     }
3203 }
3204 impl Into<UciPacketPacket> for UciNotificationBuilder {
into(self) -> UciPacketPacket3205     fn into(self) -> UciPacketPacket {
3206         self.build().into()
3207     }
3208 }
3209 
3210 #[derive(Debug)]
3211 enum CoreCommandDataChild {
3212     DeviceResetCmd(Arc<DeviceResetCmdData>),
3213     GetDeviceInfoCmd(Arc<GetDeviceInfoCmdData>),
3214     GetCapsInfoCmd(Arc<GetCapsInfoCmdData>),
3215     SetConfigCmd(Arc<SetConfigCmdData>),
3216     GetConfigCmd(Arc<GetConfigCmdData>),
3217     None,
3218 }
3219 impl CoreCommandDataChild {
get_total_size(&self) -> usize3220     fn get_total_size(&self) -> usize {
3221         match self {
3222             CoreCommandDataChild::DeviceResetCmd(value) => value.get_total_size(),
3223             CoreCommandDataChild::GetDeviceInfoCmd(value) => value.get_total_size(),
3224             CoreCommandDataChild::GetCapsInfoCmd(value) => value.get_total_size(),
3225             CoreCommandDataChild::SetConfigCmd(value) => value.get_total_size(),
3226             CoreCommandDataChild::GetConfigCmd(value) => value.get_total_size(),
3227             CoreCommandDataChild::None => 0,
3228         }
3229     }
3230 }
3231 #[derive(Debug)]
3232 pub enum CoreCommandChild {
3233     DeviceResetCmd(DeviceResetCmdPacket),
3234     GetDeviceInfoCmd(GetDeviceInfoCmdPacket),
3235     GetCapsInfoCmd(GetCapsInfoCmdPacket),
3236     SetConfigCmd(SetConfigCmdPacket),
3237     GetConfigCmd(GetConfigCmdPacket),
3238     None,
3239 }
3240 #[derive(Debug)]
3241 struct CoreCommandData {
3242     child: CoreCommandDataChild,
3243 }
3244 #[derive(Debug, Clone)]
3245 pub struct CoreCommandPacket {
3246     uci_packet: Arc<UciPacketData>,
3247     uci_command: Arc<UciCommandData>,
3248     core_command: Arc<CoreCommandData>,
3249 }
3250 #[derive(Debug)]
3251 pub struct CoreCommandBuilder {
3252     pub opcode: u8,
3253 }
3254 impl CoreCommandData {
conforms(bytes: &[u8]) -> bool3255     fn conforms(bytes: &[u8]) -> bool {
3256         if bytes.len() < 4 {
3257             return false;
3258         }
3259         true
3260     }
parse(bytes: &[u8], opcode: u8) -> Result<Self>3261     fn parse(bytes: &[u8], opcode: u8) -> Result<Self> {
3262         let child = match (opcode) {
3263             (0) if DeviceResetCmdData::conforms(&bytes[..]) => {
3264                 CoreCommandDataChild::DeviceResetCmd(Arc::new(DeviceResetCmdData::parse(
3265                     &bytes[..],
3266                 )?))
3267             }
3268             (2) if GetDeviceInfoCmdData::conforms(&bytes[..]) => {
3269                 CoreCommandDataChild::GetDeviceInfoCmd(Arc::new(GetDeviceInfoCmdData::parse(
3270                     &bytes[..],
3271                 )?))
3272             }
3273             (3) if GetCapsInfoCmdData::conforms(&bytes[..]) => {
3274                 CoreCommandDataChild::GetCapsInfoCmd(Arc::new(GetCapsInfoCmdData::parse(
3275                     &bytes[..],
3276                 )?))
3277             }
3278             (4) if SetConfigCmdData::conforms(&bytes[..]) => {
3279                 CoreCommandDataChild::SetConfigCmd(Arc::new(SetConfigCmdData::parse(&bytes[..])?))
3280             }
3281             (5) if GetConfigCmdData::conforms(&bytes[..]) => {
3282                 CoreCommandDataChild::GetConfigCmd(Arc::new(GetConfigCmdData::parse(&bytes[..])?))
3283             }
3284             (_) => return Err(Error::InvalidPacketError),
3285         };
3286         Ok(Self { child })
3287     }
write_to(&self, buffer: &mut BytesMut)3288     fn write_to(&self, buffer: &mut BytesMut) {
3289         match &self.child {
3290             CoreCommandDataChild::DeviceResetCmd(value) => value.write_to(buffer),
3291             CoreCommandDataChild::GetDeviceInfoCmd(value) => value.write_to(buffer),
3292             CoreCommandDataChild::GetCapsInfoCmd(value) => value.write_to(buffer),
3293             CoreCommandDataChild::SetConfigCmd(value) => value.write_to(buffer),
3294             CoreCommandDataChild::GetConfigCmd(value) => value.write_to(buffer),
3295             CoreCommandDataChild::None => {}
3296         }
3297     }
get_total_size(&self) -> usize3298     fn get_total_size(&self) -> usize {
3299         self.get_size() + self.child.get_total_size()
3300     }
get_size(&self) -> usize3301     fn get_size(&self) -> usize {
3302         let ret = 0;
3303         ret
3304     }
3305 }
3306 impl Packet for CoreCommandPacket {
to_bytes(self) -> Bytes3307     fn to_bytes(self) -> Bytes {
3308         let mut buffer = BytesMut::new();
3309         buffer.resize(self.uci_packet.get_total_size(), 0);
3310         self.uci_packet.write_to(&mut buffer);
3311         buffer.freeze()
3312     }
to_vec(self) -> Vec<u8>3313     fn to_vec(self) -> Vec<u8> {
3314         self.to_bytes().to_vec()
3315     }
3316 }
3317 impl From<CoreCommandPacket> for Bytes {
from(packet: CoreCommandPacket) -> Self3318     fn from(packet: CoreCommandPacket) -> Self {
3319         packet.to_bytes()
3320     }
3321 }
3322 impl From<CoreCommandPacket> for Vec<u8> {
from(packet: CoreCommandPacket) -> Self3323     fn from(packet: CoreCommandPacket) -> Self {
3324         packet.to_vec()
3325     }
3326 }
3327 impl TryFrom<UciPacketPacket> for CoreCommandPacket {
3328     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>3329     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
3330         Self::new(value.uci_packet).map_err(TryFromError)
3331     }
3332 }
3333 impl CoreCommandPacket {
specialize(&self) -> CoreCommandChild3334     pub fn specialize(&self) -> CoreCommandChild {
3335         match &self.core_command.child {
3336             CoreCommandDataChild::DeviceResetCmd(_) => CoreCommandChild::DeviceResetCmd(
3337                 DeviceResetCmdPacket::new(self.uci_packet.clone()).unwrap(),
3338             ),
3339             CoreCommandDataChild::GetDeviceInfoCmd(_) => CoreCommandChild::GetDeviceInfoCmd(
3340                 GetDeviceInfoCmdPacket::new(self.uci_packet.clone()).unwrap(),
3341             ),
3342             CoreCommandDataChild::GetCapsInfoCmd(_) => CoreCommandChild::GetCapsInfoCmd(
3343                 GetCapsInfoCmdPacket::new(self.uci_packet.clone()).unwrap(),
3344             ),
3345             CoreCommandDataChild::SetConfigCmd(_) => CoreCommandChild::SetConfigCmd(
3346                 SetConfigCmdPacket::new(self.uci_packet.clone()).unwrap(),
3347             ),
3348             CoreCommandDataChild::GetConfigCmd(_) => CoreCommandChild::GetConfigCmd(
3349                 GetConfigCmdPacket::new(self.uci_packet.clone()).unwrap(),
3350             ),
3351             CoreCommandDataChild::None => CoreCommandChild::None,
3352         }
3353     }
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>3354     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
3355         let uci_packet = root;
3356         let uci_command = match &uci_packet.child {
3357             UciPacketDataChild::UciCommand(value) => (*value).clone(),
3358             _ => return Err("inconsistent state - child was not UciCommand"),
3359         };
3360         let core_command = match &uci_command.child {
3361             UciCommandDataChild::CoreCommand(value) => (*value).clone(),
3362             _ => return Err("inconsistent state - child was not CoreCommand"),
3363         };
3364         Ok(Self {
3365             uci_packet,
3366             uci_command,
3367             core_command,
3368         })
3369     }
get_group_id(&self) -> GroupId3370     pub fn get_group_id(&self) -> GroupId {
3371         self.uci_packet.as_ref().group_id
3372     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag3373     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
3374         self.uci_packet.as_ref().packet_boundary_flag
3375     }
get_message_type(&self) -> MessageType3376     pub fn get_message_type(&self) -> MessageType {
3377         self.uci_packet.as_ref().message_type
3378     }
get_opcode(&self) -> u83379     pub fn get_opcode(&self) -> u8 {
3380         self.uci_packet.as_ref().opcode
3381     }
3382 }
3383 impl Into<UciPacketPacket> for CoreCommandPacket {
into(self) -> UciPacketPacket3384     fn into(self) -> UciPacketPacket {
3385         UciPacketPacket::new(self.uci_packet).unwrap()
3386     }
3387 }
3388 impl Into<UciCommandPacket> for CoreCommandPacket {
into(self) -> UciCommandPacket3389     fn into(self) -> UciCommandPacket {
3390         UciCommandPacket::new(self.uci_packet).unwrap()
3391     }
3392 }
3393 impl CoreCommandBuilder {
build(self) -> CoreCommandPacket3394     pub fn build(self) -> CoreCommandPacket {
3395         let core_command = Arc::new(CoreCommandData {
3396             child: CoreCommandDataChild::None,
3397         });
3398         let uci_command = Arc::new(UciCommandData {
3399             child: UciCommandDataChild::CoreCommand(core_command),
3400         });
3401         let uci_packet = Arc::new(UciPacketData {
3402             group_id: GroupId::Core,
3403             packet_boundary_flag: PacketBoundaryFlag::Complete,
3404             message_type: MessageType::Command,
3405             opcode: self.opcode,
3406             child: UciPacketDataChild::UciCommand(uci_command),
3407         });
3408         CoreCommandPacket::new(uci_packet).unwrap()
3409     }
3410 }
3411 impl Into<UciPacketPacket> for CoreCommandBuilder {
into(self) -> UciPacketPacket3412     fn into(self) -> UciPacketPacket {
3413         self.build().into()
3414     }
3415 }
3416 impl Into<UciCommandPacket> for CoreCommandBuilder {
into(self) -> UciCommandPacket3417     fn into(self) -> UciCommandPacket {
3418         self.build().into()
3419     }
3420 }
3421 
3422 #[derive(Debug)]
3423 enum CoreResponseDataChild {
3424     DeviceResetRsp(Arc<DeviceResetRspData>),
3425     GetDeviceInfoRsp(Arc<GetDeviceInfoRspData>),
3426     GetCapsInfoRsp(Arc<GetCapsInfoRspData>),
3427     SetConfigRsp(Arc<SetConfigRspData>),
3428     GetConfigRsp(Arc<GetConfigRspData>),
3429     None,
3430 }
3431 impl CoreResponseDataChild {
get_total_size(&self) -> usize3432     fn get_total_size(&self) -> usize {
3433         match self {
3434             CoreResponseDataChild::DeviceResetRsp(value) => value.get_total_size(),
3435             CoreResponseDataChild::GetDeviceInfoRsp(value) => value.get_total_size(),
3436             CoreResponseDataChild::GetCapsInfoRsp(value) => value.get_total_size(),
3437             CoreResponseDataChild::SetConfigRsp(value) => value.get_total_size(),
3438             CoreResponseDataChild::GetConfigRsp(value) => value.get_total_size(),
3439             CoreResponseDataChild::None => 0,
3440         }
3441     }
3442 }
3443 #[derive(Debug)]
3444 pub enum CoreResponseChild {
3445     DeviceResetRsp(DeviceResetRspPacket),
3446     GetDeviceInfoRsp(GetDeviceInfoRspPacket),
3447     GetCapsInfoRsp(GetCapsInfoRspPacket),
3448     SetConfigRsp(SetConfigRspPacket),
3449     GetConfigRsp(GetConfigRspPacket),
3450     None,
3451 }
3452 #[derive(Debug)]
3453 struct CoreResponseData {
3454     child: CoreResponseDataChild,
3455 }
3456 #[derive(Debug, Clone)]
3457 pub struct CoreResponsePacket {
3458     uci_packet: Arc<UciPacketData>,
3459     uci_response: Arc<UciResponseData>,
3460     core_response: Arc<CoreResponseData>,
3461 }
3462 #[derive(Debug)]
3463 pub struct CoreResponseBuilder {
3464     pub opcode: u8,
3465 }
3466 impl CoreResponseData {
conforms(bytes: &[u8]) -> bool3467     fn conforms(bytes: &[u8]) -> bool {
3468         if bytes.len() < 4 {
3469             return false;
3470         }
3471         true
3472     }
parse(bytes: &[u8], opcode: u8) -> Result<Self>3473     fn parse(bytes: &[u8], opcode: u8) -> Result<Self> {
3474         let child = match (opcode) {
3475             (0) if DeviceResetRspData::conforms(&bytes[..]) => {
3476                 CoreResponseDataChild::DeviceResetRsp(Arc::new(DeviceResetRspData::parse(
3477                     &bytes[..],
3478                 )?))
3479             }
3480             (2) if GetDeviceInfoRspData::conforms(&bytes[..]) => {
3481                 CoreResponseDataChild::GetDeviceInfoRsp(Arc::new(GetDeviceInfoRspData::parse(
3482                     &bytes[..],
3483                 )?))
3484             }
3485             (3) if GetCapsInfoRspData::conforms(&bytes[..]) => {
3486                 CoreResponseDataChild::GetCapsInfoRsp(Arc::new(GetCapsInfoRspData::parse(
3487                     &bytes[..],
3488                 )?))
3489             }
3490             (4) if SetConfigRspData::conforms(&bytes[..]) => {
3491                 CoreResponseDataChild::SetConfigRsp(Arc::new(SetConfigRspData::parse(&bytes[..])?))
3492             }
3493             (5) if GetConfigRspData::conforms(&bytes[..]) => {
3494                 CoreResponseDataChild::GetConfigRsp(Arc::new(GetConfigRspData::parse(&bytes[..])?))
3495             }
3496             (_) => return Err(Error::InvalidPacketError),
3497         };
3498         Ok(Self { child })
3499     }
write_to(&self, buffer: &mut BytesMut)3500     fn write_to(&self, buffer: &mut BytesMut) {
3501         match &self.child {
3502             CoreResponseDataChild::DeviceResetRsp(value) => value.write_to(buffer),
3503             CoreResponseDataChild::GetDeviceInfoRsp(value) => value.write_to(buffer),
3504             CoreResponseDataChild::GetCapsInfoRsp(value) => value.write_to(buffer),
3505             CoreResponseDataChild::SetConfigRsp(value) => value.write_to(buffer),
3506             CoreResponseDataChild::GetConfigRsp(value) => value.write_to(buffer),
3507             CoreResponseDataChild::None => {}
3508         }
3509     }
get_total_size(&self) -> usize3510     fn get_total_size(&self) -> usize {
3511         self.get_size() + self.child.get_total_size()
3512     }
get_size(&self) -> usize3513     fn get_size(&self) -> usize {
3514         let ret = 0;
3515         ret
3516     }
3517 }
3518 impl Packet for CoreResponsePacket {
to_bytes(self) -> Bytes3519     fn to_bytes(self) -> Bytes {
3520         let mut buffer = BytesMut::new();
3521         buffer.resize(self.uci_packet.get_total_size(), 0);
3522         self.uci_packet.write_to(&mut buffer);
3523         buffer.freeze()
3524     }
to_vec(self) -> Vec<u8>3525     fn to_vec(self) -> Vec<u8> {
3526         self.to_bytes().to_vec()
3527     }
3528 }
3529 impl From<CoreResponsePacket> for Bytes {
from(packet: CoreResponsePacket) -> Self3530     fn from(packet: CoreResponsePacket) -> Self {
3531         packet.to_bytes()
3532     }
3533 }
3534 impl From<CoreResponsePacket> for Vec<u8> {
from(packet: CoreResponsePacket) -> Self3535     fn from(packet: CoreResponsePacket) -> Self {
3536         packet.to_vec()
3537     }
3538 }
3539 impl TryFrom<UciPacketPacket> for CoreResponsePacket {
3540     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>3541     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
3542         Self::new(value.uci_packet).map_err(TryFromError)
3543     }
3544 }
3545 impl CoreResponsePacket {
specialize(&self) -> CoreResponseChild3546     pub fn specialize(&self) -> CoreResponseChild {
3547         match &self.core_response.child {
3548             CoreResponseDataChild::DeviceResetRsp(_) => CoreResponseChild::DeviceResetRsp(
3549                 DeviceResetRspPacket::new(self.uci_packet.clone()).unwrap(),
3550             ),
3551             CoreResponseDataChild::GetDeviceInfoRsp(_) => CoreResponseChild::GetDeviceInfoRsp(
3552                 GetDeviceInfoRspPacket::new(self.uci_packet.clone()).unwrap(),
3553             ),
3554             CoreResponseDataChild::GetCapsInfoRsp(_) => CoreResponseChild::GetCapsInfoRsp(
3555                 GetCapsInfoRspPacket::new(self.uci_packet.clone()).unwrap(),
3556             ),
3557             CoreResponseDataChild::SetConfigRsp(_) => CoreResponseChild::SetConfigRsp(
3558                 SetConfigRspPacket::new(self.uci_packet.clone()).unwrap(),
3559             ),
3560             CoreResponseDataChild::GetConfigRsp(_) => CoreResponseChild::GetConfigRsp(
3561                 GetConfigRspPacket::new(self.uci_packet.clone()).unwrap(),
3562             ),
3563             CoreResponseDataChild::None => CoreResponseChild::None,
3564         }
3565     }
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>3566     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
3567         let uci_packet = root;
3568         let uci_response = match &uci_packet.child {
3569             UciPacketDataChild::UciResponse(value) => (*value).clone(),
3570             _ => return Err("inconsistent state - child was not UciResponse"),
3571         };
3572         let core_response = match &uci_response.child {
3573             UciResponseDataChild::CoreResponse(value) => (*value).clone(),
3574             _ => return Err("inconsistent state - child was not CoreResponse"),
3575         };
3576         Ok(Self {
3577             uci_packet,
3578             uci_response,
3579             core_response,
3580         })
3581     }
get_group_id(&self) -> GroupId3582     pub fn get_group_id(&self) -> GroupId {
3583         self.uci_packet.as_ref().group_id
3584     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag3585     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
3586         self.uci_packet.as_ref().packet_boundary_flag
3587     }
get_message_type(&self) -> MessageType3588     pub fn get_message_type(&self) -> MessageType {
3589         self.uci_packet.as_ref().message_type
3590     }
get_opcode(&self) -> u83591     pub fn get_opcode(&self) -> u8 {
3592         self.uci_packet.as_ref().opcode
3593     }
3594 }
3595 impl Into<UciPacketPacket> for CoreResponsePacket {
into(self) -> UciPacketPacket3596     fn into(self) -> UciPacketPacket {
3597         UciPacketPacket::new(self.uci_packet).unwrap()
3598     }
3599 }
3600 impl Into<UciResponsePacket> for CoreResponsePacket {
into(self) -> UciResponsePacket3601     fn into(self) -> UciResponsePacket {
3602         UciResponsePacket::new(self.uci_packet).unwrap()
3603     }
3604 }
3605 impl CoreResponseBuilder {
build(self) -> CoreResponsePacket3606     pub fn build(self) -> CoreResponsePacket {
3607         let core_response = Arc::new(CoreResponseData {
3608             child: CoreResponseDataChild::None,
3609         });
3610         let uci_response = Arc::new(UciResponseData {
3611             child: UciResponseDataChild::CoreResponse(core_response),
3612         });
3613         let uci_packet = Arc::new(UciPacketData {
3614             group_id: GroupId::Core,
3615             packet_boundary_flag: PacketBoundaryFlag::Complete,
3616             message_type: MessageType::Response,
3617             opcode: self.opcode,
3618             child: UciPacketDataChild::UciResponse(uci_response),
3619         });
3620         CoreResponsePacket::new(uci_packet).unwrap()
3621     }
3622 }
3623 impl Into<UciPacketPacket> for CoreResponseBuilder {
into(self) -> UciPacketPacket3624     fn into(self) -> UciPacketPacket {
3625         self.build().into()
3626     }
3627 }
3628 impl Into<UciResponsePacket> for CoreResponseBuilder {
into(self) -> UciResponsePacket3629     fn into(self) -> UciResponsePacket {
3630         self.build().into()
3631     }
3632 }
3633 
3634 #[derive(Debug)]
3635 enum CoreNotificationDataChild {
3636     DeviceStatusNtf(Arc<DeviceStatusNtfData>),
3637     GenericError(Arc<GenericErrorData>),
3638     None,
3639 }
3640 impl CoreNotificationDataChild {
get_total_size(&self) -> usize3641     fn get_total_size(&self) -> usize {
3642         match self {
3643             CoreNotificationDataChild::DeviceStatusNtf(value) => value.get_total_size(),
3644             CoreNotificationDataChild::GenericError(value) => value.get_total_size(),
3645             CoreNotificationDataChild::None => 0,
3646         }
3647     }
3648 }
3649 #[derive(Debug)]
3650 pub enum CoreNotificationChild {
3651     DeviceStatusNtf(DeviceStatusNtfPacket),
3652     GenericError(GenericErrorPacket),
3653     None,
3654 }
3655 #[derive(Debug)]
3656 struct CoreNotificationData {
3657     child: CoreNotificationDataChild,
3658 }
3659 #[derive(Debug, Clone)]
3660 pub struct CoreNotificationPacket {
3661     uci_packet: Arc<UciPacketData>,
3662     uci_notification: Arc<UciNotificationData>,
3663     core_notification: Arc<CoreNotificationData>,
3664 }
3665 #[derive(Debug)]
3666 pub struct CoreNotificationBuilder {
3667     pub opcode: u8,
3668 }
3669 impl CoreNotificationData {
conforms(bytes: &[u8]) -> bool3670     fn conforms(bytes: &[u8]) -> bool {
3671         if bytes.len() < 4 {
3672             return false;
3673         }
3674         true
3675     }
parse(bytes: &[u8], opcode: u8) -> Result<Self>3676     fn parse(bytes: &[u8], opcode: u8) -> Result<Self> {
3677         let child = match (opcode) {
3678             (1) if DeviceStatusNtfData::conforms(&bytes[..]) => {
3679                 CoreNotificationDataChild::DeviceStatusNtf(Arc::new(DeviceStatusNtfData::parse(
3680                     &bytes[..],
3681                 )?))
3682             }
3683             (7) if GenericErrorData::conforms(&bytes[..]) => {
3684                 CoreNotificationDataChild::GenericError(Arc::new(GenericErrorData::parse(
3685                     &bytes[..],
3686                 )?))
3687             }
3688             (_) => return Err(Error::InvalidPacketError),
3689         };
3690         Ok(Self { child })
3691     }
write_to(&self, buffer: &mut BytesMut)3692     fn write_to(&self, buffer: &mut BytesMut) {
3693         match &self.child {
3694             CoreNotificationDataChild::DeviceStatusNtf(value) => value.write_to(buffer),
3695             CoreNotificationDataChild::GenericError(value) => value.write_to(buffer),
3696             CoreNotificationDataChild::None => {}
3697         }
3698     }
get_total_size(&self) -> usize3699     fn get_total_size(&self) -> usize {
3700         self.get_size() + self.child.get_total_size()
3701     }
get_size(&self) -> usize3702     fn get_size(&self) -> usize {
3703         let ret = 0;
3704         ret
3705     }
3706 }
3707 impl Packet for CoreNotificationPacket {
to_bytes(self) -> Bytes3708     fn to_bytes(self) -> Bytes {
3709         let mut buffer = BytesMut::new();
3710         buffer.resize(self.uci_packet.get_total_size(), 0);
3711         self.uci_packet.write_to(&mut buffer);
3712         buffer.freeze()
3713     }
to_vec(self) -> Vec<u8>3714     fn to_vec(self) -> Vec<u8> {
3715         self.to_bytes().to_vec()
3716     }
3717 }
3718 impl From<CoreNotificationPacket> for Bytes {
from(packet: CoreNotificationPacket) -> Self3719     fn from(packet: CoreNotificationPacket) -> Self {
3720         packet.to_bytes()
3721     }
3722 }
3723 impl From<CoreNotificationPacket> for Vec<u8> {
from(packet: CoreNotificationPacket) -> Self3724     fn from(packet: CoreNotificationPacket) -> Self {
3725         packet.to_vec()
3726     }
3727 }
3728 impl TryFrom<UciPacketPacket> for CoreNotificationPacket {
3729     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>3730     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
3731         Self::new(value.uci_packet).map_err(TryFromError)
3732     }
3733 }
3734 impl CoreNotificationPacket {
specialize(&self) -> CoreNotificationChild3735     pub fn specialize(&self) -> CoreNotificationChild {
3736         match &self.core_notification.child {
3737             CoreNotificationDataChild::DeviceStatusNtf(_) => {
3738                 CoreNotificationChild::DeviceStatusNtf(
3739                     DeviceStatusNtfPacket::new(self.uci_packet.clone()).unwrap(),
3740                 )
3741             }
3742             CoreNotificationDataChild::GenericError(_) => CoreNotificationChild::GenericError(
3743                 GenericErrorPacket::new(self.uci_packet.clone()).unwrap(),
3744             ),
3745             CoreNotificationDataChild::None => CoreNotificationChild::None,
3746         }
3747     }
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>3748     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
3749         let uci_packet = root;
3750         let uci_notification = match &uci_packet.child {
3751             UciPacketDataChild::UciNotification(value) => (*value).clone(),
3752             _ => return Err("inconsistent state - child was not UciNotification"),
3753         };
3754         let core_notification = match &uci_notification.child {
3755             UciNotificationDataChild::CoreNotification(value) => (*value).clone(),
3756             _ => return Err("inconsistent state - child was not CoreNotification"),
3757         };
3758         Ok(Self {
3759             uci_packet,
3760             uci_notification,
3761             core_notification,
3762         })
3763     }
get_group_id(&self) -> GroupId3764     pub fn get_group_id(&self) -> GroupId {
3765         self.uci_packet.as_ref().group_id
3766     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag3767     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
3768         self.uci_packet.as_ref().packet_boundary_flag
3769     }
get_message_type(&self) -> MessageType3770     pub fn get_message_type(&self) -> MessageType {
3771         self.uci_packet.as_ref().message_type
3772     }
get_opcode(&self) -> u83773     pub fn get_opcode(&self) -> u8 {
3774         self.uci_packet.as_ref().opcode
3775     }
3776 }
3777 impl Into<UciPacketPacket> for CoreNotificationPacket {
into(self) -> UciPacketPacket3778     fn into(self) -> UciPacketPacket {
3779         UciPacketPacket::new(self.uci_packet).unwrap()
3780     }
3781 }
3782 impl Into<UciNotificationPacket> for CoreNotificationPacket {
into(self) -> UciNotificationPacket3783     fn into(self) -> UciNotificationPacket {
3784         UciNotificationPacket::new(self.uci_packet).unwrap()
3785     }
3786 }
3787 impl CoreNotificationBuilder {
build(self) -> CoreNotificationPacket3788     pub fn build(self) -> CoreNotificationPacket {
3789         let core_notification = Arc::new(CoreNotificationData {
3790             child: CoreNotificationDataChild::None,
3791         });
3792         let uci_notification = Arc::new(UciNotificationData {
3793             child: UciNotificationDataChild::CoreNotification(core_notification),
3794         });
3795         let uci_packet = Arc::new(UciPacketData {
3796             group_id: GroupId::Core,
3797             packet_boundary_flag: PacketBoundaryFlag::Complete,
3798             message_type: MessageType::Notification,
3799             opcode: self.opcode,
3800             child: UciPacketDataChild::UciNotification(uci_notification),
3801         });
3802         CoreNotificationPacket::new(uci_packet).unwrap()
3803     }
3804 }
3805 impl Into<UciPacketPacket> for CoreNotificationBuilder {
into(self) -> UciPacketPacket3806     fn into(self) -> UciPacketPacket {
3807         self.build().into()
3808     }
3809 }
3810 impl Into<UciNotificationPacket> for CoreNotificationBuilder {
into(self) -> UciNotificationPacket3811     fn into(self) -> UciNotificationPacket {
3812         self.build().into()
3813     }
3814 }
3815 
3816 #[derive(Debug)]
3817 enum SessionCommandDataChild {
3818     SessionInitCmd(Arc<SessionInitCmdData>),
3819     SessionDeinitCmd(Arc<SessionDeinitCmdData>),
3820     SessionSetAppConfigCmd(Arc<SessionSetAppConfigCmdData>),
3821     SessionGetAppConfigCmd(Arc<SessionGetAppConfigCmdData>),
3822     SessionGetCountCmd(Arc<SessionGetCountCmdData>),
3823     SessionGetStateCmd(Arc<SessionGetStateCmdData>),
3824     SessionUpdateControllerMulticastListCmd(Arc<SessionUpdateControllerMulticastListCmdData>),
3825     None,
3826 }
3827 impl SessionCommandDataChild {
get_total_size(&self) -> usize3828     fn get_total_size(&self) -> usize {
3829         match self {
3830             SessionCommandDataChild::SessionInitCmd(value) => value.get_total_size(),
3831             SessionCommandDataChild::SessionDeinitCmd(value) => value.get_total_size(),
3832             SessionCommandDataChild::SessionSetAppConfigCmd(value) => value.get_total_size(),
3833             SessionCommandDataChild::SessionGetAppConfigCmd(value) => value.get_total_size(),
3834             SessionCommandDataChild::SessionGetCountCmd(value) => value.get_total_size(),
3835             SessionCommandDataChild::SessionGetStateCmd(value) => value.get_total_size(),
3836             SessionCommandDataChild::SessionUpdateControllerMulticastListCmd(value) => {
3837                 value.get_total_size()
3838             }
3839             SessionCommandDataChild::None => 0,
3840         }
3841     }
3842 }
3843 #[derive(Debug)]
3844 pub enum SessionCommandChild {
3845     SessionInitCmd(SessionInitCmdPacket),
3846     SessionDeinitCmd(SessionDeinitCmdPacket),
3847     SessionSetAppConfigCmd(SessionSetAppConfigCmdPacket),
3848     SessionGetAppConfigCmd(SessionGetAppConfigCmdPacket),
3849     SessionGetCountCmd(SessionGetCountCmdPacket),
3850     SessionGetStateCmd(SessionGetStateCmdPacket),
3851     SessionUpdateControllerMulticastListCmd(SessionUpdateControllerMulticastListCmdPacket),
3852     None,
3853 }
3854 #[derive(Debug)]
3855 struct SessionCommandData {
3856     child: SessionCommandDataChild,
3857 }
3858 #[derive(Debug, Clone)]
3859 pub struct SessionCommandPacket {
3860     uci_packet: Arc<UciPacketData>,
3861     uci_command: Arc<UciCommandData>,
3862     session_command: Arc<SessionCommandData>,
3863 }
3864 #[derive(Debug)]
3865 pub struct SessionCommandBuilder {
3866     pub opcode: u8,
3867 }
3868 impl SessionCommandData {
conforms(bytes: &[u8]) -> bool3869     fn conforms(bytes: &[u8]) -> bool {
3870         if bytes.len() < 4 {
3871             return false;
3872         }
3873         true
3874     }
parse(bytes: &[u8], opcode: u8) -> Result<Self>3875     fn parse(bytes: &[u8], opcode: u8) -> Result<Self> {
3876         let child = match (opcode) {
3877             (0) if SessionInitCmdData::conforms(&bytes[..]) => {
3878                 SessionCommandDataChild::SessionInitCmd(Arc::new(SessionInitCmdData::parse(
3879                     &bytes[..],
3880                 )?))
3881             }
3882             (1) if SessionDeinitCmdData::conforms(&bytes[..]) => {
3883                 SessionCommandDataChild::SessionDeinitCmd(Arc::new(SessionDeinitCmdData::parse(
3884                     &bytes[..],
3885                 )?))
3886             }
3887             (3) if SessionSetAppConfigCmdData::conforms(&bytes[..]) => {
3888                 SessionCommandDataChild::SessionSetAppConfigCmd(Arc::new(
3889                     SessionSetAppConfigCmdData::parse(&bytes[..])?,
3890                 ))
3891             }
3892             (4) if SessionGetAppConfigCmdData::conforms(&bytes[..]) => {
3893                 SessionCommandDataChild::SessionGetAppConfigCmd(Arc::new(
3894                     SessionGetAppConfigCmdData::parse(&bytes[..])?,
3895                 ))
3896             }
3897             (5) if SessionGetCountCmdData::conforms(&bytes[..]) => {
3898                 SessionCommandDataChild::SessionGetCountCmd(Arc::new(
3899                     SessionGetCountCmdData::parse(&bytes[..])?,
3900                 ))
3901             }
3902             (6) if SessionGetStateCmdData::conforms(&bytes[..]) => {
3903                 SessionCommandDataChild::SessionGetStateCmd(Arc::new(
3904                     SessionGetStateCmdData::parse(&bytes[..])?,
3905                 ))
3906             }
3907             (7) if SessionUpdateControllerMulticastListCmdData::conforms(&bytes[..]) => {
3908                 SessionCommandDataChild::SessionUpdateControllerMulticastListCmd(Arc::new(
3909                     SessionUpdateControllerMulticastListCmdData::parse(&bytes[..])?,
3910                 ))
3911             }
3912             (_) => return Err(Error::InvalidPacketError),
3913         };
3914         Ok(Self { child })
3915     }
write_to(&self, buffer: &mut BytesMut)3916     fn write_to(&self, buffer: &mut BytesMut) {
3917         match &self.child {
3918             SessionCommandDataChild::SessionInitCmd(value) => value.write_to(buffer),
3919             SessionCommandDataChild::SessionDeinitCmd(value) => value.write_to(buffer),
3920             SessionCommandDataChild::SessionSetAppConfigCmd(value) => value.write_to(buffer),
3921             SessionCommandDataChild::SessionGetAppConfigCmd(value) => value.write_to(buffer),
3922             SessionCommandDataChild::SessionGetCountCmd(value) => value.write_to(buffer),
3923             SessionCommandDataChild::SessionGetStateCmd(value) => value.write_to(buffer),
3924             SessionCommandDataChild::SessionUpdateControllerMulticastListCmd(value) => {
3925                 value.write_to(buffer)
3926             }
3927             SessionCommandDataChild::None => {}
3928         }
3929     }
get_total_size(&self) -> usize3930     fn get_total_size(&self) -> usize {
3931         self.get_size() + self.child.get_total_size()
3932     }
get_size(&self) -> usize3933     fn get_size(&self) -> usize {
3934         let ret = 0;
3935         ret
3936     }
3937 }
3938 impl Packet for SessionCommandPacket {
to_bytes(self) -> Bytes3939     fn to_bytes(self) -> Bytes {
3940         let mut buffer = BytesMut::new();
3941         buffer.resize(self.uci_packet.get_total_size(), 0);
3942         self.uci_packet.write_to(&mut buffer);
3943         buffer.freeze()
3944     }
to_vec(self) -> Vec<u8>3945     fn to_vec(self) -> Vec<u8> {
3946         self.to_bytes().to_vec()
3947     }
3948 }
3949 impl From<SessionCommandPacket> for Bytes {
from(packet: SessionCommandPacket) -> Self3950     fn from(packet: SessionCommandPacket) -> Self {
3951         packet.to_bytes()
3952     }
3953 }
3954 impl From<SessionCommandPacket> for Vec<u8> {
from(packet: SessionCommandPacket) -> Self3955     fn from(packet: SessionCommandPacket) -> Self {
3956         packet.to_vec()
3957     }
3958 }
3959 impl TryFrom<UciPacketPacket> for SessionCommandPacket {
3960     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>3961     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
3962         Self::new(value.uci_packet).map_err(TryFromError)
3963     }
3964 }
3965 impl SessionCommandPacket {
specialize(&self) -> SessionCommandChild3966     pub fn specialize(&self) -> SessionCommandChild {
3967         match &self.session_command.child {
3968             SessionCommandDataChild::SessionInitCmd(_) => SessionCommandChild::SessionInitCmd(
3969                 SessionInitCmdPacket::new(self.uci_packet.clone()).unwrap(),
3970             ),
3971             SessionCommandDataChild::SessionDeinitCmd(_) => SessionCommandChild::SessionDeinitCmd(
3972                 SessionDeinitCmdPacket::new(self.uci_packet.clone()).unwrap(),
3973             ),
3974             SessionCommandDataChild::SessionSetAppConfigCmd(_) => {
3975                 SessionCommandChild::SessionSetAppConfigCmd(
3976                     SessionSetAppConfigCmdPacket::new(self.uci_packet.clone()).unwrap(),
3977                 )
3978             }
3979             SessionCommandDataChild::SessionGetAppConfigCmd(_) => {
3980                 SessionCommandChild::SessionGetAppConfigCmd(
3981                     SessionGetAppConfigCmdPacket::new(self.uci_packet.clone()).unwrap(),
3982                 )
3983             }
3984             SessionCommandDataChild::SessionGetCountCmd(_) => {
3985                 SessionCommandChild::SessionGetCountCmd(
3986                     SessionGetCountCmdPacket::new(self.uci_packet.clone()).unwrap(),
3987                 )
3988             }
3989             SessionCommandDataChild::SessionGetStateCmd(_) => {
3990                 SessionCommandChild::SessionGetStateCmd(
3991                     SessionGetStateCmdPacket::new(self.uci_packet.clone()).unwrap(),
3992                 )
3993             }
3994             SessionCommandDataChild::SessionUpdateControllerMulticastListCmd(_) => {
3995                 SessionCommandChild::SessionUpdateControllerMulticastListCmd(
3996                     SessionUpdateControllerMulticastListCmdPacket::new(self.uci_packet.clone())
3997                         .unwrap(),
3998                 )
3999             }
4000             SessionCommandDataChild::None => SessionCommandChild::None,
4001         }
4002     }
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>4003     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
4004         let uci_packet = root;
4005         let uci_command = match &uci_packet.child {
4006             UciPacketDataChild::UciCommand(value) => (*value).clone(),
4007             _ => return Err("inconsistent state - child was not UciCommand"),
4008         };
4009         let session_command = match &uci_command.child {
4010             UciCommandDataChild::SessionCommand(value) => (*value).clone(),
4011             _ => return Err("inconsistent state - child was not SessionCommand"),
4012         };
4013         Ok(Self {
4014             uci_packet,
4015             uci_command,
4016             session_command,
4017         })
4018     }
get_group_id(&self) -> GroupId4019     pub fn get_group_id(&self) -> GroupId {
4020         self.uci_packet.as_ref().group_id
4021     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag4022     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
4023         self.uci_packet.as_ref().packet_boundary_flag
4024     }
get_message_type(&self) -> MessageType4025     pub fn get_message_type(&self) -> MessageType {
4026         self.uci_packet.as_ref().message_type
4027     }
get_opcode(&self) -> u84028     pub fn get_opcode(&self) -> u8 {
4029         self.uci_packet.as_ref().opcode
4030     }
4031 }
4032 impl Into<UciPacketPacket> for SessionCommandPacket {
into(self) -> UciPacketPacket4033     fn into(self) -> UciPacketPacket {
4034         UciPacketPacket::new(self.uci_packet).unwrap()
4035     }
4036 }
4037 impl Into<UciCommandPacket> for SessionCommandPacket {
into(self) -> UciCommandPacket4038     fn into(self) -> UciCommandPacket {
4039         UciCommandPacket::new(self.uci_packet).unwrap()
4040     }
4041 }
4042 impl SessionCommandBuilder {
build(self) -> SessionCommandPacket4043     pub fn build(self) -> SessionCommandPacket {
4044         let session_command = Arc::new(SessionCommandData {
4045             child: SessionCommandDataChild::None,
4046         });
4047         let uci_command = Arc::new(UciCommandData {
4048             child: UciCommandDataChild::SessionCommand(session_command),
4049         });
4050         let uci_packet = Arc::new(UciPacketData {
4051             group_id: GroupId::SessionConfig,
4052             packet_boundary_flag: PacketBoundaryFlag::Complete,
4053             message_type: MessageType::Command,
4054             opcode: self.opcode,
4055             child: UciPacketDataChild::UciCommand(uci_command),
4056         });
4057         SessionCommandPacket::new(uci_packet).unwrap()
4058     }
4059 }
4060 impl Into<UciPacketPacket> for SessionCommandBuilder {
into(self) -> UciPacketPacket4061     fn into(self) -> UciPacketPacket {
4062         self.build().into()
4063     }
4064 }
4065 impl Into<UciCommandPacket> for SessionCommandBuilder {
into(self) -> UciCommandPacket4066     fn into(self) -> UciCommandPacket {
4067         self.build().into()
4068     }
4069 }
4070 
4071 #[derive(Debug)]
4072 enum SessionResponseDataChild {
4073     SessionInitRsp(Arc<SessionInitRspData>),
4074     SessionDeinitRsp(Arc<SessionDeinitRspData>),
4075     SessionSetAppConfigRsp(Arc<SessionSetAppConfigRspData>),
4076     SessionGetAppConfigRsp(Arc<SessionGetAppConfigRspData>),
4077     SessionGetCountRsp(Arc<SessionGetCountRspData>),
4078     SessionGetStateRsp(Arc<SessionGetStateRspData>),
4079     SessionUpdateControllerMulticastListRsp(Arc<SessionUpdateControllerMulticastListRspData>),
4080     None,
4081 }
4082 impl SessionResponseDataChild {
get_total_size(&self) -> usize4083     fn get_total_size(&self) -> usize {
4084         match self {
4085             SessionResponseDataChild::SessionInitRsp(value) => value.get_total_size(),
4086             SessionResponseDataChild::SessionDeinitRsp(value) => value.get_total_size(),
4087             SessionResponseDataChild::SessionSetAppConfigRsp(value) => value.get_total_size(),
4088             SessionResponseDataChild::SessionGetAppConfigRsp(value) => value.get_total_size(),
4089             SessionResponseDataChild::SessionGetCountRsp(value) => value.get_total_size(),
4090             SessionResponseDataChild::SessionGetStateRsp(value) => value.get_total_size(),
4091             SessionResponseDataChild::SessionUpdateControllerMulticastListRsp(value) => {
4092                 value.get_total_size()
4093             }
4094             SessionResponseDataChild::None => 0,
4095         }
4096     }
4097 }
4098 #[derive(Debug)]
4099 pub enum SessionResponseChild {
4100     SessionInitRsp(SessionInitRspPacket),
4101     SessionDeinitRsp(SessionDeinitRspPacket),
4102     SessionSetAppConfigRsp(SessionSetAppConfigRspPacket),
4103     SessionGetAppConfigRsp(SessionGetAppConfigRspPacket),
4104     SessionGetCountRsp(SessionGetCountRspPacket),
4105     SessionGetStateRsp(SessionGetStateRspPacket),
4106     SessionUpdateControllerMulticastListRsp(SessionUpdateControllerMulticastListRspPacket),
4107     None,
4108 }
4109 #[derive(Debug)]
4110 struct SessionResponseData {
4111     child: SessionResponseDataChild,
4112 }
4113 #[derive(Debug, Clone)]
4114 pub struct SessionResponsePacket {
4115     uci_packet: Arc<UciPacketData>,
4116     uci_response: Arc<UciResponseData>,
4117     session_response: Arc<SessionResponseData>,
4118 }
4119 #[derive(Debug)]
4120 pub struct SessionResponseBuilder {
4121     pub opcode: u8,
4122 }
4123 impl SessionResponseData {
conforms(bytes: &[u8]) -> bool4124     fn conforms(bytes: &[u8]) -> bool {
4125         if bytes.len() < 4 {
4126             return false;
4127         }
4128         true
4129     }
parse(bytes: &[u8], opcode: u8) -> Result<Self>4130     fn parse(bytes: &[u8], opcode: u8) -> Result<Self> {
4131         let child = match (opcode) {
4132             (0) if SessionInitRspData::conforms(&bytes[..]) => {
4133                 SessionResponseDataChild::SessionInitRsp(Arc::new(SessionInitRspData::parse(
4134                     &bytes[..],
4135                 )?))
4136             }
4137             (1) if SessionDeinitRspData::conforms(&bytes[..]) => {
4138                 SessionResponseDataChild::SessionDeinitRsp(Arc::new(SessionDeinitRspData::parse(
4139                     &bytes[..],
4140                 )?))
4141             }
4142             (3) if SessionSetAppConfigRspData::conforms(&bytes[..]) => {
4143                 SessionResponseDataChild::SessionSetAppConfigRsp(Arc::new(
4144                     SessionSetAppConfigRspData::parse(&bytes[..])?,
4145                 ))
4146             }
4147             (4) if SessionGetAppConfigRspData::conforms(&bytes[..]) => {
4148                 SessionResponseDataChild::SessionGetAppConfigRsp(Arc::new(
4149                     SessionGetAppConfigRspData::parse(&bytes[..])?,
4150                 ))
4151             }
4152             (5) if SessionGetCountRspData::conforms(&bytes[..]) => {
4153                 SessionResponseDataChild::SessionGetCountRsp(Arc::new(
4154                     SessionGetCountRspData::parse(&bytes[..])?,
4155                 ))
4156             }
4157             (6) if SessionGetStateRspData::conforms(&bytes[..]) => {
4158                 SessionResponseDataChild::SessionGetStateRsp(Arc::new(
4159                     SessionGetStateRspData::parse(&bytes[..])?,
4160                 ))
4161             }
4162             (7) if SessionUpdateControllerMulticastListRspData::conforms(&bytes[..]) => {
4163                 SessionResponseDataChild::SessionUpdateControllerMulticastListRsp(Arc::new(
4164                     SessionUpdateControllerMulticastListRspData::parse(&bytes[..])?,
4165                 ))
4166             }
4167             (_) => return Err(Error::InvalidPacketError),
4168         };
4169         Ok(Self { child })
4170     }
write_to(&self, buffer: &mut BytesMut)4171     fn write_to(&self, buffer: &mut BytesMut) {
4172         match &self.child {
4173             SessionResponseDataChild::SessionInitRsp(value) => value.write_to(buffer),
4174             SessionResponseDataChild::SessionDeinitRsp(value) => value.write_to(buffer),
4175             SessionResponseDataChild::SessionSetAppConfigRsp(value) => value.write_to(buffer),
4176             SessionResponseDataChild::SessionGetAppConfigRsp(value) => value.write_to(buffer),
4177             SessionResponseDataChild::SessionGetCountRsp(value) => value.write_to(buffer),
4178             SessionResponseDataChild::SessionGetStateRsp(value) => value.write_to(buffer),
4179             SessionResponseDataChild::SessionUpdateControllerMulticastListRsp(value) => {
4180                 value.write_to(buffer)
4181             }
4182             SessionResponseDataChild::None => {}
4183         }
4184     }
get_total_size(&self) -> usize4185     fn get_total_size(&self) -> usize {
4186         self.get_size() + self.child.get_total_size()
4187     }
get_size(&self) -> usize4188     fn get_size(&self) -> usize {
4189         let ret = 0;
4190         ret
4191     }
4192 }
4193 impl Packet for SessionResponsePacket {
to_bytes(self) -> Bytes4194     fn to_bytes(self) -> Bytes {
4195         let mut buffer = BytesMut::new();
4196         buffer.resize(self.uci_packet.get_total_size(), 0);
4197         self.uci_packet.write_to(&mut buffer);
4198         buffer.freeze()
4199     }
to_vec(self) -> Vec<u8>4200     fn to_vec(self) -> Vec<u8> {
4201         self.to_bytes().to_vec()
4202     }
4203 }
4204 impl From<SessionResponsePacket> for Bytes {
from(packet: SessionResponsePacket) -> Self4205     fn from(packet: SessionResponsePacket) -> Self {
4206         packet.to_bytes()
4207     }
4208 }
4209 impl From<SessionResponsePacket> for Vec<u8> {
from(packet: SessionResponsePacket) -> Self4210     fn from(packet: SessionResponsePacket) -> Self {
4211         packet.to_vec()
4212     }
4213 }
4214 impl TryFrom<UciPacketPacket> for SessionResponsePacket {
4215     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>4216     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
4217         Self::new(value.uci_packet).map_err(TryFromError)
4218     }
4219 }
4220 impl SessionResponsePacket {
specialize(&self) -> SessionResponseChild4221     pub fn specialize(&self) -> SessionResponseChild {
4222         match &self.session_response.child {
4223             SessionResponseDataChild::SessionInitRsp(_) => SessionResponseChild::SessionInitRsp(
4224                 SessionInitRspPacket::new(self.uci_packet.clone()).unwrap(),
4225             ),
4226             SessionResponseDataChild::SessionDeinitRsp(_) => {
4227                 SessionResponseChild::SessionDeinitRsp(
4228                     SessionDeinitRspPacket::new(self.uci_packet.clone()).unwrap(),
4229                 )
4230             }
4231             SessionResponseDataChild::SessionSetAppConfigRsp(_) => {
4232                 SessionResponseChild::SessionSetAppConfigRsp(
4233                     SessionSetAppConfigRspPacket::new(self.uci_packet.clone()).unwrap(),
4234                 )
4235             }
4236             SessionResponseDataChild::SessionGetAppConfigRsp(_) => {
4237                 SessionResponseChild::SessionGetAppConfigRsp(
4238                     SessionGetAppConfigRspPacket::new(self.uci_packet.clone()).unwrap(),
4239                 )
4240             }
4241             SessionResponseDataChild::SessionGetCountRsp(_) => {
4242                 SessionResponseChild::SessionGetCountRsp(
4243                     SessionGetCountRspPacket::new(self.uci_packet.clone()).unwrap(),
4244                 )
4245             }
4246             SessionResponseDataChild::SessionGetStateRsp(_) => {
4247                 SessionResponseChild::SessionGetStateRsp(
4248                     SessionGetStateRspPacket::new(self.uci_packet.clone()).unwrap(),
4249                 )
4250             }
4251             SessionResponseDataChild::SessionUpdateControllerMulticastListRsp(_) => {
4252                 SessionResponseChild::SessionUpdateControllerMulticastListRsp(
4253                     SessionUpdateControllerMulticastListRspPacket::new(self.uci_packet.clone())
4254                         .unwrap(),
4255                 )
4256             }
4257             SessionResponseDataChild::None => SessionResponseChild::None,
4258         }
4259     }
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>4260     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
4261         let uci_packet = root;
4262         let uci_response = match &uci_packet.child {
4263             UciPacketDataChild::UciResponse(value) => (*value).clone(),
4264             _ => return Err("inconsistent state - child was not UciResponse"),
4265         };
4266         let session_response = match &uci_response.child {
4267             UciResponseDataChild::SessionResponse(value) => (*value).clone(),
4268             _ => return Err("inconsistent state - child was not SessionResponse"),
4269         };
4270         Ok(Self {
4271             uci_packet,
4272             uci_response,
4273             session_response,
4274         })
4275     }
get_group_id(&self) -> GroupId4276     pub fn get_group_id(&self) -> GroupId {
4277         self.uci_packet.as_ref().group_id
4278     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag4279     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
4280         self.uci_packet.as_ref().packet_boundary_flag
4281     }
get_message_type(&self) -> MessageType4282     pub fn get_message_type(&self) -> MessageType {
4283         self.uci_packet.as_ref().message_type
4284     }
get_opcode(&self) -> u84285     pub fn get_opcode(&self) -> u8 {
4286         self.uci_packet.as_ref().opcode
4287     }
4288 }
4289 impl Into<UciPacketPacket> for SessionResponsePacket {
into(self) -> UciPacketPacket4290     fn into(self) -> UciPacketPacket {
4291         UciPacketPacket::new(self.uci_packet).unwrap()
4292     }
4293 }
4294 impl Into<UciResponsePacket> for SessionResponsePacket {
into(self) -> UciResponsePacket4295     fn into(self) -> UciResponsePacket {
4296         UciResponsePacket::new(self.uci_packet).unwrap()
4297     }
4298 }
4299 impl SessionResponseBuilder {
build(self) -> SessionResponsePacket4300     pub fn build(self) -> SessionResponsePacket {
4301         let session_response = Arc::new(SessionResponseData {
4302             child: SessionResponseDataChild::None,
4303         });
4304         let uci_response = Arc::new(UciResponseData {
4305             child: UciResponseDataChild::SessionResponse(session_response),
4306         });
4307         let uci_packet = Arc::new(UciPacketData {
4308             group_id: GroupId::SessionConfig,
4309             packet_boundary_flag: PacketBoundaryFlag::Complete,
4310             message_type: MessageType::Response,
4311             opcode: self.opcode,
4312             child: UciPacketDataChild::UciResponse(uci_response),
4313         });
4314         SessionResponsePacket::new(uci_packet).unwrap()
4315     }
4316 }
4317 impl Into<UciPacketPacket> for SessionResponseBuilder {
into(self) -> UciPacketPacket4318     fn into(self) -> UciPacketPacket {
4319         self.build().into()
4320     }
4321 }
4322 impl Into<UciResponsePacket> for SessionResponseBuilder {
into(self) -> UciResponsePacket4323     fn into(self) -> UciResponsePacket {
4324         self.build().into()
4325     }
4326 }
4327 
4328 #[derive(Debug)]
4329 enum SessionNotificationDataChild {
4330     SessionStatusNtf(Arc<SessionStatusNtfData>),
4331     SessionUpdateControllerMulticastListNtf(Arc<SessionUpdateControllerMulticastListNtfData>),
4332     None,
4333 }
4334 impl SessionNotificationDataChild {
get_total_size(&self) -> usize4335     fn get_total_size(&self) -> usize {
4336         match self {
4337             SessionNotificationDataChild::SessionStatusNtf(value) => value.get_total_size(),
4338             SessionNotificationDataChild::SessionUpdateControllerMulticastListNtf(value) => {
4339                 value.get_total_size()
4340             }
4341             SessionNotificationDataChild::None => 0,
4342         }
4343     }
4344 }
4345 #[derive(Debug)]
4346 pub enum SessionNotificationChild {
4347     SessionStatusNtf(SessionStatusNtfPacket),
4348     SessionUpdateControllerMulticastListNtf(SessionUpdateControllerMulticastListNtfPacket),
4349     None,
4350 }
4351 #[derive(Debug)]
4352 struct SessionNotificationData {
4353     child: SessionNotificationDataChild,
4354 }
4355 #[derive(Debug, Clone)]
4356 pub struct SessionNotificationPacket {
4357     uci_packet: Arc<UciPacketData>,
4358     uci_notification: Arc<UciNotificationData>,
4359     session_notification: Arc<SessionNotificationData>,
4360 }
4361 #[derive(Debug)]
4362 pub struct SessionNotificationBuilder {
4363     pub opcode: u8,
4364 }
4365 impl SessionNotificationData {
conforms(bytes: &[u8]) -> bool4366     fn conforms(bytes: &[u8]) -> bool {
4367         if bytes.len() < 4 {
4368             return false;
4369         }
4370         true
4371     }
parse(bytes: &[u8], opcode: u8) -> Result<Self>4372     fn parse(bytes: &[u8], opcode: u8) -> Result<Self> {
4373         let child = match (opcode) {
4374             (2) if SessionStatusNtfData::conforms(&bytes[..]) => {
4375                 SessionNotificationDataChild::SessionStatusNtf(Arc::new(
4376                     SessionStatusNtfData::parse(&bytes[..])?,
4377                 ))
4378             }
4379             (7) if SessionUpdateControllerMulticastListNtfData::conforms(&bytes[..]) => {
4380                 SessionNotificationDataChild::SessionUpdateControllerMulticastListNtf(Arc::new(
4381                     SessionUpdateControllerMulticastListNtfData::parse(&bytes[..])?,
4382                 ))
4383             }
4384             (_) => return Err(Error::InvalidPacketError),
4385         };
4386         Ok(Self { child })
4387     }
write_to(&self, buffer: &mut BytesMut)4388     fn write_to(&self, buffer: &mut BytesMut) {
4389         match &self.child {
4390             SessionNotificationDataChild::SessionStatusNtf(value) => value.write_to(buffer),
4391             SessionNotificationDataChild::SessionUpdateControllerMulticastListNtf(value) => {
4392                 value.write_to(buffer)
4393             }
4394             SessionNotificationDataChild::None => {}
4395         }
4396     }
get_total_size(&self) -> usize4397     fn get_total_size(&self) -> usize {
4398         self.get_size() + self.child.get_total_size()
4399     }
get_size(&self) -> usize4400     fn get_size(&self) -> usize {
4401         let ret = 0;
4402         ret
4403     }
4404 }
4405 impl Packet for SessionNotificationPacket {
to_bytes(self) -> Bytes4406     fn to_bytes(self) -> Bytes {
4407         let mut buffer = BytesMut::new();
4408         buffer.resize(self.uci_packet.get_total_size(), 0);
4409         self.uci_packet.write_to(&mut buffer);
4410         buffer.freeze()
4411     }
to_vec(self) -> Vec<u8>4412     fn to_vec(self) -> Vec<u8> {
4413         self.to_bytes().to_vec()
4414     }
4415 }
4416 impl From<SessionNotificationPacket> for Bytes {
from(packet: SessionNotificationPacket) -> Self4417     fn from(packet: SessionNotificationPacket) -> Self {
4418         packet.to_bytes()
4419     }
4420 }
4421 impl From<SessionNotificationPacket> for Vec<u8> {
from(packet: SessionNotificationPacket) -> Self4422     fn from(packet: SessionNotificationPacket) -> Self {
4423         packet.to_vec()
4424     }
4425 }
4426 impl TryFrom<UciPacketPacket> for SessionNotificationPacket {
4427     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>4428     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
4429         Self::new(value.uci_packet).map_err(TryFromError)
4430     }
4431 }
4432 impl SessionNotificationPacket {
specialize(&self) -> SessionNotificationChild4433     pub fn specialize(&self) -> SessionNotificationChild {
4434         match &self.session_notification.child {
4435             SessionNotificationDataChild::SessionStatusNtf(_) => {
4436                 SessionNotificationChild::SessionStatusNtf(
4437                     SessionStatusNtfPacket::new(self.uci_packet.clone()).unwrap(),
4438                 )
4439             }
4440             SessionNotificationDataChild::SessionUpdateControllerMulticastListNtf(_) => {
4441                 SessionNotificationChild::SessionUpdateControllerMulticastListNtf(
4442                     SessionUpdateControllerMulticastListNtfPacket::new(self.uci_packet.clone())
4443                         .unwrap(),
4444                 )
4445             }
4446             SessionNotificationDataChild::None => SessionNotificationChild::None,
4447         }
4448     }
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>4449     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
4450         let uci_packet = root;
4451         let uci_notification = match &uci_packet.child {
4452             UciPacketDataChild::UciNotification(value) => (*value).clone(),
4453             _ => return Err("inconsistent state - child was not UciNotification"),
4454         };
4455         let session_notification = match &uci_notification.child {
4456             UciNotificationDataChild::SessionNotification(value) => (*value).clone(),
4457             _ => return Err("inconsistent state - child was not SessionNotification"),
4458         };
4459         Ok(Self {
4460             uci_packet,
4461             uci_notification,
4462             session_notification,
4463         })
4464     }
get_group_id(&self) -> GroupId4465     pub fn get_group_id(&self) -> GroupId {
4466         self.uci_packet.as_ref().group_id
4467     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag4468     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
4469         self.uci_packet.as_ref().packet_boundary_flag
4470     }
get_message_type(&self) -> MessageType4471     pub fn get_message_type(&self) -> MessageType {
4472         self.uci_packet.as_ref().message_type
4473     }
get_opcode(&self) -> u84474     pub fn get_opcode(&self) -> u8 {
4475         self.uci_packet.as_ref().opcode
4476     }
4477 }
4478 impl Into<UciPacketPacket> for SessionNotificationPacket {
into(self) -> UciPacketPacket4479     fn into(self) -> UciPacketPacket {
4480         UciPacketPacket::new(self.uci_packet).unwrap()
4481     }
4482 }
4483 impl Into<UciNotificationPacket> for SessionNotificationPacket {
into(self) -> UciNotificationPacket4484     fn into(self) -> UciNotificationPacket {
4485         UciNotificationPacket::new(self.uci_packet).unwrap()
4486     }
4487 }
4488 impl SessionNotificationBuilder {
build(self) -> SessionNotificationPacket4489     pub fn build(self) -> SessionNotificationPacket {
4490         let session_notification = Arc::new(SessionNotificationData {
4491             child: SessionNotificationDataChild::None,
4492         });
4493         let uci_notification = Arc::new(UciNotificationData {
4494             child: UciNotificationDataChild::SessionNotification(session_notification),
4495         });
4496         let uci_packet = Arc::new(UciPacketData {
4497             group_id: GroupId::SessionConfig,
4498             packet_boundary_flag: PacketBoundaryFlag::Complete,
4499             message_type: MessageType::Notification,
4500             opcode: self.opcode,
4501             child: UciPacketDataChild::UciNotification(uci_notification),
4502         });
4503         SessionNotificationPacket::new(uci_packet).unwrap()
4504     }
4505 }
4506 impl Into<UciPacketPacket> for SessionNotificationBuilder {
into(self) -> UciPacketPacket4507     fn into(self) -> UciPacketPacket {
4508         self.build().into()
4509     }
4510 }
4511 impl Into<UciNotificationPacket> for SessionNotificationBuilder {
into(self) -> UciNotificationPacket4512     fn into(self) -> UciNotificationPacket {
4513         self.build().into()
4514     }
4515 }
4516 
4517 #[derive(Debug)]
4518 enum RangingCommandDataChild {
4519     RangeStartCmd(Arc<RangeStartCmdData>),
4520     RangeStopCmd(Arc<RangeStopCmdData>),
4521     RangeGetRangingCountCmd(Arc<RangeGetRangingCountCmdData>),
4522     None,
4523 }
4524 impl RangingCommandDataChild {
get_total_size(&self) -> usize4525     fn get_total_size(&self) -> usize {
4526         match self {
4527             RangingCommandDataChild::RangeStartCmd(value) => value.get_total_size(),
4528             RangingCommandDataChild::RangeStopCmd(value) => value.get_total_size(),
4529             RangingCommandDataChild::RangeGetRangingCountCmd(value) => value.get_total_size(),
4530             RangingCommandDataChild::None => 0,
4531         }
4532     }
4533 }
4534 #[derive(Debug)]
4535 pub enum RangingCommandChild {
4536     RangeStartCmd(RangeStartCmdPacket),
4537     RangeStopCmd(RangeStopCmdPacket),
4538     RangeGetRangingCountCmd(RangeGetRangingCountCmdPacket),
4539     None,
4540 }
4541 #[derive(Debug)]
4542 struct RangingCommandData {
4543     session_id: u32,
4544     child: RangingCommandDataChild,
4545 }
4546 #[derive(Debug, Clone)]
4547 pub struct RangingCommandPacket {
4548     uci_packet: Arc<UciPacketData>,
4549     uci_command: Arc<UciCommandData>,
4550     ranging_command: Arc<RangingCommandData>,
4551 }
4552 #[derive(Debug)]
4553 pub struct RangingCommandBuilder {
4554     pub opcode: u8,
4555     pub session_id: u32,
4556 }
4557 impl RangingCommandData {
conforms(bytes: &[u8]) -> bool4558     fn conforms(bytes: &[u8]) -> bool {
4559         if bytes.len() < 8 {
4560             return false;
4561         }
4562         true
4563     }
parse(bytes: &[u8], opcode: u8) -> Result<Self>4564     fn parse(bytes: &[u8], opcode: u8) -> Result<Self> {
4565         if bytes.len() < 8 {
4566             return Err(Error::InvalidLengthError {
4567                 obj: "RangingCommand".to_string(),
4568                 field: "session_id".to_string(),
4569                 wanted: 8,
4570                 got: bytes.len(),
4571             });
4572         }
4573         let session_id = u32::from_le_bytes([bytes[4], bytes[5], bytes[6], bytes[7]]);
4574         let child = match (opcode) {
4575             (0) if RangeStartCmdData::conforms(&bytes[..]) => {
4576                 RangingCommandDataChild::RangeStartCmd(Arc::new(RangeStartCmdData::parse(
4577                     &bytes[..],
4578                 )?))
4579             }
4580             (1) if RangeStopCmdData::conforms(&bytes[..]) => RangingCommandDataChild::RangeStopCmd(
4581                 Arc::new(RangeStopCmdData::parse(&bytes[..])?),
4582             ),
4583             (3) if RangeGetRangingCountCmdData::conforms(&bytes[..]) => {
4584                 RangingCommandDataChild::RangeGetRangingCountCmd(Arc::new(
4585                     RangeGetRangingCountCmdData::parse(&bytes[..])?,
4586                 ))
4587             }
4588             (_) => return Err(Error::InvalidPacketError),
4589         };
4590         Ok(Self { session_id, child })
4591     }
write_to(&self, buffer: &mut BytesMut)4592     fn write_to(&self, buffer: &mut BytesMut) {
4593         let session_id = self.session_id;
4594         buffer[4..8].copy_from_slice(&session_id.to_le_bytes()[0..4]);
4595         match &self.child {
4596             RangingCommandDataChild::RangeStartCmd(value) => value.write_to(buffer),
4597             RangingCommandDataChild::RangeStopCmd(value) => value.write_to(buffer),
4598             RangingCommandDataChild::RangeGetRangingCountCmd(value) => value.write_to(buffer),
4599             RangingCommandDataChild::None => {}
4600         }
4601     }
get_total_size(&self) -> usize4602     fn get_total_size(&self) -> usize {
4603         self.get_size() + self.child.get_total_size()
4604     }
get_size(&self) -> usize4605     fn get_size(&self) -> usize {
4606         let ret = 0;
4607         let ret = ret + 4;
4608         ret
4609     }
4610 }
4611 impl Packet for RangingCommandPacket {
to_bytes(self) -> Bytes4612     fn to_bytes(self) -> Bytes {
4613         let mut buffer = BytesMut::new();
4614         buffer.resize(self.uci_packet.get_total_size(), 0);
4615         self.uci_packet.write_to(&mut buffer);
4616         buffer.freeze()
4617     }
to_vec(self) -> Vec<u8>4618     fn to_vec(self) -> Vec<u8> {
4619         self.to_bytes().to_vec()
4620     }
4621 }
4622 impl From<RangingCommandPacket> for Bytes {
from(packet: RangingCommandPacket) -> Self4623     fn from(packet: RangingCommandPacket) -> Self {
4624         packet.to_bytes()
4625     }
4626 }
4627 impl From<RangingCommandPacket> for Vec<u8> {
from(packet: RangingCommandPacket) -> Self4628     fn from(packet: RangingCommandPacket) -> Self {
4629         packet.to_vec()
4630     }
4631 }
4632 impl TryFrom<UciPacketPacket> for RangingCommandPacket {
4633     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>4634     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
4635         Self::new(value.uci_packet).map_err(TryFromError)
4636     }
4637 }
4638 impl RangingCommandPacket {
specialize(&self) -> RangingCommandChild4639     pub fn specialize(&self) -> RangingCommandChild {
4640         match &self.ranging_command.child {
4641             RangingCommandDataChild::RangeStartCmd(_) => RangingCommandChild::RangeStartCmd(
4642                 RangeStartCmdPacket::new(self.uci_packet.clone()).unwrap(),
4643             ),
4644             RangingCommandDataChild::RangeStopCmd(_) => RangingCommandChild::RangeStopCmd(
4645                 RangeStopCmdPacket::new(self.uci_packet.clone()).unwrap(),
4646             ),
4647             RangingCommandDataChild::RangeGetRangingCountCmd(_) => {
4648                 RangingCommandChild::RangeGetRangingCountCmd(
4649                     RangeGetRangingCountCmdPacket::new(self.uci_packet.clone()).unwrap(),
4650                 )
4651             }
4652             RangingCommandDataChild::None => RangingCommandChild::None,
4653         }
4654     }
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>4655     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
4656         let uci_packet = root;
4657         let uci_command = match &uci_packet.child {
4658             UciPacketDataChild::UciCommand(value) => (*value).clone(),
4659             _ => return Err("inconsistent state - child was not UciCommand"),
4660         };
4661         let ranging_command = match &uci_command.child {
4662             UciCommandDataChild::RangingCommand(value) => (*value).clone(),
4663             _ => return Err("inconsistent state - child was not RangingCommand"),
4664         };
4665         Ok(Self {
4666             uci_packet,
4667             uci_command,
4668             ranging_command,
4669         })
4670     }
get_group_id(&self) -> GroupId4671     pub fn get_group_id(&self) -> GroupId {
4672         self.uci_packet.as_ref().group_id
4673     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag4674     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
4675         self.uci_packet.as_ref().packet_boundary_flag
4676     }
get_message_type(&self) -> MessageType4677     pub fn get_message_type(&self) -> MessageType {
4678         self.uci_packet.as_ref().message_type
4679     }
get_opcode(&self) -> u84680     pub fn get_opcode(&self) -> u8 {
4681         self.uci_packet.as_ref().opcode
4682     }
get_session_id(&self) -> u324683     pub fn get_session_id(&self) -> u32 {
4684         self.ranging_command.as_ref().session_id
4685     }
4686 }
4687 impl Into<UciPacketPacket> for RangingCommandPacket {
into(self) -> UciPacketPacket4688     fn into(self) -> UciPacketPacket {
4689         UciPacketPacket::new(self.uci_packet).unwrap()
4690     }
4691 }
4692 impl Into<UciCommandPacket> for RangingCommandPacket {
into(self) -> UciCommandPacket4693     fn into(self) -> UciCommandPacket {
4694         UciCommandPacket::new(self.uci_packet).unwrap()
4695     }
4696 }
4697 impl RangingCommandBuilder {
build(self) -> RangingCommandPacket4698     pub fn build(self) -> RangingCommandPacket {
4699         let ranging_command = Arc::new(RangingCommandData {
4700             session_id: self.session_id,
4701             child: RangingCommandDataChild::None,
4702         });
4703         let uci_command = Arc::new(UciCommandData {
4704             child: UciCommandDataChild::RangingCommand(ranging_command),
4705         });
4706         let uci_packet = Arc::new(UciPacketData {
4707             group_id: GroupId::RangingSessionControl,
4708             packet_boundary_flag: PacketBoundaryFlag::Complete,
4709             message_type: MessageType::Command,
4710             opcode: self.opcode,
4711             child: UciPacketDataChild::UciCommand(uci_command),
4712         });
4713         RangingCommandPacket::new(uci_packet).unwrap()
4714     }
4715 }
4716 impl Into<UciPacketPacket> for RangingCommandBuilder {
into(self) -> UciPacketPacket4717     fn into(self) -> UciPacketPacket {
4718         self.build().into()
4719     }
4720 }
4721 impl Into<UciCommandPacket> for RangingCommandBuilder {
into(self) -> UciCommandPacket4722     fn into(self) -> UciCommandPacket {
4723         self.build().into()
4724     }
4725 }
4726 
4727 #[derive(Debug)]
4728 enum RangingResponseDataChild {
4729     RangeStartRsp(Arc<RangeStartRspData>),
4730     RangeStopRsp(Arc<RangeStopRspData>),
4731     RangeGetRangingCountRsp(Arc<RangeGetRangingCountRspData>),
4732     None,
4733 }
4734 impl RangingResponseDataChild {
get_total_size(&self) -> usize4735     fn get_total_size(&self) -> usize {
4736         match self {
4737             RangingResponseDataChild::RangeStartRsp(value) => value.get_total_size(),
4738             RangingResponseDataChild::RangeStopRsp(value) => value.get_total_size(),
4739             RangingResponseDataChild::RangeGetRangingCountRsp(value) => value.get_total_size(),
4740             RangingResponseDataChild::None => 0,
4741         }
4742     }
4743 }
4744 #[derive(Debug)]
4745 pub enum RangingResponseChild {
4746     RangeStartRsp(RangeStartRspPacket),
4747     RangeStopRsp(RangeStopRspPacket),
4748     RangeGetRangingCountRsp(RangeGetRangingCountRspPacket),
4749     None,
4750 }
4751 #[derive(Debug)]
4752 struct RangingResponseData {
4753     child: RangingResponseDataChild,
4754 }
4755 #[derive(Debug, Clone)]
4756 pub struct RangingResponsePacket {
4757     uci_packet: Arc<UciPacketData>,
4758     uci_response: Arc<UciResponseData>,
4759     ranging_response: Arc<RangingResponseData>,
4760 }
4761 #[derive(Debug)]
4762 pub struct RangingResponseBuilder {
4763     pub opcode: u8,
4764 }
4765 impl RangingResponseData {
conforms(bytes: &[u8]) -> bool4766     fn conforms(bytes: &[u8]) -> bool {
4767         if bytes.len() < 4 {
4768             return false;
4769         }
4770         true
4771     }
parse(bytes: &[u8], opcode: u8) -> Result<Self>4772     fn parse(bytes: &[u8], opcode: u8) -> Result<Self> {
4773         let child = match (opcode) {
4774             (0) if RangeStartRspData::conforms(&bytes[..]) => {
4775                 RangingResponseDataChild::RangeStartRsp(Arc::new(RangeStartRspData::parse(
4776                     &bytes[..],
4777                 )?))
4778             }
4779             (1) if RangeStopRspData::conforms(&bytes[..]) => {
4780                 RangingResponseDataChild::RangeStopRsp(Arc::new(RangeStopRspData::parse(
4781                     &bytes[..],
4782                 )?))
4783             }
4784             (3) if RangeGetRangingCountRspData::conforms(&bytes[..]) => {
4785                 RangingResponseDataChild::RangeGetRangingCountRsp(Arc::new(
4786                     RangeGetRangingCountRspData::parse(&bytes[..])?,
4787                 ))
4788             }
4789             (_) => return Err(Error::InvalidPacketError),
4790         };
4791         Ok(Self { child })
4792     }
write_to(&self, buffer: &mut BytesMut)4793     fn write_to(&self, buffer: &mut BytesMut) {
4794         match &self.child {
4795             RangingResponseDataChild::RangeStartRsp(value) => value.write_to(buffer),
4796             RangingResponseDataChild::RangeStopRsp(value) => value.write_to(buffer),
4797             RangingResponseDataChild::RangeGetRangingCountRsp(value) => value.write_to(buffer),
4798             RangingResponseDataChild::None => {}
4799         }
4800     }
get_total_size(&self) -> usize4801     fn get_total_size(&self) -> usize {
4802         self.get_size() + self.child.get_total_size()
4803     }
get_size(&self) -> usize4804     fn get_size(&self) -> usize {
4805         let ret = 0;
4806         ret
4807     }
4808 }
4809 impl Packet for RangingResponsePacket {
to_bytes(self) -> Bytes4810     fn to_bytes(self) -> Bytes {
4811         let mut buffer = BytesMut::new();
4812         buffer.resize(self.uci_packet.get_total_size(), 0);
4813         self.uci_packet.write_to(&mut buffer);
4814         buffer.freeze()
4815     }
to_vec(self) -> Vec<u8>4816     fn to_vec(self) -> Vec<u8> {
4817         self.to_bytes().to_vec()
4818     }
4819 }
4820 impl From<RangingResponsePacket> for Bytes {
from(packet: RangingResponsePacket) -> Self4821     fn from(packet: RangingResponsePacket) -> Self {
4822         packet.to_bytes()
4823     }
4824 }
4825 impl From<RangingResponsePacket> for Vec<u8> {
from(packet: RangingResponsePacket) -> Self4826     fn from(packet: RangingResponsePacket) -> Self {
4827         packet.to_vec()
4828     }
4829 }
4830 impl TryFrom<UciPacketPacket> for RangingResponsePacket {
4831     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>4832     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
4833         Self::new(value.uci_packet).map_err(TryFromError)
4834     }
4835 }
4836 impl RangingResponsePacket {
specialize(&self) -> RangingResponseChild4837     pub fn specialize(&self) -> RangingResponseChild {
4838         match &self.ranging_response.child {
4839             RangingResponseDataChild::RangeStartRsp(_) => RangingResponseChild::RangeStartRsp(
4840                 RangeStartRspPacket::new(self.uci_packet.clone()).unwrap(),
4841             ),
4842             RangingResponseDataChild::RangeStopRsp(_) => RangingResponseChild::RangeStopRsp(
4843                 RangeStopRspPacket::new(self.uci_packet.clone()).unwrap(),
4844             ),
4845             RangingResponseDataChild::RangeGetRangingCountRsp(_) => {
4846                 RangingResponseChild::RangeGetRangingCountRsp(
4847                     RangeGetRangingCountRspPacket::new(self.uci_packet.clone()).unwrap(),
4848                 )
4849             }
4850             RangingResponseDataChild::None => RangingResponseChild::None,
4851         }
4852     }
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>4853     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
4854         let uci_packet = root;
4855         let uci_response = match &uci_packet.child {
4856             UciPacketDataChild::UciResponse(value) => (*value).clone(),
4857             _ => return Err("inconsistent state - child was not UciResponse"),
4858         };
4859         let ranging_response = match &uci_response.child {
4860             UciResponseDataChild::RangingResponse(value) => (*value).clone(),
4861             _ => return Err("inconsistent state - child was not RangingResponse"),
4862         };
4863         Ok(Self {
4864             uci_packet,
4865             uci_response,
4866             ranging_response,
4867         })
4868     }
get_group_id(&self) -> GroupId4869     pub fn get_group_id(&self) -> GroupId {
4870         self.uci_packet.as_ref().group_id
4871     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag4872     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
4873         self.uci_packet.as_ref().packet_boundary_flag
4874     }
get_message_type(&self) -> MessageType4875     pub fn get_message_type(&self) -> MessageType {
4876         self.uci_packet.as_ref().message_type
4877     }
get_opcode(&self) -> u84878     pub fn get_opcode(&self) -> u8 {
4879         self.uci_packet.as_ref().opcode
4880     }
4881 }
4882 impl Into<UciPacketPacket> for RangingResponsePacket {
into(self) -> UciPacketPacket4883     fn into(self) -> UciPacketPacket {
4884         UciPacketPacket::new(self.uci_packet).unwrap()
4885     }
4886 }
4887 impl Into<UciResponsePacket> for RangingResponsePacket {
into(self) -> UciResponsePacket4888     fn into(self) -> UciResponsePacket {
4889         UciResponsePacket::new(self.uci_packet).unwrap()
4890     }
4891 }
4892 impl RangingResponseBuilder {
build(self) -> RangingResponsePacket4893     pub fn build(self) -> RangingResponsePacket {
4894         let ranging_response = Arc::new(RangingResponseData {
4895             child: RangingResponseDataChild::None,
4896         });
4897         let uci_response = Arc::new(UciResponseData {
4898             child: UciResponseDataChild::RangingResponse(ranging_response),
4899         });
4900         let uci_packet = Arc::new(UciPacketData {
4901             group_id: GroupId::RangingSessionControl,
4902             packet_boundary_flag: PacketBoundaryFlag::Complete,
4903             message_type: MessageType::Response,
4904             opcode: self.opcode,
4905             child: UciPacketDataChild::UciResponse(uci_response),
4906         });
4907         RangingResponsePacket::new(uci_packet).unwrap()
4908     }
4909 }
4910 impl Into<UciPacketPacket> for RangingResponseBuilder {
into(self) -> UciPacketPacket4911     fn into(self) -> UciPacketPacket {
4912         self.build().into()
4913     }
4914 }
4915 impl Into<UciResponsePacket> for RangingResponseBuilder {
into(self) -> UciResponsePacket4916     fn into(self) -> UciResponsePacket {
4917         self.build().into()
4918     }
4919 }
4920 
4921 #[derive(Debug)]
4922 enum RangingNotificationDataChild {
4923     RangeDataNtf(Arc<RangeDataNtfData>),
4924     None,
4925 }
4926 impl RangingNotificationDataChild {
get_total_size(&self) -> usize4927     fn get_total_size(&self) -> usize {
4928         match self {
4929             RangingNotificationDataChild::RangeDataNtf(value) => value.get_total_size(),
4930             RangingNotificationDataChild::None => 0,
4931         }
4932     }
4933 }
4934 #[derive(Debug)]
4935 pub enum RangingNotificationChild {
4936     RangeDataNtf(RangeDataNtfPacket),
4937     None,
4938 }
4939 #[derive(Debug)]
4940 struct RangingNotificationData {
4941     child: RangingNotificationDataChild,
4942 }
4943 #[derive(Debug, Clone)]
4944 pub struct RangingNotificationPacket {
4945     uci_packet: Arc<UciPacketData>,
4946     uci_notification: Arc<UciNotificationData>,
4947     ranging_notification: Arc<RangingNotificationData>,
4948 }
4949 #[derive(Debug)]
4950 pub struct RangingNotificationBuilder {
4951     pub opcode: u8,
4952 }
4953 impl RangingNotificationData {
conforms(bytes: &[u8]) -> bool4954     fn conforms(bytes: &[u8]) -> bool {
4955         if bytes.len() < 4 {
4956             return false;
4957         }
4958         true
4959     }
parse(bytes: &[u8], opcode: u8) -> Result<Self>4960     fn parse(bytes: &[u8], opcode: u8) -> Result<Self> {
4961         let child = match RangeDataNtfData::parse(&bytes[..]) {
4962             Ok(c) if RangeDataNtfData::conforms(&bytes[..]) => {
4963                 RangingNotificationDataChild::RangeDataNtf(Arc::new(c))
4964             }
4965             Err(Error::InvalidLengthError { .. }) => RangingNotificationDataChild::None,
4966             _ => return Err(Error::InvalidPacketError),
4967         };
4968         Ok(Self { child })
4969     }
write_to(&self, buffer: &mut BytesMut)4970     fn write_to(&self, buffer: &mut BytesMut) {
4971         match &self.child {
4972             RangingNotificationDataChild::RangeDataNtf(value) => value.write_to(buffer),
4973             RangingNotificationDataChild::None => {}
4974         }
4975     }
get_total_size(&self) -> usize4976     fn get_total_size(&self) -> usize {
4977         self.get_size() + self.child.get_total_size()
4978     }
get_size(&self) -> usize4979     fn get_size(&self) -> usize {
4980         let ret = 0;
4981         ret
4982     }
4983 }
4984 impl Packet for RangingNotificationPacket {
to_bytes(self) -> Bytes4985     fn to_bytes(self) -> Bytes {
4986         let mut buffer = BytesMut::new();
4987         buffer.resize(self.uci_packet.get_total_size(), 0);
4988         self.uci_packet.write_to(&mut buffer);
4989         buffer.freeze()
4990     }
to_vec(self) -> Vec<u8>4991     fn to_vec(self) -> Vec<u8> {
4992         self.to_bytes().to_vec()
4993     }
4994 }
4995 impl From<RangingNotificationPacket> for Bytes {
from(packet: RangingNotificationPacket) -> Self4996     fn from(packet: RangingNotificationPacket) -> Self {
4997         packet.to_bytes()
4998     }
4999 }
5000 impl From<RangingNotificationPacket> for Vec<u8> {
from(packet: RangingNotificationPacket) -> Self5001     fn from(packet: RangingNotificationPacket) -> Self {
5002         packet.to_vec()
5003     }
5004 }
5005 impl TryFrom<UciPacketPacket> for RangingNotificationPacket {
5006     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>5007     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
5008         Self::new(value.uci_packet).map_err(TryFromError)
5009     }
5010 }
5011 impl RangingNotificationPacket {
specialize(&self) -> RangingNotificationChild5012     pub fn specialize(&self) -> RangingNotificationChild {
5013         match &self.ranging_notification.child {
5014             RangingNotificationDataChild::RangeDataNtf(_) => {
5015                 RangingNotificationChild::RangeDataNtf(
5016                     RangeDataNtfPacket::new(self.uci_packet.clone()).unwrap(),
5017                 )
5018             }
5019             RangingNotificationDataChild::None => RangingNotificationChild::None,
5020         }
5021     }
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>5022     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
5023         let uci_packet = root;
5024         let uci_notification = match &uci_packet.child {
5025             UciPacketDataChild::UciNotification(value) => (*value).clone(),
5026             _ => return Err("inconsistent state - child was not UciNotification"),
5027         };
5028         let ranging_notification = match &uci_notification.child {
5029             UciNotificationDataChild::RangingNotification(value) => (*value).clone(),
5030             _ => return Err("inconsistent state - child was not RangingNotification"),
5031         };
5032         Ok(Self {
5033             uci_packet,
5034             uci_notification,
5035             ranging_notification,
5036         })
5037     }
get_group_id(&self) -> GroupId5038     pub fn get_group_id(&self) -> GroupId {
5039         self.uci_packet.as_ref().group_id
5040     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag5041     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
5042         self.uci_packet.as_ref().packet_boundary_flag
5043     }
get_message_type(&self) -> MessageType5044     pub fn get_message_type(&self) -> MessageType {
5045         self.uci_packet.as_ref().message_type
5046     }
get_opcode(&self) -> u85047     pub fn get_opcode(&self) -> u8 {
5048         self.uci_packet.as_ref().opcode
5049     }
5050 }
5051 impl Into<UciPacketPacket> for RangingNotificationPacket {
into(self) -> UciPacketPacket5052     fn into(self) -> UciPacketPacket {
5053         UciPacketPacket::new(self.uci_packet).unwrap()
5054     }
5055 }
5056 impl Into<UciNotificationPacket> for RangingNotificationPacket {
into(self) -> UciNotificationPacket5057     fn into(self) -> UciNotificationPacket {
5058         UciNotificationPacket::new(self.uci_packet).unwrap()
5059     }
5060 }
5061 impl RangingNotificationBuilder {
build(self) -> RangingNotificationPacket5062     pub fn build(self) -> RangingNotificationPacket {
5063         let ranging_notification = Arc::new(RangingNotificationData {
5064             child: RangingNotificationDataChild::None,
5065         });
5066         let uci_notification = Arc::new(UciNotificationData {
5067             child: UciNotificationDataChild::RangingNotification(ranging_notification),
5068         });
5069         let uci_packet = Arc::new(UciPacketData {
5070             group_id: GroupId::RangingSessionControl,
5071             packet_boundary_flag: PacketBoundaryFlag::Complete,
5072             message_type: MessageType::Notification,
5073             opcode: self.opcode,
5074             child: UciPacketDataChild::UciNotification(uci_notification),
5075         });
5076         RangingNotificationPacket::new(uci_packet).unwrap()
5077     }
5078 }
5079 impl Into<UciPacketPacket> for RangingNotificationBuilder {
into(self) -> UciPacketPacket5080     fn into(self) -> UciPacketPacket {
5081         self.build().into()
5082     }
5083 }
5084 impl Into<UciNotificationPacket> for RangingNotificationBuilder {
into(self) -> UciNotificationPacket5085     fn into(self) -> UciNotificationPacket {
5086         self.build().into()
5087     }
5088 }
5089 
5090 #[derive(Debug)]
5091 enum AndroidCommandDataChild {
5092     AndroidGetPowerStatsCmd(Arc<AndroidGetPowerStatsCmdData>),
5093     AndroidSetCountryCodeCmd(Arc<AndroidSetCountryCodeCmdData>),
5094     None,
5095 }
5096 impl AndroidCommandDataChild {
get_total_size(&self) -> usize5097     fn get_total_size(&self) -> usize {
5098         match self {
5099             AndroidCommandDataChild::AndroidGetPowerStatsCmd(value) => value.get_total_size(),
5100             AndroidCommandDataChild::AndroidSetCountryCodeCmd(value) => value.get_total_size(),
5101             AndroidCommandDataChild::None => 0,
5102         }
5103     }
5104 }
5105 #[derive(Debug)]
5106 pub enum AndroidCommandChild {
5107     AndroidGetPowerStatsCmd(AndroidGetPowerStatsCmdPacket),
5108     AndroidSetCountryCodeCmd(AndroidSetCountryCodeCmdPacket),
5109     None,
5110 }
5111 #[derive(Debug)]
5112 struct AndroidCommandData {
5113     child: AndroidCommandDataChild,
5114 }
5115 #[derive(Debug, Clone)]
5116 pub struct AndroidCommandPacket {
5117     uci_packet: Arc<UciPacketData>,
5118     uci_command: Arc<UciCommandData>,
5119     android_command: Arc<AndroidCommandData>,
5120 }
5121 #[derive(Debug)]
5122 pub struct AndroidCommandBuilder {
5123     pub opcode: u8,
5124 }
5125 impl AndroidCommandData {
conforms(bytes: &[u8]) -> bool5126     fn conforms(bytes: &[u8]) -> bool {
5127         if bytes.len() < 4 {
5128             return false;
5129         }
5130         true
5131     }
parse(bytes: &[u8], opcode: u8) -> Result<Self>5132     fn parse(bytes: &[u8], opcode: u8) -> Result<Self> {
5133         let child = match (opcode) {
5134             (0) if AndroidGetPowerStatsCmdData::conforms(&bytes[..]) => {
5135                 AndroidCommandDataChild::AndroidGetPowerStatsCmd(Arc::new(
5136                     AndroidGetPowerStatsCmdData::parse(&bytes[..])?,
5137                 ))
5138             }
5139             (1) if AndroidSetCountryCodeCmdData::conforms(&bytes[..]) => {
5140                 AndroidCommandDataChild::AndroidSetCountryCodeCmd(Arc::new(
5141                     AndroidSetCountryCodeCmdData::parse(&bytes[..])?,
5142                 ))
5143             }
5144             (_) => return Err(Error::InvalidPacketError),
5145         };
5146         Ok(Self { child })
5147     }
write_to(&self, buffer: &mut BytesMut)5148     fn write_to(&self, buffer: &mut BytesMut) {
5149         match &self.child {
5150             AndroidCommandDataChild::AndroidGetPowerStatsCmd(value) => value.write_to(buffer),
5151             AndroidCommandDataChild::AndroidSetCountryCodeCmd(value) => value.write_to(buffer),
5152             AndroidCommandDataChild::None => {}
5153         }
5154     }
get_total_size(&self) -> usize5155     fn get_total_size(&self) -> usize {
5156         self.get_size() + self.child.get_total_size()
5157     }
get_size(&self) -> usize5158     fn get_size(&self) -> usize {
5159         let ret = 0;
5160         ret
5161     }
5162 }
5163 impl Packet for AndroidCommandPacket {
to_bytes(self) -> Bytes5164     fn to_bytes(self) -> Bytes {
5165         let mut buffer = BytesMut::new();
5166         buffer.resize(self.uci_packet.get_total_size(), 0);
5167         self.uci_packet.write_to(&mut buffer);
5168         buffer.freeze()
5169     }
to_vec(self) -> Vec<u8>5170     fn to_vec(self) -> Vec<u8> {
5171         self.to_bytes().to_vec()
5172     }
5173 }
5174 impl From<AndroidCommandPacket> for Bytes {
from(packet: AndroidCommandPacket) -> Self5175     fn from(packet: AndroidCommandPacket) -> Self {
5176         packet.to_bytes()
5177     }
5178 }
5179 impl From<AndroidCommandPacket> for Vec<u8> {
from(packet: AndroidCommandPacket) -> Self5180     fn from(packet: AndroidCommandPacket) -> Self {
5181         packet.to_vec()
5182     }
5183 }
5184 impl TryFrom<UciPacketPacket> for AndroidCommandPacket {
5185     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>5186     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
5187         Self::new(value.uci_packet).map_err(TryFromError)
5188     }
5189 }
5190 impl AndroidCommandPacket {
specialize(&self) -> AndroidCommandChild5191     pub fn specialize(&self) -> AndroidCommandChild {
5192         match &self.android_command.child {
5193             AndroidCommandDataChild::AndroidGetPowerStatsCmd(_) => {
5194                 AndroidCommandChild::AndroidGetPowerStatsCmd(
5195                     AndroidGetPowerStatsCmdPacket::new(self.uci_packet.clone()).unwrap(),
5196                 )
5197             }
5198             AndroidCommandDataChild::AndroidSetCountryCodeCmd(_) => {
5199                 AndroidCommandChild::AndroidSetCountryCodeCmd(
5200                     AndroidSetCountryCodeCmdPacket::new(self.uci_packet.clone()).unwrap(),
5201                 )
5202             }
5203             AndroidCommandDataChild::None => AndroidCommandChild::None,
5204         }
5205     }
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>5206     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
5207         let uci_packet = root;
5208         let uci_command = match &uci_packet.child {
5209             UciPacketDataChild::UciCommand(value) => (*value).clone(),
5210             _ => return Err("inconsistent state - child was not UciCommand"),
5211         };
5212         let android_command = match &uci_command.child {
5213             UciCommandDataChild::AndroidCommand(value) => (*value).clone(),
5214             _ => return Err("inconsistent state - child was not AndroidCommand"),
5215         };
5216         Ok(Self {
5217             uci_packet,
5218             uci_command,
5219             android_command,
5220         })
5221     }
get_group_id(&self) -> GroupId5222     pub fn get_group_id(&self) -> GroupId {
5223         self.uci_packet.as_ref().group_id
5224     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag5225     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
5226         self.uci_packet.as_ref().packet_boundary_flag
5227     }
get_message_type(&self) -> MessageType5228     pub fn get_message_type(&self) -> MessageType {
5229         self.uci_packet.as_ref().message_type
5230     }
get_opcode(&self) -> u85231     pub fn get_opcode(&self) -> u8 {
5232         self.uci_packet.as_ref().opcode
5233     }
5234 }
5235 impl Into<UciPacketPacket> for AndroidCommandPacket {
into(self) -> UciPacketPacket5236     fn into(self) -> UciPacketPacket {
5237         UciPacketPacket::new(self.uci_packet).unwrap()
5238     }
5239 }
5240 impl Into<UciCommandPacket> for AndroidCommandPacket {
into(self) -> UciCommandPacket5241     fn into(self) -> UciCommandPacket {
5242         UciCommandPacket::new(self.uci_packet).unwrap()
5243     }
5244 }
5245 impl AndroidCommandBuilder {
build(self) -> AndroidCommandPacket5246     pub fn build(self) -> AndroidCommandPacket {
5247         let android_command = Arc::new(AndroidCommandData {
5248             child: AndroidCommandDataChild::None,
5249         });
5250         let uci_command = Arc::new(UciCommandData {
5251             child: UciCommandDataChild::AndroidCommand(android_command),
5252         });
5253         let uci_packet = Arc::new(UciPacketData {
5254             group_id: GroupId::VendorAndroid,
5255             packet_boundary_flag: PacketBoundaryFlag::Complete,
5256             message_type: MessageType::Command,
5257             opcode: self.opcode,
5258             child: UciPacketDataChild::UciCommand(uci_command),
5259         });
5260         AndroidCommandPacket::new(uci_packet).unwrap()
5261     }
5262 }
5263 impl Into<UciPacketPacket> for AndroidCommandBuilder {
into(self) -> UciPacketPacket5264     fn into(self) -> UciPacketPacket {
5265         self.build().into()
5266     }
5267 }
5268 impl Into<UciCommandPacket> for AndroidCommandBuilder {
into(self) -> UciCommandPacket5269     fn into(self) -> UciCommandPacket {
5270         self.build().into()
5271     }
5272 }
5273 
5274 #[derive(Debug)]
5275 enum AndroidResponseDataChild {
5276     AndroidGetPowerStatsRsp(Arc<AndroidGetPowerStatsRspData>),
5277     AndroidSetCountryCodeRsp(Arc<AndroidSetCountryCodeRspData>),
5278     None,
5279 }
5280 impl AndroidResponseDataChild {
get_total_size(&self) -> usize5281     fn get_total_size(&self) -> usize {
5282         match self {
5283             AndroidResponseDataChild::AndroidGetPowerStatsRsp(value) => value.get_total_size(),
5284             AndroidResponseDataChild::AndroidSetCountryCodeRsp(value) => value.get_total_size(),
5285             AndroidResponseDataChild::None => 0,
5286         }
5287     }
5288 }
5289 #[derive(Debug)]
5290 pub enum AndroidResponseChild {
5291     AndroidGetPowerStatsRsp(AndroidGetPowerStatsRspPacket),
5292     AndroidSetCountryCodeRsp(AndroidSetCountryCodeRspPacket),
5293     None,
5294 }
5295 #[derive(Debug)]
5296 struct AndroidResponseData {
5297     child: AndroidResponseDataChild,
5298 }
5299 #[derive(Debug, Clone)]
5300 pub struct AndroidResponsePacket {
5301     uci_packet: Arc<UciPacketData>,
5302     uci_response: Arc<UciResponseData>,
5303     android_response: Arc<AndroidResponseData>,
5304 }
5305 #[derive(Debug)]
5306 pub struct AndroidResponseBuilder {
5307     pub opcode: u8,
5308 }
5309 impl AndroidResponseData {
conforms(bytes: &[u8]) -> bool5310     fn conforms(bytes: &[u8]) -> bool {
5311         if bytes.len() < 4 {
5312             return false;
5313         }
5314         true
5315     }
parse(bytes: &[u8], opcode: u8) -> Result<Self>5316     fn parse(bytes: &[u8], opcode: u8) -> Result<Self> {
5317         let child = match (opcode) {
5318             (0) if AndroidGetPowerStatsRspData::conforms(&bytes[..]) => {
5319                 AndroidResponseDataChild::AndroidGetPowerStatsRsp(Arc::new(
5320                     AndroidGetPowerStatsRspData::parse(&bytes[..])?,
5321                 ))
5322             }
5323             (1) if AndroidSetCountryCodeRspData::conforms(&bytes[..]) => {
5324                 AndroidResponseDataChild::AndroidSetCountryCodeRsp(Arc::new(
5325                     AndroidSetCountryCodeRspData::parse(&bytes[..])?,
5326                 ))
5327             }
5328             (_) => return Err(Error::InvalidPacketError),
5329         };
5330         Ok(Self { child })
5331     }
write_to(&self, buffer: &mut BytesMut)5332     fn write_to(&self, buffer: &mut BytesMut) {
5333         match &self.child {
5334             AndroidResponseDataChild::AndroidGetPowerStatsRsp(value) => value.write_to(buffer),
5335             AndroidResponseDataChild::AndroidSetCountryCodeRsp(value) => value.write_to(buffer),
5336             AndroidResponseDataChild::None => {}
5337         }
5338     }
get_total_size(&self) -> usize5339     fn get_total_size(&self) -> usize {
5340         self.get_size() + self.child.get_total_size()
5341     }
get_size(&self) -> usize5342     fn get_size(&self) -> usize {
5343         let ret = 0;
5344         ret
5345     }
5346 }
5347 impl Packet for AndroidResponsePacket {
to_bytes(self) -> Bytes5348     fn to_bytes(self) -> Bytes {
5349         let mut buffer = BytesMut::new();
5350         buffer.resize(self.uci_packet.get_total_size(), 0);
5351         self.uci_packet.write_to(&mut buffer);
5352         buffer.freeze()
5353     }
to_vec(self) -> Vec<u8>5354     fn to_vec(self) -> Vec<u8> {
5355         self.to_bytes().to_vec()
5356     }
5357 }
5358 impl From<AndroidResponsePacket> for Bytes {
from(packet: AndroidResponsePacket) -> Self5359     fn from(packet: AndroidResponsePacket) -> Self {
5360         packet.to_bytes()
5361     }
5362 }
5363 impl From<AndroidResponsePacket> for Vec<u8> {
from(packet: AndroidResponsePacket) -> Self5364     fn from(packet: AndroidResponsePacket) -> Self {
5365         packet.to_vec()
5366     }
5367 }
5368 impl TryFrom<UciPacketPacket> for AndroidResponsePacket {
5369     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>5370     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
5371         Self::new(value.uci_packet).map_err(TryFromError)
5372     }
5373 }
5374 impl AndroidResponsePacket {
specialize(&self) -> AndroidResponseChild5375     pub fn specialize(&self) -> AndroidResponseChild {
5376         match &self.android_response.child {
5377             AndroidResponseDataChild::AndroidGetPowerStatsRsp(_) => {
5378                 AndroidResponseChild::AndroidGetPowerStatsRsp(
5379                     AndroidGetPowerStatsRspPacket::new(self.uci_packet.clone()).unwrap(),
5380                 )
5381             }
5382             AndroidResponseDataChild::AndroidSetCountryCodeRsp(_) => {
5383                 AndroidResponseChild::AndroidSetCountryCodeRsp(
5384                     AndroidSetCountryCodeRspPacket::new(self.uci_packet.clone()).unwrap(),
5385                 )
5386             }
5387             AndroidResponseDataChild::None => AndroidResponseChild::None,
5388         }
5389     }
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>5390     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
5391         let uci_packet = root;
5392         let uci_response = match &uci_packet.child {
5393             UciPacketDataChild::UciResponse(value) => (*value).clone(),
5394             _ => return Err("inconsistent state - child was not UciResponse"),
5395         };
5396         let android_response = match &uci_response.child {
5397             UciResponseDataChild::AndroidResponse(value) => (*value).clone(),
5398             _ => return Err("inconsistent state - child was not AndroidResponse"),
5399         };
5400         Ok(Self {
5401             uci_packet,
5402             uci_response,
5403             android_response,
5404         })
5405     }
get_group_id(&self) -> GroupId5406     pub fn get_group_id(&self) -> GroupId {
5407         self.uci_packet.as_ref().group_id
5408     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag5409     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
5410         self.uci_packet.as_ref().packet_boundary_flag
5411     }
get_message_type(&self) -> MessageType5412     pub fn get_message_type(&self) -> MessageType {
5413         self.uci_packet.as_ref().message_type
5414     }
get_opcode(&self) -> u85415     pub fn get_opcode(&self) -> u8 {
5416         self.uci_packet.as_ref().opcode
5417     }
5418 }
5419 impl Into<UciPacketPacket> for AndroidResponsePacket {
into(self) -> UciPacketPacket5420     fn into(self) -> UciPacketPacket {
5421         UciPacketPacket::new(self.uci_packet).unwrap()
5422     }
5423 }
5424 impl Into<UciResponsePacket> for AndroidResponsePacket {
into(self) -> UciResponsePacket5425     fn into(self) -> UciResponsePacket {
5426         UciResponsePacket::new(self.uci_packet).unwrap()
5427     }
5428 }
5429 impl AndroidResponseBuilder {
build(self) -> AndroidResponsePacket5430     pub fn build(self) -> AndroidResponsePacket {
5431         let android_response = Arc::new(AndroidResponseData {
5432             child: AndroidResponseDataChild::None,
5433         });
5434         let uci_response = Arc::new(UciResponseData {
5435             child: UciResponseDataChild::AndroidResponse(android_response),
5436         });
5437         let uci_packet = Arc::new(UciPacketData {
5438             group_id: GroupId::VendorAndroid,
5439             packet_boundary_flag: PacketBoundaryFlag::Complete,
5440             message_type: MessageType::Response,
5441             opcode: self.opcode,
5442             child: UciPacketDataChild::UciResponse(uci_response),
5443         });
5444         AndroidResponsePacket::new(uci_packet).unwrap()
5445     }
5446 }
5447 impl Into<UciPacketPacket> for AndroidResponseBuilder {
into(self) -> UciPacketPacket5448     fn into(self) -> UciPacketPacket {
5449         self.build().into()
5450     }
5451 }
5452 impl Into<UciResponsePacket> for AndroidResponseBuilder {
into(self) -> UciResponsePacket5453     fn into(self) -> UciResponsePacket {
5454         self.build().into()
5455     }
5456 }
5457 
5458 #[derive(Debug)]
5459 struct AndroidNotificationData {}
5460 #[derive(Debug, Clone)]
5461 pub struct AndroidNotificationPacket {
5462     uci_packet: Arc<UciPacketData>,
5463     uci_notification: Arc<UciNotificationData>,
5464     android_notification: Arc<AndroidNotificationData>,
5465 }
5466 #[derive(Debug)]
5467 pub struct AndroidNotificationBuilder {
5468     pub opcode: u8,
5469 }
5470 impl AndroidNotificationData {
conforms(bytes: &[u8]) -> bool5471     fn conforms(bytes: &[u8]) -> bool {
5472         if bytes.len() < 4 {
5473             return false;
5474         }
5475         true
5476     }
parse(bytes: &[u8]) -> Result<Self>5477     fn parse(bytes: &[u8]) -> Result<Self> {
5478         Ok(Self {})
5479     }
write_to(&self, buffer: &mut BytesMut)5480     fn write_to(&self, buffer: &mut BytesMut) {}
get_total_size(&self) -> usize5481     fn get_total_size(&self) -> usize {
5482         self.get_size()
5483     }
get_size(&self) -> usize5484     fn get_size(&self) -> usize {
5485         let ret = 0;
5486         ret
5487     }
5488 }
5489 impl Packet for AndroidNotificationPacket {
to_bytes(self) -> Bytes5490     fn to_bytes(self) -> Bytes {
5491         let mut buffer = BytesMut::new();
5492         buffer.resize(self.uci_packet.get_total_size(), 0);
5493         self.uci_packet.write_to(&mut buffer);
5494         buffer.freeze()
5495     }
to_vec(self) -> Vec<u8>5496     fn to_vec(self) -> Vec<u8> {
5497         self.to_bytes().to_vec()
5498     }
5499 }
5500 impl From<AndroidNotificationPacket> for Bytes {
from(packet: AndroidNotificationPacket) -> Self5501     fn from(packet: AndroidNotificationPacket) -> Self {
5502         packet.to_bytes()
5503     }
5504 }
5505 impl From<AndroidNotificationPacket> for Vec<u8> {
from(packet: AndroidNotificationPacket) -> Self5506     fn from(packet: AndroidNotificationPacket) -> Self {
5507         packet.to_vec()
5508     }
5509 }
5510 impl TryFrom<UciPacketPacket> for AndroidNotificationPacket {
5511     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>5512     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
5513         Self::new(value.uci_packet).map_err(TryFromError)
5514     }
5515 }
5516 impl AndroidNotificationPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>5517     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
5518         let uci_packet = root;
5519         let uci_notification = match &uci_packet.child {
5520             UciPacketDataChild::UciNotification(value) => (*value).clone(),
5521             _ => return Err("inconsistent state - child was not UciNotification"),
5522         };
5523         let android_notification = match &uci_notification.child {
5524             UciNotificationDataChild::AndroidNotification(value) => (*value).clone(),
5525             _ => return Err("inconsistent state - child was not AndroidNotification"),
5526         };
5527         Ok(Self {
5528             uci_packet,
5529             uci_notification,
5530             android_notification,
5531         })
5532     }
get_group_id(&self) -> GroupId5533     pub fn get_group_id(&self) -> GroupId {
5534         self.uci_packet.as_ref().group_id
5535     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag5536     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
5537         self.uci_packet.as_ref().packet_boundary_flag
5538     }
get_message_type(&self) -> MessageType5539     pub fn get_message_type(&self) -> MessageType {
5540         self.uci_packet.as_ref().message_type
5541     }
get_opcode(&self) -> u85542     pub fn get_opcode(&self) -> u8 {
5543         self.uci_packet.as_ref().opcode
5544     }
5545 }
5546 impl Into<UciPacketPacket> for AndroidNotificationPacket {
into(self) -> UciPacketPacket5547     fn into(self) -> UciPacketPacket {
5548         UciPacketPacket::new(self.uci_packet).unwrap()
5549     }
5550 }
5551 impl Into<UciNotificationPacket> for AndroidNotificationPacket {
into(self) -> UciNotificationPacket5552     fn into(self) -> UciNotificationPacket {
5553         UciNotificationPacket::new(self.uci_packet).unwrap()
5554     }
5555 }
5556 impl AndroidNotificationBuilder {
build(self) -> AndroidNotificationPacket5557     pub fn build(self) -> AndroidNotificationPacket {
5558         let android_notification = Arc::new(AndroidNotificationData {});
5559         let uci_notification = Arc::new(UciNotificationData {
5560             child: UciNotificationDataChild::AndroidNotification(android_notification),
5561         });
5562         let uci_packet = Arc::new(UciPacketData {
5563             group_id: GroupId::VendorAndroid,
5564             packet_boundary_flag: PacketBoundaryFlag::Complete,
5565             message_type: MessageType::Notification,
5566             opcode: self.opcode,
5567             child: UciPacketDataChild::UciNotification(uci_notification),
5568         });
5569         AndroidNotificationPacket::new(uci_packet).unwrap()
5570     }
5571 }
5572 impl Into<UciPacketPacket> for AndroidNotificationBuilder {
into(self) -> UciPacketPacket5573     fn into(self) -> UciPacketPacket {
5574         self.build().into()
5575     }
5576 }
5577 impl Into<UciNotificationPacket> for AndroidNotificationBuilder {
into(self) -> UciNotificationPacket5578     fn into(self) -> UciNotificationPacket {
5579         self.build().into()
5580     }
5581 }
5582 
5583 #[derive(Debug)]
5584 struct DeviceResetCmdData {
5585     reset_config: ResetConfig,
5586 }
5587 #[derive(Debug, Clone)]
5588 pub struct DeviceResetCmdPacket {
5589     uci_packet: Arc<UciPacketData>,
5590     uci_command: Arc<UciCommandData>,
5591     core_command: Arc<CoreCommandData>,
5592     device_reset_cmd: Arc<DeviceResetCmdData>,
5593 }
5594 #[derive(Debug)]
5595 pub struct DeviceResetCmdBuilder {
5596     pub reset_config: ResetConfig,
5597 }
5598 impl DeviceResetCmdData {
conforms(bytes: &[u8]) -> bool5599     fn conforms(bytes: &[u8]) -> bool {
5600         if bytes.len() < 5 {
5601             return false;
5602         }
5603         true
5604     }
parse(bytes: &[u8]) -> Result<Self>5605     fn parse(bytes: &[u8]) -> Result<Self> {
5606         if bytes.len() < 5 {
5607             return Err(Error::InvalidLengthError {
5608                 obj: "DeviceResetCmd".to_string(),
5609                 field: "reset_config".to_string(),
5610                 wanted: 5,
5611                 got: bytes.len(),
5612             });
5613         }
5614         let reset_config = u8::from_le_bytes([bytes[4]]);
5615         let reset_config =
5616             ResetConfig::from_u8(reset_config).ok_or_else(|| Error::InvalidEnumValueError {
5617                 obj: "DeviceResetCmd".to_string(),
5618                 field: "reset_config".to_string(),
5619                 value: reset_config as u64,
5620                 type_: "ResetConfig".to_string(),
5621             })?;
5622         Ok(Self { reset_config })
5623     }
write_to(&self, buffer: &mut BytesMut)5624     fn write_to(&self, buffer: &mut BytesMut) {
5625         let reset_config = self.reset_config.to_u8().unwrap();
5626         buffer[4..5].copy_from_slice(&reset_config.to_le_bytes()[0..1]);
5627     }
get_total_size(&self) -> usize5628     fn get_total_size(&self) -> usize {
5629         self.get_size()
5630     }
get_size(&self) -> usize5631     fn get_size(&self) -> usize {
5632         let ret = 0;
5633         let ret = ret + 1;
5634         ret
5635     }
5636 }
5637 impl Packet for DeviceResetCmdPacket {
to_bytes(self) -> Bytes5638     fn to_bytes(self) -> Bytes {
5639         let mut buffer = BytesMut::new();
5640         buffer.resize(self.uci_packet.get_total_size(), 0);
5641         self.uci_packet.write_to(&mut buffer);
5642         buffer.freeze()
5643     }
to_vec(self) -> Vec<u8>5644     fn to_vec(self) -> Vec<u8> {
5645         self.to_bytes().to_vec()
5646     }
5647 }
5648 impl From<DeviceResetCmdPacket> for Bytes {
from(packet: DeviceResetCmdPacket) -> Self5649     fn from(packet: DeviceResetCmdPacket) -> Self {
5650         packet.to_bytes()
5651     }
5652 }
5653 impl From<DeviceResetCmdPacket> for Vec<u8> {
from(packet: DeviceResetCmdPacket) -> Self5654     fn from(packet: DeviceResetCmdPacket) -> Self {
5655         packet.to_vec()
5656     }
5657 }
5658 impl TryFrom<UciPacketPacket> for DeviceResetCmdPacket {
5659     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>5660     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
5661         Self::new(value.uci_packet).map_err(TryFromError)
5662     }
5663 }
5664 impl DeviceResetCmdPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>5665     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
5666         let uci_packet = root;
5667         let uci_command = match &uci_packet.child {
5668             UciPacketDataChild::UciCommand(value) => (*value).clone(),
5669             _ => return Err("inconsistent state - child was not UciCommand"),
5670         };
5671         let core_command = match &uci_command.child {
5672             UciCommandDataChild::CoreCommand(value) => (*value).clone(),
5673             _ => return Err("inconsistent state - child was not CoreCommand"),
5674         };
5675         let device_reset_cmd = match &core_command.child {
5676             CoreCommandDataChild::DeviceResetCmd(value) => (*value).clone(),
5677             _ => return Err("inconsistent state - child was not DeviceResetCmd"),
5678         };
5679         Ok(Self {
5680             uci_packet,
5681             uci_command,
5682             core_command,
5683             device_reset_cmd,
5684         })
5685     }
get_group_id(&self) -> GroupId5686     pub fn get_group_id(&self) -> GroupId {
5687         self.uci_packet.as_ref().group_id
5688     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag5689     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
5690         self.uci_packet.as_ref().packet_boundary_flag
5691     }
get_message_type(&self) -> MessageType5692     pub fn get_message_type(&self) -> MessageType {
5693         self.uci_packet.as_ref().message_type
5694     }
get_opcode(&self) -> u85695     pub fn get_opcode(&self) -> u8 {
5696         self.uci_packet.as_ref().opcode
5697     }
get_reset_config(&self) -> ResetConfig5698     pub fn get_reset_config(&self) -> ResetConfig {
5699         self.device_reset_cmd.as_ref().reset_config
5700     }
5701 }
5702 impl Into<UciPacketPacket> for DeviceResetCmdPacket {
into(self) -> UciPacketPacket5703     fn into(self) -> UciPacketPacket {
5704         UciPacketPacket::new(self.uci_packet).unwrap()
5705     }
5706 }
5707 impl Into<UciCommandPacket> for DeviceResetCmdPacket {
into(self) -> UciCommandPacket5708     fn into(self) -> UciCommandPacket {
5709         UciCommandPacket::new(self.uci_packet).unwrap()
5710     }
5711 }
5712 impl Into<CoreCommandPacket> for DeviceResetCmdPacket {
into(self) -> CoreCommandPacket5713     fn into(self) -> CoreCommandPacket {
5714         CoreCommandPacket::new(self.uci_packet).unwrap()
5715     }
5716 }
5717 impl DeviceResetCmdBuilder {
build(self) -> DeviceResetCmdPacket5718     pub fn build(self) -> DeviceResetCmdPacket {
5719         let device_reset_cmd = Arc::new(DeviceResetCmdData {
5720             reset_config: self.reset_config,
5721         });
5722         let core_command = Arc::new(CoreCommandData {
5723             child: CoreCommandDataChild::DeviceResetCmd(device_reset_cmd),
5724         });
5725         let uci_command = Arc::new(UciCommandData {
5726             child: UciCommandDataChild::CoreCommand(core_command),
5727         });
5728         let uci_packet = Arc::new(UciPacketData {
5729             group_id: GroupId::Core,
5730             packet_boundary_flag: PacketBoundaryFlag::Complete,
5731             message_type: MessageType::Command,
5732             opcode: 0,
5733             child: UciPacketDataChild::UciCommand(uci_command),
5734         });
5735         DeviceResetCmdPacket::new(uci_packet).unwrap()
5736     }
5737 }
5738 impl Into<UciPacketPacket> for DeviceResetCmdBuilder {
into(self) -> UciPacketPacket5739     fn into(self) -> UciPacketPacket {
5740         self.build().into()
5741     }
5742 }
5743 impl Into<UciCommandPacket> for DeviceResetCmdBuilder {
into(self) -> UciCommandPacket5744     fn into(self) -> UciCommandPacket {
5745         self.build().into()
5746     }
5747 }
5748 impl Into<CoreCommandPacket> for DeviceResetCmdBuilder {
into(self) -> CoreCommandPacket5749     fn into(self) -> CoreCommandPacket {
5750         self.build().into()
5751     }
5752 }
5753 macro_rules! device_reset_cmd_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
5754 #[test]
5755 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
5756 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
5757 UciPacketChild::UciCommand(uci_command_packet) => {match uci_command_packet.specialize() {/* (2) */
5758 UciCommandChild::CoreCommand(core_command_packet) => {match core_command_packet.specialize() {/* (3) */
5759 CoreCommandChild::DeviceResetCmd(packet) => {let rebuilder = DeviceResetCmdBuilder {reset_config : packet.get_reset_config(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse device_reset_cmd
5760  {:#02x?}", core_command_packet); }}}_ => {panic!("Couldn't parse core_command
5761  {:#02x?}", uci_command_packet); }}}_ => {panic!("Couldn't parse uci_command
5762  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
5763 device_reset_cmd_builder_tests! { device_reset_cmd_builder_test_00: b"\x20\x00\x00\x01\x00",}
5764 
5765 #[derive(Debug)]
5766 struct DeviceResetRspData {
5767     status: StatusCode,
5768 }
5769 #[derive(Debug, Clone)]
5770 pub struct DeviceResetRspPacket {
5771     uci_packet: Arc<UciPacketData>,
5772     uci_response: Arc<UciResponseData>,
5773     core_response: Arc<CoreResponseData>,
5774     device_reset_rsp: Arc<DeviceResetRspData>,
5775 }
5776 #[derive(Debug)]
5777 pub struct DeviceResetRspBuilder {
5778     pub status: StatusCode,
5779 }
5780 impl DeviceResetRspData {
conforms(bytes: &[u8]) -> bool5781     fn conforms(bytes: &[u8]) -> bool {
5782         if bytes.len() < 5 {
5783             return false;
5784         }
5785         true
5786     }
parse(bytes: &[u8]) -> Result<Self>5787     fn parse(bytes: &[u8]) -> Result<Self> {
5788         if bytes.len() < 5 {
5789             return Err(Error::InvalidLengthError {
5790                 obj: "DeviceResetRsp".to_string(),
5791                 field: "status".to_string(),
5792                 wanted: 5,
5793                 got: bytes.len(),
5794             });
5795         }
5796         let status = u8::from_le_bytes([bytes[4]]);
5797         let status = StatusCode::from_u8(status).ok_or_else(|| Error::InvalidEnumValueError {
5798             obj: "DeviceResetRsp".to_string(),
5799             field: "status".to_string(),
5800             value: status as u64,
5801             type_: "StatusCode".to_string(),
5802         })?;
5803         Ok(Self { status })
5804     }
write_to(&self, buffer: &mut BytesMut)5805     fn write_to(&self, buffer: &mut BytesMut) {
5806         let status = self.status.to_u8().unwrap();
5807         buffer[4..5].copy_from_slice(&status.to_le_bytes()[0..1]);
5808     }
get_total_size(&self) -> usize5809     fn get_total_size(&self) -> usize {
5810         self.get_size()
5811     }
get_size(&self) -> usize5812     fn get_size(&self) -> usize {
5813         let ret = 0;
5814         let ret = ret + 1;
5815         ret
5816     }
5817 }
5818 impl Packet for DeviceResetRspPacket {
to_bytes(self) -> Bytes5819     fn to_bytes(self) -> Bytes {
5820         let mut buffer = BytesMut::new();
5821         buffer.resize(self.uci_packet.get_total_size(), 0);
5822         self.uci_packet.write_to(&mut buffer);
5823         buffer.freeze()
5824     }
to_vec(self) -> Vec<u8>5825     fn to_vec(self) -> Vec<u8> {
5826         self.to_bytes().to_vec()
5827     }
5828 }
5829 impl From<DeviceResetRspPacket> for Bytes {
from(packet: DeviceResetRspPacket) -> Self5830     fn from(packet: DeviceResetRspPacket) -> Self {
5831         packet.to_bytes()
5832     }
5833 }
5834 impl From<DeviceResetRspPacket> for Vec<u8> {
from(packet: DeviceResetRspPacket) -> Self5835     fn from(packet: DeviceResetRspPacket) -> Self {
5836         packet.to_vec()
5837     }
5838 }
5839 impl TryFrom<UciPacketPacket> for DeviceResetRspPacket {
5840     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>5841     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
5842         Self::new(value.uci_packet).map_err(TryFromError)
5843     }
5844 }
5845 impl DeviceResetRspPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>5846     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
5847         let uci_packet = root;
5848         let uci_response = match &uci_packet.child {
5849             UciPacketDataChild::UciResponse(value) => (*value).clone(),
5850             _ => return Err("inconsistent state - child was not UciResponse"),
5851         };
5852         let core_response = match &uci_response.child {
5853             UciResponseDataChild::CoreResponse(value) => (*value).clone(),
5854             _ => return Err("inconsistent state - child was not CoreResponse"),
5855         };
5856         let device_reset_rsp = match &core_response.child {
5857             CoreResponseDataChild::DeviceResetRsp(value) => (*value).clone(),
5858             _ => return Err("inconsistent state - child was not DeviceResetRsp"),
5859         };
5860         Ok(Self {
5861             uci_packet,
5862             uci_response,
5863             core_response,
5864             device_reset_rsp,
5865         })
5866     }
get_group_id(&self) -> GroupId5867     pub fn get_group_id(&self) -> GroupId {
5868         self.uci_packet.as_ref().group_id
5869     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag5870     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
5871         self.uci_packet.as_ref().packet_boundary_flag
5872     }
get_message_type(&self) -> MessageType5873     pub fn get_message_type(&self) -> MessageType {
5874         self.uci_packet.as_ref().message_type
5875     }
get_opcode(&self) -> u85876     pub fn get_opcode(&self) -> u8 {
5877         self.uci_packet.as_ref().opcode
5878     }
get_status(&self) -> StatusCode5879     pub fn get_status(&self) -> StatusCode {
5880         self.device_reset_rsp.as_ref().status
5881     }
5882 }
5883 impl Into<UciPacketPacket> for DeviceResetRspPacket {
into(self) -> UciPacketPacket5884     fn into(self) -> UciPacketPacket {
5885         UciPacketPacket::new(self.uci_packet).unwrap()
5886     }
5887 }
5888 impl Into<UciResponsePacket> for DeviceResetRspPacket {
into(self) -> UciResponsePacket5889     fn into(self) -> UciResponsePacket {
5890         UciResponsePacket::new(self.uci_packet).unwrap()
5891     }
5892 }
5893 impl Into<CoreResponsePacket> for DeviceResetRspPacket {
into(self) -> CoreResponsePacket5894     fn into(self) -> CoreResponsePacket {
5895         CoreResponsePacket::new(self.uci_packet).unwrap()
5896     }
5897 }
5898 impl DeviceResetRspBuilder {
build(self) -> DeviceResetRspPacket5899     pub fn build(self) -> DeviceResetRspPacket {
5900         let device_reset_rsp = Arc::new(DeviceResetRspData {
5901             status: self.status,
5902         });
5903         let core_response = Arc::new(CoreResponseData {
5904             child: CoreResponseDataChild::DeviceResetRsp(device_reset_rsp),
5905         });
5906         let uci_response = Arc::new(UciResponseData {
5907             child: UciResponseDataChild::CoreResponse(core_response),
5908         });
5909         let uci_packet = Arc::new(UciPacketData {
5910             group_id: GroupId::Core,
5911             packet_boundary_flag: PacketBoundaryFlag::Complete,
5912             message_type: MessageType::Response,
5913             opcode: 0,
5914             child: UciPacketDataChild::UciResponse(uci_response),
5915         });
5916         DeviceResetRspPacket::new(uci_packet).unwrap()
5917     }
5918 }
5919 impl Into<UciPacketPacket> for DeviceResetRspBuilder {
into(self) -> UciPacketPacket5920     fn into(self) -> UciPacketPacket {
5921         self.build().into()
5922     }
5923 }
5924 impl Into<UciResponsePacket> for DeviceResetRspBuilder {
into(self) -> UciResponsePacket5925     fn into(self) -> UciResponsePacket {
5926         self.build().into()
5927     }
5928 }
5929 impl Into<CoreResponsePacket> for DeviceResetRspBuilder {
into(self) -> CoreResponsePacket5930     fn into(self) -> CoreResponsePacket {
5931         self.build().into()
5932     }
5933 }
5934 macro_rules! device_reset_rsp_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
5935 #[test]
5936 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
5937 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
5938 UciPacketChild::UciResponse(uci_response_packet) => {match uci_response_packet.specialize() {/* (2) */
5939 UciResponseChild::CoreResponse(core_response_packet) => {match core_response_packet.specialize() {/* (3) */
5940 CoreResponseChild::DeviceResetRsp(packet) => {let rebuilder = DeviceResetRspBuilder {status : packet.get_status(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse device_reset_rsp
5941  {:#02x?}", core_response_packet); }}}_ => {panic!("Couldn't parse core_response
5942  {:#02x?}", uci_response_packet); }}}_ => {panic!("Couldn't parse uci_response
5943  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
5944 device_reset_rsp_builder_tests! { device_reset_rsp_builder_test_00: b"\x40\x00\x00\x01\x00",}
5945 
5946 #[derive(Debug)]
5947 struct DeviceStatusNtfData {
5948     device_state: DeviceState,
5949 }
5950 #[derive(Debug, Clone)]
5951 pub struct DeviceStatusNtfPacket {
5952     uci_packet: Arc<UciPacketData>,
5953     uci_notification: Arc<UciNotificationData>,
5954     core_notification: Arc<CoreNotificationData>,
5955     device_status_ntf: Arc<DeviceStatusNtfData>,
5956 }
5957 #[derive(Debug)]
5958 pub struct DeviceStatusNtfBuilder {
5959     pub device_state: DeviceState,
5960 }
5961 impl DeviceStatusNtfData {
conforms(bytes: &[u8]) -> bool5962     fn conforms(bytes: &[u8]) -> bool {
5963         if bytes.len() < 5 {
5964             return false;
5965         }
5966         true
5967     }
parse(bytes: &[u8]) -> Result<Self>5968     fn parse(bytes: &[u8]) -> Result<Self> {
5969         if bytes.len() < 5 {
5970             return Err(Error::InvalidLengthError {
5971                 obj: "DeviceStatusNtf".to_string(),
5972                 field: "device_state".to_string(),
5973                 wanted: 5,
5974                 got: bytes.len(),
5975             });
5976         }
5977         let device_state = u8::from_le_bytes([bytes[4]]);
5978         let device_state =
5979             DeviceState::from_u8(device_state).ok_or_else(|| Error::InvalidEnumValueError {
5980                 obj: "DeviceStatusNtf".to_string(),
5981                 field: "device_state".to_string(),
5982                 value: device_state as u64,
5983                 type_: "DeviceState".to_string(),
5984             })?;
5985         Ok(Self { device_state })
5986     }
write_to(&self, buffer: &mut BytesMut)5987     fn write_to(&self, buffer: &mut BytesMut) {
5988         let device_state = self.device_state.to_u8().unwrap();
5989         buffer[4..5].copy_from_slice(&device_state.to_le_bytes()[0..1]);
5990     }
get_total_size(&self) -> usize5991     fn get_total_size(&self) -> usize {
5992         self.get_size()
5993     }
get_size(&self) -> usize5994     fn get_size(&self) -> usize {
5995         let ret = 0;
5996         let ret = ret + 1;
5997         ret
5998     }
5999 }
6000 impl Packet for DeviceStatusNtfPacket {
to_bytes(self) -> Bytes6001     fn to_bytes(self) -> Bytes {
6002         let mut buffer = BytesMut::new();
6003         buffer.resize(self.uci_packet.get_total_size(), 0);
6004         self.uci_packet.write_to(&mut buffer);
6005         buffer.freeze()
6006     }
to_vec(self) -> Vec<u8>6007     fn to_vec(self) -> Vec<u8> {
6008         self.to_bytes().to_vec()
6009     }
6010 }
6011 impl From<DeviceStatusNtfPacket> for Bytes {
from(packet: DeviceStatusNtfPacket) -> Self6012     fn from(packet: DeviceStatusNtfPacket) -> Self {
6013         packet.to_bytes()
6014     }
6015 }
6016 impl From<DeviceStatusNtfPacket> for Vec<u8> {
from(packet: DeviceStatusNtfPacket) -> Self6017     fn from(packet: DeviceStatusNtfPacket) -> Self {
6018         packet.to_vec()
6019     }
6020 }
6021 impl TryFrom<UciPacketPacket> for DeviceStatusNtfPacket {
6022     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>6023     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
6024         Self::new(value.uci_packet).map_err(TryFromError)
6025     }
6026 }
6027 impl DeviceStatusNtfPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>6028     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
6029         let uci_packet = root;
6030         let uci_notification = match &uci_packet.child {
6031             UciPacketDataChild::UciNotification(value) => (*value).clone(),
6032             _ => return Err("inconsistent state - child was not UciNotification"),
6033         };
6034         let core_notification = match &uci_notification.child {
6035             UciNotificationDataChild::CoreNotification(value) => (*value).clone(),
6036             _ => return Err("inconsistent state - child was not CoreNotification"),
6037         };
6038         let device_status_ntf = match &core_notification.child {
6039             CoreNotificationDataChild::DeviceStatusNtf(value) => (*value).clone(),
6040             _ => return Err("inconsistent state - child was not DeviceStatusNtf"),
6041         };
6042         Ok(Self {
6043             uci_packet,
6044             uci_notification,
6045             core_notification,
6046             device_status_ntf,
6047         })
6048     }
get_group_id(&self) -> GroupId6049     pub fn get_group_id(&self) -> GroupId {
6050         self.uci_packet.as_ref().group_id
6051     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag6052     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
6053         self.uci_packet.as_ref().packet_boundary_flag
6054     }
get_message_type(&self) -> MessageType6055     pub fn get_message_type(&self) -> MessageType {
6056         self.uci_packet.as_ref().message_type
6057     }
get_opcode(&self) -> u86058     pub fn get_opcode(&self) -> u8 {
6059         self.uci_packet.as_ref().opcode
6060     }
get_device_state(&self) -> DeviceState6061     pub fn get_device_state(&self) -> DeviceState {
6062         self.device_status_ntf.as_ref().device_state
6063     }
6064 }
6065 impl Into<UciPacketPacket> for DeviceStatusNtfPacket {
into(self) -> UciPacketPacket6066     fn into(self) -> UciPacketPacket {
6067         UciPacketPacket::new(self.uci_packet).unwrap()
6068     }
6069 }
6070 impl Into<UciNotificationPacket> for DeviceStatusNtfPacket {
into(self) -> UciNotificationPacket6071     fn into(self) -> UciNotificationPacket {
6072         UciNotificationPacket::new(self.uci_packet).unwrap()
6073     }
6074 }
6075 impl Into<CoreNotificationPacket> for DeviceStatusNtfPacket {
into(self) -> CoreNotificationPacket6076     fn into(self) -> CoreNotificationPacket {
6077         CoreNotificationPacket::new(self.uci_packet).unwrap()
6078     }
6079 }
6080 impl DeviceStatusNtfBuilder {
build(self) -> DeviceStatusNtfPacket6081     pub fn build(self) -> DeviceStatusNtfPacket {
6082         let device_status_ntf = Arc::new(DeviceStatusNtfData {
6083             device_state: self.device_state,
6084         });
6085         let core_notification = Arc::new(CoreNotificationData {
6086             child: CoreNotificationDataChild::DeviceStatusNtf(device_status_ntf),
6087         });
6088         let uci_notification = Arc::new(UciNotificationData {
6089             child: UciNotificationDataChild::CoreNotification(core_notification),
6090         });
6091         let uci_packet = Arc::new(UciPacketData {
6092             group_id: GroupId::Core,
6093             packet_boundary_flag: PacketBoundaryFlag::Complete,
6094             message_type: MessageType::Notification,
6095             opcode: 1,
6096             child: UciPacketDataChild::UciNotification(uci_notification),
6097         });
6098         DeviceStatusNtfPacket::new(uci_packet).unwrap()
6099     }
6100 }
6101 impl Into<UciPacketPacket> for DeviceStatusNtfBuilder {
into(self) -> UciPacketPacket6102     fn into(self) -> UciPacketPacket {
6103         self.build().into()
6104     }
6105 }
6106 impl Into<UciNotificationPacket> for DeviceStatusNtfBuilder {
into(self) -> UciNotificationPacket6107     fn into(self) -> UciNotificationPacket {
6108         self.build().into()
6109     }
6110 }
6111 impl Into<CoreNotificationPacket> for DeviceStatusNtfBuilder {
into(self) -> CoreNotificationPacket6112     fn into(self) -> CoreNotificationPacket {
6113         self.build().into()
6114     }
6115 }
6116 macro_rules! device_status_ntf_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
6117 #[test]
6118 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
6119 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
6120 UciPacketChild::UciNotification(uci_notification_packet) => {match uci_notification_packet.specialize() {/* (2) */
6121 UciNotificationChild::CoreNotification(core_notification_packet) => {match core_notification_packet.specialize() {/* (3) */
6122 CoreNotificationChild::DeviceStatusNtf(packet) => {let rebuilder = DeviceStatusNtfBuilder {device_state : packet.get_device_state(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse device_status_ntf
6123  {:#02x?}", core_notification_packet); }}}_ => {panic!("Couldn't parse core_notification
6124  {:#02x?}", uci_notification_packet); }}}_ => {panic!("Couldn't parse uci_notification
6125  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
6126 device_status_ntf_builder_tests! { device_status_ntf_builder_test_00: b"\x60\x01\x00\x01\x01",}
6127 
6128 #[derive(Debug)]
6129 struct GetDeviceInfoCmdData {}
6130 #[derive(Debug, Clone)]
6131 pub struct GetDeviceInfoCmdPacket {
6132     uci_packet: Arc<UciPacketData>,
6133     uci_command: Arc<UciCommandData>,
6134     core_command: Arc<CoreCommandData>,
6135     get_device_info_cmd: Arc<GetDeviceInfoCmdData>,
6136 }
6137 #[derive(Debug)]
6138 pub struct GetDeviceInfoCmdBuilder {}
6139 impl GetDeviceInfoCmdData {
conforms(bytes: &[u8]) -> bool6140     fn conforms(bytes: &[u8]) -> bool {
6141         if bytes.len() < 4 {
6142             return false;
6143         }
6144         true
6145     }
parse(bytes: &[u8]) -> Result<Self>6146     fn parse(bytes: &[u8]) -> Result<Self> {
6147         Ok(Self {})
6148     }
write_to(&self, buffer: &mut BytesMut)6149     fn write_to(&self, buffer: &mut BytesMut) {}
get_total_size(&self) -> usize6150     fn get_total_size(&self) -> usize {
6151         self.get_size()
6152     }
get_size(&self) -> usize6153     fn get_size(&self) -> usize {
6154         let ret = 0;
6155         ret
6156     }
6157 }
6158 impl Packet for GetDeviceInfoCmdPacket {
to_bytes(self) -> Bytes6159     fn to_bytes(self) -> Bytes {
6160         let mut buffer = BytesMut::new();
6161         buffer.resize(self.uci_packet.get_total_size(), 0);
6162         self.uci_packet.write_to(&mut buffer);
6163         buffer.freeze()
6164     }
to_vec(self) -> Vec<u8>6165     fn to_vec(self) -> Vec<u8> {
6166         self.to_bytes().to_vec()
6167     }
6168 }
6169 impl From<GetDeviceInfoCmdPacket> for Bytes {
from(packet: GetDeviceInfoCmdPacket) -> Self6170     fn from(packet: GetDeviceInfoCmdPacket) -> Self {
6171         packet.to_bytes()
6172     }
6173 }
6174 impl From<GetDeviceInfoCmdPacket> for Vec<u8> {
from(packet: GetDeviceInfoCmdPacket) -> Self6175     fn from(packet: GetDeviceInfoCmdPacket) -> Self {
6176         packet.to_vec()
6177     }
6178 }
6179 impl TryFrom<UciPacketPacket> for GetDeviceInfoCmdPacket {
6180     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>6181     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
6182         Self::new(value.uci_packet).map_err(TryFromError)
6183     }
6184 }
6185 impl GetDeviceInfoCmdPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>6186     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
6187         let uci_packet = root;
6188         let uci_command = match &uci_packet.child {
6189             UciPacketDataChild::UciCommand(value) => (*value).clone(),
6190             _ => return Err("inconsistent state - child was not UciCommand"),
6191         };
6192         let core_command = match &uci_command.child {
6193             UciCommandDataChild::CoreCommand(value) => (*value).clone(),
6194             _ => return Err("inconsistent state - child was not CoreCommand"),
6195         };
6196         let get_device_info_cmd = match &core_command.child {
6197             CoreCommandDataChild::GetDeviceInfoCmd(value) => (*value).clone(),
6198             _ => return Err("inconsistent state - child was not GetDeviceInfoCmd"),
6199         };
6200         Ok(Self {
6201             uci_packet,
6202             uci_command,
6203             core_command,
6204             get_device_info_cmd,
6205         })
6206     }
get_group_id(&self) -> GroupId6207     pub fn get_group_id(&self) -> GroupId {
6208         self.uci_packet.as_ref().group_id
6209     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag6210     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
6211         self.uci_packet.as_ref().packet_boundary_flag
6212     }
get_message_type(&self) -> MessageType6213     pub fn get_message_type(&self) -> MessageType {
6214         self.uci_packet.as_ref().message_type
6215     }
get_opcode(&self) -> u86216     pub fn get_opcode(&self) -> u8 {
6217         self.uci_packet.as_ref().opcode
6218     }
6219 }
6220 impl Into<UciPacketPacket> for GetDeviceInfoCmdPacket {
into(self) -> UciPacketPacket6221     fn into(self) -> UciPacketPacket {
6222         UciPacketPacket::new(self.uci_packet).unwrap()
6223     }
6224 }
6225 impl Into<UciCommandPacket> for GetDeviceInfoCmdPacket {
into(self) -> UciCommandPacket6226     fn into(self) -> UciCommandPacket {
6227         UciCommandPacket::new(self.uci_packet).unwrap()
6228     }
6229 }
6230 impl Into<CoreCommandPacket> for GetDeviceInfoCmdPacket {
into(self) -> CoreCommandPacket6231     fn into(self) -> CoreCommandPacket {
6232         CoreCommandPacket::new(self.uci_packet).unwrap()
6233     }
6234 }
6235 impl GetDeviceInfoCmdBuilder {
build(self) -> GetDeviceInfoCmdPacket6236     pub fn build(self) -> GetDeviceInfoCmdPacket {
6237         let get_device_info_cmd = Arc::new(GetDeviceInfoCmdData {});
6238         let core_command = Arc::new(CoreCommandData {
6239             child: CoreCommandDataChild::GetDeviceInfoCmd(get_device_info_cmd),
6240         });
6241         let uci_command = Arc::new(UciCommandData {
6242             child: UciCommandDataChild::CoreCommand(core_command),
6243         });
6244         let uci_packet = Arc::new(UciPacketData {
6245             group_id: GroupId::Core,
6246             packet_boundary_flag: PacketBoundaryFlag::Complete,
6247             message_type: MessageType::Command,
6248             opcode: 2,
6249             child: UciPacketDataChild::UciCommand(uci_command),
6250         });
6251         GetDeviceInfoCmdPacket::new(uci_packet).unwrap()
6252     }
6253 }
6254 impl Into<UciPacketPacket> for GetDeviceInfoCmdBuilder {
into(self) -> UciPacketPacket6255     fn into(self) -> UciPacketPacket {
6256         self.build().into()
6257     }
6258 }
6259 impl Into<UciCommandPacket> for GetDeviceInfoCmdBuilder {
into(self) -> UciCommandPacket6260     fn into(self) -> UciCommandPacket {
6261         self.build().into()
6262     }
6263 }
6264 impl Into<CoreCommandPacket> for GetDeviceInfoCmdBuilder {
into(self) -> CoreCommandPacket6265     fn into(self) -> CoreCommandPacket {
6266         self.build().into()
6267     }
6268 }
6269 macro_rules! get_device_info_cmd_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
6270 #[test]
6271 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
6272 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
6273 UciPacketChild::UciCommand(uci_command_packet) => {match uci_command_packet.specialize() {/* (2) */
6274 UciCommandChild::CoreCommand(core_command_packet) => {match core_command_packet.specialize() {/* (3) */
6275 CoreCommandChild::GetDeviceInfoCmd(packet) => {let rebuilder = GetDeviceInfoCmdBuilder {};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse get_device_info_cmd
6276  {:#02x?}", core_command_packet); }}}_ => {panic!("Couldn't parse core_command
6277  {:#02x?}", uci_command_packet); }}}_ => {panic!("Couldn't parse uci_command
6278  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
6279 get_device_info_cmd_builder_tests! { get_device_info_cmd_builder_test_00: b"\x20\x02\x00\x00",}
6280 
6281 #[derive(Debug)]
6282 struct GetDeviceInfoRspData {
6283     status: StatusCode,
6284     uci_version: u16,
6285     mac_version: u16,
6286     phy_version: u16,
6287     uci_test_version: u16,
6288     vendor_spec_info: Vec<u8>,
6289 }
6290 #[derive(Debug, Clone)]
6291 pub struct GetDeviceInfoRspPacket {
6292     uci_packet: Arc<UciPacketData>,
6293     uci_response: Arc<UciResponseData>,
6294     core_response: Arc<CoreResponseData>,
6295     get_device_info_rsp: Arc<GetDeviceInfoRspData>,
6296 }
6297 #[derive(Debug)]
6298 pub struct GetDeviceInfoRspBuilder {
6299     pub status: StatusCode,
6300     pub uci_version: u16,
6301     pub mac_version: u16,
6302     pub phy_version: u16,
6303     pub uci_test_version: u16,
6304     pub vendor_spec_info: Vec<u8>,
6305 }
6306 impl GetDeviceInfoRspData {
conforms(bytes: &[u8]) -> bool6307     fn conforms(bytes: &[u8]) -> bool {
6308         if bytes.len() < 14 {
6309             return false;
6310         }
6311         true
6312     }
parse(bytes: &[u8]) -> Result<Self>6313     fn parse(bytes: &[u8]) -> Result<Self> {
6314         if bytes.len() < 5 {
6315             return Err(Error::InvalidLengthError {
6316                 obj: "GetDeviceInfoRsp".to_string(),
6317                 field: "status".to_string(),
6318                 wanted: 5,
6319                 got: bytes.len(),
6320             });
6321         }
6322         let status = u8::from_le_bytes([bytes[4]]);
6323         let status = StatusCode::from_u8(status).ok_or_else(|| Error::InvalidEnumValueError {
6324             obj: "GetDeviceInfoRsp".to_string(),
6325             field: "status".to_string(),
6326             value: status as u64,
6327             type_: "StatusCode".to_string(),
6328         })?;
6329         if bytes.len() < 7 {
6330             return Err(Error::InvalidLengthError {
6331                 obj: "GetDeviceInfoRsp".to_string(),
6332                 field: "uci_version".to_string(),
6333                 wanted: 7,
6334                 got: bytes.len(),
6335             });
6336         }
6337         let uci_version = u16::from_le_bytes([bytes[5], bytes[6]]);
6338         if bytes.len() < 9 {
6339             return Err(Error::InvalidLengthError {
6340                 obj: "GetDeviceInfoRsp".to_string(),
6341                 field: "mac_version".to_string(),
6342                 wanted: 9,
6343                 got: bytes.len(),
6344             });
6345         }
6346         let mac_version = u16::from_le_bytes([bytes[7], bytes[8]]);
6347         if bytes.len() < 11 {
6348             return Err(Error::InvalidLengthError {
6349                 obj: "GetDeviceInfoRsp".to_string(),
6350                 field: "phy_version".to_string(),
6351                 wanted: 11,
6352                 got: bytes.len(),
6353             });
6354         }
6355         let phy_version = u16::from_le_bytes([bytes[9], bytes[10]]);
6356         if bytes.len() < 13 {
6357             return Err(Error::InvalidLengthError {
6358                 obj: "GetDeviceInfoRsp".to_string(),
6359                 field: "uci_test_version".to_string(),
6360                 wanted: 13,
6361                 got: bytes.len(),
6362             });
6363         }
6364         let uci_test_version = u16::from_le_bytes([bytes[11], bytes[12]]);
6365         if bytes.len() < 14 {
6366             return Err(Error::InvalidLengthError {
6367                 obj: "GetDeviceInfoRsp".to_string(),
6368                 field: "vendor_spec_info_count".to_string(),
6369                 wanted: 14,
6370                 got: bytes.len(),
6371             });
6372         }
6373         let vendor_spec_info_count = u8::from_le_bytes([bytes[13]]);
6374         let want_ = 14 + ((vendor_spec_info_count as usize) * 1);
6375         if bytes.len() < want_ {
6376             return Err(Error::InvalidLengthError {
6377                 obj: "GetDeviceInfoRsp".to_string(),
6378                 field: "vendor_spec_info".to_string(),
6379                 wanted: want_,
6380                 got: bytes.len(),
6381             });
6382         }
6383         let vendor_spec_info: Vec<u8> = bytes[14..14 + ((vendor_spec_info_count as usize) * 1)]
6384             .to_vec()
6385             .chunks_exact(1)
6386             .into_iter()
6387             .map(|i| u8::from_le_bytes([i[0]]))
6388             .collect();
6389         Ok(Self {
6390             status,
6391             uci_version,
6392             mac_version,
6393             phy_version,
6394             uci_test_version,
6395             vendor_spec_info,
6396         })
6397     }
write_to(&self, buffer: &mut BytesMut)6398     fn write_to(&self, buffer: &mut BytesMut) {
6399         let status = self.status.to_u8().unwrap();
6400         buffer[4..5].copy_from_slice(&status.to_le_bytes()[0..1]);
6401         let uci_version = self.uci_version;
6402         buffer[5..7].copy_from_slice(&uci_version.to_le_bytes()[0..2]);
6403         let mac_version = self.mac_version;
6404         buffer[7..9].copy_from_slice(&mac_version.to_le_bytes()[0..2]);
6405         let phy_version = self.phy_version;
6406         buffer[9..11].copy_from_slice(&phy_version.to_le_bytes()[0..2]);
6407         let uci_test_version = self.uci_test_version;
6408         buffer[11..13].copy_from_slice(&uci_test_version.to_le_bytes()[0..2]);
6409         buffer[13..14].copy_from_slice(&(self.vendor_spec_info.len() as u8).to_le_bytes());
6410         for (i, e) in self.vendor_spec_info.iter().enumerate() {
6411             buffer[14 + i..14 + i + 1].copy_from_slice(&e.to_le_bytes())
6412         }
6413     }
get_total_size(&self) -> usize6414     fn get_total_size(&self) -> usize {
6415         self.get_size()
6416     }
get_size(&self) -> usize6417     fn get_size(&self) -> usize {
6418         let ret = 0;
6419         let ret = ret + 10;
6420         let ret = ret + (self.vendor_spec_info.len() * ((/* Bits: */8 + /* Dynamic: */ 0) / 8));
6421         ret
6422     }
6423 }
6424 impl Packet for GetDeviceInfoRspPacket {
to_bytes(self) -> Bytes6425     fn to_bytes(self) -> Bytes {
6426         let mut buffer = BytesMut::new();
6427         buffer.resize(self.uci_packet.get_total_size(), 0);
6428         self.uci_packet.write_to(&mut buffer);
6429         buffer.freeze()
6430     }
to_vec(self) -> Vec<u8>6431     fn to_vec(self) -> Vec<u8> {
6432         self.to_bytes().to_vec()
6433     }
6434 }
6435 impl From<GetDeviceInfoRspPacket> for Bytes {
from(packet: GetDeviceInfoRspPacket) -> Self6436     fn from(packet: GetDeviceInfoRspPacket) -> Self {
6437         packet.to_bytes()
6438     }
6439 }
6440 impl From<GetDeviceInfoRspPacket> for Vec<u8> {
from(packet: GetDeviceInfoRspPacket) -> Self6441     fn from(packet: GetDeviceInfoRspPacket) -> Self {
6442         packet.to_vec()
6443     }
6444 }
6445 impl TryFrom<UciPacketPacket> for GetDeviceInfoRspPacket {
6446     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>6447     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
6448         Self::new(value.uci_packet).map_err(TryFromError)
6449     }
6450 }
6451 impl GetDeviceInfoRspPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>6452     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
6453         let uci_packet = root;
6454         let uci_response = match &uci_packet.child {
6455             UciPacketDataChild::UciResponse(value) => (*value).clone(),
6456             _ => return Err("inconsistent state - child was not UciResponse"),
6457         };
6458         let core_response = match &uci_response.child {
6459             UciResponseDataChild::CoreResponse(value) => (*value).clone(),
6460             _ => return Err("inconsistent state - child was not CoreResponse"),
6461         };
6462         let get_device_info_rsp = match &core_response.child {
6463             CoreResponseDataChild::GetDeviceInfoRsp(value) => (*value).clone(),
6464             _ => return Err("inconsistent state - child was not GetDeviceInfoRsp"),
6465         };
6466         Ok(Self {
6467             uci_packet,
6468             uci_response,
6469             core_response,
6470             get_device_info_rsp,
6471         })
6472     }
get_group_id(&self) -> GroupId6473     pub fn get_group_id(&self) -> GroupId {
6474         self.uci_packet.as_ref().group_id
6475     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag6476     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
6477         self.uci_packet.as_ref().packet_boundary_flag
6478     }
get_message_type(&self) -> MessageType6479     pub fn get_message_type(&self) -> MessageType {
6480         self.uci_packet.as_ref().message_type
6481     }
get_opcode(&self) -> u86482     pub fn get_opcode(&self) -> u8 {
6483         self.uci_packet.as_ref().opcode
6484     }
get_status(&self) -> StatusCode6485     pub fn get_status(&self) -> StatusCode {
6486         self.get_device_info_rsp.as_ref().status
6487     }
get_uci_version(&self) -> u166488     pub fn get_uci_version(&self) -> u16 {
6489         self.get_device_info_rsp.as_ref().uci_version
6490     }
get_mac_version(&self) -> u166491     pub fn get_mac_version(&self) -> u16 {
6492         self.get_device_info_rsp.as_ref().mac_version
6493     }
get_phy_version(&self) -> u166494     pub fn get_phy_version(&self) -> u16 {
6495         self.get_device_info_rsp.as_ref().phy_version
6496     }
get_uci_test_version(&self) -> u166497     pub fn get_uci_test_version(&self) -> u16 {
6498         self.get_device_info_rsp.as_ref().uci_test_version
6499     }
get_vendor_spec_info(&self) -> &Vec<u8>6500     pub fn get_vendor_spec_info(&self) -> &Vec<u8> {
6501         &self.get_device_info_rsp.as_ref().vendor_spec_info
6502     }
6503 }
6504 impl Into<UciPacketPacket> for GetDeviceInfoRspPacket {
into(self) -> UciPacketPacket6505     fn into(self) -> UciPacketPacket {
6506         UciPacketPacket::new(self.uci_packet).unwrap()
6507     }
6508 }
6509 impl Into<UciResponsePacket> for GetDeviceInfoRspPacket {
into(self) -> UciResponsePacket6510     fn into(self) -> UciResponsePacket {
6511         UciResponsePacket::new(self.uci_packet).unwrap()
6512     }
6513 }
6514 impl Into<CoreResponsePacket> for GetDeviceInfoRspPacket {
into(self) -> CoreResponsePacket6515     fn into(self) -> CoreResponsePacket {
6516         CoreResponsePacket::new(self.uci_packet).unwrap()
6517     }
6518 }
6519 impl GetDeviceInfoRspBuilder {
build(self) -> GetDeviceInfoRspPacket6520     pub fn build(self) -> GetDeviceInfoRspPacket {
6521         let get_device_info_rsp = Arc::new(GetDeviceInfoRspData {
6522             status: self.status,
6523             uci_version: self.uci_version,
6524             mac_version: self.mac_version,
6525             phy_version: self.phy_version,
6526             uci_test_version: self.uci_test_version,
6527             vendor_spec_info: self.vendor_spec_info,
6528         });
6529         let core_response = Arc::new(CoreResponseData {
6530             child: CoreResponseDataChild::GetDeviceInfoRsp(get_device_info_rsp),
6531         });
6532         let uci_response = Arc::new(UciResponseData {
6533             child: UciResponseDataChild::CoreResponse(core_response),
6534         });
6535         let uci_packet = Arc::new(UciPacketData {
6536             group_id: GroupId::Core,
6537             packet_boundary_flag: PacketBoundaryFlag::Complete,
6538             message_type: MessageType::Response,
6539             opcode: 2,
6540             child: UciPacketDataChild::UciResponse(uci_response),
6541         });
6542         GetDeviceInfoRspPacket::new(uci_packet).unwrap()
6543     }
6544 }
6545 impl Into<UciPacketPacket> for GetDeviceInfoRspBuilder {
into(self) -> UciPacketPacket6546     fn into(self) -> UciPacketPacket {
6547         self.build().into()
6548     }
6549 }
6550 impl Into<UciResponsePacket> for GetDeviceInfoRspBuilder {
into(self) -> UciResponsePacket6551     fn into(self) -> UciResponsePacket {
6552         self.build().into()
6553     }
6554 }
6555 impl Into<CoreResponsePacket> for GetDeviceInfoRspBuilder {
into(self) -> CoreResponsePacket6556     fn into(self) -> CoreResponsePacket {
6557         self.build().into()
6558     }
6559 }
6560 macro_rules! get_device_info_rsp_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
6561 #[test]
6562 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
6563 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
6564 UciPacketChild::UciResponse(uci_response_packet) => {match uci_response_packet.specialize() {/* (2) */
6565 UciResponseChild::CoreResponse(core_response_packet) => {match core_response_packet.specialize() {/* (3) */
6566 CoreResponseChild::GetDeviceInfoRsp(packet) => {let rebuilder = GetDeviceInfoRspBuilder {status : packet.get_status(),uci_version : packet.get_uci_version(),mac_version : packet.get_mac_version(),phy_version : packet.get_phy_version(),uci_test_version : packet.get_uci_test_version(),vendor_spec_info : packet.get_vendor_spec_info().to_vec(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse get_device_info_rsp
6567  {:#02x?}", core_response_packet); }}}_ => {panic!("Couldn't parse core_response
6568  {:#02x?}", uci_response_packet); }}}_ => {panic!("Couldn't parse uci_response
6569  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
6570 get_device_info_rsp_builder_tests! { get_device_info_rsp_builder_test_00: b"\x40\x02\x00\x0b\x01\x01\x00\x02\x00\x03\x00\x04\x00\x01\x0a",}
6571 
6572 #[derive(Debug)]
6573 struct GetCapsInfoCmdData {}
6574 #[derive(Debug, Clone)]
6575 pub struct GetCapsInfoCmdPacket {
6576     uci_packet: Arc<UciPacketData>,
6577     uci_command: Arc<UciCommandData>,
6578     core_command: Arc<CoreCommandData>,
6579     get_caps_info_cmd: Arc<GetCapsInfoCmdData>,
6580 }
6581 #[derive(Debug)]
6582 pub struct GetCapsInfoCmdBuilder {}
6583 impl GetCapsInfoCmdData {
conforms(bytes: &[u8]) -> bool6584     fn conforms(bytes: &[u8]) -> bool {
6585         if bytes.len() < 4 {
6586             return false;
6587         }
6588         true
6589     }
parse(bytes: &[u8]) -> Result<Self>6590     fn parse(bytes: &[u8]) -> Result<Self> {
6591         Ok(Self {})
6592     }
write_to(&self, buffer: &mut BytesMut)6593     fn write_to(&self, buffer: &mut BytesMut) {}
get_total_size(&self) -> usize6594     fn get_total_size(&self) -> usize {
6595         self.get_size()
6596     }
get_size(&self) -> usize6597     fn get_size(&self) -> usize {
6598         let ret = 0;
6599         ret
6600     }
6601 }
6602 impl Packet for GetCapsInfoCmdPacket {
to_bytes(self) -> Bytes6603     fn to_bytes(self) -> Bytes {
6604         let mut buffer = BytesMut::new();
6605         buffer.resize(self.uci_packet.get_total_size(), 0);
6606         self.uci_packet.write_to(&mut buffer);
6607         buffer.freeze()
6608     }
to_vec(self) -> Vec<u8>6609     fn to_vec(self) -> Vec<u8> {
6610         self.to_bytes().to_vec()
6611     }
6612 }
6613 impl From<GetCapsInfoCmdPacket> for Bytes {
from(packet: GetCapsInfoCmdPacket) -> Self6614     fn from(packet: GetCapsInfoCmdPacket) -> Self {
6615         packet.to_bytes()
6616     }
6617 }
6618 impl From<GetCapsInfoCmdPacket> for Vec<u8> {
from(packet: GetCapsInfoCmdPacket) -> Self6619     fn from(packet: GetCapsInfoCmdPacket) -> Self {
6620         packet.to_vec()
6621     }
6622 }
6623 impl TryFrom<UciPacketPacket> for GetCapsInfoCmdPacket {
6624     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>6625     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
6626         Self::new(value.uci_packet).map_err(TryFromError)
6627     }
6628 }
6629 impl GetCapsInfoCmdPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>6630     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
6631         let uci_packet = root;
6632         let uci_command = match &uci_packet.child {
6633             UciPacketDataChild::UciCommand(value) => (*value).clone(),
6634             _ => return Err("inconsistent state - child was not UciCommand"),
6635         };
6636         let core_command = match &uci_command.child {
6637             UciCommandDataChild::CoreCommand(value) => (*value).clone(),
6638             _ => return Err("inconsistent state - child was not CoreCommand"),
6639         };
6640         let get_caps_info_cmd = match &core_command.child {
6641             CoreCommandDataChild::GetCapsInfoCmd(value) => (*value).clone(),
6642             _ => return Err("inconsistent state - child was not GetCapsInfoCmd"),
6643         };
6644         Ok(Self {
6645             uci_packet,
6646             uci_command,
6647             core_command,
6648             get_caps_info_cmd,
6649         })
6650     }
get_group_id(&self) -> GroupId6651     pub fn get_group_id(&self) -> GroupId {
6652         self.uci_packet.as_ref().group_id
6653     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag6654     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
6655         self.uci_packet.as_ref().packet_boundary_flag
6656     }
get_message_type(&self) -> MessageType6657     pub fn get_message_type(&self) -> MessageType {
6658         self.uci_packet.as_ref().message_type
6659     }
get_opcode(&self) -> u86660     pub fn get_opcode(&self) -> u8 {
6661         self.uci_packet.as_ref().opcode
6662     }
6663 }
6664 impl Into<UciPacketPacket> for GetCapsInfoCmdPacket {
into(self) -> UciPacketPacket6665     fn into(self) -> UciPacketPacket {
6666         UciPacketPacket::new(self.uci_packet).unwrap()
6667     }
6668 }
6669 impl Into<UciCommandPacket> for GetCapsInfoCmdPacket {
into(self) -> UciCommandPacket6670     fn into(self) -> UciCommandPacket {
6671         UciCommandPacket::new(self.uci_packet).unwrap()
6672     }
6673 }
6674 impl Into<CoreCommandPacket> for GetCapsInfoCmdPacket {
into(self) -> CoreCommandPacket6675     fn into(self) -> CoreCommandPacket {
6676         CoreCommandPacket::new(self.uci_packet).unwrap()
6677     }
6678 }
6679 impl GetCapsInfoCmdBuilder {
build(self) -> GetCapsInfoCmdPacket6680     pub fn build(self) -> GetCapsInfoCmdPacket {
6681         let get_caps_info_cmd = Arc::new(GetCapsInfoCmdData {});
6682         let core_command = Arc::new(CoreCommandData {
6683             child: CoreCommandDataChild::GetCapsInfoCmd(get_caps_info_cmd),
6684         });
6685         let uci_command = Arc::new(UciCommandData {
6686             child: UciCommandDataChild::CoreCommand(core_command),
6687         });
6688         let uci_packet = Arc::new(UciPacketData {
6689             group_id: GroupId::Core,
6690             packet_boundary_flag: PacketBoundaryFlag::Complete,
6691             message_type: MessageType::Command,
6692             opcode: 3,
6693             child: UciPacketDataChild::UciCommand(uci_command),
6694         });
6695         GetCapsInfoCmdPacket::new(uci_packet).unwrap()
6696     }
6697 }
6698 impl Into<UciPacketPacket> for GetCapsInfoCmdBuilder {
into(self) -> UciPacketPacket6699     fn into(self) -> UciPacketPacket {
6700         self.build().into()
6701     }
6702 }
6703 impl Into<UciCommandPacket> for GetCapsInfoCmdBuilder {
into(self) -> UciCommandPacket6704     fn into(self) -> UciCommandPacket {
6705         self.build().into()
6706     }
6707 }
6708 impl Into<CoreCommandPacket> for GetCapsInfoCmdBuilder {
into(self) -> CoreCommandPacket6709     fn into(self) -> CoreCommandPacket {
6710         self.build().into()
6711     }
6712 }
6713 macro_rules! get_caps_info_cmd_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
6714 #[test]
6715 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
6716 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
6717 UciPacketChild::UciCommand(uci_command_packet) => {match uci_command_packet.specialize() {/* (2) */
6718 UciCommandChild::CoreCommand(core_command_packet) => {match core_command_packet.specialize() {/* (3) */
6719 CoreCommandChild::GetCapsInfoCmd(packet) => {let rebuilder = GetCapsInfoCmdBuilder {};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse get_caps_info_cmd
6720  {:#02x?}", core_command_packet); }}}_ => {panic!("Couldn't parse core_command
6721  {:#02x?}", uci_command_packet); }}}_ => {panic!("Couldn't parse uci_command
6722  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
6723 get_caps_info_cmd_builder_tests! { get_caps_info_cmd_builder_test_00: b"\x20\x03\x00\x00",}
6724 
6725 #[derive(Debug)]
6726 struct GetCapsInfoRspData {
6727     status: StatusCode,
6728     tlvs: Vec<CapTlv>,
6729 }
6730 #[derive(Debug, Clone)]
6731 pub struct GetCapsInfoRspPacket {
6732     uci_packet: Arc<UciPacketData>,
6733     uci_response: Arc<UciResponseData>,
6734     core_response: Arc<CoreResponseData>,
6735     get_caps_info_rsp: Arc<GetCapsInfoRspData>,
6736 }
6737 #[derive(Debug)]
6738 pub struct GetCapsInfoRspBuilder {
6739     pub status: StatusCode,
6740     pub tlvs: Vec<CapTlv>,
6741 }
6742 impl GetCapsInfoRspData {
conforms(bytes: &[u8]) -> bool6743     fn conforms(bytes: &[u8]) -> bool {
6744         if bytes.len() < 6 {
6745             return false;
6746         }
6747         true
6748     }
parse(bytes: &[u8]) -> Result<Self>6749     fn parse(bytes: &[u8]) -> Result<Self> {
6750         if bytes.len() < 5 {
6751             return Err(Error::InvalidLengthError {
6752                 obj: "GetCapsInfoRsp".to_string(),
6753                 field: "status".to_string(),
6754                 wanted: 5,
6755                 got: bytes.len(),
6756             });
6757         }
6758         let status = u8::from_le_bytes([bytes[4]]);
6759         let status = StatusCode::from_u8(status).ok_or_else(|| Error::InvalidEnumValueError {
6760             obj: "GetCapsInfoRsp".to_string(),
6761             field: "status".to_string(),
6762             value: status as u64,
6763             type_: "StatusCode".to_string(),
6764         })?;
6765         if bytes.len() < 6 {
6766             return Err(Error::InvalidLengthError {
6767                 obj: "GetCapsInfoRsp".to_string(),
6768                 field: "tlvs_count".to_string(),
6769                 wanted: 6,
6770                 got: bytes.len(),
6771             });
6772         }
6773         let tlvs_count = u8::from_le_bytes([bytes[5]]);
6774         let mut tlvs: Vec<CapTlv> = Vec::new();
6775         let mut parsable_ = &bytes[6..];
6776         let count_ = tlvs_count as usize;
6777         for _ in 0..count_ {
6778             match CapTlv::parse(&parsable_) {
6779                 Ok(parsed) => {
6780                     parsable_ = &parsable_[parsed.get_total_size()..];
6781                     tlvs.push(parsed);
6782                 }
6783                 Err(Error::ImpossibleStructError) => break,
6784                 Err(e) => return Err(e),
6785             }
6786         }
6787         Ok(Self { status, tlvs })
6788     }
write_to(&self, buffer: &mut BytesMut)6789     fn write_to(&self, buffer: &mut BytesMut) {
6790         let status = self.status.to_u8().unwrap();
6791         buffer[4..5].copy_from_slice(&status.to_le_bytes()[0..1]);
6792         buffer[5..6].copy_from_slice(&(self.tlvs.len() as u8).to_le_bytes());
6793         let mut vec_buffer_ = &mut buffer[6..];
6794         for e_ in &self.tlvs {
6795             e_.write_to(&mut vec_buffer_[0..e_.get_total_size()]);
6796             vec_buffer_ = &mut vec_buffer_[e_.get_total_size()..];
6797         }
6798     }
get_total_size(&self) -> usize6799     fn get_total_size(&self) -> usize {
6800         self.get_size()
6801     }
get_size(&self) -> usize6802     fn get_size(&self) -> usize {
6803         let ret = 0;
6804         let ret = ret + 2;
6805         let ret = ret + self.tlvs.iter().fold(0, |acc, x| acc + x.get_total_size());
6806         ret
6807     }
6808 }
6809 impl Packet for GetCapsInfoRspPacket {
to_bytes(self) -> Bytes6810     fn to_bytes(self) -> Bytes {
6811         let mut buffer = BytesMut::new();
6812         buffer.resize(self.uci_packet.get_total_size(), 0);
6813         self.uci_packet.write_to(&mut buffer);
6814         buffer.freeze()
6815     }
to_vec(self) -> Vec<u8>6816     fn to_vec(self) -> Vec<u8> {
6817         self.to_bytes().to_vec()
6818     }
6819 }
6820 impl From<GetCapsInfoRspPacket> for Bytes {
from(packet: GetCapsInfoRspPacket) -> Self6821     fn from(packet: GetCapsInfoRspPacket) -> Self {
6822         packet.to_bytes()
6823     }
6824 }
6825 impl From<GetCapsInfoRspPacket> for Vec<u8> {
from(packet: GetCapsInfoRspPacket) -> Self6826     fn from(packet: GetCapsInfoRspPacket) -> Self {
6827         packet.to_vec()
6828     }
6829 }
6830 impl TryFrom<UciPacketPacket> for GetCapsInfoRspPacket {
6831     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>6832     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
6833         Self::new(value.uci_packet).map_err(TryFromError)
6834     }
6835 }
6836 impl GetCapsInfoRspPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>6837     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
6838         let uci_packet = root;
6839         let uci_response = match &uci_packet.child {
6840             UciPacketDataChild::UciResponse(value) => (*value).clone(),
6841             _ => return Err("inconsistent state - child was not UciResponse"),
6842         };
6843         let core_response = match &uci_response.child {
6844             UciResponseDataChild::CoreResponse(value) => (*value).clone(),
6845             _ => return Err("inconsistent state - child was not CoreResponse"),
6846         };
6847         let get_caps_info_rsp = match &core_response.child {
6848             CoreResponseDataChild::GetCapsInfoRsp(value) => (*value).clone(),
6849             _ => return Err("inconsistent state - child was not GetCapsInfoRsp"),
6850         };
6851         Ok(Self {
6852             uci_packet,
6853             uci_response,
6854             core_response,
6855             get_caps_info_rsp,
6856         })
6857     }
get_group_id(&self) -> GroupId6858     pub fn get_group_id(&self) -> GroupId {
6859         self.uci_packet.as_ref().group_id
6860     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag6861     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
6862         self.uci_packet.as_ref().packet_boundary_flag
6863     }
get_message_type(&self) -> MessageType6864     pub fn get_message_type(&self) -> MessageType {
6865         self.uci_packet.as_ref().message_type
6866     }
get_opcode(&self) -> u86867     pub fn get_opcode(&self) -> u8 {
6868         self.uci_packet.as_ref().opcode
6869     }
get_status(&self) -> StatusCode6870     pub fn get_status(&self) -> StatusCode {
6871         self.get_caps_info_rsp.as_ref().status
6872     }
get_tlvs(&self) -> &Vec<CapTlv>6873     pub fn get_tlvs(&self) -> &Vec<CapTlv> {
6874         &self.get_caps_info_rsp.as_ref().tlvs
6875     }
6876 }
6877 impl Into<UciPacketPacket> for GetCapsInfoRspPacket {
into(self) -> UciPacketPacket6878     fn into(self) -> UciPacketPacket {
6879         UciPacketPacket::new(self.uci_packet).unwrap()
6880     }
6881 }
6882 impl Into<UciResponsePacket> for GetCapsInfoRspPacket {
into(self) -> UciResponsePacket6883     fn into(self) -> UciResponsePacket {
6884         UciResponsePacket::new(self.uci_packet).unwrap()
6885     }
6886 }
6887 impl Into<CoreResponsePacket> for GetCapsInfoRspPacket {
into(self) -> CoreResponsePacket6888     fn into(self) -> CoreResponsePacket {
6889         CoreResponsePacket::new(self.uci_packet).unwrap()
6890     }
6891 }
6892 impl GetCapsInfoRspBuilder {
build(self) -> GetCapsInfoRspPacket6893     pub fn build(self) -> GetCapsInfoRspPacket {
6894         let get_caps_info_rsp = Arc::new(GetCapsInfoRspData {
6895             status: self.status,
6896             tlvs: self.tlvs,
6897         });
6898         let core_response = Arc::new(CoreResponseData {
6899             child: CoreResponseDataChild::GetCapsInfoRsp(get_caps_info_rsp),
6900         });
6901         let uci_response = Arc::new(UciResponseData {
6902             child: UciResponseDataChild::CoreResponse(core_response),
6903         });
6904         let uci_packet = Arc::new(UciPacketData {
6905             group_id: GroupId::Core,
6906             packet_boundary_flag: PacketBoundaryFlag::Complete,
6907             message_type: MessageType::Response,
6908             opcode: 3,
6909             child: UciPacketDataChild::UciResponse(uci_response),
6910         });
6911         GetCapsInfoRspPacket::new(uci_packet).unwrap()
6912     }
6913 }
6914 impl Into<UciPacketPacket> for GetCapsInfoRspBuilder {
into(self) -> UciPacketPacket6915     fn into(self) -> UciPacketPacket {
6916         self.build().into()
6917     }
6918 }
6919 impl Into<UciResponsePacket> for GetCapsInfoRspBuilder {
into(self) -> UciResponsePacket6920     fn into(self) -> UciResponsePacket {
6921         self.build().into()
6922     }
6923 }
6924 impl Into<CoreResponsePacket> for GetCapsInfoRspBuilder {
into(self) -> CoreResponsePacket6925     fn into(self) -> CoreResponsePacket {
6926         self.build().into()
6927     }
6928 }
6929 macro_rules! get_caps_info_rsp_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
6930 #[test]
6931 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
6932 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
6933 UciPacketChild::UciResponse(uci_response_packet) => {match uci_response_packet.specialize() {/* (2) */
6934 UciResponseChild::CoreResponse(core_response_packet) => {match core_response_packet.specialize() {/* (3) */
6935 CoreResponseChild::GetCapsInfoRsp(packet) => {let rebuilder = GetCapsInfoRspBuilder {status : packet.get_status(),tlvs : packet.get_tlvs().to_vec(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse get_caps_info_rsp
6936  {:#02x?}", core_response_packet); }}}_ => {panic!("Couldn't parse core_response
6937  {:#02x?}", uci_response_packet); }}}_ => {panic!("Couldn't parse uci_response
6938  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
6939 get_caps_info_rsp_builder_tests! { get_caps_info_rsp_builder_test_00: b"\x40\x03\x00\x05\x00\x01\x00\x01\x01",}
6940 
6941 #[derive(Debug)]
6942 struct SetConfigCmdData {
6943     parameters: Vec<DeviceParameter>,
6944 }
6945 #[derive(Debug, Clone)]
6946 pub struct SetConfigCmdPacket {
6947     uci_packet: Arc<UciPacketData>,
6948     uci_command: Arc<UciCommandData>,
6949     core_command: Arc<CoreCommandData>,
6950     set_config_cmd: Arc<SetConfigCmdData>,
6951 }
6952 #[derive(Debug)]
6953 pub struct SetConfigCmdBuilder {
6954     pub parameters: Vec<DeviceParameter>,
6955 }
6956 impl SetConfigCmdData {
conforms(bytes: &[u8]) -> bool6957     fn conforms(bytes: &[u8]) -> bool {
6958         if bytes.len() < 5 {
6959             return false;
6960         }
6961         true
6962     }
parse(bytes: &[u8]) -> Result<Self>6963     fn parse(bytes: &[u8]) -> Result<Self> {
6964         if bytes.len() < 5 {
6965             return Err(Error::InvalidLengthError {
6966                 obj: "SetConfigCmd".to_string(),
6967                 field: "parameters_count".to_string(),
6968                 wanted: 5,
6969                 got: bytes.len(),
6970             });
6971         }
6972         let parameters_count = u8::from_le_bytes([bytes[4]]);
6973         let mut parameters: Vec<DeviceParameter> = Vec::new();
6974         let mut parsable_ = &bytes[5..];
6975         let count_ = parameters_count as usize;
6976         for _ in 0..count_ {
6977             match DeviceParameter::parse(&parsable_) {
6978                 Ok(parsed) => {
6979                     parsable_ = &parsable_[parsed.get_total_size()..];
6980                     parameters.push(parsed);
6981                 }
6982                 Err(Error::ImpossibleStructError) => break,
6983                 Err(e) => return Err(e),
6984             }
6985         }
6986         Ok(Self { parameters })
6987     }
write_to(&self, buffer: &mut BytesMut)6988     fn write_to(&self, buffer: &mut BytesMut) {
6989         buffer[4..5].copy_from_slice(&(self.parameters.len() as u8).to_le_bytes());
6990         let mut vec_buffer_ = &mut buffer[5..];
6991         for e_ in &self.parameters {
6992             e_.write_to(&mut vec_buffer_[0..e_.get_total_size()]);
6993             vec_buffer_ = &mut vec_buffer_[e_.get_total_size()..];
6994         }
6995     }
get_total_size(&self) -> usize6996     fn get_total_size(&self) -> usize {
6997         self.get_size()
6998     }
get_size(&self) -> usize6999     fn get_size(&self) -> usize {
7000         let ret = 0;
7001         let ret = ret + 1;
7002         let ret = ret
7003             + self
7004                 .parameters
7005                 .iter()
7006                 .fold(0, |acc, x| acc + x.get_total_size());
7007         ret
7008     }
7009 }
7010 impl Packet for SetConfigCmdPacket {
to_bytes(self) -> Bytes7011     fn to_bytes(self) -> Bytes {
7012         let mut buffer = BytesMut::new();
7013         buffer.resize(self.uci_packet.get_total_size(), 0);
7014         self.uci_packet.write_to(&mut buffer);
7015         buffer.freeze()
7016     }
to_vec(self) -> Vec<u8>7017     fn to_vec(self) -> Vec<u8> {
7018         self.to_bytes().to_vec()
7019     }
7020 }
7021 impl From<SetConfigCmdPacket> for Bytes {
from(packet: SetConfigCmdPacket) -> Self7022     fn from(packet: SetConfigCmdPacket) -> Self {
7023         packet.to_bytes()
7024     }
7025 }
7026 impl From<SetConfigCmdPacket> for Vec<u8> {
from(packet: SetConfigCmdPacket) -> Self7027     fn from(packet: SetConfigCmdPacket) -> Self {
7028         packet.to_vec()
7029     }
7030 }
7031 impl TryFrom<UciPacketPacket> for SetConfigCmdPacket {
7032     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>7033     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
7034         Self::new(value.uci_packet).map_err(TryFromError)
7035     }
7036 }
7037 impl SetConfigCmdPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>7038     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
7039         let uci_packet = root;
7040         let uci_command = match &uci_packet.child {
7041             UciPacketDataChild::UciCommand(value) => (*value).clone(),
7042             _ => return Err("inconsistent state - child was not UciCommand"),
7043         };
7044         let core_command = match &uci_command.child {
7045             UciCommandDataChild::CoreCommand(value) => (*value).clone(),
7046             _ => return Err("inconsistent state - child was not CoreCommand"),
7047         };
7048         let set_config_cmd = match &core_command.child {
7049             CoreCommandDataChild::SetConfigCmd(value) => (*value).clone(),
7050             _ => return Err("inconsistent state - child was not SetConfigCmd"),
7051         };
7052         Ok(Self {
7053             uci_packet,
7054             uci_command,
7055             core_command,
7056             set_config_cmd,
7057         })
7058     }
get_group_id(&self) -> GroupId7059     pub fn get_group_id(&self) -> GroupId {
7060         self.uci_packet.as_ref().group_id
7061     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag7062     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
7063         self.uci_packet.as_ref().packet_boundary_flag
7064     }
get_message_type(&self) -> MessageType7065     pub fn get_message_type(&self) -> MessageType {
7066         self.uci_packet.as_ref().message_type
7067     }
get_opcode(&self) -> u87068     pub fn get_opcode(&self) -> u8 {
7069         self.uci_packet.as_ref().opcode
7070     }
get_parameters(&self) -> &Vec<DeviceParameter>7071     pub fn get_parameters(&self) -> &Vec<DeviceParameter> {
7072         &self.set_config_cmd.as_ref().parameters
7073     }
7074 }
7075 impl Into<UciPacketPacket> for SetConfigCmdPacket {
into(self) -> UciPacketPacket7076     fn into(self) -> UciPacketPacket {
7077         UciPacketPacket::new(self.uci_packet).unwrap()
7078     }
7079 }
7080 impl Into<UciCommandPacket> for SetConfigCmdPacket {
into(self) -> UciCommandPacket7081     fn into(self) -> UciCommandPacket {
7082         UciCommandPacket::new(self.uci_packet).unwrap()
7083     }
7084 }
7085 impl Into<CoreCommandPacket> for SetConfigCmdPacket {
into(self) -> CoreCommandPacket7086     fn into(self) -> CoreCommandPacket {
7087         CoreCommandPacket::new(self.uci_packet).unwrap()
7088     }
7089 }
7090 impl SetConfigCmdBuilder {
build(self) -> SetConfigCmdPacket7091     pub fn build(self) -> SetConfigCmdPacket {
7092         let set_config_cmd = Arc::new(SetConfigCmdData {
7093             parameters: self.parameters,
7094         });
7095         let core_command = Arc::new(CoreCommandData {
7096             child: CoreCommandDataChild::SetConfigCmd(set_config_cmd),
7097         });
7098         let uci_command = Arc::new(UciCommandData {
7099             child: UciCommandDataChild::CoreCommand(core_command),
7100         });
7101         let uci_packet = Arc::new(UciPacketData {
7102             group_id: GroupId::Core,
7103             packet_boundary_flag: PacketBoundaryFlag::Complete,
7104             message_type: MessageType::Command,
7105             opcode: 4,
7106             child: UciPacketDataChild::UciCommand(uci_command),
7107         });
7108         SetConfigCmdPacket::new(uci_packet).unwrap()
7109     }
7110 }
7111 impl Into<UciPacketPacket> for SetConfigCmdBuilder {
into(self) -> UciPacketPacket7112     fn into(self) -> UciPacketPacket {
7113         self.build().into()
7114     }
7115 }
7116 impl Into<UciCommandPacket> for SetConfigCmdBuilder {
into(self) -> UciCommandPacket7117     fn into(self) -> UciCommandPacket {
7118         self.build().into()
7119     }
7120 }
7121 impl Into<CoreCommandPacket> for SetConfigCmdBuilder {
into(self) -> CoreCommandPacket7122     fn into(self) -> CoreCommandPacket {
7123         self.build().into()
7124     }
7125 }
7126 macro_rules! set_config_cmd_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
7127 #[test]
7128 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
7129 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
7130 UciPacketChild::UciCommand(uci_command_packet) => {match uci_command_packet.specialize() {/* (2) */
7131 UciCommandChild::CoreCommand(core_command_packet) => {match core_command_packet.specialize() {/* (3) */
7132 CoreCommandChild::SetConfigCmd(packet) => {let rebuilder = SetConfigCmdBuilder {parameters : packet.get_parameters().to_vec(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse set_config_cmd
7133  {:#02x?}", core_command_packet); }}}_ => {panic!("Couldn't parse core_command
7134  {:#02x?}", uci_command_packet); }}}_ => {panic!("Couldn't parse uci_command
7135  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
7136 set_config_cmd_builder_tests! { set_config_cmd_builder_test_00: b"\x20\x04\x00\x03\x01\x01\x00",}
7137 
7138 #[derive(Debug)]
7139 struct SetConfigRspData {
7140     status: StatusCode,
7141     parameters: Vec<DeviceConfigStatus>,
7142 }
7143 #[derive(Debug, Clone)]
7144 pub struct SetConfigRspPacket {
7145     uci_packet: Arc<UciPacketData>,
7146     uci_response: Arc<UciResponseData>,
7147     core_response: Arc<CoreResponseData>,
7148     set_config_rsp: Arc<SetConfigRspData>,
7149 }
7150 #[derive(Debug)]
7151 pub struct SetConfigRspBuilder {
7152     pub status: StatusCode,
7153     pub parameters: Vec<DeviceConfigStatus>,
7154 }
7155 impl SetConfigRspData {
conforms(bytes: &[u8]) -> bool7156     fn conforms(bytes: &[u8]) -> bool {
7157         if bytes.len() < 6 {
7158             return false;
7159         }
7160         true
7161     }
parse(bytes: &[u8]) -> Result<Self>7162     fn parse(bytes: &[u8]) -> Result<Self> {
7163         if bytes.len() < 5 {
7164             return Err(Error::InvalidLengthError {
7165                 obj: "SetConfigRsp".to_string(),
7166                 field: "status".to_string(),
7167                 wanted: 5,
7168                 got: bytes.len(),
7169             });
7170         }
7171         let status = u8::from_le_bytes([bytes[4]]);
7172         let status = StatusCode::from_u8(status).ok_or_else(|| Error::InvalidEnumValueError {
7173             obj: "SetConfigRsp".to_string(),
7174             field: "status".to_string(),
7175             value: status as u64,
7176             type_: "StatusCode".to_string(),
7177         })?;
7178         if bytes.len() < 6 {
7179             return Err(Error::InvalidLengthError {
7180                 obj: "SetConfigRsp".to_string(),
7181                 field: "parameters_count".to_string(),
7182                 wanted: 6,
7183                 got: bytes.len(),
7184             });
7185         }
7186         let parameters_count = u8::from_le_bytes([bytes[5]]);
7187         let want_ = 6 + ((parameters_count as usize) * 2);
7188         if bytes.len() < want_ {
7189             return Err(Error::InvalidLengthError {
7190                 obj: "SetConfigRsp".to_string(),
7191                 field: "parameters".to_string(),
7192                 wanted: want_,
7193                 got: bytes.len(),
7194             });
7195         }
7196         let mut parameters: Vec<DeviceConfigStatus> = Vec::new();
7197         let mut parsable_ = &bytes[6..];
7198         let count_ = parameters_count as usize;
7199         for _ in 0..count_ {
7200             match DeviceConfigStatus::parse(&parsable_) {
7201                 Ok(parsed) => {
7202                     parsable_ = &parsable_[parsed.get_total_size()..];
7203                     parameters.push(parsed);
7204                 }
7205                 Err(Error::ImpossibleStructError) => break,
7206                 Err(e) => return Err(e),
7207             }
7208         }
7209         Ok(Self { status, parameters })
7210     }
write_to(&self, buffer: &mut BytesMut)7211     fn write_to(&self, buffer: &mut BytesMut) {
7212         let status = self.status.to_u8().unwrap();
7213         buffer[4..5].copy_from_slice(&status.to_le_bytes()[0..1]);
7214         buffer[5..6].copy_from_slice(&(self.parameters.len() as u8).to_le_bytes());
7215         let mut vec_buffer_ = &mut buffer[6..];
7216         for e_ in &self.parameters {
7217             e_.write_to(&mut vec_buffer_[0..e_.get_total_size()]);
7218             vec_buffer_ = &mut vec_buffer_[e_.get_total_size()..];
7219         }
7220     }
get_total_size(&self) -> usize7221     fn get_total_size(&self) -> usize {
7222         self.get_size()
7223     }
get_size(&self) -> usize7224     fn get_size(&self) -> usize {
7225         let ret = 0;
7226         let ret = ret + 2;
7227         let ret = ret + (self.parameters.len() * ((/* Bits: */16 + /* Dynamic: */ 0) / 8));
7228         ret
7229     }
7230 }
7231 impl Packet for SetConfigRspPacket {
to_bytes(self) -> Bytes7232     fn to_bytes(self) -> Bytes {
7233         let mut buffer = BytesMut::new();
7234         buffer.resize(self.uci_packet.get_total_size(), 0);
7235         self.uci_packet.write_to(&mut buffer);
7236         buffer.freeze()
7237     }
to_vec(self) -> Vec<u8>7238     fn to_vec(self) -> Vec<u8> {
7239         self.to_bytes().to_vec()
7240     }
7241 }
7242 impl From<SetConfigRspPacket> for Bytes {
from(packet: SetConfigRspPacket) -> Self7243     fn from(packet: SetConfigRspPacket) -> Self {
7244         packet.to_bytes()
7245     }
7246 }
7247 impl From<SetConfigRspPacket> for Vec<u8> {
from(packet: SetConfigRspPacket) -> Self7248     fn from(packet: SetConfigRspPacket) -> Self {
7249         packet.to_vec()
7250     }
7251 }
7252 impl TryFrom<UciPacketPacket> for SetConfigRspPacket {
7253     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>7254     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
7255         Self::new(value.uci_packet).map_err(TryFromError)
7256     }
7257 }
7258 impl SetConfigRspPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>7259     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
7260         let uci_packet = root;
7261         let uci_response = match &uci_packet.child {
7262             UciPacketDataChild::UciResponse(value) => (*value).clone(),
7263             _ => return Err("inconsistent state - child was not UciResponse"),
7264         };
7265         let core_response = match &uci_response.child {
7266             UciResponseDataChild::CoreResponse(value) => (*value).clone(),
7267             _ => return Err("inconsistent state - child was not CoreResponse"),
7268         };
7269         let set_config_rsp = match &core_response.child {
7270             CoreResponseDataChild::SetConfigRsp(value) => (*value).clone(),
7271             _ => return Err("inconsistent state - child was not SetConfigRsp"),
7272         };
7273         Ok(Self {
7274             uci_packet,
7275             uci_response,
7276             core_response,
7277             set_config_rsp,
7278         })
7279     }
get_group_id(&self) -> GroupId7280     pub fn get_group_id(&self) -> GroupId {
7281         self.uci_packet.as_ref().group_id
7282     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag7283     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
7284         self.uci_packet.as_ref().packet_boundary_flag
7285     }
get_message_type(&self) -> MessageType7286     pub fn get_message_type(&self) -> MessageType {
7287         self.uci_packet.as_ref().message_type
7288     }
get_opcode(&self) -> u87289     pub fn get_opcode(&self) -> u8 {
7290         self.uci_packet.as_ref().opcode
7291     }
get_status(&self) -> StatusCode7292     pub fn get_status(&self) -> StatusCode {
7293         self.set_config_rsp.as_ref().status
7294     }
get_parameters(&self) -> &Vec<DeviceConfigStatus>7295     pub fn get_parameters(&self) -> &Vec<DeviceConfigStatus> {
7296         &self.set_config_rsp.as_ref().parameters
7297     }
7298 }
7299 impl Into<UciPacketPacket> for SetConfigRspPacket {
into(self) -> UciPacketPacket7300     fn into(self) -> UciPacketPacket {
7301         UciPacketPacket::new(self.uci_packet).unwrap()
7302     }
7303 }
7304 impl Into<UciResponsePacket> for SetConfigRspPacket {
into(self) -> UciResponsePacket7305     fn into(self) -> UciResponsePacket {
7306         UciResponsePacket::new(self.uci_packet).unwrap()
7307     }
7308 }
7309 impl Into<CoreResponsePacket> for SetConfigRspPacket {
into(self) -> CoreResponsePacket7310     fn into(self) -> CoreResponsePacket {
7311         CoreResponsePacket::new(self.uci_packet).unwrap()
7312     }
7313 }
7314 impl SetConfigRspBuilder {
build(self) -> SetConfigRspPacket7315     pub fn build(self) -> SetConfigRspPacket {
7316         let set_config_rsp = Arc::new(SetConfigRspData {
7317             status: self.status,
7318             parameters: self.parameters,
7319         });
7320         let core_response = Arc::new(CoreResponseData {
7321             child: CoreResponseDataChild::SetConfigRsp(set_config_rsp),
7322         });
7323         let uci_response = Arc::new(UciResponseData {
7324             child: UciResponseDataChild::CoreResponse(core_response),
7325         });
7326         let uci_packet = Arc::new(UciPacketData {
7327             group_id: GroupId::Core,
7328             packet_boundary_flag: PacketBoundaryFlag::Complete,
7329             message_type: MessageType::Response,
7330             opcode: 4,
7331             child: UciPacketDataChild::UciResponse(uci_response),
7332         });
7333         SetConfigRspPacket::new(uci_packet).unwrap()
7334     }
7335 }
7336 impl Into<UciPacketPacket> for SetConfigRspBuilder {
into(self) -> UciPacketPacket7337     fn into(self) -> UciPacketPacket {
7338         self.build().into()
7339     }
7340 }
7341 impl Into<UciResponsePacket> for SetConfigRspBuilder {
into(self) -> UciResponsePacket7342     fn into(self) -> UciResponsePacket {
7343         self.build().into()
7344     }
7345 }
7346 impl Into<CoreResponsePacket> for SetConfigRspBuilder {
into(self) -> CoreResponsePacket7347     fn into(self) -> CoreResponsePacket {
7348         self.build().into()
7349     }
7350 }
7351 macro_rules! set_config_rsp_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
7352 #[test]
7353 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
7354 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
7355 UciPacketChild::UciResponse(uci_response_packet) => {match uci_response_packet.specialize() {/* (2) */
7356 UciResponseChild::CoreResponse(core_response_packet) => {match core_response_packet.specialize() {/* (3) */
7357 CoreResponseChild::SetConfigRsp(packet) => {let rebuilder = SetConfigRspBuilder {status : packet.get_status(),parameters : packet.get_parameters().to_vec(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse set_config_rsp
7358  {:#02x?}", core_response_packet); }}}_ => {panic!("Couldn't parse core_response
7359  {:#02x?}", uci_response_packet); }}}_ => {panic!("Couldn't parse uci_response
7360  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
7361 set_config_rsp_builder_tests! { set_config_rsp_builder_test_00: b"\x40\x04\x00\x04\x01\x01\x01\x01",}
7362 
7363 #[derive(Debug)]
7364 struct GetConfigCmdData {
7365     parameter_ids: Vec<u8>,
7366 }
7367 #[derive(Debug, Clone)]
7368 pub struct GetConfigCmdPacket {
7369     uci_packet: Arc<UciPacketData>,
7370     uci_command: Arc<UciCommandData>,
7371     core_command: Arc<CoreCommandData>,
7372     get_config_cmd: Arc<GetConfigCmdData>,
7373 }
7374 #[derive(Debug)]
7375 pub struct GetConfigCmdBuilder {
7376     pub parameter_ids: Vec<u8>,
7377 }
7378 impl GetConfigCmdData {
conforms(bytes: &[u8]) -> bool7379     fn conforms(bytes: &[u8]) -> bool {
7380         if bytes.len() < 5 {
7381             return false;
7382         }
7383         true
7384     }
parse(bytes: &[u8]) -> Result<Self>7385     fn parse(bytes: &[u8]) -> Result<Self> {
7386         if bytes.len() < 5 {
7387             return Err(Error::InvalidLengthError {
7388                 obj: "GetConfigCmd".to_string(),
7389                 field: "parameter_ids_count".to_string(),
7390                 wanted: 5,
7391                 got: bytes.len(),
7392             });
7393         }
7394         let parameter_ids_count = u8::from_le_bytes([bytes[4]]);
7395         let want_ = 5 + ((parameter_ids_count as usize) * 1);
7396         if bytes.len() < want_ {
7397             return Err(Error::InvalidLengthError {
7398                 obj: "GetConfigCmd".to_string(),
7399                 field: "parameter_ids".to_string(),
7400                 wanted: want_,
7401                 got: bytes.len(),
7402             });
7403         }
7404         let parameter_ids: Vec<u8> = bytes[5..5 + ((parameter_ids_count as usize) * 1)]
7405             .to_vec()
7406             .chunks_exact(1)
7407             .into_iter()
7408             .map(|i| u8::from_le_bytes([i[0]]))
7409             .collect();
7410         Ok(Self { parameter_ids })
7411     }
write_to(&self, buffer: &mut BytesMut)7412     fn write_to(&self, buffer: &mut BytesMut) {
7413         buffer[4..5].copy_from_slice(&(self.parameter_ids.len() as u8).to_le_bytes());
7414         for (i, e) in self.parameter_ids.iter().enumerate() {
7415             buffer[5 + i..5 + i + 1].copy_from_slice(&e.to_le_bytes())
7416         }
7417     }
get_total_size(&self) -> usize7418     fn get_total_size(&self) -> usize {
7419         self.get_size()
7420     }
get_size(&self) -> usize7421     fn get_size(&self) -> usize {
7422         let ret = 0;
7423         let ret = ret + 1;
7424         let ret = ret + (self.parameter_ids.len() * ((/* Bits: */8 + /* Dynamic: */ 0) / 8));
7425         ret
7426     }
7427 }
7428 impl Packet for GetConfigCmdPacket {
to_bytes(self) -> Bytes7429     fn to_bytes(self) -> Bytes {
7430         let mut buffer = BytesMut::new();
7431         buffer.resize(self.uci_packet.get_total_size(), 0);
7432         self.uci_packet.write_to(&mut buffer);
7433         buffer.freeze()
7434     }
to_vec(self) -> Vec<u8>7435     fn to_vec(self) -> Vec<u8> {
7436         self.to_bytes().to_vec()
7437     }
7438 }
7439 impl From<GetConfigCmdPacket> for Bytes {
from(packet: GetConfigCmdPacket) -> Self7440     fn from(packet: GetConfigCmdPacket) -> Self {
7441         packet.to_bytes()
7442     }
7443 }
7444 impl From<GetConfigCmdPacket> for Vec<u8> {
from(packet: GetConfigCmdPacket) -> Self7445     fn from(packet: GetConfigCmdPacket) -> Self {
7446         packet.to_vec()
7447     }
7448 }
7449 impl TryFrom<UciPacketPacket> for GetConfigCmdPacket {
7450     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>7451     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
7452         Self::new(value.uci_packet).map_err(TryFromError)
7453     }
7454 }
7455 impl GetConfigCmdPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>7456     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
7457         let uci_packet = root;
7458         let uci_command = match &uci_packet.child {
7459             UciPacketDataChild::UciCommand(value) => (*value).clone(),
7460             _ => return Err("inconsistent state - child was not UciCommand"),
7461         };
7462         let core_command = match &uci_command.child {
7463             UciCommandDataChild::CoreCommand(value) => (*value).clone(),
7464             _ => return Err("inconsistent state - child was not CoreCommand"),
7465         };
7466         let get_config_cmd = match &core_command.child {
7467             CoreCommandDataChild::GetConfigCmd(value) => (*value).clone(),
7468             _ => return Err("inconsistent state - child was not GetConfigCmd"),
7469         };
7470         Ok(Self {
7471             uci_packet,
7472             uci_command,
7473             core_command,
7474             get_config_cmd,
7475         })
7476     }
get_group_id(&self) -> GroupId7477     pub fn get_group_id(&self) -> GroupId {
7478         self.uci_packet.as_ref().group_id
7479     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag7480     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
7481         self.uci_packet.as_ref().packet_boundary_flag
7482     }
get_message_type(&self) -> MessageType7483     pub fn get_message_type(&self) -> MessageType {
7484         self.uci_packet.as_ref().message_type
7485     }
get_opcode(&self) -> u87486     pub fn get_opcode(&self) -> u8 {
7487         self.uci_packet.as_ref().opcode
7488     }
get_parameter_ids(&self) -> &Vec<u8>7489     pub fn get_parameter_ids(&self) -> &Vec<u8> {
7490         &self.get_config_cmd.as_ref().parameter_ids
7491     }
7492 }
7493 impl Into<UciPacketPacket> for GetConfigCmdPacket {
into(self) -> UciPacketPacket7494     fn into(self) -> UciPacketPacket {
7495         UciPacketPacket::new(self.uci_packet).unwrap()
7496     }
7497 }
7498 impl Into<UciCommandPacket> for GetConfigCmdPacket {
into(self) -> UciCommandPacket7499     fn into(self) -> UciCommandPacket {
7500         UciCommandPacket::new(self.uci_packet).unwrap()
7501     }
7502 }
7503 impl Into<CoreCommandPacket> for GetConfigCmdPacket {
into(self) -> CoreCommandPacket7504     fn into(self) -> CoreCommandPacket {
7505         CoreCommandPacket::new(self.uci_packet).unwrap()
7506     }
7507 }
7508 impl GetConfigCmdBuilder {
build(self) -> GetConfigCmdPacket7509     pub fn build(self) -> GetConfigCmdPacket {
7510         let get_config_cmd = Arc::new(GetConfigCmdData {
7511             parameter_ids: self.parameter_ids,
7512         });
7513         let core_command = Arc::new(CoreCommandData {
7514             child: CoreCommandDataChild::GetConfigCmd(get_config_cmd),
7515         });
7516         let uci_command = Arc::new(UciCommandData {
7517             child: UciCommandDataChild::CoreCommand(core_command),
7518         });
7519         let uci_packet = Arc::new(UciPacketData {
7520             group_id: GroupId::Core,
7521             packet_boundary_flag: PacketBoundaryFlag::Complete,
7522             message_type: MessageType::Command,
7523             opcode: 5,
7524             child: UciPacketDataChild::UciCommand(uci_command),
7525         });
7526         GetConfigCmdPacket::new(uci_packet).unwrap()
7527     }
7528 }
7529 impl Into<UciPacketPacket> for GetConfigCmdBuilder {
into(self) -> UciPacketPacket7530     fn into(self) -> UciPacketPacket {
7531         self.build().into()
7532     }
7533 }
7534 impl Into<UciCommandPacket> for GetConfigCmdBuilder {
into(self) -> UciCommandPacket7535     fn into(self) -> UciCommandPacket {
7536         self.build().into()
7537     }
7538 }
7539 impl Into<CoreCommandPacket> for GetConfigCmdBuilder {
into(self) -> CoreCommandPacket7540     fn into(self) -> CoreCommandPacket {
7541         self.build().into()
7542     }
7543 }
7544 macro_rules! get_config_cmd_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
7545 #[test]
7546 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
7547 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
7548 UciPacketChild::UciCommand(uci_command_packet) => {match uci_command_packet.specialize() {/* (2) */
7549 UciCommandChild::CoreCommand(core_command_packet) => {match core_command_packet.specialize() {/* (3) */
7550 CoreCommandChild::GetConfigCmd(packet) => {let rebuilder = GetConfigCmdBuilder {parameter_ids : packet.get_parameter_ids().to_vec(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse get_config_cmd
7551  {:#02x?}", core_command_packet); }}}_ => {panic!("Couldn't parse core_command
7552  {:#02x?}", uci_command_packet); }}}_ => {panic!("Couldn't parse uci_command
7553  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
7554 get_config_cmd_builder_tests! { get_config_cmd_builder_test_00: b"\x20\x05\x00\x02\x01\x01",}
7555 
7556 #[derive(Debug)]
7557 struct GetConfigRspData {
7558     status: StatusCode,
7559     parameters: Vec<DeviceParameter>,
7560 }
7561 #[derive(Debug, Clone)]
7562 pub struct GetConfigRspPacket {
7563     uci_packet: Arc<UciPacketData>,
7564     uci_response: Arc<UciResponseData>,
7565     core_response: Arc<CoreResponseData>,
7566     get_config_rsp: Arc<GetConfigRspData>,
7567 }
7568 #[derive(Debug)]
7569 pub struct GetConfigRspBuilder {
7570     pub status: StatusCode,
7571     pub parameters: Vec<DeviceParameter>,
7572 }
7573 impl GetConfigRspData {
conforms(bytes: &[u8]) -> bool7574     fn conforms(bytes: &[u8]) -> bool {
7575         if bytes.len() < 6 {
7576             return false;
7577         }
7578         true
7579     }
parse(bytes: &[u8]) -> Result<Self>7580     fn parse(bytes: &[u8]) -> Result<Self> {
7581         if bytes.len() < 5 {
7582             return Err(Error::InvalidLengthError {
7583                 obj: "GetConfigRsp".to_string(),
7584                 field: "status".to_string(),
7585                 wanted: 5,
7586                 got: bytes.len(),
7587             });
7588         }
7589         let status = u8::from_le_bytes([bytes[4]]);
7590         let status = StatusCode::from_u8(status).ok_or_else(|| Error::InvalidEnumValueError {
7591             obj: "GetConfigRsp".to_string(),
7592             field: "status".to_string(),
7593             value: status as u64,
7594             type_: "StatusCode".to_string(),
7595         })?;
7596         if bytes.len() < 6 {
7597             return Err(Error::InvalidLengthError {
7598                 obj: "GetConfigRsp".to_string(),
7599                 field: "parameters_count".to_string(),
7600                 wanted: 6,
7601                 got: bytes.len(),
7602             });
7603         }
7604         let parameters_count = u8::from_le_bytes([bytes[5]]);
7605         let mut parameters: Vec<DeviceParameter> = Vec::new();
7606         let mut parsable_ = &bytes[6..];
7607         let count_ = parameters_count as usize;
7608         for _ in 0..count_ {
7609             match DeviceParameter::parse(&parsable_) {
7610                 Ok(parsed) => {
7611                     parsable_ = &parsable_[parsed.get_total_size()..];
7612                     parameters.push(parsed);
7613                 }
7614                 Err(Error::ImpossibleStructError) => break,
7615                 Err(e) => return Err(e),
7616             }
7617         }
7618         Ok(Self { status, parameters })
7619     }
write_to(&self, buffer: &mut BytesMut)7620     fn write_to(&self, buffer: &mut BytesMut) {
7621         let status = self.status.to_u8().unwrap();
7622         buffer[4..5].copy_from_slice(&status.to_le_bytes()[0..1]);
7623         buffer[5..6].copy_from_slice(&(self.parameters.len() as u8).to_le_bytes());
7624         let mut vec_buffer_ = &mut buffer[6..];
7625         for e_ in &self.parameters {
7626             e_.write_to(&mut vec_buffer_[0..e_.get_total_size()]);
7627             vec_buffer_ = &mut vec_buffer_[e_.get_total_size()..];
7628         }
7629     }
get_total_size(&self) -> usize7630     fn get_total_size(&self) -> usize {
7631         self.get_size()
7632     }
get_size(&self) -> usize7633     fn get_size(&self) -> usize {
7634         let ret = 0;
7635         let ret = ret + 2;
7636         let ret = ret
7637             + self
7638                 .parameters
7639                 .iter()
7640                 .fold(0, |acc, x| acc + x.get_total_size());
7641         ret
7642     }
7643 }
7644 impl Packet for GetConfigRspPacket {
to_bytes(self) -> Bytes7645     fn to_bytes(self) -> Bytes {
7646         let mut buffer = BytesMut::new();
7647         buffer.resize(self.uci_packet.get_total_size(), 0);
7648         self.uci_packet.write_to(&mut buffer);
7649         buffer.freeze()
7650     }
to_vec(self) -> Vec<u8>7651     fn to_vec(self) -> Vec<u8> {
7652         self.to_bytes().to_vec()
7653     }
7654 }
7655 impl From<GetConfigRspPacket> for Bytes {
from(packet: GetConfigRspPacket) -> Self7656     fn from(packet: GetConfigRspPacket) -> Self {
7657         packet.to_bytes()
7658     }
7659 }
7660 impl From<GetConfigRspPacket> for Vec<u8> {
from(packet: GetConfigRspPacket) -> Self7661     fn from(packet: GetConfigRspPacket) -> Self {
7662         packet.to_vec()
7663     }
7664 }
7665 impl TryFrom<UciPacketPacket> for GetConfigRspPacket {
7666     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>7667     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
7668         Self::new(value.uci_packet).map_err(TryFromError)
7669     }
7670 }
7671 impl GetConfigRspPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>7672     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
7673         let uci_packet = root;
7674         let uci_response = match &uci_packet.child {
7675             UciPacketDataChild::UciResponse(value) => (*value).clone(),
7676             _ => return Err("inconsistent state - child was not UciResponse"),
7677         };
7678         let core_response = match &uci_response.child {
7679             UciResponseDataChild::CoreResponse(value) => (*value).clone(),
7680             _ => return Err("inconsistent state - child was not CoreResponse"),
7681         };
7682         let get_config_rsp = match &core_response.child {
7683             CoreResponseDataChild::GetConfigRsp(value) => (*value).clone(),
7684             _ => return Err("inconsistent state - child was not GetConfigRsp"),
7685         };
7686         Ok(Self {
7687             uci_packet,
7688             uci_response,
7689             core_response,
7690             get_config_rsp,
7691         })
7692     }
get_group_id(&self) -> GroupId7693     pub fn get_group_id(&self) -> GroupId {
7694         self.uci_packet.as_ref().group_id
7695     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag7696     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
7697         self.uci_packet.as_ref().packet_boundary_flag
7698     }
get_message_type(&self) -> MessageType7699     pub fn get_message_type(&self) -> MessageType {
7700         self.uci_packet.as_ref().message_type
7701     }
get_opcode(&self) -> u87702     pub fn get_opcode(&self) -> u8 {
7703         self.uci_packet.as_ref().opcode
7704     }
get_status(&self) -> StatusCode7705     pub fn get_status(&self) -> StatusCode {
7706         self.get_config_rsp.as_ref().status
7707     }
get_parameters(&self) -> &Vec<DeviceParameter>7708     pub fn get_parameters(&self) -> &Vec<DeviceParameter> {
7709         &self.get_config_rsp.as_ref().parameters
7710     }
7711 }
7712 impl Into<UciPacketPacket> for GetConfigRspPacket {
into(self) -> UciPacketPacket7713     fn into(self) -> UciPacketPacket {
7714         UciPacketPacket::new(self.uci_packet).unwrap()
7715     }
7716 }
7717 impl Into<UciResponsePacket> for GetConfigRspPacket {
into(self) -> UciResponsePacket7718     fn into(self) -> UciResponsePacket {
7719         UciResponsePacket::new(self.uci_packet).unwrap()
7720     }
7721 }
7722 impl Into<CoreResponsePacket> for GetConfigRspPacket {
into(self) -> CoreResponsePacket7723     fn into(self) -> CoreResponsePacket {
7724         CoreResponsePacket::new(self.uci_packet).unwrap()
7725     }
7726 }
7727 impl GetConfigRspBuilder {
build(self) -> GetConfigRspPacket7728     pub fn build(self) -> GetConfigRspPacket {
7729         let get_config_rsp = Arc::new(GetConfigRspData {
7730             status: self.status,
7731             parameters: self.parameters,
7732         });
7733         let core_response = Arc::new(CoreResponseData {
7734             child: CoreResponseDataChild::GetConfigRsp(get_config_rsp),
7735         });
7736         let uci_response = Arc::new(UciResponseData {
7737             child: UciResponseDataChild::CoreResponse(core_response),
7738         });
7739         let uci_packet = Arc::new(UciPacketData {
7740             group_id: GroupId::Core,
7741             packet_boundary_flag: PacketBoundaryFlag::Complete,
7742             message_type: MessageType::Response,
7743             opcode: 5,
7744             child: UciPacketDataChild::UciResponse(uci_response),
7745         });
7746         GetConfigRspPacket::new(uci_packet).unwrap()
7747     }
7748 }
7749 impl Into<UciPacketPacket> for GetConfigRspBuilder {
into(self) -> UciPacketPacket7750     fn into(self) -> UciPacketPacket {
7751         self.build().into()
7752     }
7753 }
7754 impl Into<UciResponsePacket> for GetConfigRspBuilder {
into(self) -> UciResponsePacket7755     fn into(self) -> UciResponsePacket {
7756         self.build().into()
7757     }
7758 }
7759 impl Into<CoreResponsePacket> for GetConfigRspBuilder {
into(self) -> CoreResponsePacket7760     fn into(self) -> CoreResponsePacket {
7761         self.build().into()
7762     }
7763 }
7764 macro_rules! get_config_rsp_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
7765 #[test]
7766 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
7767 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
7768 UciPacketChild::UciResponse(uci_response_packet) => {match uci_response_packet.specialize() {/* (2) */
7769 UciResponseChild::CoreResponse(core_response_packet) => {match core_response_packet.specialize() {/* (3) */
7770 CoreResponseChild::GetConfigRsp(packet) => {let rebuilder = GetConfigRspBuilder {status : packet.get_status(),parameters : packet.get_parameters().to_vec(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse get_config_rsp
7771  {:#02x?}", core_response_packet); }}}_ => {panic!("Couldn't parse core_response
7772  {:#02x?}", uci_response_packet); }}}_ => {panic!("Couldn't parse uci_response
7773  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
7774 get_config_rsp_builder_tests! { get_config_rsp_builder_test_00: b"\x40\x05\x00\x05\x01\x01\x00\x01\x01",}
7775 
7776 #[derive(Debug)]
7777 struct GenericErrorData {
7778     status: StatusCode,
7779 }
7780 #[derive(Debug, Clone)]
7781 pub struct GenericErrorPacket {
7782     uci_packet: Arc<UciPacketData>,
7783     uci_notification: Arc<UciNotificationData>,
7784     core_notification: Arc<CoreNotificationData>,
7785     generic_error: Arc<GenericErrorData>,
7786 }
7787 #[derive(Debug)]
7788 pub struct GenericErrorBuilder {
7789     pub status: StatusCode,
7790 }
7791 impl GenericErrorData {
conforms(bytes: &[u8]) -> bool7792     fn conforms(bytes: &[u8]) -> bool {
7793         if bytes.len() < 5 {
7794             return false;
7795         }
7796         true
7797     }
parse(bytes: &[u8]) -> Result<Self>7798     fn parse(bytes: &[u8]) -> Result<Self> {
7799         if bytes.len() < 5 {
7800             return Err(Error::InvalidLengthError {
7801                 obj: "GenericError".to_string(),
7802                 field: "status".to_string(),
7803                 wanted: 5,
7804                 got: bytes.len(),
7805             });
7806         }
7807         let status = u8::from_le_bytes([bytes[4]]);
7808         let status = StatusCode::from_u8(status).ok_or_else(|| Error::InvalidEnumValueError {
7809             obj: "GenericError".to_string(),
7810             field: "status".to_string(),
7811             value: status as u64,
7812             type_: "StatusCode".to_string(),
7813         })?;
7814         Ok(Self { status })
7815     }
write_to(&self, buffer: &mut BytesMut)7816     fn write_to(&self, buffer: &mut BytesMut) {
7817         let status = self.status.to_u8().unwrap();
7818         buffer[4..5].copy_from_slice(&status.to_le_bytes()[0..1]);
7819     }
get_total_size(&self) -> usize7820     fn get_total_size(&self) -> usize {
7821         self.get_size()
7822     }
get_size(&self) -> usize7823     fn get_size(&self) -> usize {
7824         let ret = 0;
7825         let ret = ret + 1;
7826         ret
7827     }
7828 }
7829 impl Packet for GenericErrorPacket {
to_bytes(self) -> Bytes7830     fn to_bytes(self) -> Bytes {
7831         let mut buffer = BytesMut::new();
7832         buffer.resize(self.uci_packet.get_total_size(), 0);
7833         self.uci_packet.write_to(&mut buffer);
7834         buffer.freeze()
7835     }
to_vec(self) -> Vec<u8>7836     fn to_vec(self) -> Vec<u8> {
7837         self.to_bytes().to_vec()
7838     }
7839 }
7840 impl From<GenericErrorPacket> for Bytes {
from(packet: GenericErrorPacket) -> Self7841     fn from(packet: GenericErrorPacket) -> Self {
7842         packet.to_bytes()
7843     }
7844 }
7845 impl From<GenericErrorPacket> for Vec<u8> {
from(packet: GenericErrorPacket) -> Self7846     fn from(packet: GenericErrorPacket) -> Self {
7847         packet.to_vec()
7848     }
7849 }
7850 impl TryFrom<UciPacketPacket> for GenericErrorPacket {
7851     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>7852     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
7853         Self::new(value.uci_packet).map_err(TryFromError)
7854     }
7855 }
7856 impl GenericErrorPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>7857     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
7858         let uci_packet = root;
7859         let uci_notification = match &uci_packet.child {
7860             UciPacketDataChild::UciNotification(value) => (*value).clone(),
7861             _ => return Err("inconsistent state - child was not UciNotification"),
7862         };
7863         let core_notification = match &uci_notification.child {
7864             UciNotificationDataChild::CoreNotification(value) => (*value).clone(),
7865             _ => return Err("inconsistent state - child was not CoreNotification"),
7866         };
7867         let generic_error = match &core_notification.child {
7868             CoreNotificationDataChild::GenericError(value) => (*value).clone(),
7869             _ => return Err("inconsistent state - child was not GenericError"),
7870         };
7871         Ok(Self {
7872             uci_packet,
7873             uci_notification,
7874             core_notification,
7875             generic_error,
7876         })
7877     }
get_group_id(&self) -> GroupId7878     pub fn get_group_id(&self) -> GroupId {
7879         self.uci_packet.as_ref().group_id
7880     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag7881     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
7882         self.uci_packet.as_ref().packet_boundary_flag
7883     }
get_message_type(&self) -> MessageType7884     pub fn get_message_type(&self) -> MessageType {
7885         self.uci_packet.as_ref().message_type
7886     }
get_opcode(&self) -> u87887     pub fn get_opcode(&self) -> u8 {
7888         self.uci_packet.as_ref().opcode
7889     }
get_status(&self) -> StatusCode7890     pub fn get_status(&self) -> StatusCode {
7891         self.generic_error.as_ref().status
7892     }
7893 }
7894 impl Into<UciPacketPacket> for GenericErrorPacket {
into(self) -> UciPacketPacket7895     fn into(self) -> UciPacketPacket {
7896         UciPacketPacket::new(self.uci_packet).unwrap()
7897     }
7898 }
7899 impl Into<UciNotificationPacket> for GenericErrorPacket {
into(self) -> UciNotificationPacket7900     fn into(self) -> UciNotificationPacket {
7901         UciNotificationPacket::new(self.uci_packet).unwrap()
7902     }
7903 }
7904 impl Into<CoreNotificationPacket> for GenericErrorPacket {
into(self) -> CoreNotificationPacket7905     fn into(self) -> CoreNotificationPacket {
7906         CoreNotificationPacket::new(self.uci_packet).unwrap()
7907     }
7908 }
7909 impl GenericErrorBuilder {
build(self) -> GenericErrorPacket7910     pub fn build(self) -> GenericErrorPacket {
7911         let generic_error = Arc::new(GenericErrorData {
7912             status: self.status,
7913         });
7914         let core_notification = Arc::new(CoreNotificationData {
7915             child: CoreNotificationDataChild::GenericError(generic_error),
7916         });
7917         let uci_notification = Arc::new(UciNotificationData {
7918             child: UciNotificationDataChild::CoreNotification(core_notification),
7919         });
7920         let uci_packet = Arc::new(UciPacketData {
7921             group_id: GroupId::Core,
7922             packet_boundary_flag: PacketBoundaryFlag::Complete,
7923             message_type: MessageType::Notification,
7924             opcode: 7,
7925             child: UciPacketDataChild::UciNotification(uci_notification),
7926         });
7927         GenericErrorPacket::new(uci_packet).unwrap()
7928     }
7929 }
7930 impl Into<UciPacketPacket> for GenericErrorBuilder {
into(self) -> UciPacketPacket7931     fn into(self) -> UciPacketPacket {
7932         self.build().into()
7933     }
7934 }
7935 impl Into<UciNotificationPacket> for GenericErrorBuilder {
into(self) -> UciNotificationPacket7936     fn into(self) -> UciNotificationPacket {
7937         self.build().into()
7938     }
7939 }
7940 impl Into<CoreNotificationPacket> for GenericErrorBuilder {
into(self) -> CoreNotificationPacket7941     fn into(self) -> CoreNotificationPacket {
7942         self.build().into()
7943     }
7944 }
7945 macro_rules! generic_error_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
7946 #[test]
7947 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
7948 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
7949 UciPacketChild::UciNotification(uci_notification_packet) => {match uci_notification_packet.specialize() {/* (2) */
7950 UciNotificationChild::CoreNotification(core_notification_packet) => {match core_notification_packet.specialize() {/* (3) */
7951 CoreNotificationChild::GenericError(packet) => {let rebuilder = GenericErrorBuilder {status : packet.get_status(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse generic_error
7952  {:#02x?}", core_notification_packet); }}}_ => {panic!("Couldn't parse core_notification
7953  {:#02x?}", uci_notification_packet); }}}_ => {panic!("Couldn't parse uci_notification
7954  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
7955 generic_error_builder_tests! { generic_error_builder_test_00: b"\x60\x07\x00\x01\x01",}
7956 
7957 #[derive(Debug)]
7958 struct SessionInitCmdData {
7959     session_id: u32,
7960     session_type: SessionType,
7961 }
7962 #[derive(Debug, Clone)]
7963 pub struct SessionInitCmdPacket {
7964     uci_packet: Arc<UciPacketData>,
7965     uci_command: Arc<UciCommandData>,
7966     session_command: Arc<SessionCommandData>,
7967     session_init_cmd: Arc<SessionInitCmdData>,
7968 }
7969 #[derive(Debug)]
7970 pub struct SessionInitCmdBuilder {
7971     pub session_id: u32,
7972     pub session_type: SessionType,
7973 }
7974 impl SessionInitCmdData {
conforms(bytes: &[u8]) -> bool7975     fn conforms(bytes: &[u8]) -> bool {
7976         if bytes.len() < 9 {
7977             return false;
7978         }
7979         true
7980     }
parse(bytes: &[u8]) -> Result<Self>7981     fn parse(bytes: &[u8]) -> Result<Self> {
7982         if bytes.len() < 8 {
7983             return Err(Error::InvalidLengthError {
7984                 obj: "SessionInitCmd".to_string(),
7985                 field: "session_id".to_string(),
7986                 wanted: 8,
7987                 got: bytes.len(),
7988             });
7989         }
7990         let session_id = u32::from_le_bytes([bytes[4], bytes[5], bytes[6], bytes[7]]);
7991         if bytes.len() < 9 {
7992             return Err(Error::InvalidLengthError {
7993                 obj: "SessionInitCmd".to_string(),
7994                 field: "session_type".to_string(),
7995                 wanted: 9,
7996                 got: bytes.len(),
7997             });
7998         }
7999         let session_type = u8::from_le_bytes([bytes[8]]);
8000         let session_type =
8001             SessionType::from_u8(session_type).ok_or_else(|| Error::InvalidEnumValueError {
8002                 obj: "SessionInitCmd".to_string(),
8003                 field: "session_type".to_string(),
8004                 value: session_type as u64,
8005                 type_: "SessionType".to_string(),
8006             })?;
8007         Ok(Self {
8008             session_id,
8009             session_type,
8010         })
8011     }
write_to(&self, buffer: &mut BytesMut)8012     fn write_to(&self, buffer: &mut BytesMut) {
8013         let session_id = self.session_id;
8014         buffer[4..8].copy_from_slice(&session_id.to_le_bytes()[0..4]);
8015         let session_type = self.session_type.to_u8().unwrap();
8016         buffer[8..9].copy_from_slice(&session_type.to_le_bytes()[0..1]);
8017     }
get_total_size(&self) -> usize8018     fn get_total_size(&self) -> usize {
8019         self.get_size()
8020     }
get_size(&self) -> usize8021     fn get_size(&self) -> usize {
8022         let ret = 0;
8023         let ret = ret + 5;
8024         ret
8025     }
8026 }
8027 impl Packet for SessionInitCmdPacket {
to_bytes(self) -> Bytes8028     fn to_bytes(self) -> Bytes {
8029         let mut buffer = BytesMut::new();
8030         buffer.resize(self.uci_packet.get_total_size(), 0);
8031         self.uci_packet.write_to(&mut buffer);
8032         buffer.freeze()
8033     }
to_vec(self) -> Vec<u8>8034     fn to_vec(self) -> Vec<u8> {
8035         self.to_bytes().to_vec()
8036     }
8037 }
8038 impl From<SessionInitCmdPacket> for Bytes {
from(packet: SessionInitCmdPacket) -> Self8039     fn from(packet: SessionInitCmdPacket) -> Self {
8040         packet.to_bytes()
8041     }
8042 }
8043 impl From<SessionInitCmdPacket> for Vec<u8> {
from(packet: SessionInitCmdPacket) -> Self8044     fn from(packet: SessionInitCmdPacket) -> Self {
8045         packet.to_vec()
8046     }
8047 }
8048 impl TryFrom<UciPacketPacket> for SessionInitCmdPacket {
8049     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>8050     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
8051         Self::new(value.uci_packet).map_err(TryFromError)
8052     }
8053 }
8054 impl SessionInitCmdPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>8055     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
8056         let uci_packet = root;
8057         let uci_command = match &uci_packet.child {
8058             UciPacketDataChild::UciCommand(value) => (*value).clone(),
8059             _ => return Err("inconsistent state - child was not UciCommand"),
8060         };
8061         let session_command = match &uci_command.child {
8062             UciCommandDataChild::SessionCommand(value) => (*value).clone(),
8063             _ => return Err("inconsistent state - child was not SessionCommand"),
8064         };
8065         let session_init_cmd = match &session_command.child {
8066             SessionCommandDataChild::SessionInitCmd(value) => (*value).clone(),
8067             _ => return Err("inconsistent state - child was not SessionInitCmd"),
8068         };
8069         Ok(Self {
8070             uci_packet,
8071             uci_command,
8072             session_command,
8073             session_init_cmd,
8074         })
8075     }
get_group_id(&self) -> GroupId8076     pub fn get_group_id(&self) -> GroupId {
8077         self.uci_packet.as_ref().group_id
8078     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag8079     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
8080         self.uci_packet.as_ref().packet_boundary_flag
8081     }
get_message_type(&self) -> MessageType8082     pub fn get_message_type(&self) -> MessageType {
8083         self.uci_packet.as_ref().message_type
8084     }
get_opcode(&self) -> u88085     pub fn get_opcode(&self) -> u8 {
8086         self.uci_packet.as_ref().opcode
8087     }
get_session_id(&self) -> u328088     pub fn get_session_id(&self) -> u32 {
8089         self.session_init_cmd.as_ref().session_id
8090     }
get_session_type(&self) -> SessionType8091     pub fn get_session_type(&self) -> SessionType {
8092         self.session_init_cmd.as_ref().session_type
8093     }
8094 }
8095 impl Into<UciPacketPacket> for SessionInitCmdPacket {
into(self) -> UciPacketPacket8096     fn into(self) -> UciPacketPacket {
8097         UciPacketPacket::new(self.uci_packet).unwrap()
8098     }
8099 }
8100 impl Into<UciCommandPacket> for SessionInitCmdPacket {
into(self) -> UciCommandPacket8101     fn into(self) -> UciCommandPacket {
8102         UciCommandPacket::new(self.uci_packet).unwrap()
8103     }
8104 }
8105 impl Into<SessionCommandPacket> for SessionInitCmdPacket {
into(self) -> SessionCommandPacket8106     fn into(self) -> SessionCommandPacket {
8107         SessionCommandPacket::new(self.uci_packet).unwrap()
8108     }
8109 }
8110 impl SessionInitCmdBuilder {
build(self) -> SessionInitCmdPacket8111     pub fn build(self) -> SessionInitCmdPacket {
8112         let session_init_cmd = Arc::new(SessionInitCmdData {
8113             session_id: self.session_id,
8114             session_type: self.session_type,
8115         });
8116         let session_command = Arc::new(SessionCommandData {
8117             child: SessionCommandDataChild::SessionInitCmd(session_init_cmd),
8118         });
8119         let uci_command = Arc::new(UciCommandData {
8120             child: UciCommandDataChild::SessionCommand(session_command),
8121         });
8122         let uci_packet = Arc::new(UciPacketData {
8123             group_id: GroupId::SessionConfig,
8124             packet_boundary_flag: PacketBoundaryFlag::Complete,
8125             message_type: MessageType::Command,
8126             opcode: 0,
8127             child: UciPacketDataChild::UciCommand(uci_command),
8128         });
8129         SessionInitCmdPacket::new(uci_packet).unwrap()
8130     }
8131 }
8132 impl Into<UciPacketPacket> for SessionInitCmdBuilder {
into(self) -> UciPacketPacket8133     fn into(self) -> UciPacketPacket {
8134         self.build().into()
8135     }
8136 }
8137 impl Into<UciCommandPacket> for SessionInitCmdBuilder {
into(self) -> UciCommandPacket8138     fn into(self) -> UciCommandPacket {
8139         self.build().into()
8140     }
8141 }
8142 impl Into<SessionCommandPacket> for SessionInitCmdBuilder {
into(self) -> SessionCommandPacket8143     fn into(self) -> SessionCommandPacket {
8144         self.build().into()
8145     }
8146 }
8147 macro_rules! session_init_cmd_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
8148 #[test]
8149 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
8150 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
8151 UciPacketChild::UciCommand(uci_command_packet) => {match uci_command_packet.specialize() {/* (2) */
8152 UciCommandChild::SessionCommand(session_command_packet) => {match session_command_packet.specialize() {/* (3) */
8153 SessionCommandChild::SessionInitCmd(packet) => {let rebuilder = SessionInitCmdBuilder {session_id : packet.get_session_id(),session_type : packet.get_session_type(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse session_init_cmd
8154  {:#02x?}", session_command_packet); }}}_ => {panic!("Couldn't parse session_command
8155  {:#02x?}", uci_command_packet); }}}_ => {panic!("Couldn't parse uci_command
8156  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
8157 session_init_cmd_builder_tests! { session_init_cmd_builder_test_00: b"\x22\x00\x00\x05\x01\x02\x03\x04\x01",}
8158 
8159 #[derive(Debug)]
8160 struct SessionInitRspData {
8161     status: StatusCode,
8162 }
8163 #[derive(Debug, Clone)]
8164 pub struct SessionInitRspPacket {
8165     uci_packet: Arc<UciPacketData>,
8166     uci_response: Arc<UciResponseData>,
8167     session_response: Arc<SessionResponseData>,
8168     session_init_rsp: Arc<SessionInitRspData>,
8169 }
8170 #[derive(Debug)]
8171 pub struct SessionInitRspBuilder {
8172     pub status: StatusCode,
8173 }
8174 impl SessionInitRspData {
conforms(bytes: &[u8]) -> bool8175     fn conforms(bytes: &[u8]) -> bool {
8176         if bytes.len() < 5 {
8177             return false;
8178         }
8179         true
8180     }
parse(bytes: &[u8]) -> Result<Self>8181     fn parse(bytes: &[u8]) -> Result<Self> {
8182         if bytes.len() < 5 {
8183             return Err(Error::InvalidLengthError {
8184                 obj: "SessionInitRsp".to_string(),
8185                 field: "status".to_string(),
8186                 wanted: 5,
8187                 got: bytes.len(),
8188             });
8189         }
8190         let status = u8::from_le_bytes([bytes[4]]);
8191         let status = StatusCode::from_u8(status).ok_or_else(|| Error::InvalidEnumValueError {
8192             obj: "SessionInitRsp".to_string(),
8193             field: "status".to_string(),
8194             value: status as u64,
8195             type_: "StatusCode".to_string(),
8196         })?;
8197         Ok(Self { status })
8198     }
write_to(&self, buffer: &mut BytesMut)8199     fn write_to(&self, buffer: &mut BytesMut) {
8200         let status = self.status.to_u8().unwrap();
8201         buffer[4..5].copy_from_slice(&status.to_le_bytes()[0..1]);
8202     }
get_total_size(&self) -> usize8203     fn get_total_size(&self) -> usize {
8204         self.get_size()
8205     }
get_size(&self) -> usize8206     fn get_size(&self) -> usize {
8207         let ret = 0;
8208         let ret = ret + 1;
8209         ret
8210     }
8211 }
8212 impl Packet for SessionInitRspPacket {
to_bytes(self) -> Bytes8213     fn to_bytes(self) -> Bytes {
8214         let mut buffer = BytesMut::new();
8215         buffer.resize(self.uci_packet.get_total_size(), 0);
8216         self.uci_packet.write_to(&mut buffer);
8217         buffer.freeze()
8218     }
to_vec(self) -> Vec<u8>8219     fn to_vec(self) -> Vec<u8> {
8220         self.to_bytes().to_vec()
8221     }
8222 }
8223 impl From<SessionInitRspPacket> for Bytes {
from(packet: SessionInitRspPacket) -> Self8224     fn from(packet: SessionInitRspPacket) -> Self {
8225         packet.to_bytes()
8226     }
8227 }
8228 impl From<SessionInitRspPacket> for Vec<u8> {
from(packet: SessionInitRspPacket) -> Self8229     fn from(packet: SessionInitRspPacket) -> Self {
8230         packet.to_vec()
8231     }
8232 }
8233 impl TryFrom<UciPacketPacket> for SessionInitRspPacket {
8234     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>8235     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
8236         Self::new(value.uci_packet).map_err(TryFromError)
8237     }
8238 }
8239 impl SessionInitRspPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>8240     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
8241         let uci_packet = root;
8242         let uci_response = match &uci_packet.child {
8243             UciPacketDataChild::UciResponse(value) => (*value).clone(),
8244             _ => return Err("inconsistent state - child was not UciResponse"),
8245         };
8246         let session_response = match &uci_response.child {
8247             UciResponseDataChild::SessionResponse(value) => (*value).clone(),
8248             _ => return Err("inconsistent state - child was not SessionResponse"),
8249         };
8250         let session_init_rsp = match &session_response.child {
8251             SessionResponseDataChild::SessionInitRsp(value) => (*value).clone(),
8252             _ => return Err("inconsistent state - child was not SessionInitRsp"),
8253         };
8254         Ok(Self {
8255             uci_packet,
8256             uci_response,
8257             session_response,
8258             session_init_rsp,
8259         })
8260     }
get_group_id(&self) -> GroupId8261     pub fn get_group_id(&self) -> GroupId {
8262         self.uci_packet.as_ref().group_id
8263     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag8264     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
8265         self.uci_packet.as_ref().packet_boundary_flag
8266     }
get_message_type(&self) -> MessageType8267     pub fn get_message_type(&self) -> MessageType {
8268         self.uci_packet.as_ref().message_type
8269     }
get_opcode(&self) -> u88270     pub fn get_opcode(&self) -> u8 {
8271         self.uci_packet.as_ref().opcode
8272     }
get_status(&self) -> StatusCode8273     pub fn get_status(&self) -> StatusCode {
8274         self.session_init_rsp.as_ref().status
8275     }
8276 }
8277 impl Into<UciPacketPacket> for SessionInitRspPacket {
into(self) -> UciPacketPacket8278     fn into(self) -> UciPacketPacket {
8279         UciPacketPacket::new(self.uci_packet).unwrap()
8280     }
8281 }
8282 impl Into<UciResponsePacket> for SessionInitRspPacket {
into(self) -> UciResponsePacket8283     fn into(self) -> UciResponsePacket {
8284         UciResponsePacket::new(self.uci_packet).unwrap()
8285     }
8286 }
8287 impl Into<SessionResponsePacket> for SessionInitRspPacket {
into(self) -> SessionResponsePacket8288     fn into(self) -> SessionResponsePacket {
8289         SessionResponsePacket::new(self.uci_packet).unwrap()
8290     }
8291 }
8292 impl SessionInitRspBuilder {
build(self) -> SessionInitRspPacket8293     pub fn build(self) -> SessionInitRspPacket {
8294         let session_init_rsp = Arc::new(SessionInitRspData {
8295             status: self.status,
8296         });
8297         let session_response = Arc::new(SessionResponseData {
8298             child: SessionResponseDataChild::SessionInitRsp(session_init_rsp),
8299         });
8300         let uci_response = Arc::new(UciResponseData {
8301             child: UciResponseDataChild::SessionResponse(session_response),
8302         });
8303         let uci_packet = Arc::new(UciPacketData {
8304             group_id: GroupId::SessionConfig,
8305             packet_boundary_flag: PacketBoundaryFlag::Complete,
8306             message_type: MessageType::Response,
8307             opcode: 0,
8308             child: UciPacketDataChild::UciResponse(uci_response),
8309         });
8310         SessionInitRspPacket::new(uci_packet).unwrap()
8311     }
8312 }
8313 impl Into<UciPacketPacket> for SessionInitRspBuilder {
into(self) -> UciPacketPacket8314     fn into(self) -> UciPacketPacket {
8315         self.build().into()
8316     }
8317 }
8318 impl Into<UciResponsePacket> for SessionInitRspBuilder {
into(self) -> UciResponsePacket8319     fn into(self) -> UciResponsePacket {
8320         self.build().into()
8321     }
8322 }
8323 impl Into<SessionResponsePacket> for SessionInitRspBuilder {
into(self) -> SessionResponsePacket8324     fn into(self) -> SessionResponsePacket {
8325         self.build().into()
8326     }
8327 }
8328 macro_rules! session_init_rsp_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
8329 #[test]
8330 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
8331 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
8332 UciPacketChild::UciResponse(uci_response_packet) => {match uci_response_packet.specialize() {/* (2) */
8333 UciResponseChild::SessionResponse(session_response_packet) => {match session_response_packet.specialize() {/* (3) */
8334 SessionResponseChild::SessionInitRsp(packet) => {let rebuilder = SessionInitRspBuilder {status : packet.get_status(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse session_init_rsp
8335  {:#02x?}", session_response_packet); }}}_ => {panic!("Couldn't parse session_response
8336  {:#02x?}", uci_response_packet); }}}_ => {panic!("Couldn't parse uci_response
8337  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
8338 session_init_rsp_builder_tests! { session_init_rsp_builder_test_00: b"\x41\x00\x00\x01\x11",}
8339 
8340 #[derive(Debug)]
8341 struct SessionDeinitCmdData {
8342     session_id: u32,
8343 }
8344 #[derive(Debug, Clone)]
8345 pub struct SessionDeinitCmdPacket {
8346     uci_packet: Arc<UciPacketData>,
8347     uci_command: Arc<UciCommandData>,
8348     session_command: Arc<SessionCommandData>,
8349     session_deinit_cmd: Arc<SessionDeinitCmdData>,
8350 }
8351 #[derive(Debug)]
8352 pub struct SessionDeinitCmdBuilder {
8353     pub session_id: u32,
8354 }
8355 impl SessionDeinitCmdData {
conforms(bytes: &[u8]) -> bool8356     fn conforms(bytes: &[u8]) -> bool {
8357         if bytes.len() < 8 {
8358             return false;
8359         }
8360         true
8361     }
parse(bytes: &[u8]) -> Result<Self>8362     fn parse(bytes: &[u8]) -> Result<Self> {
8363         if bytes.len() < 8 {
8364             return Err(Error::InvalidLengthError {
8365                 obj: "SessionDeinitCmd".to_string(),
8366                 field: "session_id".to_string(),
8367                 wanted: 8,
8368                 got: bytes.len(),
8369             });
8370         }
8371         let session_id = u32::from_le_bytes([bytes[4], bytes[5], bytes[6], bytes[7]]);
8372         Ok(Self { session_id })
8373     }
write_to(&self, buffer: &mut BytesMut)8374     fn write_to(&self, buffer: &mut BytesMut) {
8375         let session_id = self.session_id;
8376         buffer[4..8].copy_from_slice(&session_id.to_le_bytes()[0..4]);
8377     }
get_total_size(&self) -> usize8378     fn get_total_size(&self) -> usize {
8379         self.get_size()
8380     }
get_size(&self) -> usize8381     fn get_size(&self) -> usize {
8382         let ret = 0;
8383         let ret = ret + 4;
8384         ret
8385     }
8386 }
8387 impl Packet for SessionDeinitCmdPacket {
to_bytes(self) -> Bytes8388     fn to_bytes(self) -> Bytes {
8389         let mut buffer = BytesMut::new();
8390         buffer.resize(self.uci_packet.get_total_size(), 0);
8391         self.uci_packet.write_to(&mut buffer);
8392         buffer.freeze()
8393     }
to_vec(self) -> Vec<u8>8394     fn to_vec(self) -> Vec<u8> {
8395         self.to_bytes().to_vec()
8396     }
8397 }
8398 impl From<SessionDeinitCmdPacket> for Bytes {
from(packet: SessionDeinitCmdPacket) -> Self8399     fn from(packet: SessionDeinitCmdPacket) -> Self {
8400         packet.to_bytes()
8401     }
8402 }
8403 impl From<SessionDeinitCmdPacket> for Vec<u8> {
from(packet: SessionDeinitCmdPacket) -> Self8404     fn from(packet: SessionDeinitCmdPacket) -> Self {
8405         packet.to_vec()
8406     }
8407 }
8408 impl TryFrom<UciPacketPacket> for SessionDeinitCmdPacket {
8409     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>8410     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
8411         Self::new(value.uci_packet).map_err(TryFromError)
8412     }
8413 }
8414 impl SessionDeinitCmdPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>8415     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
8416         let uci_packet = root;
8417         let uci_command = match &uci_packet.child {
8418             UciPacketDataChild::UciCommand(value) => (*value).clone(),
8419             _ => return Err("inconsistent state - child was not UciCommand"),
8420         };
8421         let session_command = match &uci_command.child {
8422             UciCommandDataChild::SessionCommand(value) => (*value).clone(),
8423             _ => return Err("inconsistent state - child was not SessionCommand"),
8424         };
8425         let session_deinit_cmd = match &session_command.child {
8426             SessionCommandDataChild::SessionDeinitCmd(value) => (*value).clone(),
8427             _ => return Err("inconsistent state - child was not SessionDeinitCmd"),
8428         };
8429         Ok(Self {
8430             uci_packet,
8431             uci_command,
8432             session_command,
8433             session_deinit_cmd,
8434         })
8435     }
get_group_id(&self) -> GroupId8436     pub fn get_group_id(&self) -> GroupId {
8437         self.uci_packet.as_ref().group_id
8438     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag8439     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
8440         self.uci_packet.as_ref().packet_boundary_flag
8441     }
get_message_type(&self) -> MessageType8442     pub fn get_message_type(&self) -> MessageType {
8443         self.uci_packet.as_ref().message_type
8444     }
get_opcode(&self) -> u88445     pub fn get_opcode(&self) -> u8 {
8446         self.uci_packet.as_ref().opcode
8447     }
get_session_id(&self) -> u328448     pub fn get_session_id(&self) -> u32 {
8449         self.session_deinit_cmd.as_ref().session_id
8450     }
8451 }
8452 impl Into<UciPacketPacket> for SessionDeinitCmdPacket {
into(self) -> UciPacketPacket8453     fn into(self) -> UciPacketPacket {
8454         UciPacketPacket::new(self.uci_packet).unwrap()
8455     }
8456 }
8457 impl Into<UciCommandPacket> for SessionDeinitCmdPacket {
into(self) -> UciCommandPacket8458     fn into(self) -> UciCommandPacket {
8459         UciCommandPacket::new(self.uci_packet).unwrap()
8460     }
8461 }
8462 impl Into<SessionCommandPacket> for SessionDeinitCmdPacket {
into(self) -> SessionCommandPacket8463     fn into(self) -> SessionCommandPacket {
8464         SessionCommandPacket::new(self.uci_packet).unwrap()
8465     }
8466 }
8467 impl SessionDeinitCmdBuilder {
build(self) -> SessionDeinitCmdPacket8468     pub fn build(self) -> SessionDeinitCmdPacket {
8469         let session_deinit_cmd = Arc::new(SessionDeinitCmdData {
8470             session_id: self.session_id,
8471         });
8472         let session_command = Arc::new(SessionCommandData {
8473             child: SessionCommandDataChild::SessionDeinitCmd(session_deinit_cmd),
8474         });
8475         let uci_command = Arc::new(UciCommandData {
8476             child: UciCommandDataChild::SessionCommand(session_command),
8477         });
8478         let uci_packet = Arc::new(UciPacketData {
8479             group_id: GroupId::SessionConfig,
8480             packet_boundary_flag: PacketBoundaryFlag::Complete,
8481             message_type: MessageType::Command,
8482             opcode: 1,
8483             child: UciPacketDataChild::UciCommand(uci_command),
8484         });
8485         SessionDeinitCmdPacket::new(uci_packet).unwrap()
8486     }
8487 }
8488 impl Into<UciPacketPacket> for SessionDeinitCmdBuilder {
into(self) -> UciPacketPacket8489     fn into(self) -> UciPacketPacket {
8490         self.build().into()
8491     }
8492 }
8493 impl Into<UciCommandPacket> for SessionDeinitCmdBuilder {
into(self) -> UciCommandPacket8494     fn into(self) -> UciCommandPacket {
8495         self.build().into()
8496     }
8497 }
8498 impl Into<SessionCommandPacket> for SessionDeinitCmdBuilder {
into(self) -> SessionCommandPacket8499     fn into(self) -> SessionCommandPacket {
8500         self.build().into()
8501     }
8502 }
8503 macro_rules! session_deinit_cmd_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
8504 #[test]
8505 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
8506 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
8507 UciPacketChild::UciCommand(uci_command_packet) => {match uci_command_packet.specialize() {/* (2) */
8508 UciCommandChild::SessionCommand(session_command_packet) => {match session_command_packet.specialize() {/* (3) */
8509 SessionCommandChild::SessionDeinitCmd(packet) => {let rebuilder = SessionDeinitCmdBuilder {session_id : packet.get_session_id(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse session_deinit_cmd
8510  {:#02x?}", session_command_packet); }}}_ => {panic!("Couldn't parse session_command
8511  {:#02x?}", uci_command_packet); }}}_ => {panic!("Couldn't parse uci_command
8512  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
8513 session_deinit_cmd_builder_tests! { session_deinit_cmd_builder_test_00: b"\x21\x01\x00\x04\x01\x02\x03\x04",}
8514 
8515 #[derive(Debug)]
8516 struct SessionDeinitRspData {
8517     status: StatusCode,
8518 }
8519 #[derive(Debug, Clone)]
8520 pub struct SessionDeinitRspPacket {
8521     uci_packet: Arc<UciPacketData>,
8522     uci_response: Arc<UciResponseData>,
8523     session_response: Arc<SessionResponseData>,
8524     session_deinit_rsp: Arc<SessionDeinitRspData>,
8525 }
8526 #[derive(Debug)]
8527 pub struct SessionDeinitRspBuilder {
8528     pub status: StatusCode,
8529 }
8530 impl SessionDeinitRspData {
conforms(bytes: &[u8]) -> bool8531     fn conforms(bytes: &[u8]) -> bool {
8532         if bytes.len() < 5 {
8533             return false;
8534         }
8535         true
8536     }
parse(bytes: &[u8]) -> Result<Self>8537     fn parse(bytes: &[u8]) -> Result<Self> {
8538         if bytes.len() < 5 {
8539             return Err(Error::InvalidLengthError {
8540                 obj: "SessionDeinitRsp".to_string(),
8541                 field: "status".to_string(),
8542                 wanted: 5,
8543                 got: bytes.len(),
8544             });
8545         }
8546         let status = u8::from_le_bytes([bytes[4]]);
8547         let status = StatusCode::from_u8(status).ok_or_else(|| Error::InvalidEnumValueError {
8548             obj: "SessionDeinitRsp".to_string(),
8549             field: "status".to_string(),
8550             value: status as u64,
8551             type_: "StatusCode".to_string(),
8552         })?;
8553         Ok(Self { status })
8554     }
write_to(&self, buffer: &mut BytesMut)8555     fn write_to(&self, buffer: &mut BytesMut) {
8556         let status = self.status.to_u8().unwrap();
8557         buffer[4..5].copy_from_slice(&status.to_le_bytes()[0..1]);
8558     }
get_total_size(&self) -> usize8559     fn get_total_size(&self) -> usize {
8560         self.get_size()
8561     }
get_size(&self) -> usize8562     fn get_size(&self) -> usize {
8563         let ret = 0;
8564         let ret = ret + 1;
8565         ret
8566     }
8567 }
8568 impl Packet for SessionDeinitRspPacket {
to_bytes(self) -> Bytes8569     fn to_bytes(self) -> Bytes {
8570         let mut buffer = BytesMut::new();
8571         buffer.resize(self.uci_packet.get_total_size(), 0);
8572         self.uci_packet.write_to(&mut buffer);
8573         buffer.freeze()
8574     }
to_vec(self) -> Vec<u8>8575     fn to_vec(self) -> Vec<u8> {
8576         self.to_bytes().to_vec()
8577     }
8578 }
8579 impl From<SessionDeinitRspPacket> for Bytes {
from(packet: SessionDeinitRspPacket) -> Self8580     fn from(packet: SessionDeinitRspPacket) -> Self {
8581         packet.to_bytes()
8582     }
8583 }
8584 impl From<SessionDeinitRspPacket> for Vec<u8> {
from(packet: SessionDeinitRspPacket) -> Self8585     fn from(packet: SessionDeinitRspPacket) -> Self {
8586         packet.to_vec()
8587     }
8588 }
8589 impl TryFrom<UciPacketPacket> for SessionDeinitRspPacket {
8590     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>8591     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
8592         Self::new(value.uci_packet).map_err(TryFromError)
8593     }
8594 }
8595 impl SessionDeinitRspPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>8596     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
8597         let uci_packet = root;
8598         let uci_response = match &uci_packet.child {
8599             UciPacketDataChild::UciResponse(value) => (*value).clone(),
8600             _ => return Err("inconsistent state - child was not UciResponse"),
8601         };
8602         let session_response = match &uci_response.child {
8603             UciResponseDataChild::SessionResponse(value) => (*value).clone(),
8604             _ => return Err("inconsistent state - child was not SessionResponse"),
8605         };
8606         let session_deinit_rsp = match &session_response.child {
8607             SessionResponseDataChild::SessionDeinitRsp(value) => (*value).clone(),
8608             _ => return Err("inconsistent state - child was not SessionDeinitRsp"),
8609         };
8610         Ok(Self {
8611             uci_packet,
8612             uci_response,
8613             session_response,
8614             session_deinit_rsp,
8615         })
8616     }
get_group_id(&self) -> GroupId8617     pub fn get_group_id(&self) -> GroupId {
8618         self.uci_packet.as_ref().group_id
8619     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag8620     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
8621         self.uci_packet.as_ref().packet_boundary_flag
8622     }
get_message_type(&self) -> MessageType8623     pub fn get_message_type(&self) -> MessageType {
8624         self.uci_packet.as_ref().message_type
8625     }
get_opcode(&self) -> u88626     pub fn get_opcode(&self) -> u8 {
8627         self.uci_packet.as_ref().opcode
8628     }
get_status(&self) -> StatusCode8629     pub fn get_status(&self) -> StatusCode {
8630         self.session_deinit_rsp.as_ref().status
8631     }
8632 }
8633 impl Into<UciPacketPacket> for SessionDeinitRspPacket {
into(self) -> UciPacketPacket8634     fn into(self) -> UciPacketPacket {
8635         UciPacketPacket::new(self.uci_packet).unwrap()
8636     }
8637 }
8638 impl Into<UciResponsePacket> for SessionDeinitRspPacket {
into(self) -> UciResponsePacket8639     fn into(self) -> UciResponsePacket {
8640         UciResponsePacket::new(self.uci_packet).unwrap()
8641     }
8642 }
8643 impl Into<SessionResponsePacket> for SessionDeinitRspPacket {
into(self) -> SessionResponsePacket8644     fn into(self) -> SessionResponsePacket {
8645         SessionResponsePacket::new(self.uci_packet).unwrap()
8646     }
8647 }
8648 impl SessionDeinitRspBuilder {
build(self) -> SessionDeinitRspPacket8649     pub fn build(self) -> SessionDeinitRspPacket {
8650         let session_deinit_rsp = Arc::new(SessionDeinitRspData {
8651             status: self.status,
8652         });
8653         let session_response = Arc::new(SessionResponseData {
8654             child: SessionResponseDataChild::SessionDeinitRsp(session_deinit_rsp),
8655         });
8656         let uci_response = Arc::new(UciResponseData {
8657             child: UciResponseDataChild::SessionResponse(session_response),
8658         });
8659         let uci_packet = Arc::new(UciPacketData {
8660             group_id: GroupId::SessionConfig,
8661             packet_boundary_flag: PacketBoundaryFlag::Complete,
8662             message_type: MessageType::Response,
8663             opcode: 1,
8664             child: UciPacketDataChild::UciResponse(uci_response),
8665         });
8666         SessionDeinitRspPacket::new(uci_packet).unwrap()
8667     }
8668 }
8669 impl Into<UciPacketPacket> for SessionDeinitRspBuilder {
into(self) -> UciPacketPacket8670     fn into(self) -> UciPacketPacket {
8671         self.build().into()
8672     }
8673 }
8674 impl Into<UciResponsePacket> for SessionDeinitRspBuilder {
into(self) -> UciResponsePacket8675     fn into(self) -> UciResponsePacket {
8676         self.build().into()
8677     }
8678 }
8679 impl Into<SessionResponsePacket> for SessionDeinitRspBuilder {
into(self) -> SessionResponsePacket8680     fn into(self) -> SessionResponsePacket {
8681         self.build().into()
8682     }
8683 }
8684 macro_rules! session_deinit_rsp_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
8685 #[test]
8686 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
8687 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
8688 UciPacketChild::UciResponse(uci_response_packet) => {match uci_response_packet.specialize() {/* (2) */
8689 UciResponseChild::SessionResponse(session_response_packet) => {match session_response_packet.specialize() {/* (3) */
8690 SessionResponseChild::SessionDeinitRsp(packet) => {let rebuilder = SessionDeinitRspBuilder {status : packet.get_status(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse session_deinit_rsp
8691  {:#02x?}", session_response_packet); }}}_ => {panic!("Couldn't parse session_response
8692  {:#02x?}", uci_response_packet); }}}_ => {panic!("Couldn't parse uci_response
8693  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
8694 session_deinit_rsp_builder_tests! { session_deinit_rsp_builder_test_00: b"\x41\x01\x00\x01\x00",}
8695 
8696 #[derive(Debug)]
8697 struct SessionStatusNtfData {
8698     session_id: u32,
8699     session_state: SessionState,
8700     reason_code: ReasonCode,
8701 }
8702 #[derive(Debug, Clone)]
8703 pub struct SessionStatusNtfPacket {
8704     uci_packet: Arc<UciPacketData>,
8705     uci_notification: Arc<UciNotificationData>,
8706     session_notification: Arc<SessionNotificationData>,
8707     session_status_ntf: Arc<SessionStatusNtfData>,
8708 }
8709 #[derive(Debug)]
8710 pub struct SessionStatusNtfBuilder {
8711     pub session_id: u32,
8712     pub session_state: SessionState,
8713     pub reason_code: ReasonCode,
8714 }
8715 impl SessionStatusNtfData {
conforms(bytes: &[u8]) -> bool8716     fn conforms(bytes: &[u8]) -> bool {
8717         if bytes.len() < 10 {
8718             return false;
8719         }
8720         true
8721     }
parse(bytes: &[u8]) -> Result<Self>8722     fn parse(bytes: &[u8]) -> Result<Self> {
8723         if bytes.len() < 8 {
8724             return Err(Error::InvalidLengthError {
8725                 obj: "SessionStatusNtf".to_string(),
8726                 field: "session_id".to_string(),
8727                 wanted: 8,
8728                 got: bytes.len(),
8729             });
8730         }
8731         let session_id = u32::from_le_bytes([bytes[4], bytes[5], bytes[6], bytes[7]]);
8732         if bytes.len() < 9 {
8733             return Err(Error::InvalidLengthError {
8734                 obj: "SessionStatusNtf".to_string(),
8735                 field: "session_state".to_string(),
8736                 wanted: 9,
8737                 got: bytes.len(),
8738             });
8739         }
8740         let session_state = u8::from_le_bytes([bytes[8]]);
8741         let session_state =
8742             SessionState::from_u8(session_state).ok_or_else(|| Error::InvalidEnumValueError {
8743                 obj: "SessionStatusNtf".to_string(),
8744                 field: "session_state".to_string(),
8745                 value: session_state as u64,
8746                 type_: "SessionState".to_string(),
8747             })?;
8748         if bytes.len() < 10 {
8749             return Err(Error::InvalidLengthError {
8750                 obj: "SessionStatusNtf".to_string(),
8751                 field: "reason_code".to_string(),
8752                 wanted: 10,
8753                 got: bytes.len(),
8754             });
8755         }
8756         let reason_code = u8::from_le_bytes([bytes[9]]);
8757         let reason_code =
8758             ReasonCode::from_u8(reason_code).ok_or_else(|| Error::InvalidEnumValueError {
8759                 obj: "SessionStatusNtf".to_string(),
8760                 field: "reason_code".to_string(),
8761                 value: reason_code as u64,
8762                 type_: "ReasonCode".to_string(),
8763             })?;
8764         Ok(Self {
8765             session_id,
8766             session_state,
8767             reason_code,
8768         })
8769     }
write_to(&self, buffer: &mut BytesMut)8770     fn write_to(&self, buffer: &mut BytesMut) {
8771         let session_id = self.session_id;
8772         buffer[4..8].copy_from_slice(&session_id.to_le_bytes()[0..4]);
8773         let session_state = self.session_state.to_u8().unwrap();
8774         buffer[8..9].copy_from_slice(&session_state.to_le_bytes()[0..1]);
8775         let reason_code = self.reason_code.to_u8().unwrap();
8776         buffer[9..10].copy_from_slice(&reason_code.to_le_bytes()[0..1]);
8777     }
get_total_size(&self) -> usize8778     fn get_total_size(&self) -> usize {
8779         self.get_size()
8780     }
get_size(&self) -> usize8781     fn get_size(&self) -> usize {
8782         let ret = 0;
8783         let ret = ret + 6;
8784         ret
8785     }
8786 }
8787 impl Packet for SessionStatusNtfPacket {
to_bytes(self) -> Bytes8788     fn to_bytes(self) -> Bytes {
8789         let mut buffer = BytesMut::new();
8790         buffer.resize(self.uci_packet.get_total_size(), 0);
8791         self.uci_packet.write_to(&mut buffer);
8792         buffer.freeze()
8793     }
to_vec(self) -> Vec<u8>8794     fn to_vec(self) -> Vec<u8> {
8795         self.to_bytes().to_vec()
8796     }
8797 }
8798 impl From<SessionStatusNtfPacket> for Bytes {
from(packet: SessionStatusNtfPacket) -> Self8799     fn from(packet: SessionStatusNtfPacket) -> Self {
8800         packet.to_bytes()
8801     }
8802 }
8803 impl From<SessionStatusNtfPacket> for Vec<u8> {
from(packet: SessionStatusNtfPacket) -> Self8804     fn from(packet: SessionStatusNtfPacket) -> Self {
8805         packet.to_vec()
8806     }
8807 }
8808 impl TryFrom<UciPacketPacket> for SessionStatusNtfPacket {
8809     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>8810     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
8811         Self::new(value.uci_packet).map_err(TryFromError)
8812     }
8813 }
8814 impl SessionStatusNtfPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>8815     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
8816         let uci_packet = root;
8817         let uci_notification = match &uci_packet.child {
8818             UciPacketDataChild::UciNotification(value) => (*value).clone(),
8819             _ => return Err("inconsistent state - child was not UciNotification"),
8820         };
8821         let session_notification = match &uci_notification.child {
8822             UciNotificationDataChild::SessionNotification(value) => (*value).clone(),
8823             _ => return Err("inconsistent state - child was not SessionNotification"),
8824         };
8825         let session_status_ntf = match &session_notification.child {
8826             SessionNotificationDataChild::SessionStatusNtf(value) => (*value).clone(),
8827             _ => return Err("inconsistent state - child was not SessionStatusNtf"),
8828         };
8829         Ok(Self {
8830             uci_packet,
8831             uci_notification,
8832             session_notification,
8833             session_status_ntf,
8834         })
8835     }
get_group_id(&self) -> GroupId8836     pub fn get_group_id(&self) -> GroupId {
8837         self.uci_packet.as_ref().group_id
8838     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag8839     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
8840         self.uci_packet.as_ref().packet_boundary_flag
8841     }
get_message_type(&self) -> MessageType8842     pub fn get_message_type(&self) -> MessageType {
8843         self.uci_packet.as_ref().message_type
8844     }
get_opcode(&self) -> u88845     pub fn get_opcode(&self) -> u8 {
8846         self.uci_packet.as_ref().opcode
8847     }
get_session_id(&self) -> u328848     pub fn get_session_id(&self) -> u32 {
8849         self.session_status_ntf.as_ref().session_id
8850     }
get_session_state(&self) -> SessionState8851     pub fn get_session_state(&self) -> SessionState {
8852         self.session_status_ntf.as_ref().session_state
8853     }
get_reason_code(&self) -> ReasonCode8854     pub fn get_reason_code(&self) -> ReasonCode {
8855         self.session_status_ntf.as_ref().reason_code
8856     }
8857 }
8858 impl Into<UciPacketPacket> for SessionStatusNtfPacket {
into(self) -> UciPacketPacket8859     fn into(self) -> UciPacketPacket {
8860         UciPacketPacket::new(self.uci_packet).unwrap()
8861     }
8862 }
8863 impl Into<UciNotificationPacket> for SessionStatusNtfPacket {
into(self) -> UciNotificationPacket8864     fn into(self) -> UciNotificationPacket {
8865         UciNotificationPacket::new(self.uci_packet).unwrap()
8866     }
8867 }
8868 impl Into<SessionNotificationPacket> for SessionStatusNtfPacket {
into(self) -> SessionNotificationPacket8869     fn into(self) -> SessionNotificationPacket {
8870         SessionNotificationPacket::new(self.uci_packet).unwrap()
8871     }
8872 }
8873 impl SessionStatusNtfBuilder {
build(self) -> SessionStatusNtfPacket8874     pub fn build(self) -> SessionStatusNtfPacket {
8875         let session_status_ntf = Arc::new(SessionStatusNtfData {
8876             session_id: self.session_id,
8877             session_state: self.session_state,
8878             reason_code: self.reason_code,
8879         });
8880         let session_notification = Arc::new(SessionNotificationData {
8881             child: SessionNotificationDataChild::SessionStatusNtf(session_status_ntf),
8882         });
8883         let uci_notification = Arc::new(UciNotificationData {
8884             child: UciNotificationDataChild::SessionNotification(session_notification),
8885         });
8886         let uci_packet = Arc::new(UciPacketData {
8887             group_id: GroupId::SessionConfig,
8888             packet_boundary_flag: PacketBoundaryFlag::Complete,
8889             message_type: MessageType::Notification,
8890             opcode: 2,
8891             child: UciPacketDataChild::UciNotification(uci_notification),
8892         });
8893         SessionStatusNtfPacket::new(uci_packet).unwrap()
8894     }
8895 }
8896 impl Into<UciPacketPacket> for SessionStatusNtfBuilder {
into(self) -> UciPacketPacket8897     fn into(self) -> UciPacketPacket {
8898         self.build().into()
8899     }
8900 }
8901 impl Into<UciNotificationPacket> for SessionStatusNtfBuilder {
into(self) -> UciNotificationPacket8902     fn into(self) -> UciNotificationPacket {
8903         self.build().into()
8904     }
8905 }
8906 impl Into<SessionNotificationPacket> for SessionStatusNtfBuilder {
into(self) -> SessionNotificationPacket8907     fn into(self) -> SessionNotificationPacket {
8908         self.build().into()
8909     }
8910 }
8911 macro_rules! session_status_ntf_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
8912 #[test]
8913 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
8914 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
8915 UciPacketChild::UciNotification(uci_notification_packet) => {match uci_notification_packet.specialize() {/* (2) */
8916 UciNotificationChild::SessionNotification(session_notification_packet) => {match session_notification_packet.specialize() {/* (3) */
8917 SessionNotificationChild::SessionStatusNtf(packet) => {let rebuilder = SessionStatusNtfBuilder {session_id : packet.get_session_id(),session_state : packet.get_session_state(),reason_code : packet.get_reason_code(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse session_status_ntf
8918  {:#02x?}", session_notification_packet); }}}_ => {panic!("Couldn't parse session_notification
8919  {:#02x?}", uci_notification_packet); }}}_ => {panic!("Couldn't parse uci_notification
8920  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
8921 session_status_ntf_builder_tests! { session_status_ntf_builder_test_00: b"\x61\x02\x00\x06\x01\x02\x03\x04\x02\x21",}
8922 
8923 #[derive(Debug)]
8924 struct SessionSetAppConfigCmdData {
8925     session_id: u32,
8926     parameters: Vec<AppConfigParameter>,
8927 }
8928 #[derive(Debug, Clone)]
8929 pub struct SessionSetAppConfigCmdPacket {
8930     uci_packet: Arc<UciPacketData>,
8931     uci_command: Arc<UciCommandData>,
8932     session_command: Arc<SessionCommandData>,
8933     session_set_app_config_cmd: Arc<SessionSetAppConfigCmdData>,
8934 }
8935 #[derive(Debug)]
8936 pub struct SessionSetAppConfigCmdBuilder {
8937     pub session_id: u32,
8938     pub parameters: Vec<AppConfigParameter>,
8939 }
8940 impl SessionSetAppConfigCmdData {
conforms(bytes: &[u8]) -> bool8941     fn conforms(bytes: &[u8]) -> bool {
8942         if bytes.len() < 9 {
8943             return false;
8944         }
8945         true
8946     }
parse(bytes: &[u8]) -> Result<Self>8947     fn parse(bytes: &[u8]) -> Result<Self> {
8948         if bytes.len() < 8 {
8949             return Err(Error::InvalidLengthError {
8950                 obj: "SessionSetAppConfigCmd".to_string(),
8951                 field: "session_id".to_string(),
8952                 wanted: 8,
8953                 got: bytes.len(),
8954             });
8955         }
8956         let session_id = u32::from_le_bytes([bytes[4], bytes[5], bytes[6], bytes[7]]);
8957         if bytes.len() < 9 {
8958             return Err(Error::InvalidLengthError {
8959                 obj: "SessionSetAppConfigCmd".to_string(),
8960                 field: "parameters_count".to_string(),
8961                 wanted: 9,
8962                 got: bytes.len(),
8963             });
8964         }
8965         let parameters_count = u8::from_le_bytes([bytes[8]]);
8966         let mut parameters: Vec<AppConfigParameter> = Vec::new();
8967         let mut parsable_ = &bytes[9..];
8968         let count_ = parameters_count as usize;
8969         for _ in 0..count_ {
8970             match AppConfigParameter::parse(&parsable_) {
8971                 Ok(parsed) => {
8972                     parsable_ = &parsable_[parsed.get_total_size()..];
8973                     parameters.push(parsed);
8974                 }
8975                 Err(Error::ImpossibleStructError) => break,
8976                 Err(e) => return Err(e),
8977             }
8978         }
8979         Ok(Self {
8980             session_id,
8981             parameters,
8982         })
8983     }
write_to(&self, buffer: &mut BytesMut)8984     fn write_to(&self, buffer: &mut BytesMut) {
8985         let session_id = self.session_id;
8986         buffer[4..8].copy_from_slice(&session_id.to_le_bytes()[0..4]);
8987         buffer[8..9].copy_from_slice(&(self.parameters.len() as u8).to_le_bytes());
8988         let mut vec_buffer_ = &mut buffer[9..];
8989         for e_ in &self.parameters {
8990             e_.write_to(&mut vec_buffer_[0..e_.get_total_size()]);
8991             vec_buffer_ = &mut vec_buffer_[e_.get_total_size()..];
8992         }
8993     }
get_total_size(&self) -> usize8994     fn get_total_size(&self) -> usize {
8995         self.get_size()
8996     }
get_size(&self) -> usize8997     fn get_size(&self) -> usize {
8998         let ret = 0;
8999         let ret = ret + 5;
9000         let ret = ret
9001             + self
9002                 .parameters
9003                 .iter()
9004                 .fold(0, |acc, x| acc + x.get_total_size());
9005         ret
9006     }
9007 }
9008 impl Packet for SessionSetAppConfigCmdPacket {
to_bytes(self) -> Bytes9009     fn to_bytes(self) -> Bytes {
9010         let mut buffer = BytesMut::new();
9011         buffer.resize(self.uci_packet.get_total_size(), 0);
9012         self.uci_packet.write_to(&mut buffer);
9013         buffer.freeze()
9014     }
to_vec(self) -> Vec<u8>9015     fn to_vec(self) -> Vec<u8> {
9016         self.to_bytes().to_vec()
9017     }
9018 }
9019 impl From<SessionSetAppConfigCmdPacket> for Bytes {
from(packet: SessionSetAppConfigCmdPacket) -> Self9020     fn from(packet: SessionSetAppConfigCmdPacket) -> Self {
9021         packet.to_bytes()
9022     }
9023 }
9024 impl From<SessionSetAppConfigCmdPacket> for Vec<u8> {
from(packet: SessionSetAppConfigCmdPacket) -> Self9025     fn from(packet: SessionSetAppConfigCmdPacket) -> Self {
9026         packet.to_vec()
9027     }
9028 }
9029 impl TryFrom<UciPacketPacket> for SessionSetAppConfigCmdPacket {
9030     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>9031     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
9032         Self::new(value.uci_packet).map_err(TryFromError)
9033     }
9034 }
9035 impl SessionSetAppConfigCmdPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>9036     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
9037         let uci_packet = root;
9038         let uci_command = match &uci_packet.child {
9039             UciPacketDataChild::UciCommand(value) => (*value).clone(),
9040             _ => return Err("inconsistent state - child was not UciCommand"),
9041         };
9042         let session_command = match &uci_command.child {
9043             UciCommandDataChild::SessionCommand(value) => (*value).clone(),
9044             _ => return Err("inconsistent state - child was not SessionCommand"),
9045         };
9046         let session_set_app_config_cmd = match &session_command.child {
9047             SessionCommandDataChild::SessionSetAppConfigCmd(value) => (*value).clone(),
9048             _ => return Err("inconsistent state - child was not SessionSetAppConfigCmd"),
9049         };
9050         Ok(Self {
9051             uci_packet,
9052             uci_command,
9053             session_command,
9054             session_set_app_config_cmd,
9055         })
9056     }
get_group_id(&self) -> GroupId9057     pub fn get_group_id(&self) -> GroupId {
9058         self.uci_packet.as_ref().group_id
9059     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag9060     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
9061         self.uci_packet.as_ref().packet_boundary_flag
9062     }
get_message_type(&self) -> MessageType9063     pub fn get_message_type(&self) -> MessageType {
9064         self.uci_packet.as_ref().message_type
9065     }
get_opcode(&self) -> u89066     pub fn get_opcode(&self) -> u8 {
9067         self.uci_packet.as_ref().opcode
9068     }
get_session_id(&self) -> u329069     pub fn get_session_id(&self) -> u32 {
9070         self.session_set_app_config_cmd.as_ref().session_id
9071     }
get_parameters(&self) -> &Vec<AppConfigParameter>9072     pub fn get_parameters(&self) -> &Vec<AppConfigParameter> {
9073         &self.session_set_app_config_cmd.as_ref().parameters
9074     }
9075 }
9076 impl Into<UciPacketPacket> for SessionSetAppConfigCmdPacket {
into(self) -> UciPacketPacket9077     fn into(self) -> UciPacketPacket {
9078         UciPacketPacket::new(self.uci_packet).unwrap()
9079     }
9080 }
9081 impl Into<UciCommandPacket> for SessionSetAppConfigCmdPacket {
into(self) -> UciCommandPacket9082     fn into(self) -> UciCommandPacket {
9083         UciCommandPacket::new(self.uci_packet).unwrap()
9084     }
9085 }
9086 impl Into<SessionCommandPacket> for SessionSetAppConfigCmdPacket {
into(self) -> SessionCommandPacket9087     fn into(self) -> SessionCommandPacket {
9088         SessionCommandPacket::new(self.uci_packet).unwrap()
9089     }
9090 }
9091 impl SessionSetAppConfigCmdBuilder {
build(self) -> SessionSetAppConfigCmdPacket9092     pub fn build(self) -> SessionSetAppConfigCmdPacket {
9093         let session_set_app_config_cmd = Arc::new(SessionSetAppConfigCmdData {
9094             session_id: self.session_id,
9095             parameters: self.parameters,
9096         });
9097         let session_command = Arc::new(SessionCommandData {
9098             child: SessionCommandDataChild::SessionSetAppConfigCmd(session_set_app_config_cmd),
9099         });
9100         let uci_command = Arc::new(UciCommandData {
9101             child: UciCommandDataChild::SessionCommand(session_command),
9102         });
9103         let uci_packet = Arc::new(UciPacketData {
9104             group_id: GroupId::SessionConfig,
9105             packet_boundary_flag: PacketBoundaryFlag::Complete,
9106             message_type: MessageType::Command,
9107             opcode: 3,
9108             child: UciPacketDataChild::UciCommand(uci_command),
9109         });
9110         SessionSetAppConfigCmdPacket::new(uci_packet).unwrap()
9111     }
9112 }
9113 impl Into<UciPacketPacket> for SessionSetAppConfigCmdBuilder {
into(self) -> UciPacketPacket9114     fn into(self) -> UciPacketPacket {
9115         self.build().into()
9116     }
9117 }
9118 impl Into<UciCommandPacket> for SessionSetAppConfigCmdBuilder {
into(self) -> UciCommandPacket9119     fn into(self) -> UciCommandPacket {
9120         self.build().into()
9121     }
9122 }
9123 impl Into<SessionCommandPacket> for SessionSetAppConfigCmdBuilder {
into(self) -> SessionCommandPacket9124     fn into(self) -> SessionCommandPacket {
9125         self.build().into()
9126     }
9127 }
9128 macro_rules! session_set_app_config_cmd_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
9129 #[test]
9130 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
9131 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
9132 UciPacketChild::UciCommand(uci_command_packet) => {match uci_command_packet.specialize() {/* (2) */
9133 UciCommandChild::SessionCommand(session_command_packet) => {match session_command_packet.specialize() {/* (3) */
9134 SessionCommandChild::SessionSetAppConfigCmd(packet) => {let rebuilder = SessionSetAppConfigCmdBuilder {session_id : packet.get_session_id(),parameters : packet.get_parameters().to_vec(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse session_set_app_config_cmd
9135  {:#02x?}", session_command_packet); }}}_ => {panic!("Couldn't parse session_command
9136  {:#02x?}", uci_command_packet); }}}_ => {panic!("Couldn't parse uci_command
9137  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
9138 session_set_app_config_cmd_builder_tests! { session_set_app_config_cmd_builder_test_00: b"\x21\x03\x00\x05\x01\x02\x03\x04\x00",}
9139 
9140 #[derive(Debug)]
9141 struct SessionSetAppConfigRspData {
9142     status: StatusCode,
9143     parameters: Vec<AppConfigStatus>,
9144 }
9145 #[derive(Debug, Clone)]
9146 pub struct SessionSetAppConfigRspPacket {
9147     uci_packet: Arc<UciPacketData>,
9148     uci_response: Arc<UciResponseData>,
9149     session_response: Arc<SessionResponseData>,
9150     session_set_app_config_rsp: Arc<SessionSetAppConfigRspData>,
9151 }
9152 #[derive(Debug)]
9153 pub struct SessionSetAppConfigRspBuilder {
9154     pub status: StatusCode,
9155     pub parameters: Vec<AppConfigStatus>,
9156 }
9157 impl SessionSetAppConfigRspData {
conforms(bytes: &[u8]) -> bool9158     fn conforms(bytes: &[u8]) -> bool {
9159         if bytes.len() < 6 {
9160             return false;
9161         }
9162         true
9163     }
parse(bytes: &[u8]) -> Result<Self>9164     fn parse(bytes: &[u8]) -> Result<Self> {
9165         if bytes.len() < 5 {
9166             return Err(Error::InvalidLengthError {
9167                 obj: "SessionSetAppConfigRsp".to_string(),
9168                 field: "status".to_string(),
9169                 wanted: 5,
9170                 got: bytes.len(),
9171             });
9172         }
9173         let status = u8::from_le_bytes([bytes[4]]);
9174         let status = StatusCode::from_u8(status).ok_or_else(|| Error::InvalidEnumValueError {
9175             obj: "SessionSetAppConfigRsp".to_string(),
9176             field: "status".to_string(),
9177             value: status as u64,
9178             type_: "StatusCode".to_string(),
9179         })?;
9180         if bytes.len() < 6 {
9181             return Err(Error::InvalidLengthError {
9182                 obj: "SessionSetAppConfigRsp".to_string(),
9183                 field: "parameters_count".to_string(),
9184                 wanted: 6,
9185                 got: bytes.len(),
9186             });
9187         }
9188         let parameters_count = u8::from_le_bytes([bytes[5]]);
9189         let want_ = 6 + ((parameters_count as usize) * 2);
9190         if bytes.len() < want_ {
9191             return Err(Error::InvalidLengthError {
9192                 obj: "SessionSetAppConfigRsp".to_string(),
9193                 field: "parameters".to_string(),
9194                 wanted: want_,
9195                 got: bytes.len(),
9196             });
9197         }
9198         let mut parameters: Vec<AppConfigStatus> = Vec::new();
9199         let mut parsable_ = &bytes[6..];
9200         let count_ = parameters_count as usize;
9201         for _ in 0..count_ {
9202             match AppConfigStatus::parse(&parsable_) {
9203                 Ok(parsed) => {
9204                     parsable_ = &parsable_[parsed.get_total_size()..];
9205                     parameters.push(parsed);
9206                 }
9207                 Err(Error::ImpossibleStructError) => break,
9208                 Err(e) => return Err(e),
9209             }
9210         }
9211         Ok(Self { status, parameters })
9212     }
write_to(&self, buffer: &mut BytesMut)9213     fn write_to(&self, buffer: &mut BytesMut) {
9214         let status = self.status.to_u8().unwrap();
9215         buffer[4..5].copy_from_slice(&status.to_le_bytes()[0..1]);
9216         buffer[5..6].copy_from_slice(&(self.parameters.len() as u8).to_le_bytes());
9217         let mut vec_buffer_ = &mut buffer[6..];
9218         for e_ in &self.parameters {
9219             e_.write_to(&mut vec_buffer_[0..e_.get_total_size()]);
9220             vec_buffer_ = &mut vec_buffer_[e_.get_total_size()..];
9221         }
9222     }
get_total_size(&self) -> usize9223     fn get_total_size(&self) -> usize {
9224         self.get_size()
9225     }
get_size(&self) -> usize9226     fn get_size(&self) -> usize {
9227         let ret = 0;
9228         let ret = ret + 2;
9229         let ret = ret + (self.parameters.len() * ((/* Bits: */16 + /* Dynamic: */ 0) / 8));
9230         ret
9231     }
9232 }
9233 impl Packet for SessionSetAppConfigRspPacket {
to_bytes(self) -> Bytes9234     fn to_bytes(self) -> Bytes {
9235         let mut buffer = BytesMut::new();
9236         buffer.resize(self.uci_packet.get_total_size(), 0);
9237         self.uci_packet.write_to(&mut buffer);
9238         buffer.freeze()
9239     }
to_vec(self) -> Vec<u8>9240     fn to_vec(self) -> Vec<u8> {
9241         self.to_bytes().to_vec()
9242     }
9243 }
9244 impl From<SessionSetAppConfigRspPacket> for Bytes {
from(packet: SessionSetAppConfigRspPacket) -> Self9245     fn from(packet: SessionSetAppConfigRspPacket) -> Self {
9246         packet.to_bytes()
9247     }
9248 }
9249 impl From<SessionSetAppConfigRspPacket> for Vec<u8> {
from(packet: SessionSetAppConfigRspPacket) -> Self9250     fn from(packet: SessionSetAppConfigRspPacket) -> Self {
9251         packet.to_vec()
9252     }
9253 }
9254 impl TryFrom<UciPacketPacket> for SessionSetAppConfigRspPacket {
9255     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>9256     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
9257         Self::new(value.uci_packet).map_err(TryFromError)
9258     }
9259 }
9260 impl SessionSetAppConfigRspPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>9261     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
9262         let uci_packet = root;
9263         let uci_response = match &uci_packet.child {
9264             UciPacketDataChild::UciResponse(value) => (*value).clone(),
9265             _ => return Err("inconsistent state - child was not UciResponse"),
9266         };
9267         let session_response = match &uci_response.child {
9268             UciResponseDataChild::SessionResponse(value) => (*value).clone(),
9269             _ => return Err("inconsistent state - child was not SessionResponse"),
9270         };
9271         let session_set_app_config_rsp = match &session_response.child {
9272             SessionResponseDataChild::SessionSetAppConfigRsp(value) => (*value).clone(),
9273             _ => return Err("inconsistent state - child was not SessionSetAppConfigRsp"),
9274         };
9275         Ok(Self {
9276             uci_packet,
9277             uci_response,
9278             session_response,
9279             session_set_app_config_rsp,
9280         })
9281     }
get_group_id(&self) -> GroupId9282     pub fn get_group_id(&self) -> GroupId {
9283         self.uci_packet.as_ref().group_id
9284     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag9285     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
9286         self.uci_packet.as_ref().packet_boundary_flag
9287     }
get_message_type(&self) -> MessageType9288     pub fn get_message_type(&self) -> MessageType {
9289         self.uci_packet.as_ref().message_type
9290     }
get_opcode(&self) -> u89291     pub fn get_opcode(&self) -> u8 {
9292         self.uci_packet.as_ref().opcode
9293     }
get_status(&self) -> StatusCode9294     pub fn get_status(&self) -> StatusCode {
9295         self.session_set_app_config_rsp.as_ref().status
9296     }
get_parameters(&self) -> &Vec<AppConfigStatus>9297     pub fn get_parameters(&self) -> &Vec<AppConfigStatus> {
9298         &self.session_set_app_config_rsp.as_ref().parameters
9299     }
9300 }
9301 impl Into<UciPacketPacket> for SessionSetAppConfigRspPacket {
into(self) -> UciPacketPacket9302     fn into(self) -> UciPacketPacket {
9303         UciPacketPacket::new(self.uci_packet).unwrap()
9304     }
9305 }
9306 impl Into<UciResponsePacket> for SessionSetAppConfigRspPacket {
into(self) -> UciResponsePacket9307     fn into(self) -> UciResponsePacket {
9308         UciResponsePacket::new(self.uci_packet).unwrap()
9309     }
9310 }
9311 impl Into<SessionResponsePacket> for SessionSetAppConfigRspPacket {
into(self) -> SessionResponsePacket9312     fn into(self) -> SessionResponsePacket {
9313         SessionResponsePacket::new(self.uci_packet).unwrap()
9314     }
9315 }
9316 impl SessionSetAppConfigRspBuilder {
build(self) -> SessionSetAppConfigRspPacket9317     pub fn build(self) -> SessionSetAppConfigRspPacket {
9318         let session_set_app_config_rsp = Arc::new(SessionSetAppConfigRspData {
9319             status: self.status,
9320             parameters: self.parameters,
9321         });
9322         let session_response = Arc::new(SessionResponseData {
9323             child: SessionResponseDataChild::SessionSetAppConfigRsp(session_set_app_config_rsp),
9324         });
9325         let uci_response = Arc::new(UciResponseData {
9326             child: UciResponseDataChild::SessionResponse(session_response),
9327         });
9328         let uci_packet = Arc::new(UciPacketData {
9329             group_id: GroupId::SessionConfig,
9330             packet_boundary_flag: PacketBoundaryFlag::Complete,
9331             message_type: MessageType::Response,
9332             opcode: 3,
9333             child: UciPacketDataChild::UciResponse(uci_response),
9334         });
9335         SessionSetAppConfigRspPacket::new(uci_packet).unwrap()
9336     }
9337 }
9338 impl Into<UciPacketPacket> for SessionSetAppConfigRspBuilder {
into(self) -> UciPacketPacket9339     fn into(self) -> UciPacketPacket {
9340         self.build().into()
9341     }
9342 }
9343 impl Into<UciResponsePacket> for SessionSetAppConfigRspBuilder {
into(self) -> UciResponsePacket9344     fn into(self) -> UciResponsePacket {
9345         self.build().into()
9346     }
9347 }
9348 impl Into<SessionResponsePacket> for SessionSetAppConfigRspBuilder {
into(self) -> SessionResponsePacket9349     fn into(self) -> SessionResponsePacket {
9350         self.build().into()
9351     }
9352 }
9353 macro_rules! session_set_app_config_rsp_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
9354 #[test]
9355 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
9356 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
9357 UciPacketChild::UciResponse(uci_response_packet) => {match uci_response_packet.specialize() {/* (2) */
9358 UciResponseChild::SessionResponse(session_response_packet) => {match session_response_packet.specialize() {/* (3) */
9359 SessionResponseChild::SessionSetAppConfigRsp(packet) => {let rebuilder = SessionSetAppConfigRspBuilder {status : packet.get_status(),parameters : packet.get_parameters().to_vec(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse session_set_app_config_rsp
9360  {:#02x?}", session_response_packet); }}}_ => {panic!("Couldn't parse session_response
9361  {:#02x?}", uci_response_packet); }}}_ => {panic!("Couldn't parse uci_response
9362  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
9363 session_set_app_config_rsp_builder_tests! { session_set_app_config_rsp_builder_test_00: b"\x41\x03\x00\x04\x01\x01\x01\x00",}
9364 
9365 #[derive(Debug)]
9366 struct SessionGetAppConfigCmdData {
9367     session_id: u32,
9368     parameters: Vec<u8>,
9369 }
9370 #[derive(Debug, Clone)]
9371 pub struct SessionGetAppConfigCmdPacket {
9372     uci_packet: Arc<UciPacketData>,
9373     uci_command: Arc<UciCommandData>,
9374     session_command: Arc<SessionCommandData>,
9375     session_get_app_config_cmd: Arc<SessionGetAppConfigCmdData>,
9376 }
9377 #[derive(Debug)]
9378 pub struct SessionGetAppConfigCmdBuilder {
9379     pub session_id: u32,
9380     pub parameters: Vec<u8>,
9381 }
9382 impl SessionGetAppConfigCmdData {
conforms(bytes: &[u8]) -> bool9383     fn conforms(bytes: &[u8]) -> bool {
9384         if bytes.len() < 9 {
9385             return false;
9386         }
9387         true
9388     }
parse(bytes: &[u8]) -> Result<Self>9389     fn parse(bytes: &[u8]) -> Result<Self> {
9390         if bytes.len() < 8 {
9391             return Err(Error::InvalidLengthError {
9392                 obj: "SessionGetAppConfigCmd".to_string(),
9393                 field: "session_id".to_string(),
9394                 wanted: 8,
9395                 got: bytes.len(),
9396             });
9397         }
9398         let session_id = u32::from_le_bytes([bytes[4], bytes[5], bytes[6], bytes[7]]);
9399         if bytes.len() < 9 {
9400             return Err(Error::InvalidLengthError {
9401                 obj: "SessionGetAppConfigCmd".to_string(),
9402                 field: "parameters_count".to_string(),
9403                 wanted: 9,
9404                 got: bytes.len(),
9405             });
9406         }
9407         let parameters_count = u8::from_le_bytes([bytes[8]]);
9408         let want_ = 9 + ((parameters_count as usize) * 1);
9409         if bytes.len() < want_ {
9410             return Err(Error::InvalidLengthError {
9411                 obj: "SessionGetAppConfigCmd".to_string(),
9412                 field: "parameters".to_string(),
9413                 wanted: want_,
9414                 got: bytes.len(),
9415             });
9416         }
9417         let parameters: Vec<u8> = bytes[9..9 + ((parameters_count as usize) * 1)]
9418             .to_vec()
9419             .chunks_exact(1)
9420             .into_iter()
9421             .map(|i| u8::from_le_bytes([i[0]]))
9422             .collect();
9423         Ok(Self {
9424             session_id,
9425             parameters,
9426         })
9427     }
write_to(&self, buffer: &mut BytesMut)9428     fn write_to(&self, buffer: &mut BytesMut) {
9429         let session_id = self.session_id;
9430         buffer[4..8].copy_from_slice(&session_id.to_le_bytes()[0..4]);
9431         buffer[8..9].copy_from_slice(&(self.parameters.len() as u8).to_le_bytes());
9432         for (i, e) in self.parameters.iter().enumerate() {
9433             buffer[9 + i..9 + i + 1].copy_from_slice(&e.to_le_bytes())
9434         }
9435     }
get_total_size(&self) -> usize9436     fn get_total_size(&self) -> usize {
9437         self.get_size()
9438     }
get_size(&self) -> usize9439     fn get_size(&self) -> usize {
9440         let ret = 0;
9441         let ret = ret + 5;
9442         let ret = ret + (self.parameters.len() * ((/* Bits: */8 + /* Dynamic: */ 0) / 8));
9443         ret
9444     }
9445 }
9446 impl Packet for SessionGetAppConfigCmdPacket {
to_bytes(self) -> Bytes9447     fn to_bytes(self) -> Bytes {
9448         let mut buffer = BytesMut::new();
9449         buffer.resize(self.uci_packet.get_total_size(), 0);
9450         self.uci_packet.write_to(&mut buffer);
9451         buffer.freeze()
9452     }
to_vec(self) -> Vec<u8>9453     fn to_vec(self) -> Vec<u8> {
9454         self.to_bytes().to_vec()
9455     }
9456 }
9457 impl From<SessionGetAppConfigCmdPacket> for Bytes {
from(packet: SessionGetAppConfigCmdPacket) -> Self9458     fn from(packet: SessionGetAppConfigCmdPacket) -> Self {
9459         packet.to_bytes()
9460     }
9461 }
9462 impl From<SessionGetAppConfigCmdPacket> for Vec<u8> {
from(packet: SessionGetAppConfigCmdPacket) -> Self9463     fn from(packet: SessionGetAppConfigCmdPacket) -> Self {
9464         packet.to_vec()
9465     }
9466 }
9467 impl TryFrom<UciPacketPacket> for SessionGetAppConfigCmdPacket {
9468     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>9469     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
9470         Self::new(value.uci_packet).map_err(TryFromError)
9471     }
9472 }
9473 impl SessionGetAppConfigCmdPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>9474     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
9475         let uci_packet = root;
9476         let uci_command = match &uci_packet.child {
9477             UciPacketDataChild::UciCommand(value) => (*value).clone(),
9478             _ => return Err("inconsistent state - child was not UciCommand"),
9479         };
9480         let session_command = match &uci_command.child {
9481             UciCommandDataChild::SessionCommand(value) => (*value).clone(),
9482             _ => return Err("inconsistent state - child was not SessionCommand"),
9483         };
9484         let session_get_app_config_cmd = match &session_command.child {
9485             SessionCommandDataChild::SessionGetAppConfigCmd(value) => (*value).clone(),
9486             _ => return Err("inconsistent state - child was not SessionGetAppConfigCmd"),
9487         };
9488         Ok(Self {
9489             uci_packet,
9490             uci_command,
9491             session_command,
9492             session_get_app_config_cmd,
9493         })
9494     }
get_group_id(&self) -> GroupId9495     pub fn get_group_id(&self) -> GroupId {
9496         self.uci_packet.as_ref().group_id
9497     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag9498     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
9499         self.uci_packet.as_ref().packet_boundary_flag
9500     }
get_message_type(&self) -> MessageType9501     pub fn get_message_type(&self) -> MessageType {
9502         self.uci_packet.as_ref().message_type
9503     }
get_opcode(&self) -> u89504     pub fn get_opcode(&self) -> u8 {
9505         self.uci_packet.as_ref().opcode
9506     }
get_session_id(&self) -> u329507     pub fn get_session_id(&self) -> u32 {
9508         self.session_get_app_config_cmd.as_ref().session_id
9509     }
get_parameters(&self) -> &Vec<u8>9510     pub fn get_parameters(&self) -> &Vec<u8> {
9511         &self.session_get_app_config_cmd.as_ref().parameters
9512     }
9513 }
9514 impl Into<UciPacketPacket> for SessionGetAppConfigCmdPacket {
into(self) -> UciPacketPacket9515     fn into(self) -> UciPacketPacket {
9516         UciPacketPacket::new(self.uci_packet).unwrap()
9517     }
9518 }
9519 impl Into<UciCommandPacket> for SessionGetAppConfigCmdPacket {
into(self) -> UciCommandPacket9520     fn into(self) -> UciCommandPacket {
9521         UciCommandPacket::new(self.uci_packet).unwrap()
9522     }
9523 }
9524 impl Into<SessionCommandPacket> for SessionGetAppConfigCmdPacket {
into(self) -> SessionCommandPacket9525     fn into(self) -> SessionCommandPacket {
9526         SessionCommandPacket::new(self.uci_packet).unwrap()
9527     }
9528 }
9529 impl SessionGetAppConfigCmdBuilder {
build(self) -> SessionGetAppConfigCmdPacket9530     pub fn build(self) -> SessionGetAppConfigCmdPacket {
9531         let session_get_app_config_cmd = Arc::new(SessionGetAppConfigCmdData {
9532             session_id: self.session_id,
9533             parameters: self.parameters,
9534         });
9535         let session_command = Arc::new(SessionCommandData {
9536             child: SessionCommandDataChild::SessionGetAppConfigCmd(session_get_app_config_cmd),
9537         });
9538         let uci_command = Arc::new(UciCommandData {
9539             child: UciCommandDataChild::SessionCommand(session_command),
9540         });
9541         let uci_packet = Arc::new(UciPacketData {
9542             group_id: GroupId::SessionConfig,
9543             packet_boundary_flag: PacketBoundaryFlag::Complete,
9544             message_type: MessageType::Command,
9545             opcode: 4,
9546             child: UciPacketDataChild::UciCommand(uci_command),
9547         });
9548         SessionGetAppConfigCmdPacket::new(uci_packet).unwrap()
9549     }
9550 }
9551 impl Into<UciPacketPacket> for SessionGetAppConfigCmdBuilder {
into(self) -> UciPacketPacket9552     fn into(self) -> UciPacketPacket {
9553         self.build().into()
9554     }
9555 }
9556 impl Into<UciCommandPacket> for SessionGetAppConfigCmdBuilder {
into(self) -> UciCommandPacket9557     fn into(self) -> UciCommandPacket {
9558         self.build().into()
9559     }
9560 }
9561 impl Into<SessionCommandPacket> for SessionGetAppConfigCmdBuilder {
into(self) -> SessionCommandPacket9562     fn into(self) -> SessionCommandPacket {
9563         self.build().into()
9564     }
9565 }
9566 macro_rules! session_get_app_config_cmd_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
9567 #[test]
9568 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
9569 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
9570 UciPacketChild::UciCommand(uci_command_packet) => {match uci_command_packet.specialize() {/* (2) */
9571 UciCommandChild::SessionCommand(session_command_packet) => {match session_command_packet.specialize() {/* (3) */
9572 SessionCommandChild::SessionGetAppConfigCmd(packet) => {let rebuilder = SessionGetAppConfigCmdBuilder {session_id : packet.get_session_id(),parameters : packet.get_parameters().to_vec(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse session_get_app_config_cmd
9573  {:#02x?}", session_command_packet); }}}_ => {panic!("Couldn't parse session_command
9574  {:#02x?}", uci_command_packet); }}}_ => {panic!("Couldn't parse uci_command
9575  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
9576 session_get_app_config_cmd_builder_tests! { session_get_app_config_cmd_builder_test_00: b"\x21\x04\x00\x05\x01\x02\x03\x04\x00",}
9577 
9578 #[derive(Debug)]
9579 struct SessionGetAppConfigRspData {
9580     status: StatusCode,
9581     parameters: Vec<AppConfigParameter>,
9582 }
9583 #[derive(Debug, Clone)]
9584 pub struct SessionGetAppConfigRspPacket {
9585     uci_packet: Arc<UciPacketData>,
9586     uci_response: Arc<UciResponseData>,
9587     session_response: Arc<SessionResponseData>,
9588     session_get_app_config_rsp: Arc<SessionGetAppConfigRspData>,
9589 }
9590 #[derive(Debug)]
9591 pub struct SessionGetAppConfigRspBuilder {
9592     pub status: StatusCode,
9593     pub parameters: Vec<AppConfigParameter>,
9594 }
9595 impl SessionGetAppConfigRspData {
conforms(bytes: &[u8]) -> bool9596     fn conforms(bytes: &[u8]) -> bool {
9597         if bytes.len() < 6 {
9598             return false;
9599         }
9600         true
9601     }
parse(bytes: &[u8]) -> Result<Self>9602     fn parse(bytes: &[u8]) -> Result<Self> {
9603         if bytes.len() < 5 {
9604             return Err(Error::InvalidLengthError {
9605                 obj: "SessionGetAppConfigRsp".to_string(),
9606                 field: "status".to_string(),
9607                 wanted: 5,
9608                 got: bytes.len(),
9609             });
9610         }
9611         let status = u8::from_le_bytes([bytes[4]]);
9612         let status = StatusCode::from_u8(status).ok_or_else(|| Error::InvalidEnumValueError {
9613             obj: "SessionGetAppConfigRsp".to_string(),
9614             field: "status".to_string(),
9615             value: status as u64,
9616             type_: "StatusCode".to_string(),
9617         })?;
9618         if bytes.len() < 6 {
9619             return Err(Error::InvalidLengthError {
9620                 obj: "SessionGetAppConfigRsp".to_string(),
9621                 field: "parameters_count".to_string(),
9622                 wanted: 6,
9623                 got: bytes.len(),
9624             });
9625         }
9626         let parameters_count = u8::from_le_bytes([bytes[5]]);
9627         let mut parameters: Vec<AppConfigParameter> = Vec::new();
9628         let mut parsable_ = &bytes[6..];
9629         let count_ = parameters_count as usize;
9630         for _ in 0..count_ {
9631             match AppConfigParameter::parse(&parsable_) {
9632                 Ok(parsed) => {
9633                     parsable_ = &parsable_[parsed.get_total_size()..];
9634                     parameters.push(parsed);
9635                 }
9636                 Err(Error::ImpossibleStructError) => break,
9637                 Err(e) => return Err(e),
9638             }
9639         }
9640         Ok(Self { status, parameters })
9641     }
write_to(&self, buffer: &mut BytesMut)9642     fn write_to(&self, buffer: &mut BytesMut) {
9643         let status = self.status.to_u8().unwrap();
9644         buffer[4..5].copy_from_slice(&status.to_le_bytes()[0..1]);
9645         buffer[5..6].copy_from_slice(&(self.parameters.len() as u8).to_le_bytes());
9646         let mut vec_buffer_ = &mut buffer[6..];
9647         for e_ in &self.parameters {
9648             e_.write_to(&mut vec_buffer_[0..e_.get_total_size()]);
9649             vec_buffer_ = &mut vec_buffer_[e_.get_total_size()..];
9650         }
9651     }
get_total_size(&self) -> usize9652     fn get_total_size(&self) -> usize {
9653         self.get_size()
9654     }
get_size(&self) -> usize9655     fn get_size(&self) -> usize {
9656         let ret = 0;
9657         let ret = ret + 2;
9658         let ret = ret
9659             + self
9660                 .parameters
9661                 .iter()
9662                 .fold(0, |acc, x| acc + x.get_total_size());
9663         ret
9664     }
9665 }
9666 impl Packet for SessionGetAppConfigRspPacket {
to_bytes(self) -> Bytes9667     fn to_bytes(self) -> Bytes {
9668         let mut buffer = BytesMut::new();
9669         buffer.resize(self.uci_packet.get_total_size(), 0);
9670         self.uci_packet.write_to(&mut buffer);
9671         buffer.freeze()
9672     }
to_vec(self) -> Vec<u8>9673     fn to_vec(self) -> Vec<u8> {
9674         self.to_bytes().to_vec()
9675     }
9676 }
9677 impl From<SessionGetAppConfigRspPacket> for Bytes {
from(packet: SessionGetAppConfigRspPacket) -> Self9678     fn from(packet: SessionGetAppConfigRspPacket) -> Self {
9679         packet.to_bytes()
9680     }
9681 }
9682 impl From<SessionGetAppConfigRspPacket> for Vec<u8> {
from(packet: SessionGetAppConfigRspPacket) -> Self9683     fn from(packet: SessionGetAppConfigRspPacket) -> Self {
9684         packet.to_vec()
9685     }
9686 }
9687 impl TryFrom<UciPacketPacket> for SessionGetAppConfigRspPacket {
9688     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>9689     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
9690         Self::new(value.uci_packet).map_err(TryFromError)
9691     }
9692 }
9693 impl SessionGetAppConfigRspPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>9694     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
9695         let uci_packet = root;
9696         let uci_response = match &uci_packet.child {
9697             UciPacketDataChild::UciResponse(value) => (*value).clone(),
9698             _ => return Err("inconsistent state - child was not UciResponse"),
9699         };
9700         let session_response = match &uci_response.child {
9701             UciResponseDataChild::SessionResponse(value) => (*value).clone(),
9702             _ => return Err("inconsistent state - child was not SessionResponse"),
9703         };
9704         let session_get_app_config_rsp = match &session_response.child {
9705             SessionResponseDataChild::SessionGetAppConfigRsp(value) => (*value).clone(),
9706             _ => return Err("inconsistent state - child was not SessionGetAppConfigRsp"),
9707         };
9708         Ok(Self {
9709             uci_packet,
9710             uci_response,
9711             session_response,
9712             session_get_app_config_rsp,
9713         })
9714     }
get_group_id(&self) -> GroupId9715     pub fn get_group_id(&self) -> GroupId {
9716         self.uci_packet.as_ref().group_id
9717     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag9718     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
9719         self.uci_packet.as_ref().packet_boundary_flag
9720     }
get_message_type(&self) -> MessageType9721     pub fn get_message_type(&self) -> MessageType {
9722         self.uci_packet.as_ref().message_type
9723     }
get_opcode(&self) -> u89724     pub fn get_opcode(&self) -> u8 {
9725         self.uci_packet.as_ref().opcode
9726     }
get_status(&self) -> StatusCode9727     pub fn get_status(&self) -> StatusCode {
9728         self.session_get_app_config_rsp.as_ref().status
9729     }
get_parameters(&self) -> &Vec<AppConfigParameter>9730     pub fn get_parameters(&self) -> &Vec<AppConfigParameter> {
9731         &self.session_get_app_config_rsp.as_ref().parameters
9732     }
9733 }
9734 impl Into<UciPacketPacket> for SessionGetAppConfigRspPacket {
into(self) -> UciPacketPacket9735     fn into(self) -> UciPacketPacket {
9736         UciPacketPacket::new(self.uci_packet).unwrap()
9737     }
9738 }
9739 impl Into<UciResponsePacket> for SessionGetAppConfigRspPacket {
into(self) -> UciResponsePacket9740     fn into(self) -> UciResponsePacket {
9741         UciResponsePacket::new(self.uci_packet).unwrap()
9742     }
9743 }
9744 impl Into<SessionResponsePacket> for SessionGetAppConfigRspPacket {
into(self) -> SessionResponsePacket9745     fn into(self) -> SessionResponsePacket {
9746         SessionResponsePacket::new(self.uci_packet).unwrap()
9747     }
9748 }
9749 impl SessionGetAppConfigRspBuilder {
build(self) -> SessionGetAppConfigRspPacket9750     pub fn build(self) -> SessionGetAppConfigRspPacket {
9751         let session_get_app_config_rsp = Arc::new(SessionGetAppConfigRspData {
9752             status: self.status,
9753             parameters: self.parameters,
9754         });
9755         let session_response = Arc::new(SessionResponseData {
9756             child: SessionResponseDataChild::SessionGetAppConfigRsp(session_get_app_config_rsp),
9757         });
9758         let uci_response = Arc::new(UciResponseData {
9759             child: UciResponseDataChild::SessionResponse(session_response),
9760         });
9761         let uci_packet = Arc::new(UciPacketData {
9762             group_id: GroupId::SessionConfig,
9763             packet_boundary_flag: PacketBoundaryFlag::Complete,
9764             message_type: MessageType::Response,
9765             opcode: 4,
9766             child: UciPacketDataChild::UciResponse(uci_response),
9767         });
9768         SessionGetAppConfigRspPacket::new(uci_packet).unwrap()
9769     }
9770 }
9771 impl Into<UciPacketPacket> for SessionGetAppConfigRspBuilder {
into(self) -> UciPacketPacket9772     fn into(self) -> UciPacketPacket {
9773         self.build().into()
9774     }
9775 }
9776 impl Into<UciResponsePacket> for SessionGetAppConfigRspBuilder {
into(self) -> UciResponsePacket9777     fn into(self) -> UciResponsePacket {
9778         self.build().into()
9779     }
9780 }
9781 impl Into<SessionResponsePacket> for SessionGetAppConfigRspBuilder {
into(self) -> SessionResponsePacket9782     fn into(self) -> SessionResponsePacket {
9783         self.build().into()
9784     }
9785 }
9786 macro_rules! session_get_app_config_rsp_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
9787 #[test]
9788 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
9789 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
9790 UciPacketChild::UciResponse(uci_response_packet) => {match uci_response_packet.specialize() {/* (2) */
9791 UciResponseChild::SessionResponse(session_response_packet) => {match session_response_packet.specialize() {/* (3) */
9792 SessionResponseChild::SessionGetAppConfigRsp(packet) => {let rebuilder = SessionGetAppConfigRspBuilder {status : packet.get_status(),parameters : packet.get_parameters().to_vec(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse session_get_app_config_rsp
9793  {:#02x?}", session_response_packet); }}}_ => {panic!("Couldn't parse session_response
9794  {:#02x?}", uci_response_packet); }}}_ => {panic!("Couldn't parse uci_response
9795  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
9796 session_get_app_config_rsp_builder_tests! { session_get_app_config_rsp_builder_test_00: b"\x41\x04\x00\x02\x01\x00",}
9797 
9798 #[derive(Debug)]
9799 struct SessionGetCountCmdData {}
9800 #[derive(Debug, Clone)]
9801 pub struct SessionGetCountCmdPacket {
9802     uci_packet: Arc<UciPacketData>,
9803     uci_command: Arc<UciCommandData>,
9804     session_command: Arc<SessionCommandData>,
9805     session_get_count_cmd: Arc<SessionGetCountCmdData>,
9806 }
9807 #[derive(Debug)]
9808 pub struct SessionGetCountCmdBuilder {}
9809 impl SessionGetCountCmdData {
conforms(bytes: &[u8]) -> bool9810     fn conforms(bytes: &[u8]) -> bool {
9811         if bytes.len() < 4 {
9812             return false;
9813         }
9814         true
9815     }
parse(bytes: &[u8]) -> Result<Self>9816     fn parse(bytes: &[u8]) -> Result<Self> {
9817         Ok(Self {})
9818     }
write_to(&self, buffer: &mut BytesMut)9819     fn write_to(&self, buffer: &mut BytesMut) {}
get_total_size(&self) -> usize9820     fn get_total_size(&self) -> usize {
9821         self.get_size()
9822     }
get_size(&self) -> usize9823     fn get_size(&self) -> usize {
9824         let ret = 0;
9825         ret
9826     }
9827 }
9828 impl Packet for SessionGetCountCmdPacket {
to_bytes(self) -> Bytes9829     fn to_bytes(self) -> Bytes {
9830         let mut buffer = BytesMut::new();
9831         buffer.resize(self.uci_packet.get_total_size(), 0);
9832         self.uci_packet.write_to(&mut buffer);
9833         buffer.freeze()
9834     }
to_vec(self) -> Vec<u8>9835     fn to_vec(self) -> Vec<u8> {
9836         self.to_bytes().to_vec()
9837     }
9838 }
9839 impl From<SessionGetCountCmdPacket> for Bytes {
from(packet: SessionGetCountCmdPacket) -> Self9840     fn from(packet: SessionGetCountCmdPacket) -> Self {
9841         packet.to_bytes()
9842     }
9843 }
9844 impl From<SessionGetCountCmdPacket> for Vec<u8> {
from(packet: SessionGetCountCmdPacket) -> Self9845     fn from(packet: SessionGetCountCmdPacket) -> Self {
9846         packet.to_vec()
9847     }
9848 }
9849 impl TryFrom<UciPacketPacket> for SessionGetCountCmdPacket {
9850     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>9851     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
9852         Self::new(value.uci_packet).map_err(TryFromError)
9853     }
9854 }
9855 impl SessionGetCountCmdPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>9856     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
9857         let uci_packet = root;
9858         let uci_command = match &uci_packet.child {
9859             UciPacketDataChild::UciCommand(value) => (*value).clone(),
9860             _ => return Err("inconsistent state - child was not UciCommand"),
9861         };
9862         let session_command = match &uci_command.child {
9863             UciCommandDataChild::SessionCommand(value) => (*value).clone(),
9864             _ => return Err("inconsistent state - child was not SessionCommand"),
9865         };
9866         let session_get_count_cmd = match &session_command.child {
9867             SessionCommandDataChild::SessionGetCountCmd(value) => (*value).clone(),
9868             _ => return Err("inconsistent state - child was not SessionGetCountCmd"),
9869         };
9870         Ok(Self {
9871             uci_packet,
9872             uci_command,
9873             session_command,
9874             session_get_count_cmd,
9875         })
9876     }
get_group_id(&self) -> GroupId9877     pub fn get_group_id(&self) -> GroupId {
9878         self.uci_packet.as_ref().group_id
9879     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag9880     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
9881         self.uci_packet.as_ref().packet_boundary_flag
9882     }
get_message_type(&self) -> MessageType9883     pub fn get_message_type(&self) -> MessageType {
9884         self.uci_packet.as_ref().message_type
9885     }
get_opcode(&self) -> u89886     pub fn get_opcode(&self) -> u8 {
9887         self.uci_packet.as_ref().opcode
9888     }
9889 }
9890 impl Into<UciPacketPacket> for SessionGetCountCmdPacket {
into(self) -> UciPacketPacket9891     fn into(self) -> UciPacketPacket {
9892         UciPacketPacket::new(self.uci_packet).unwrap()
9893     }
9894 }
9895 impl Into<UciCommandPacket> for SessionGetCountCmdPacket {
into(self) -> UciCommandPacket9896     fn into(self) -> UciCommandPacket {
9897         UciCommandPacket::new(self.uci_packet).unwrap()
9898     }
9899 }
9900 impl Into<SessionCommandPacket> for SessionGetCountCmdPacket {
into(self) -> SessionCommandPacket9901     fn into(self) -> SessionCommandPacket {
9902         SessionCommandPacket::new(self.uci_packet).unwrap()
9903     }
9904 }
9905 impl SessionGetCountCmdBuilder {
build(self) -> SessionGetCountCmdPacket9906     pub fn build(self) -> SessionGetCountCmdPacket {
9907         let session_get_count_cmd = Arc::new(SessionGetCountCmdData {});
9908         let session_command = Arc::new(SessionCommandData {
9909             child: SessionCommandDataChild::SessionGetCountCmd(session_get_count_cmd),
9910         });
9911         let uci_command = Arc::new(UciCommandData {
9912             child: UciCommandDataChild::SessionCommand(session_command),
9913         });
9914         let uci_packet = Arc::new(UciPacketData {
9915             group_id: GroupId::SessionConfig,
9916             packet_boundary_flag: PacketBoundaryFlag::Complete,
9917             message_type: MessageType::Command,
9918             opcode: 5,
9919             child: UciPacketDataChild::UciCommand(uci_command),
9920         });
9921         SessionGetCountCmdPacket::new(uci_packet).unwrap()
9922     }
9923 }
9924 impl Into<UciPacketPacket> for SessionGetCountCmdBuilder {
into(self) -> UciPacketPacket9925     fn into(self) -> UciPacketPacket {
9926         self.build().into()
9927     }
9928 }
9929 impl Into<UciCommandPacket> for SessionGetCountCmdBuilder {
into(self) -> UciCommandPacket9930     fn into(self) -> UciCommandPacket {
9931         self.build().into()
9932     }
9933 }
9934 impl Into<SessionCommandPacket> for SessionGetCountCmdBuilder {
into(self) -> SessionCommandPacket9935     fn into(self) -> SessionCommandPacket {
9936         self.build().into()
9937     }
9938 }
9939 macro_rules! session_get_count_cmd_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
9940 #[test]
9941 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
9942 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
9943 UciPacketChild::UciCommand(uci_command_packet) => {match uci_command_packet.specialize() {/* (2) */
9944 UciCommandChild::SessionCommand(session_command_packet) => {match session_command_packet.specialize() {/* (3) */
9945 SessionCommandChild::SessionGetCountCmd(packet) => {let rebuilder = SessionGetCountCmdBuilder {};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse session_get_count_cmd
9946  {:#02x?}", session_command_packet); }}}_ => {panic!("Couldn't parse session_command
9947  {:#02x?}", uci_command_packet); }}}_ => {panic!("Couldn't parse uci_command
9948  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
9949 session_get_count_cmd_builder_tests! { session_get_count_cmd_builder_test_00: b"\x21\x05\x00\x00",}
9950 
9951 #[derive(Debug)]
9952 struct SessionGetCountRspData {
9953     status: StatusCode,
9954     session_count: u8,
9955 }
9956 #[derive(Debug, Clone)]
9957 pub struct SessionGetCountRspPacket {
9958     uci_packet: Arc<UciPacketData>,
9959     uci_response: Arc<UciResponseData>,
9960     session_response: Arc<SessionResponseData>,
9961     session_get_count_rsp: Arc<SessionGetCountRspData>,
9962 }
9963 #[derive(Debug)]
9964 pub struct SessionGetCountRspBuilder {
9965     pub status: StatusCode,
9966     pub session_count: u8,
9967 }
9968 impl SessionGetCountRspData {
conforms(bytes: &[u8]) -> bool9969     fn conforms(bytes: &[u8]) -> bool {
9970         if bytes.len() < 6 {
9971             return false;
9972         }
9973         true
9974     }
parse(bytes: &[u8]) -> Result<Self>9975     fn parse(bytes: &[u8]) -> Result<Self> {
9976         if bytes.len() < 5 {
9977             return Err(Error::InvalidLengthError {
9978                 obj: "SessionGetCountRsp".to_string(),
9979                 field: "status".to_string(),
9980                 wanted: 5,
9981                 got: bytes.len(),
9982             });
9983         }
9984         let status = u8::from_le_bytes([bytes[4]]);
9985         let status = StatusCode::from_u8(status).ok_or_else(|| Error::InvalidEnumValueError {
9986             obj: "SessionGetCountRsp".to_string(),
9987             field: "status".to_string(),
9988             value: status as u64,
9989             type_: "StatusCode".to_string(),
9990         })?;
9991         if bytes.len() < 6 {
9992             return Err(Error::InvalidLengthError {
9993                 obj: "SessionGetCountRsp".to_string(),
9994                 field: "session_count".to_string(),
9995                 wanted: 6,
9996                 got: bytes.len(),
9997             });
9998         }
9999         let session_count = u8::from_le_bytes([bytes[5]]);
10000         Ok(Self {
10001             status,
10002             session_count,
10003         })
10004     }
write_to(&self, buffer: &mut BytesMut)10005     fn write_to(&self, buffer: &mut BytesMut) {
10006         let status = self.status.to_u8().unwrap();
10007         buffer[4..5].copy_from_slice(&status.to_le_bytes()[0..1]);
10008         let session_count = self.session_count;
10009         buffer[5..6].copy_from_slice(&session_count.to_le_bytes()[0..1]);
10010     }
get_total_size(&self) -> usize10011     fn get_total_size(&self) -> usize {
10012         self.get_size()
10013     }
get_size(&self) -> usize10014     fn get_size(&self) -> usize {
10015         let ret = 0;
10016         let ret = ret + 2;
10017         ret
10018     }
10019 }
10020 impl Packet for SessionGetCountRspPacket {
to_bytes(self) -> Bytes10021     fn to_bytes(self) -> Bytes {
10022         let mut buffer = BytesMut::new();
10023         buffer.resize(self.uci_packet.get_total_size(), 0);
10024         self.uci_packet.write_to(&mut buffer);
10025         buffer.freeze()
10026     }
to_vec(self) -> Vec<u8>10027     fn to_vec(self) -> Vec<u8> {
10028         self.to_bytes().to_vec()
10029     }
10030 }
10031 impl From<SessionGetCountRspPacket> for Bytes {
from(packet: SessionGetCountRspPacket) -> Self10032     fn from(packet: SessionGetCountRspPacket) -> Self {
10033         packet.to_bytes()
10034     }
10035 }
10036 impl From<SessionGetCountRspPacket> for Vec<u8> {
from(packet: SessionGetCountRspPacket) -> Self10037     fn from(packet: SessionGetCountRspPacket) -> Self {
10038         packet.to_vec()
10039     }
10040 }
10041 impl TryFrom<UciPacketPacket> for SessionGetCountRspPacket {
10042     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>10043     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
10044         Self::new(value.uci_packet).map_err(TryFromError)
10045     }
10046 }
10047 impl SessionGetCountRspPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>10048     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
10049         let uci_packet = root;
10050         let uci_response = match &uci_packet.child {
10051             UciPacketDataChild::UciResponse(value) => (*value).clone(),
10052             _ => return Err("inconsistent state - child was not UciResponse"),
10053         };
10054         let session_response = match &uci_response.child {
10055             UciResponseDataChild::SessionResponse(value) => (*value).clone(),
10056             _ => return Err("inconsistent state - child was not SessionResponse"),
10057         };
10058         let session_get_count_rsp = match &session_response.child {
10059             SessionResponseDataChild::SessionGetCountRsp(value) => (*value).clone(),
10060             _ => return Err("inconsistent state - child was not SessionGetCountRsp"),
10061         };
10062         Ok(Self {
10063             uci_packet,
10064             uci_response,
10065             session_response,
10066             session_get_count_rsp,
10067         })
10068     }
get_group_id(&self) -> GroupId10069     pub fn get_group_id(&self) -> GroupId {
10070         self.uci_packet.as_ref().group_id
10071     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag10072     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
10073         self.uci_packet.as_ref().packet_boundary_flag
10074     }
get_message_type(&self) -> MessageType10075     pub fn get_message_type(&self) -> MessageType {
10076         self.uci_packet.as_ref().message_type
10077     }
get_opcode(&self) -> u810078     pub fn get_opcode(&self) -> u8 {
10079         self.uci_packet.as_ref().opcode
10080     }
get_status(&self) -> StatusCode10081     pub fn get_status(&self) -> StatusCode {
10082         self.session_get_count_rsp.as_ref().status
10083     }
get_session_count(&self) -> u810084     pub fn get_session_count(&self) -> u8 {
10085         self.session_get_count_rsp.as_ref().session_count
10086     }
10087 }
10088 impl Into<UciPacketPacket> for SessionGetCountRspPacket {
into(self) -> UciPacketPacket10089     fn into(self) -> UciPacketPacket {
10090         UciPacketPacket::new(self.uci_packet).unwrap()
10091     }
10092 }
10093 impl Into<UciResponsePacket> for SessionGetCountRspPacket {
into(self) -> UciResponsePacket10094     fn into(self) -> UciResponsePacket {
10095         UciResponsePacket::new(self.uci_packet).unwrap()
10096     }
10097 }
10098 impl Into<SessionResponsePacket> for SessionGetCountRspPacket {
into(self) -> SessionResponsePacket10099     fn into(self) -> SessionResponsePacket {
10100         SessionResponsePacket::new(self.uci_packet).unwrap()
10101     }
10102 }
10103 impl SessionGetCountRspBuilder {
build(self) -> SessionGetCountRspPacket10104     pub fn build(self) -> SessionGetCountRspPacket {
10105         let session_get_count_rsp = Arc::new(SessionGetCountRspData {
10106             status: self.status,
10107             session_count: self.session_count,
10108         });
10109         let session_response = Arc::new(SessionResponseData {
10110             child: SessionResponseDataChild::SessionGetCountRsp(session_get_count_rsp),
10111         });
10112         let uci_response = Arc::new(UciResponseData {
10113             child: UciResponseDataChild::SessionResponse(session_response),
10114         });
10115         let uci_packet = Arc::new(UciPacketData {
10116             group_id: GroupId::SessionConfig,
10117             packet_boundary_flag: PacketBoundaryFlag::Complete,
10118             message_type: MessageType::Response,
10119             opcode: 5,
10120             child: UciPacketDataChild::UciResponse(uci_response),
10121         });
10122         SessionGetCountRspPacket::new(uci_packet).unwrap()
10123     }
10124 }
10125 impl Into<UciPacketPacket> for SessionGetCountRspBuilder {
into(self) -> UciPacketPacket10126     fn into(self) -> UciPacketPacket {
10127         self.build().into()
10128     }
10129 }
10130 impl Into<UciResponsePacket> for SessionGetCountRspBuilder {
into(self) -> UciResponsePacket10131     fn into(self) -> UciResponsePacket {
10132         self.build().into()
10133     }
10134 }
10135 impl Into<SessionResponsePacket> for SessionGetCountRspBuilder {
into(self) -> SessionResponsePacket10136     fn into(self) -> SessionResponsePacket {
10137         self.build().into()
10138     }
10139 }
10140 macro_rules! session_get_count_rsp_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
10141 #[test]
10142 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
10143 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
10144 UciPacketChild::UciResponse(uci_response_packet) => {match uci_response_packet.specialize() {/* (2) */
10145 UciResponseChild::SessionResponse(session_response_packet) => {match session_response_packet.specialize() {/* (3) */
10146 SessionResponseChild::SessionGetCountRsp(packet) => {let rebuilder = SessionGetCountRspBuilder {status : packet.get_status(),session_count : packet.get_session_count(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse session_get_count_rsp
10147  {:#02x?}", session_response_packet); }}}_ => {panic!("Couldn't parse session_response
10148  {:#02x?}", uci_response_packet); }}}_ => {panic!("Couldn't parse uci_response
10149  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
10150 session_get_count_rsp_builder_tests! { session_get_count_rsp_builder_test_00: b"\x41\x05\x00\x02\x00\x01",}
10151 
10152 #[derive(Debug)]
10153 struct SessionGetStateCmdData {
10154     session_id: u32,
10155 }
10156 #[derive(Debug, Clone)]
10157 pub struct SessionGetStateCmdPacket {
10158     uci_packet: Arc<UciPacketData>,
10159     uci_command: Arc<UciCommandData>,
10160     session_command: Arc<SessionCommandData>,
10161     session_get_state_cmd: Arc<SessionGetStateCmdData>,
10162 }
10163 #[derive(Debug)]
10164 pub struct SessionGetStateCmdBuilder {
10165     pub session_id: u32,
10166 }
10167 impl SessionGetStateCmdData {
conforms(bytes: &[u8]) -> bool10168     fn conforms(bytes: &[u8]) -> bool {
10169         if bytes.len() < 8 {
10170             return false;
10171         }
10172         true
10173     }
parse(bytes: &[u8]) -> Result<Self>10174     fn parse(bytes: &[u8]) -> Result<Self> {
10175         if bytes.len() < 8 {
10176             return Err(Error::InvalidLengthError {
10177                 obj: "SessionGetStateCmd".to_string(),
10178                 field: "session_id".to_string(),
10179                 wanted: 8,
10180                 got: bytes.len(),
10181             });
10182         }
10183         let session_id = u32::from_le_bytes([bytes[4], bytes[5], bytes[6], bytes[7]]);
10184         Ok(Self { session_id })
10185     }
write_to(&self, buffer: &mut BytesMut)10186     fn write_to(&self, buffer: &mut BytesMut) {
10187         let session_id = self.session_id;
10188         buffer[4..8].copy_from_slice(&session_id.to_le_bytes()[0..4]);
10189     }
get_total_size(&self) -> usize10190     fn get_total_size(&self) -> usize {
10191         self.get_size()
10192     }
get_size(&self) -> usize10193     fn get_size(&self) -> usize {
10194         let ret = 0;
10195         let ret = ret + 4;
10196         ret
10197     }
10198 }
10199 impl Packet for SessionGetStateCmdPacket {
to_bytes(self) -> Bytes10200     fn to_bytes(self) -> Bytes {
10201         let mut buffer = BytesMut::new();
10202         buffer.resize(self.uci_packet.get_total_size(), 0);
10203         self.uci_packet.write_to(&mut buffer);
10204         buffer.freeze()
10205     }
to_vec(self) -> Vec<u8>10206     fn to_vec(self) -> Vec<u8> {
10207         self.to_bytes().to_vec()
10208     }
10209 }
10210 impl From<SessionGetStateCmdPacket> for Bytes {
from(packet: SessionGetStateCmdPacket) -> Self10211     fn from(packet: SessionGetStateCmdPacket) -> Self {
10212         packet.to_bytes()
10213     }
10214 }
10215 impl From<SessionGetStateCmdPacket> for Vec<u8> {
from(packet: SessionGetStateCmdPacket) -> Self10216     fn from(packet: SessionGetStateCmdPacket) -> Self {
10217         packet.to_vec()
10218     }
10219 }
10220 impl TryFrom<UciPacketPacket> for SessionGetStateCmdPacket {
10221     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>10222     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
10223         Self::new(value.uci_packet).map_err(TryFromError)
10224     }
10225 }
10226 impl SessionGetStateCmdPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>10227     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
10228         let uci_packet = root;
10229         let uci_command = match &uci_packet.child {
10230             UciPacketDataChild::UciCommand(value) => (*value).clone(),
10231             _ => return Err("inconsistent state - child was not UciCommand"),
10232         };
10233         let session_command = match &uci_command.child {
10234             UciCommandDataChild::SessionCommand(value) => (*value).clone(),
10235             _ => return Err("inconsistent state - child was not SessionCommand"),
10236         };
10237         let session_get_state_cmd = match &session_command.child {
10238             SessionCommandDataChild::SessionGetStateCmd(value) => (*value).clone(),
10239             _ => return Err("inconsistent state - child was not SessionGetStateCmd"),
10240         };
10241         Ok(Self {
10242             uci_packet,
10243             uci_command,
10244             session_command,
10245             session_get_state_cmd,
10246         })
10247     }
get_group_id(&self) -> GroupId10248     pub fn get_group_id(&self) -> GroupId {
10249         self.uci_packet.as_ref().group_id
10250     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag10251     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
10252         self.uci_packet.as_ref().packet_boundary_flag
10253     }
get_message_type(&self) -> MessageType10254     pub fn get_message_type(&self) -> MessageType {
10255         self.uci_packet.as_ref().message_type
10256     }
get_opcode(&self) -> u810257     pub fn get_opcode(&self) -> u8 {
10258         self.uci_packet.as_ref().opcode
10259     }
get_session_id(&self) -> u3210260     pub fn get_session_id(&self) -> u32 {
10261         self.session_get_state_cmd.as_ref().session_id
10262     }
10263 }
10264 impl Into<UciPacketPacket> for SessionGetStateCmdPacket {
into(self) -> UciPacketPacket10265     fn into(self) -> UciPacketPacket {
10266         UciPacketPacket::new(self.uci_packet).unwrap()
10267     }
10268 }
10269 impl Into<UciCommandPacket> for SessionGetStateCmdPacket {
into(self) -> UciCommandPacket10270     fn into(self) -> UciCommandPacket {
10271         UciCommandPacket::new(self.uci_packet).unwrap()
10272     }
10273 }
10274 impl Into<SessionCommandPacket> for SessionGetStateCmdPacket {
into(self) -> SessionCommandPacket10275     fn into(self) -> SessionCommandPacket {
10276         SessionCommandPacket::new(self.uci_packet).unwrap()
10277     }
10278 }
10279 impl SessionGetStateCmdBuilder {
build(self) -> SessionGetStateCmdPacket10280     pub fn build(self) -> SessionGetStateCmdPacket {
10281         let session_get_state_cmd = Arc::new(SessionGetStateCmdData {
10282             session_id: self.session_id,
10283         });
10284         let session_command = Arc::new(SessionCommandData {
10285             child: SessionCommandDataChild::SessionGetStateCmd(session_get_state_cmd),
10286         });
10287         let uci_command = Arc::new(UciCommandData {
10288             child: UciCommandDataChild::SessionCommand(session_command),
10289         });
10290         let uci_packet = Arc::new(UciPacketData {
10291             group_id: GroupId::SessionConfig,
10292             packet_boundary_flag: PacketBoundaryFlag::Complete,
10293             message_type: MessageType::Command,
10294             opcode: 6,
10295             child: UciPacketDataChild::UciCommand(uci_command),
10296         });
10297         SessionGetStateCmdPacket::new(uci_packet).unwrap()
10298     }
10299 }
10300 impl Into<UciPacketPacket> for SessionGetStateCmdBuilder {
into(self) -> UciPacketPacket10301     fn into(self) -> UciPacketPacket {
10302         self.build().into()
10303     }
10304 }
10305 impl Into<UciCommandPacket> for SessionGetStateCmdBuilder {
into(self) -> UciCommandPacket10306     fn into(self) -> UciCommandPacket {
10307         self.build().into()
10308     }
10309 }
10310 impl Into<SessionCommandPacket> for SessionGetStateCmdBuilder {
into(self) -> SessionCommandPacket10311     fn into(self) -> SessionCommandPacket {
10312         self.build().into()
10313     }
10314 }
10315 macro_rules! session_get_state_cmd_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
10316 #[test]
10317 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
10318 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
10319 UciPacketChild::UciCommand(uci_command_packet) => {match uci_command_packet.specialize() {/* (2) */
10320 UciCommandChild::SessionCommand(session_command_packet) => {match session_command_packet.specialize() {/* (3) */
10321 SessionCommandChild::SessionGetStateCmd(packet) => {let rebuilder = SessionGetStateCmdBuilder {session_id : packet.get_session_id(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse session_get_state_cmd
10322  {:#02x?}", session_command_packet); }}}_ => {panic!("Couldn't parse session_command
10323  {:#02x?}", uci_command_packet); }}}_ => {panic!("Couldn't parse uci_command
10324  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
10325 session_get_state_cmd_builder_tests! { session_get_state_cmd_builder_test_00: b"\x21\x06\x00\x04\x00\x01\x02\x03",}
10326 
10327 #[derive(Debug)]
10328 struct SessionGetStateRspData {
10329     status: StatusCode,
10330     session_state: SessionState,
10331 }
10332 #[derive(Debug, Clone)]
10333 pub struct SessionGetStateRspPacket {
10334     uci_packet: Arc<UciPacketData>,
10335     uci_response: Arc<UciResponseData>,
10336     session_response: Arc<SessionResponseData>,
10337     session_get_state_rsp: Arc<SessionGetStateRspData>,
10338 }
10339 #[derive(Debug)]
10340 pub struct SessionGetStateRspBuilder {
10341     pub status: StatusCode,
10342     pub session_state: SessionState,
10343 }
10344 impl SessionGetStateRspData {
conforms(bytes: &[u8]) -> bool10345     fn conforms(bytes: &[u8]) -> bool {
10346         if bytes.len() < 6 {
10347             return false;
10348         }
10349         true
10350     }
parse(bytes: &[u8]) -> Result<Self>10351     fn parse(bytes: &[u8]) -> Result<Self> {
10352         if bytes.len() < 5 {
10353             return Err(Error::InvalidLengthError {
10354                 obj: "SessionGetStateRsp".to_string(),
10355                 field: "status".to_string(),
10356                 wanted: 5,
10357                 got: bytes.len(),
10358             });
10359         }
10360         let status = u8::from_le_bytes([bytes[4]]);
10361         let status = StatusCode::from_u8(status).ok_or_else(|| Error::InvalidEnumValueError {
10362             obj: "SessionGetStateRsp".to_string(),
10363             field: "status".to_string(),
10364             value: status as u64,
10365             type_: "StatusCode".to_string(),
10366         })?;
10367         if bytes.len() < 6 {
10368             return Err(Error::InvalidLengthError {
10369                 obj: "SessionGetStateRsp".to_string(),
10370                 field: "session_state".to_string(),
10371                 wanted: 6,
10372                 got: bytes.len(),
10373             });
10374         }
10375         let session_state = u8::from_le_bytes([bytes[5]]);
10376         let session_state =
10377             SessionState::from_u8(session_state).ok_or_else(|| Error::InvalidEnumValueError {
10378                 obj: "SessionGetStateRsp".to_string(),
10379                 field: "session_state".to_string(),
10380                 value: session_state as u64,
10381                 type_: "SessionState".to_string(),
10382             })?;
10383         Ok(Self {
10384             status,
10385             session_state,
10386         })
10387     }
write_to(&self, buffer: &mut BytesMut)10388     fn write_to(&self, buffer: &mut BytesMut) {
10389         let status = self.status.to_u8().unwrap();
10390         buffer[4..5].copy_from_slice(&status.to_le_bytes()[0..1]);
10391         let session_state = self.session_state.to_u8().unwrap();
10392         buffer[5..6].copy_from_slice(&session_state.to_le_bytes()[0..1]);
10393     }
get_total_size(&self) -> usize10394     fn get_total_size(&self) -> usize {
10395         self.get_size()
10396     }
get_size(&self) -> usize10397     fn get_size(&self) -> usize {
10398         let ret = 0;
10399         let ret = ret + 2;
10400         ret
10401     }
10402 }
10403 impl Packet for SessionGetStateRspPacket {
to_bytes(self) -> Bytes10404     fn to_bytes(self) -> Bytes {
10405         let mut buffer = BytesMut::new();
10406         buffer.resize(self.uci_packet.get_total_size(), 0);
10407         self.uci_packet.write_to(&mut buffer);
10408         buffer.freeze()
10409     }
to_vec(self) -> Vec<u8>10410     fn to_vec(self) -> Vec<u8> {
10411         self.to_bytes().to_vec()
10412     }
10413 }
10414 impl From<SessionGetStateRspPacket> for Bytes {
from(packet: SessionGetStateRspPacket) -> Self10415     fn from(packet: SessionGetStateRspPacket) -> Self {
10416         packet.to_bytes()
10417     }
10418 }
10419 impl From<SessionGetStateRspPacket> for Vec<u8> {
from(packet: SessionGetStateRspPacket) -> Self10420     fn from(packet: SessionGetStateRspPacket) -> Self {
10421         packet.to_vec()
10422     }
10423 }
10424 impl TryFrom<UciPacketPacket> for SessionGetStateRspPacket {
10425     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>10426     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
10427         Self::new(value.uci_packet).map_err(TryFromError)
10428     }
10429 }
10430 impl SessionGetStateRspPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>10431     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
10432         let uci_packet = root;
10433         let uci_response = match &uci_packet.child {
10434             UciPacketDataChild::UciResponse(value) => (*value).clone(),
10435             _ => return Err("inconsistent state - child was not UciResponse"),
10436         };
10437         let session_response = match &uci_response.child {
10438             UciResponseDataChild::SessionResponse(value) => (*value).clone(),
10439             _ => return Err("inconsistent state - child was not SessionResponse"),
10440         };
10441         let session_get_state_rsp = match &session_response.child {
10442             SessionResponseDataChild::SessionGetStateRsp(value) => (*value).clone(),
10443             _ => return Err("inconsistent state - child was not SessionGetStateRsp"),
10444         };
10445         Ok(Self {
10446             uci_packet,
10447             uci_response,
10448             session_response,
10449             session_get_state_rsp,
10450         })
10451     }
get_group_id(&self) -> GroupId10452     pub fn get_group_id(&self) -> GroupId {
10453         self.uci_packet.as_ref().group_id
10454     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag10455     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
10456         self.uci_packet.as_ref().packet_boundary_flag
10457     }
get_message_type(&self) -> MessageType10458     pub fn get_message_type(&self) -> MessageType {
10459         self.uci_packet.as_ref().message_type
10460     }
get_opcode(&self) -> u810461     pub fn get_opcode(&self) -> u8 {
10462         self.uci_packet.as_ref().opcode
10463     }
get_status(&self) -> StatusCode10464     pub fn get_status(&self) -> StatusCode {
10465         self.session_get_state_rsp.as_ref().status
10466     }
get_session_state(&self) -> SessionState10467     pub fn get_session_state(&self) -> SessionState {
10468         self.session_get_state_rsp.as_ref().session_state
10469     }
10470 }
10471 impl Into<UciPacketPacket> for SessionGetStateRspPacket {
into(self) -> UciPacketPacket10472     fn into(self) -> UciPacketPacket {
10473         UciPacketPacket::new(self.uci_packet).unwrap()
10474     }
10475 }
10476 impl Into<UciResponsePacket> for SessionGetStateRspPacket {
into(self) -> UciResponsePacket10477     fn into(self) -> UciResponsePacket {
10478         UciResponsePacket::new(self.uci_packet).unwrap()
10479     }
10480 }
10481 impl Into<SessionResponsePacket> for SessionGetStateRspPacket {
into(self) -> SessionResponsePacket10482     fn into(self) -> SessionResponsePacket {
10483         SessionResponsePacket::new(self.uci_packet).unwrap()
10484     }
10485 }
10486 impl SessionGetStateRspBuilder {
build(self) -> SessionGetStateRspPacket10487     pub fn build(self) -> SessionGetStateRspPacket {
10488         let session_get_state_rsp = Arc::new(SessionGetStateRspData {
10489             status: self.status,
10490             session_state: self.session_state,
10491         });
10492         let session_response = Arc::new(SessionResponseData {
10493             child: SessionResponseDataChild::SessionGetStateRsp(session_get_state_rsp),
10494         });
10495         let uci_response = Arc::new(UciResponseData {
10496             child: UciResponseDataChild::SessionResponse(session_response),
10497         });
10498         let uci_packet = Arc::new(UciPacketData {
10499             group_id: GroupId::SessionConfig,
10500             packet_boundary_flag: PacketBoundaryFlag::Complete,
10501             message_type: MessageType::Response,
10502             opcode: 6,
10503             child: UciPacketDataChild::UciResponse(uci_response),
10504         });
10505         SessionGetStateRspPacket::new(uci_packet).unwrap()
10506     }
10507 }
10508 impl Into<UciPacketPacket> for SessionGetStateRspBuilder {
into(self) -> UciPacketPacket10509     fn into(self) -> UciPacketPacket {
10510         self.build().into()
10511     }
10512 }
10513 impl Into<UciResponsePacket> for SessionGetStateRspBuilder {
into(self) -> UciResponsePacket10514     fn into(self) -> UciResponsePacket {
10515         self.build().into()
10516     }
10517 }
10518 impl Into<SessionResponsePacket> for SessionGetStateRspBuilder {
into(self) -> SessionResponsePacket10519     fn into(self) -> SessionResponsePacket {
10520         self.build().into()
10521     }
10522 }
10523 macro_rules! session_get_state_rsp_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
10524 #[test]
10525 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
10526 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
10527 UciPacketChild::UciResponse(uci_response_packet) => {match uci_response_packet.specialize() {/* (2) */
10528 UciResponseChild::SessionResponse(session_response_packet) => {match session_response_packet.specialize() {/* (3) */
10529 SessionResponseChild::SessionGetStateRsp(packet) => {let rebuilder = SessionGetStateRspBuilder {status : packet.get_status(),session_state : packet.get_session_state(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse session_get_state_rsp
10530  {:#02x?}", session_response_packet); }}}_ => {panic!("Couldn't parse session_response
10531  {:#02x?}", uci_response_packet); }}}_ => {panic!("Couldn't parse uci_response
10532  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
10533 session_get_state_rsp_builder_tests! { session_get_state_rsp_builder_test_00: b"\x41\x06\x00\x02\x00\x01",}
10534 
10535 #[derive(Debug)]
10536 struct SessionUpdateControllerMulticastListCmdData {
10537     session_id: u32,
10538     action: u8,
10539     controlees: Vec<Controlee>,
10540 }
10541 #[derive(Debug, Clone)]
10542 pub struct SessionUpdateControllerMulticastListCmdPacket {
10543     uci_packet: Arc<UciPacketData>,
10544     uci_command: Arc<UciCommandData>,
10545     session_command: Arc<SessionCommandData>,
10546     session_update_controller_multicast_list_cmd: Arc<SessionUpdateControllerMulticastListCmdData>,
10547 }
10548 #[derive(Debug)]
10549 pub struct SessionUpdateControllerMulticastListCmdBuilder {
10550     pub session_id: u32,
10551     pub action: u8,
10552     pub controlees: Vec<Controlee>,
10553 }
10554 impl SessionUpdateControllerMulticastListCmdData {
conforms(bytes: &[u8]) -> bool10555     fn conforms(bytes: &[u8]) -> bool {
10556         if bytes.len() < 10 {
10557             return false;
10558         }
10559         true
10560     }
parse(bytes: &[u8]) -> Result<Self>10561     fn parse(bytes: &[u8]) -> Result<Self> {
10562         if bytes.len() < 8 {
10563             return Err(Error::InvalidLengthError {
10564                 obj: "SessionUpdateControllerMulticastListCmd".to_string(),
10565                 field: "session_id".to_string(),
10566                 wanted: 8,
10567                 got: bytes.len(),
10568             });
10569         }
10570         let session_id = u32::from_le_bytes([bytes[4], bytes[5], bytes[6], bytes[7]]);
10571         if bytes.len() < 9 {
10572             return Err(Error::InvalidLengthError {
10573                 obj: "SessionUpdateControllerMulticastListCmd".to_string(),
10574                 field: "action".to_string(),
10575                 wanted: 9,
10576                 got: bytes.len(),
10577             });
10578         }
10579         let action = u8::from_le_bytes([bytes[8]]);
10580         if bytes.len() < 10 {
10581             return Err(Error::InvalidLengthError {
10582                 obj: "SessionUpdateControllerMulticastListCmd".to_string(),
10583                 field: "controlees_count".to_string(),
10584                 wanted: 10,
10585                 got: bytes.len(),
10586             });
10587         }
10588         let controlees_count = u8::from_le_bytes([bytes[9]]);
10589         let want_ = 10 + ((controlees_count as usize) * 6);
10590         if bytes.len() < want_ {
10591             return Err(Error::InvalidLengthError {
10592                 obj: "SessionUpdateControllerMulticastListCmd".to_string(),
10593                 field: "controlees".to_string(),
10594                 wanted: want_,
10595                 got: bytes.len(),
10596             });
10597         }
10598         let mut controlees: Vec<Controlee> = Vec::new();
10599         let mut parsable_ = &bytes[10..];
10600         let count_ = controlees_count as usize;
10601         for _ in 0..count_ {
10602             match Controlee::parse(&parsable_) {
10603                 Ok(parsed) => {
10604                     parsable_ = &parsable_[parsed.get_total_size()..];
10605                     controlees.push(parsed);
10606                 }
10607                 Err(Error::ImpossibleStructError) => break,
10608                 Err(e) => return Err(e),
10609             }
10610         }
10611         Ok(Self {
10612             session_id,
10613             action,
10614             controlees,
10615         })
10616     }
write_to(&self, buffer: &mut BytesMut)10617     fn write_to(&self, buffer: &mut BytesMut) {
10618         let session_id = self.session_id;
10619         buffer[4..8].copy_from_slice(&session_id.to_le_bytes()[0..4]);
10620         let action = self.action;
10621         buffer[8..9].copy_from_slice(&action.to_le_bytes()[0..1]);
10622         buffer[9..10].copy_from_slice(&(self.controlees.len() as u8).to_le_bytes());
10623         let mut vec_buffer_ = &mut buffer[10..];
10624         for e_ in &self.controlees {
10625             e_.write_to(&mut vec_buffer_[0..e_.get_total_size()]);
10626             vec_buffer_ = &mut vec_buffer_[e_.get_total_size()..];
10627         }
10628     }
get_total_size(&self) -> usize10629     fn get_total_size(&self) -> usize {
10630         self.get_size()
10631     }
get_size(&self) -> usize10632     fn get_size(&self) -> usize {
10633         let ret = 0;
10634         let ret = ret + 6;
10635         let ret = ret + (self.controlees.len() * ((/* Bits: */48 + /* Dynamic: */ 0) / 8));
10636         ret
10637     }
10638 }
10639 impl Packet for SessionUpdateControllerMulticastListCmdPacket {
to_bytes(self) -> Bytes10640     fn to_bytes(self) -> Bytes {
10641         let mut buffer = BytesMut::new();
10642         buffer.resize(self.uci_packet.get_total_size(), 0);
10643         self.uci_packet.write_to(&mut buffer);
10644         buffer.freeze()
10645     }
to_vec(self) -> Vec<u8>10646     fn to_vec(self) -> Vec<u8> {
10647         self.to_bytes().to_vec()
10648     }
10649 }
10650 impl From<SessionUpdateControllerMulticastListCmdPacket> for Bytes {
from(packet: SessionUpdateControllerMulticastListCmdPacket) -> Self10651     fn from(packet: SessionUpdateControllerMulticastListCmdPacket) -> Self {
10652         packet.to_bytes()
10653     }
10654 }
10655 impl From<SessionUpdateControllerMulticastListCmdPacket> for Vec<u8> {
from(packet: SessionUpdateControllerMulticastListCmdPacket) -> Self10656     fn from(packet: SessionUpdateControllerMulticastListCmdPacket) -> Self {
10657         packet.to_vec()
10658     }
10659 }
10660 impl TryFrom<UciPacketPacket> for SessionUpdateControllerMulticastListCmdPacket {
10661     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>10662     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
10663         Self::new(value.uci_packet).map_err(TryFromError)
10664     }
10665 }
10666 impl SessionUpdateControllerMulticastListCmdPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>10667     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
10668         let uci_packet = root;
10669         let uci_command = match &uci_packet.child {
10670             UciPacketDataChild::UciCommand(value) => (*value).clone(),
10671             _ => return Err("inconsistent state - child was not UciCommand"),
10672         };
10673         let session_command = match &uci_command.child {
10674             UciCommandDataChild::SessionCommand(value) => (*value).clone(),
10675             _ => return Err("inconsistent state - child was not SessionCommand"),
10676         };
10677         let session_update_controller_multicast_list_cmd =
10678             match &session_command.child {
10679                 SessionCommandDataChild::SessionUpdateControllerMulticastListCmd(value) => {
10680                     (*value).clone()
10681                 }
10682                 _ => return Err(
10683                     "inconsistent state - child was not SessionUpdateControllerMulticastListCmd",
10684                 ),
10685             };
10686         Ok(Self {
10687             uci_packet,
10688             uci_command,
10689             session_command,
10690             session_update_controller_multicast_list_cmd,
10691         })
10692     }
get_group_id(&self) -> GroupId10693     pub fn get_group_id(&self) -> GroupId {
10694         self.uci_packet.as_ref().group_id
10695     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag10696     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
10697         self.uci_packet.as_ref().packet_boundary_flag
10698     }
get_message_type(&self) -> MessageType10699     pub fn get_message_type(&self) -> MessageType {
10700         self.uci_packet.as_ref().message_type
10701     }
get_opcode(&self) -> u810702     pub fn get_opcode(&self) -> u8 {
10703         self.uci_packet.as_ref().opcode
10704     }
get_session_id(&self) -> u3210705     pub fn get_session_id(&self) -> u32 {
10706         self.session_update_controller_multicast_list_cmd
10707             .as_ref()
10708             .session_id
10709     }
get_action(&self) -> u810710     pub fn get_action(&self) -> u8 {
10711         self.session_update_controller_multicast_list_cmd
10712             .as_ref()
10713             .action
10714     }
get_controlees(&self) -> &Vec<Controlee>10715     pub fn get_controlees(&self) -> &Vec<Controlee> {
10716         &self
10717             .session_update_controller_multicast_list_cmd
10718             .as_ref()
10719             .controlees
10720     }
10721 }
10722 impl Into<UciPacketPacket> for SessionUpdateControllerMulticastListCmdPacket {
into(self) -> UciPacketPacket10723     fn into(self) -> UciPacketPacket {
10724         UciPacketPacket::new(self.uci_packet).unwrap()
10725     }
10726 }
10727 impl Into<UciCommandPacket> for SessionUpdateControllerMulticastListCmdPacket {
into(self) -> UciCommandPacket10728     fn into(self) -> UciCommandPacket {
10729         UciCommandPacket::new(self.uci_packet).unwrap()
10730     }
10731 }
10732 impl Into<SessionCommandPacket> for SessionUpdateControllerMulticastListCmdPacket {
into(self) -> SessionCommandPacket10733     fn into(self) -> SessionCommandPacket {
10734         SessionCommandPacket::new(self.uci_packet).unwrap()
10735     }
10736 }
10737 impl SessionUpdateControllerMulticastListCmdBuilder {
build(self) -> SessionUpdateControllerMulticastListCmdPacket10738     pub fn build(self) -> SessionUpdateControllerMulticastListCmdPacket {
10739         let session_update_controller_multicast_list_cmd =
10740             Arc::new(SessionUpdateControllerMulticastListCmdData {
10741                 session_id: self.session_id,
10742                 action: self.action,
10743                 controlees: self.controlees,
10744             });
10745         let session_command = Arc::new(SessionCommandData {
10746             child: SessionCommandDataChild::SessionUpdateControllerMulticastListCmd(
10747                 session_update_controller_multicast_list_cmd,
10748             ),
10749         });
10750         let uci_command = Arc::new(UciCommandData {
10751             child: UciCommandDataChild::SessionCommand(session_command),
10752         });
10753         let uci_packet = Arc::new(UciPacketData {
10754             group_id: GroupId::SessionConfig,
10755             packet_boundary_flag: PacketBoundaryFlag::Complete,
10756             message_type: MessageType::Command,
10757             opcode: 7,
10758             child: UciPacketDataChild::UciCommand(uci_command),
10759         });
10760         SessionUpdateControllerMulticastListCmdPacket::new(uci_packet).unwrap()
10761     }
10762 }
10763 impl Into<UciPacketPacket> for SessionUpdateControllerMulticastListCmdBuilder {
into(self) -> UciPacketPacket10764     fn into(self) -> UciPacketPacket {
10765         self.build().into()
10766     }
10767 }
10768 impl Into<UciCommandPacket> for SessionUpdateControllerMulticastListCmdBuilder {
into(self) -> UciCommandPacket10769     fn into(self) -> UciCommandPacket {
10770         self.build().into()
10771     }
10772 }
10773 impl Into<SessionCommandPacket> for SessionUpdateControllerMulticastListCmdBuilder {
into(self) -> SessionCommandPacket10774     fn into(self) -> SessionCommandPacket {
10775         self.build().into()
10776     }
10777 }
10778 macro_rules! session_update_controller_multicast_list_cmd_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
10779 #[test]
10780 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
10781 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
10782 UciPacketChild::UciCommand(uci_command_packet) => {match uci_command_packet.specialize() {/* (2) */
10783 UciCommandChild::SessionCommand(session_command_packet) => {match session_command_packet.specialize() {/* (3) */
10784 SessionCommandChild::SessionUpdateControllerMulticastListCmd(packet) => {let rebuilder = SessionUpdateControllerMulticastListCmdBuilder {session_id : packet.get_session_id(),action : packet.get_action(),controlees : packet.get_controlees().to_vec(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse session_update_controller_multicast_list_cmd
10785  {:#02x?}", session_command_packet); }}}_ => {panic!("Couldn't parse session_command
10786  {:#02x?}", uci_command_packet); }}}_ => {panic!("Couldn't parse uci_command
10787  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
10788 session_update_controller_multicast_list_cmd_builder_tests! { session_update_controller_multicast_list_cmd_builder_test_00: b"\x21\x07\x00\x06\x00\x01\x02\x03\x04\x00",}
10789 
10790 #[derive(Debug)]
10791 struct SessionUpdateControllerMulticastListRspData {
10792     status: StatusCode,
10793 }
10794 #[derive(Debug, Clone)]
10795 pub struct SessionUpdateControllerMulticastListRspPacket {
10796     uci_packet: Arc<UciPacketData>,
10797     uci_response: Arc<UciResponseData>,
10798     session_response: Arc<SessionResponseData>,
10799     session_update_controller_multicast_list_rsp: Arc<SessionUpdateControllerMulticastListRspData>,
10800 }
10801 #[derive(Debug)]
10802 pub struct SessionUpdateControllerMulticastListRspBuilder {
10803     pub status: StatusCode,
10804 }
10805 impl SessionUpdateControllerMulticastListRspData {
conforms(bytes: &[u8]) -> bool10806     fn conforms(bytes: &[u8]) -> bool {
10807         if bytes.len() < 5 {
10808             return false;
10809         }
10810         true
10811     }
parse(bytes: &[u8]) -> Result<Self>10812     fn parse(bytes: &[u8]) -> Result<Self> {
10813         if bytes.len() < 5 {
10814             return Err(Error::InvalidLengthError {
10815                 obj: "SessionUpdateControllerMulticastListRsp".to_string(),
10816                 field: "status".to_string(),
10817                 wanted: 5,
10818                 got: bytes.len(),
10819             });
10820         }
10821         let status = u8::from_le_bytes([bytes[4]]);
10822         let status = StatusCode::from_u8(status).ok_or_else(|| Error::InvalidEnumValueError {
10823             obj: "SessionUpdateControllerMulticastListRsp".to_string(),
10824             field: "status".to_string(),
10825             value: status as u64,
10826             type_: "StatusCode".to_string(),
10827         })?;
10828         Ok(Self { status })
10829     }
write_to(&self, buffer: &mut BytesMut)10830     fn write_to(&self, buffer: &mut BytesMut) {
10831         let status = self.status.to_u8().unwrap();
10832         buffer[4..5].copy_from_slice(&status.to_le_bytes()[0..1]);
10833     }
get_total_size(&self) -> usize10834     fn get_total_size(&self) -> usize {
10835         self.get_size()
10836     }
get_size(&self) -> usize10837     fn get_size(&self) -> usize {
10838         let ret = 0;
10839         let ret = ret + 1;
10840         ret
10841     }
10842 }
10843 impl Packet for SessionUpdateControllerMulticastListRspPacket {
to_bytes(self) -> Bytes10844     fn to_bytes(self) -> Bytes {
10845         let mut buffer = BytesMut::new();
10846         buffer.resize(self.uci_packet.get_total_size(), 0);
10847         self.uci_packet.write_to(&mut buffer);
10848         buffer.freeze()
10849     }
to_vec(self) -> Vec<u8>10850     fn to_vec(self) -> Vec<u8> {
10851         self.to_bytes().to_vec()
10852     }
10853 }
10854 impl From<SessionUpdateControllerMulticastListRspPacket> for Bytes {
from(packet: SessionUpdateControllerMulticastListRspPacket) -> Self10855     fn from(packet: SessionUpdateControllerMulticastListRspPacket) -> Self {
10856         packet.to_bytes()
10857     }
10858 }
10859 impl From<SessionUpdateControllerMulticastListRspPacket> for Vec<u8> {
from(packet: SessionUpdateControllerMulticastListRspPacket) -> Self10860     fn from(packet: SessionUpdateControllerMulticastListRspPacket) -> Self {
10861         packet.to_vec()
10862     }
10863 }
10864 impl TryFrom<UciPacketPacket> for SessionUpdateControllerMulticastListRspPacket {
10865     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>10866     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
10867         Self::new(value.uci_packet).map_err(TryFromError)
10868     }
10869 }
10870 impl SessionUpdateControllerMulticastListRspPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>10871     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
10872         let uci_packet = root;
10873         let uci_response = match &uci_packet.child {
10874             UciPacketDataChild::UciResponse(value) => (*value).clone(),
10875             _ => return Err("inconsistent state - child was not UciResponse"),
10876         };
10877         let session_response = match &uci_response.child {
10878             UciResponseDataChild::SessionResponse(value) => (*value).clone(),
10879             _ => return Err("inconsistent state - child was not SessionResponse"),
10880         };
10881         let session_update_controller_multicast_list_rsp =
10882             match &session_response.child {
10883                 SessionResponseDataChild::SessionUpdateControllerMulticastListRsp(value) => {
10884                     (*value).clone()
10885                 }
10886                 _ => return Err(
10887                     "inconsistent state - child was not SessionUpdateControllerMulticastListRsp",
10888                 ),
10889             };
10890         Ok(Self {
10891             uci_packet,
10892             uci_response,
10893             session_response,
10894             session_update_controller_multicast_list_rsp,
10895         })
10896     }
get_group_id(&self) -> GroupId10897     pub fn get_group_id(&self) -> GroupId {
10898         self.uci_packet.as_ref().group_id
10899     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag10900     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
10901         self.uci_packet.as_ref().packet_boundary_flag
10902     }
get_message_type(&self) -> MessageType10903     pub fn get_message_type(&self) -> MessageType {
10904         self.uci_packet.as_ref().message_type
10905     }
get_opcode(&self) -> u810906     pub fn get_opcode(&self) -> u8 {
10907         self.uci_packet.as_ref().opcode
10908     }
get_status(&self) -> StatusCode10909     pub fn get_status(&self) -> StatusCode {
10910         self.session_update_controller_multicast_list_rsp
10911             .as_ref()
10912             .status
10913     }
10914 }
10915 impl Into<UciPacketPacket> for SessionUpdateControllerMulticastListRspPacket {
into(self) -> UciPacketPacket10916     fn into(self) -> UciPacketPacket {
10917         UciPacketPacket::new(self.uci_packet).unwrap()
10918     }
10919 }
10920 impl Into<UciResponsePacket> for SessionUpdateControllerMulticastListRspPacket {
into(self) -> UciResponsePacket10921     fn into(self) -> UciResponsePacket {
10922         UciResponsePacket::new(self.uci_packet).unwrap()
10923     }
10924 }
10925 impl Into<SessionResponsePacket> for SessionUpdateControllerMulticastListRspPacket {
into(self) -> SessionResponsePacket10926     fn into(self) -> SessionResponsePacket {
10927         SessionResponsePacket::new(self.uci_packet).unwrap()
10928     }
10929 }
10930 impl SessionUpdateControllerMulticastListRspBuilder {
build(self) -> SessionUpdateControllerMulticastListRspPacket10931     pub fn build(self) -> SessionUpdateControllerMulticastListRspPacket {
10932         let session_update_controller_multicast_list_rsp =
10933             Arc::new(SessionUpdateControllerMulticastListRspData {
10934                 status: self.status,
10935             });
10936         let session_response = Arc::new(SessionResponseData {
10937             child: SessionResponseDataChild::SessionUpdateControllerMulticastListRsp(
10938                 session_update_controller_multicast_list_rsp,
10939             ),
10940         });
10941         let uci_response = Arc::new(UciResponseData {
10942             child: UciResponseDataChild::SessionResponse(session_response),
10943         });
10944         let uci_packet = Arc::new(UciPacketData {
10945             group_id: GroupId::SessionConfig,
10946             packet_boundary_flag: PacketBoundaryFlag::Complete,
10947             message_type: MessageType::Response,
10948             opcode: 7,
10949             child: UciPacketDataChild::UciResponse(uci_response),
10950         });
10951         SessionUpdateControllerMulticastListRspPacket::new(uci_packet).unwrap()
10952     }
10953 }
10954 impl Into<UciPacketPacket> for SessionUpdateControllerMulticastListRspBuilder {
into(self) -> UciPacketPacket10955     fn into(self) -> UciPacketPacket {
10956         self.build().into()
10957     }
10958 }
10959 impl Into<UciResponsePacket> for SessionUpdateControllerMulticastListRspBuilder {
into(self) -> UciResponsePacket10960     fn into(self) -> UciResponsePacket {
10961         self.build().into()
10962     }
10963 }
10964 impl Into<SessionResponsePacket> for SessionUpdateControllerMulticastListRspBuilder {
into(self) -> SessionResponsePacket10965     fn into(self) -> SessionResponsePacket {
10966         self.build().into()
10967     }
10968 }
10969 macro_rules! session_update_controller_multicast_list_rsp_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
10970 #[test]
10971 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
10972 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
10973 UciPacketChild::UciResponse(uci_response_packet) => {match uci_response_packet.specialize() {/* (2) */
10974 UciResponseChild::SessionResponse(session_response_packet) => {match session_response_packet.specialize() {/* (3) */
10975 SessionResponseChild::SessionUpdateControllerMulticastListRsp(packet) => {let rebuilder = SessionUpdateControllerMulticastListRspBuilder {status : packet.get_status(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse session_update_controller_multicast_list_rsp
10976  {:#02x?}", session_response_packet); }}}_ => {panic!("Couldn't parse session_response
10977  {:#02x?}", uci_response_packet); }}}_ => {panic!("Couldn't parse uci_response
10978  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
10979 session_update_controller_multicast_list_rsp_builder_tests! { session_update_controller_multicast_list_rsp_builder_test_00: b"\x41\x07\x00\x01\x00",}
10980 
10981 #[derive(Debug)]
10982 struct SessionUpdateControllerMulticastListNtfData {
10983     session_id: u32,
10984     remaining_multicast_list_size: u8,
10985     controlee_status: Vec<ControleeStatus>,
10986 }
10987 #[derive(Debug, Clone)]
10988 pub struct SessionUpdateControllerMulticastListNtfPacket {
10989     uci_packet: Arc<UciPacketData>,
10990     uci_notification: Arc<UciNotificationData>,
10991     session_notification: Arc<SessionNotificationData>,
10992     session_update_controller_multicast_list_ntf: Arc<SessionUpdateControllerMulticastListNtfData>,
10993 }
10994 #[derive(Debug)]
10995 pub struct SessionUpdateControllerMulticastListNtfBuilder {
10996     pub session_id: u32,
10997     pub remaining_multicast_list_size: u8,
10998     pub controlee_status: Vec<ControleeStatus>,
10999 }
11000 impl SessionUpdateControllerMulticastListNtfData {
conforms(bytes: &[u8]) -> bool11001     fn conforms(bytes: &[u8]) -> bool {
11002         if bytes.len() < 10 {
11003             return false;
11004         }
11005         true
11006     }
parse(bytes: &[u8]) -> Result<Self>11007     fn parse(bytes: &[u8]) -> Result<Self> {
11008         if bytes.len() < 8 {
11009             return Err(Error::InvalidLengthError {
11010                 obj: "SessionUpdateControllerMulticastListNtf".to_string(),
11011                 field: "session_id".to_string(),
11012                 wanted: 8,
11013                 got: bytes.len(),
11014             });
11015         }
11016         let session_id = u32::from_le_bytes([bytes[4], bytes[5], bytes[6], bytes[7]]);
11017         if bytes.len() < 9 {
11018             return Err(Error::InvalidLengthError {
11019                 obj: "SessionUpdateControllerMulticastListNtf".to_string(),
11020                 field: "remaining_multicast_list_size".to_string(),
11021                 wanted: 9,
11022                 got: bytes.len(),
11023             });
11024         }
11025         let remaining_multicast_list_size = u8::from_le_bytes([bytes[8]]);
11026         if bytes.len() < 10 {
11027             return Err(Error::InvalidLengthError {
11028                 obj: "SessionUpdateControllerMulticastListNtf".to_string(),
11029                 field: "controlee_status_count".to_string(),
11030                 wanted: 10,
11031                 got: bytes.len(),
11032             });
11033         }
11034         let controlee_status_count = u8::from_le_bytes([bytes[9]]);
11035         let want_ = 10 + ((controlee_status_count as usize) * 7);
11036         if bytes.len() < want_ {
11037             return Err(Error::InvalidLengthError {
11038                 obj: "SessionUpdateControllerMulticastListNtf".to_string(),
11039                 field: "controlee_status".to_string(),
11040                 wanted: want_,
11041                 got: bytes.len(),
11042             });
11043         }
11044         let mut controlee_status: Vec<ControleeStatus> = Vec::new();
11045         let mut parsable_ = &bytes[10..];
11046         let count_ = controlee_status_count as usize;
11047         for _ in 0..count_ {
11048             match ControleeStatus::parse(&parsable_) {
11049                 Ok(parsed) => {
11050                     parsable_ = &parsable_[parsed.get_total_size()..];
11051                     controlee_status.push(parsed);
11052                 }
11053                 Err(Error::ImpossibleStructError) => break,
11054                 Err(e) => return Err(e),
11055             }
11056         }
11057         Ok(Self {
11058             session_id,
11059             remaining_multicast_list_size,
11060             controlee_status,
11061         })
11062     }
write_to(&self, buffer: &mut BytesMut)11063     fn write_to(&self, buffer: &mut BytesMut) {
11064         let session_id = self.session_id;
11065         buffer[4..8].copy_from_slice(&session_id.to_le_bytes()[0..4]);
11066         let remaining_multicast_list_size = self.remaining_multicast_list_size;
11067         buffer[8..9].copy_from_slice(&remaining_multicast_list_size.to_le_bytes()[0..1]);
11068         buffer[9..10].copy_from_slice(&(self.controlee_status.len() as u8).to_le_bytes());
11069         let mut vec_buffer_ = &mut buffer[10..];
11070         for e_ in &self.controlee_status {
11071             e_.write_to(&mut vec_buffer_[0..e_.get_total_size()]);
11072             vec_buffer_ = &mut vec_buffer_[e_.get_total_size()..];
11073         }
11074     }
get_total_size(&self) -> usize11075     fn get_total_size(&self) -> usize {
11076         self.get_size()
11077     }
get_size(&self) -> usize11078     fn get_size(&self) -> usize {
11079         let ret = 0;
11080         let ret = ret + 6;
11081         let ret = ret + (self.controlee_status.len() * ((/* Bits: */56 + /* Dynamic: */ 0) / 8));
11082         ret
11083     }
11084 }
11085 impl Packet for SessionUpdateControllerMulticastListNtfPacket {
to_bytes(self) -> Bytes11086     fn to_bytes(self) -> Bytes {
11087         let mut buffer = BytesMut::new();
11088         buffer.resize(self.uci_packet.get_total_size(), 0);
11089         self.uci_packet.write_to(&mut buffer);
11090         buffer.freeze()
11091     }
to_vec(self) -> Vec<u8>11092     fn to_vec(self) -> Vec<u8> {
11093         self.to_bytes().to_vec()
11094     }
11095 }
11096 impl From<SessionUpdateControllerMulticastListNtfPacket> for Bytes {
from(packet: SessionUpdateControllerMulticastListNtfPacket) -> Self11097     fn from(packet: SessionUpdateControllerMulticastListNtfPacket) -> Self {
11098         packet.to_bytes()
11099     }
11100 }
11101 impl From<SessionUpdateControllerMulticastListNtfPacket> for Vec<u8> {
from(packet: SessionUpdateControllerMulticastListNtfPacket) -> Self11102     fn from(packet: SessionUpdateControllerMulticastListNtfPacket) -> Self {
11103         packet.to_vec()
11104     }
11105 }
11106 impl TryFrom<UciPacketPacket> for SessionUpdateControllerMulticastListNtfPacket {
11107     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>11108     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
11109         Self::new(value.uci_packet).map_err(TryFromError)
11110     }
11111 }
11112 impl SessionUpdateControllerMulticastListNtfPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>11113     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
11114         let uci_packet = root;
11115         let uci_notification = match &uci_packet.child {
11116             UciPacketDataChild::UciNotification(value) => (*value).clone(),
11117             _ => return Err("inconsistent state - child was not UciNotification"),
11118         };
11119         let session_notification = match &uci_notification.child {
11120             UciNotificationDataChild::SessionNotification(value) => (*value).clone(),
11121             _ => return Err("inconsistent state - child was not SessionNotification"),
11122         };
11123         let session_update_controller_multicast_list_ntf =
11124             match &session_notification.child {
11125                 SessionNotificationDataChild::SessionUpdateControllerMulticastListNtf(value) => {
11126                     (*value).clone()
11127                 }
11128                 _ => return Err(
11129                     "inconsistent state - child was not SessionUpdateControllerMulticastListNtf",
11130                 ),
11131             };
11132         Ok(Self {
11133             uci_packet,
11134             uci_notification,
11135             session_notification,
11136             session_update_controller_multicast_list_ntf,
11137         })
11138     }
get_group_id(&self) -> GroupId11139     pub fn get_group_id(&self) -> GroupId {
11140         self.uci_packet.as_ref().group_id
11141     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag11142     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
11143         self.uci_packet.as_ref().packet_boundary_flag
11144     }
get_message_type(&self) -> MessageType11145     pub fn get_message_type(&self) -> MessageType {
11146         self.uci_packet.as_ref().message_type
11147     }
get_opcode(&self) -> u811148     pub fn get_opcode(&self) -> u8 {
11149         self.uci_packet.as_ref().opcode
11150     }
get_session_id(&self) -> u3211151     pub fn get_session_id(&self) -> u32 {
11152         self.session_update_controller_multicast_list_ntf
11153             .as_ref()
11154             .session_id
11155     }
get_remaining_multicast_list_size(&self) -> u811156     pub fn get_remaining_multicast_list_size(&self) -> u8 {
11157         self.session_update_controller_multicast_list_ntf
11158             .as_ref()
11159             .remaining_multicast_list_size
11160     }
get_controlee_status(&self) -> &Vec<ControleeStatus>11161     pub fn get_controlee_status(&self) -> &Vec<ControleeStatus> {
11162         &self
11163             .session_update_controller_multicast_list_ntf
11164             .as_ref()
11165             .controlee_status
11166     }
11167 }
11168 impl Into<UciPacketPacket> for SessionUpdateControllerMulticastListNtfPacket {
into(self) -> UciPacketPacket11169     fn into(self) -> UciPacketPacket {
11170         UciPacketPacket::new(self.uci_packet).unwrap()
11171     }
11172 }
11173 impl Into<UciNotificationPacket> for SessionUpdateControllerMulticastListNtfPacket {
into(self) -> UciNotificationPacket11174     fn into(self) -> UciNotificationPacket {
11175         UciNotificationPacket::new(self.uci_packet).unwrap()
11176     }
11177 }
11178 impl Into<SessionNotificationPacket> for SessionUpdateControllerMulticastListNtfPacket {
into(self) -> SessionNotificationPacket11179     fn into(self) -> SessionNotificationPacket {
11180         SessionNotificationPacket::new(self.uci_packet).unwrap()
11181     }
11182 }
11183 impl SessionUpdateControllerMulticastListNtfBuilder {
build(self) -> SessionUpdateControllerMulticastListNtfPacket11184     pub fn build(self) -> SessionUpdateControllerMulticastListNtfPacket {
11185         let session_update_controller_multicast_list_ntf =
11186             Arc::new(SessionUpdateControllerMulticastListNtfData {
11187                 session_id: self.session_id,
11188                 remaining_multicast_list_size: self.remaining_multicast_list_size,
11189                 controlee_status: self.controlee_status,
11190             });
11191         let session_notification = Arc::new(SessionNotificationData {
11192             child: SessionNotificationDataChild::SessionUpdateControllerMulticastListNtf(
11193                 session_update_controller_multicast_list_ntf,
11194             ),
11195         });
11196         let uci_notification = Arc::new(UciNotificationData {
11197             child: UciNotificationDataChild::SessionNotification(session_notification),
11198         });
11199         let uci_packet = Arc::new(UciPacketData {
11200             group_id: GroupId::SessionConfig,
11201             packet_boundary_flag: PacketBoundaryFlag::Complete,
11202             message_type: MessageType::Notification,
11203             opcode: 7,
11204             child: UciPacketDataChild::UciNotification(uci_notification),
11205         });
11206         SessionUpdateControllerMulticastListNtfPacket::new(uci_packet).unwrap()
11207     }
11208 }
11209 impl Into<UciPacketPacket> for SessionUpdateControllerMulticastListNtfBuilder {
into(self) -> UciPacketPacket11210     fn into(self) -> UciPacketPacket {
11211         self.build().into()
11212     }
11213 }
11214 impl Into<UciNotificationPacket> for SessionUpdateControllerMulticastListNtfBuilder {
into(self) -> UciNotificationPacket11215     fn into(self) -> UciNotificationPacket {
11216         self.build().into()
11217     }
11218 }
11219 impl Into<SessionNotificationPacket> for SessionUpdateControllerMulticastListNtfBuilder {
into(self) -> SessionNotificationPacket11220     fn into(self) -> SessionNotificationPacket {
11221         self.build().into()
11222     }
11223 }
11224 macro_rules! session_update_controller_multicast_list_ntf_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
11225 #[test]
11226 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
11227 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
11228 UciPacketChild::UciNotification(uci_notification_packet) => {match uci_notification_packet.specialize() {/* (2) */
11229 UciNotificationChild::SessionNotification(session_notification_packet) => {match session_notification_packet.specialize() {/* (3) */
11230 SessionNotificationChild::SessionUpdateControllerMulticastListNtf(packet) => {let rebuilder = SessionUpdateControllerMulticastListNtfBuilder {session_id : packet.get_session_id(),remaining_multicast_list_size : packet.get_remaining_multicast_list_size(),controlee_status : packet.get_controlee_status().to_vec(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse session_update_controller_multicast_list_ntf
11231  {:#02x?}", session_notification_packet); }}}_ => {panic!("Couldn't parse session_notification
11232  {:#02x?}", uci_notification_packet); }}}_ => {panic!("Couldn't parse uci_notification
11233  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
11234 session_update_controller_multicast_list_ntf_builder_tests! { session_update_controller_multicast_list_ntf_builder_test_00: b"\x61\x07\x00\x06\x00\x01\x02\x03\x04\x00",}
11235 
11236 #[derive(Debug)]
11237 struct RangeStartCmdData {}
11238 #[derive(Debug, Clone)]
11239 pub struct RangeStartCmdPacket {
11240     uci_packet: Arc<UciPacketData>,
11241     uci_command: Arc<UciCommandData>,
11242     ranging_command: Arc<RangingCommandData>,
11243     range_start_cmd: Arc<RangeStartCmdData>,
11244 }
11245 #[derive(Debug)]
11246 pub struct RangeStartCmdBuilder {
11247     pub session_id: u32,
11248 }
11249 impl RangeStartCmdData {
conforms(bytes: &[u8]) -> bool11250     fn conforms(bytes: &[u8]) -> bool {
11251         if bytes.len() < 8 {
11252             return false;
11253         }
11254         true
11255     }
parse(bytes: &[u8]) -> Result<Self>11256     fn parse(bytes: &[u8]) -> Result<Self> {
11257         Ok(Self {})
11258     }
write_to(&self, buffer: &mut BytesMut)11259     fn write_to(&self, buffer: &mut BytesMut) {}
get_total_size(&self) -> usize11260     fn get_total_size(&self) -> usize {
11261         self.get_size()
11262     }
get_size(&self) -> usize11263     fn get_size(&self) -> usize {
11264         let ret = 0;
11265         ret
11266     }
11267 }
11268 impl Packet for RangeStartCmdPacket {
to_bytes(self) -> Bytes11269     fn to_bytes(self) -> Bytes {
11270         let mut buffer = BytesMut::new();
11271         buffer.resize(self.uci_packet.get_total_size(), 0);
11272         self.uci_packet.write_to(&mut buffer);
11273         buffer.freeze()
11274     }
to_vec(self) -> Vec<u8>11275     fn to_vec(self) -> Vec<u8> {
11276         self.to_bytes().to_vec()
11277     }
11278 }
11279 impl From<RangeStartCmdPacket> for Bytes {
from(packet: RangeStartCmdPacket) -> Self11280     fn from(packet: RangeStartCmdPacket) -> Self {
11281         packet.to_bytes()
11282     }
11283 }
11284 impl From<RangeStartCmdPacket> for Vec<u8> {
from(packet: RangeStartCmdPacket) -> Self11285     fn from(packet: RangeStartCmdPacket) -> Self {
11286         packet.to_vec()
11287     }
11288 }
11289 impl TryFrom<UciPacketPacket> for RangeStartCmdPacket {
11290     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>11291     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
11292         Self::new(value.uci_packet).map_err(TryFromError)
11293     }
11294 }
11295 impl RangeStartCmdPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>11296     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
11297         let uci_packet = root;
11298         let uci_command = match &uci_packet.child {
11299             UciPacketDataChild::UciCommand(value) => (*value).clone(),
11300             _ => return Err("inconsistent state - child was not UciCommand"),
11301         };
11302         let ranging_command = match &uci_command.child {
11303             UciCommandDataChild::RangingCommand(value) => (*value).clone(),
11304             _ => return Err("inconsistent state - child was not RangingCommand"),
11305         };
11306         let range_start_cmd = match &ranging_command.child {
11307             RangingCommandDataChild::RangeStartCmd(value) => (*value).clone(),
11308             _ => return Err("inconsistent state - child was not RangeStartCmd"),
11309         };
11310         Ok(Self {
11311             uci_packet,
11312             uci_command,
11313             ranging_command,
11314             range_start_cmd,
11315         })
11316     }
get_group_id(&self) -> GroupId11317     pub fn get_group_id(&self) -> GroupId {
11318         self.uci_packet.as_ref().group_id
11319     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag11320     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
11321         self.uci_packet.as_ref().packet_boundary_flag
11322     }
get_message_type(&self) -> MessageType11323     pub fn get_message_type(&self) -> MessageType {
11324         self.uci_packet.as_ref().message_type
11325     }
get_opcode(&self) -> u811326     pub fn get_opcode(&self) -> u8 {
11327         self.uci_packet.as_ref().opcode
11328     }
get_session_id(&self) -> u3211329     pub fn get_session_id(&self) -> u32 {
11330         self.ranging_command.as_ref().session_id
11331     }
11332 }
11333 impl Into<UciPacketPacket> for RangeStartCmdPacket {
into(self) -> UciPacketPacket11334     fn into(self) -> UciPacketPacket {
11335         UciPacketPacket::new(self.uci_packet).unwrap()
11336     }
11337 }
11338 impl Into<UciCommandPacket> for RangeStartCmdPacket {
into(self) -> UciCommandPacket11339     fn into(self) -> UciCommandPacket {
11340         UciCommandPacket::new(self.uci_packet).unwrap()
11341     }
11342 }
11343 impl Into<RangingCommandPacket> for RangeStartCmdPacket {
into(self) -> RangingCommandPacket11344     fn into(self) -> RangingCommandPacket {
11345         RangingCommandPacket::new(self.uci_packet).unwrap()
11346     }
11347 }
11348 impl RangeStartCmdBuilder {
build(self) -> RangeStartCmdPacket11349     pub fn build(self) -> RangeStartCmdPacket {
11350         let range_start_cmd = Arc::new(RangeStartCmdData {});
11351         let ranging_command = Arc::new(RangingCommandData {
11352             session_id: self.session_id,
11353             child: RangingCommandDataChild::RangeStartCmd(range_start_cmd),
11354         });
11355         let uci_command = Arc::new(UciCommandData {
11356             child: UciCommandDataChild::RangingCommand(ranging_command),
11357         });
11358         let uci_packet = Arc::new(UciPacketData {
11359             group_id: GroupId::RangingSessionControl,
11360             packet_boundary_flag: PacketBoundaryFlag::Complete,
11361             message_type: MessageType::Command,
11362             opcode: 0,
11363             child: UciPacketDataChild::UciCommand(uci_command),
11364         });
11365         RangeStartCmdPacket::new(uci_packet).unwrap()
11366     }
11367 }
11368 impl Into<UciPacketPacket> for RangeStartCmdBuilder {
into(self) -> UciPacketPacket11369     fn into(self) -> UciPacketPacket {
11370         self.build().into()
11371     }
11372 }
11373 impl Into<UciCommandPacket> for RangeStartCmdBuilder {
into(self) -> UciCommandPacket11374     fn into(self) -> UciCommandPacket {
11375         self.build().into()
11376     }
11377 }
11378 impl Into<RangingCommandPacket> for RangeStartCmdBuilder {
into(self) -> RangingCommandPacket11379     fn into(self) -> RangingCommandPacket {
11380         self.build().into()
11381     }
11382 }
11383 macro_rules! range_start_cmd_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
11384 #[test]
11385 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
11386 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
11387 UciPacketChild::UciCommand(uci_command_packet) => {match uci_command_packet.specialize() {/* (2) */
11388 UciCommandChild::RangingCommand(ranging_command_packet) => {match ranging_command_packet.specialize() {/* (3) */
11389 RangingCommandChild::RangeStartCmd(packet) => {let rebuilder = RangeStartCmdBuilder {session_id : packet.get_session_id(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse range_start_cmd
11390  {:#02x?}", ranging_command_packet); }}}_ => {panic!("Couldn't parse ranging_command
11391  {:#02x?}", uci_command_packet); }}}_ => {panic!("Couldn't parse uci_command
11392  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
11393 range_start_cmd_builder_tests! { range_start_cmd_builder_test_00: b"\x22\x00\x00\x04\x00\x01\x02\x03",}
11394 
11395 #[derive(Debug)]
11396 struct RangeStartRspData {
11397     status: StatusCode,
11398 }
11399 #[derive(Debug, Clone)]
11400 pub struct RangeStartRspPacket {
11401     uci_packet: Arc<UciPacketData>,
11402     uci_response: Arc<UciResponseData>,
11403     ranging_response: Arc<RangingResponseData>,
11404     range_start_rsp: Arc<RangeStartRspData>,
11405 }
11406 #[derive(Debug)]
11407 pub struct RangeStartRspBuilder {
11408     pub status: StatusCode,
11409 }
11410 impl RangeStartRspData {
conforms(bytes: &[u8]) -> bool11411     fn conforms(bytes: &[u8]) -> bool {
11412         if bytes.len() < 5 {
11413             return false;
11414         }
11415         true
11416     }
parse(bytes: &[u8]) -> Result<Self>11417     fn parse(bytes: &[u8]) -> Result<Self> {
11418         if bytes.len() < 5 {
11419             return Err(Error::InvalidLengthError {
11420                 obj: "RangeStartRsp".to_string(),
11421                 field: "status".to_string(),
11422                 wanted: 5,
11423                 got: bytes.len(),
11424             });
11425         }
11426         let status = u8::from_le_bytes([bytes[4]]);
11427         let status = StatusCode::from_u8(status).ok_or_else(|| Error::InvalidEnumValueError {
11428             obj: "RangeStartRsp".to_string(),
11429             field: "status".to_string(),
11430             value: status as u64,
11431             type_: "StatusCode".to_string(),
11432         })?;
11433         Ok(Self { status })
11434     }
write_to(&self, buffer: &mut BytesMut)11435     fn write_to(&self, buffer: &mut BytesMut) {
11436         let status = self.status.to_u8().unwrap();
11437         buffer[4..5].copy_from_slice(&status.to_le_bytes()[0..1]);
11438     }
get_total_size(&self) -> usize11439     fn get_total_size(&self) -> usize {
11440         self.get_size()
11441     }
get_size(&self) -> usize11442     fn get_size(&self) -> usize {
11443         let ret = 0;
11444         let ret = ret + 1;
11445         ret
11446     }
11447 }
11448 impl Packet for RangeStartRspPacket {
to_bytes(self) -> Bytes11449     fn to_bytes(self) -> Bytes {
11450         let mut buffer = BytesMut::new();
11451         buffer.resize(self.uci_packet.get_total_size(), 0);
11452         self.uci_packet.write_to(&mut buffer);
11453         buffer.freeze()
11454     }
to_vec(self) -> Vec<u8>11455     fn to_vec(self) -> Vec<u8> {
11456         self.to_bytes().to_vec()
11457     }
11458 }
11459 impl From<RangeStartRspPacket> for Bytes {
from(packet: RangeStartRspPacket) -> Self11460     fn from(packet: RangeStartRspPacket) -> Self {
11461         packet.to_bytes()
11462     }
11463 }
11464 impl From<RangeStartRspPacket> for Vec<u8> {
from(packet: RangeStartRspPacket) -> Self11465     fn from(packet: RangeStartRspPacket) -> Self {
11466         packet.to_vec()
11467     }
11468 }
11469 impl TryFrom<UciPacketPacket> for RangeStartRspPacket {
11470     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>11471     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
11472         Self::new(value.uci_packet).map_err(TryFromError)
11473     }
11474 }
11475 impl RangeStartRspPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>11476     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
11477         let uci_packet = root;
11478         let uci_response = match &uci_packet.child {
11479             UciPacketDataChild::UciResponse(value) => (*value).clone(),
11480             _ => return Err("inconsistent state - child was not UciResponse"),
11481         };
11482         let ranging_response = match &uci_response.child {
11483             UciResponseDataChild::RangingResponse(value) => (*value).clone(),
11484             _ => return Err("inconsistent state - child was not RangingResponse"),
11485         };
11486         let range_start_rsp = match &ranging_response.child {
11487             RangingResponseDataChild::RangeStartRsp(value) => (*value).clone(),
11488             _ => return Err("inconsistent state - child was not RangeStartRsp"),
11489         };
11490         Ok(Self {
11491             uci_packet,
11492             uci_response,
11493             ranging_response,
11494             range_start_rsp,
11495         })
11496     }
get_group_id(&self) -> GroupId11497     pub fn get_group_id(&self) -> GroupId {
11498         self.uci_packet.as_ref().group_id
11499     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag11500     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
11501         self.uci_packet.as_ref().packet_boundary_flag
11502     }
get_message_type(&self) -> MessageType11503     pub fn get_message_type(&self) -> MessageType {
11504         self.uci_packet.as_ref().message_type
11505     }
get_opcode(&self) -> u811506     pub fn get_opcode(&self) -> u8 {
11507         self.uci_packet.as_ref().opcode
11508     }
get_status(&self) -> StatusCode11509     pub fn get_status(&self) -> StatusCode {
11510         self.range_start_rsp.as_ref().status
11511     }
11512 }
11513 impl Into<UciPacketPacket> for RangeStartRspPacket {
into(self) -> UciPacketPacket11514     fn into(self) -> UciPacketPacket {
11515         UciPacketPacket::new(self.uci_packet).unwrap()
11516     }
11517 }
11518 impl Into<UciResponsePacket> for RangeStartRspPacket {
into(self) -> UciResponsePacket11519     fn into(self) -> UciResponsePacket {
11520         UciResponsePacket::new(self.uci_packet).unwrap()
11521     }
11522 }
11523 impl Into<RangingResponsePacket> for RangeStartRspPacket {
into(self) -> RangingResponsePacket11524     fn into(self) -> RangingResponsePacket {
11525         RangingResponsePacket::new(self.uci_packet).unwrap()
11526     }
11527 }
11528 impl RangeStartRspBuilder {
build(self) -> RangeStartRspPacket11529     pub fn build(self) -> RangeStartRspPacket {
11530         let range_start_rsp = Arc::new(RangeStartRspData {
11531             status: self.status,
11532         });
11533         let ranging_response = Arc::new(RangingResponseData {
11534             child: RangingResponseDataChild::RangeStartRsp(range_start_rsp),
11535         });
11536         let uci_response = Arc::new(UciResponseData {
11537             child: UciResponseDataChild::RangingResponse(ranging_response),
11538         });
11539         let uci_packet = Arc::new(UciPacketData {
11540             group_id: GroupId::RangingSessionControl,
11541             packet_boundary_flag: PacketBoundaryFlag::Complete,
11542             message_type: MessageType::Response,
11543             opcode: 0,
11544             child: UciPacketDataChild::UciResponse(uci_response),
11545         });
11546         RangeStartRspPacket::new(uci_packet).unwrap()
11547     }
11548 }
11549 impl Into<UciPacketPacket> for RangeStartRspBuilder {
into(self) -> UciPacketPacket11550     fn into(self) -> UciPacketPacket {
11551         self.build().into()
11552     }
11553 }
11554 impl Into<UciResponsePacket> for RangeStartRspBuilder {
into(self) -> UciResponsePacket11555     fn into(self) -> UciResponsePacket {
11556         self.build().into()
11557     }
11558 }
11559 impl Into<RangingResponsePacket> for RangeStartRspBuilder {
into(self) -> RangingResponsePacket11560     fn into(self) -> RangingResponsePacket {
11561         self.build().into()
11562     }
11563 }
11564 macro_rules! range_start_rsp_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
11565 #[test]
11566 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
11567 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
11568 UciPacketChild::UciResponse(uci_response_packet) => {match uci_response_packet.specialize() {/* (2) */
11569 UciResponseChild::RangingResponse(ranging_response_packet) => {match ranging_response_packet.specialize() {/* (3) */
11570 RangingResponseChild::RangeStartRsp(packet) => {let rebuilder = RangeStartRspBuilder {status : packet.get_status(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse range_start_rsp
11571  {:#02x?}", ranging_response_packet); }}}_ => {panic!("Couldn't parse ranging_response
11572  {:#02x?}", uci_response_packet); }}}_ => {panic!("Couldn't parse uci_response
11573  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
11574 range_start_rsp_builder_tests! { range_start_rsp_builder_test_00: b"\x42\x00\x00\x01\x00",}
11575 
11576 #[derive(Debug)]
11577 enum RangeDataNtfDataChild {
11578     ShortMacTwoWayRangeDataNtf(Arc<ShortMacTwoWayRangeDataNtfData>),
11579     ExtendedMacTwoWayRangeDataNtf(Arc<ExtendedMacTwoWayRangeDataNtfData>),
11580     None,
11581 }
11582 impl RangeDataNtfDataChild {
get_total_size(&self) -> usize11583     fn get_total_size(&self) -> usize {
11584         match self {
11585             RangeDataNtfDataChild::ShortMacTwoWayRangeDataNtf(value) => value.get_total_size(),
11586             RangeDataNtfDataChild::ExtendedMacTwoWayRangeDataNtf(value) => value.get_total_size(),
11587             RangeDataNtfDataChild::None => 0,
11588         }
11589     }
11590 }
11591 #[derive(Debug)]
11592 pub enum RangeDataNtfChild {
11593     ShortMacTwoWayRangeDataNtf(ShortMacTwoWayRangeDataNtfPacket),
11594     ExtendedMacTwoWayRangeDataNtf(ExtendedMacTwoWayRangeDataNtfPacket),
11595     None,
11596 }
11597 #[derive(Debug)]
11598 struct RangeDataNtfData {
11599     sequence_number: u32,
11600     session_id: u32,
11601     rcr_indicator: u8,
11602     current_ranging_interval: u32,
11603     ranging_measurement_type: RangingMeasurementType,
11604     mac_address_indicator: MacAddressIndicator,
11605     child: RangeDataNtfDataChild,
11606 }
11607 #[derive(Debug, Clone)]
11608 pub struct RangeDataNtfPacket {
11609     uci_packet: Arc<UciPacketData>,
11610     uci_notification: Arc<UciNotificationData>,
11611     ranging_notification: Arc<RangingNotificationData>,
11612     range_data_ntf: Arc<RangeDataNtfData>,
11613 }
11614 #[derive(Debug)]
11615 pub struct RangeDataNtfBuilder {
11616     pub sequence_number: u32,
11617     pub session_id: u32,
11618     pub rcr_indicator: u8,
11619     pub current_ranging_interval: u32,
11620     pub ranging_measurement_type: RangingMeasurementType,
11621     pub mac_address_indicator: MacAddressIndicator,
11622 }
11623 impl RangeDataNtfData {
conforms(bytes: &[u8]) -> bool11624     fn conforms(bytes: &[u8]) -> bool {
11625         if bytes.len() < 28 {
11626             return false;
11627         }
11628         true
11629     }
parse(bytes: &[u8]) -> Result<Self>11630     fn parse(bytes: &[u8]) -> Result<Self> {
11631         if bytes.len() < 8 {
11632             return Err(Error::InvalidLengthError {
11633                 obj: "RangeDataNtf".to_string(),
11634                 field: "sequence_number".to_string(),
11635                 wanted: 8,
11636                 got: bytes.len(),
11637             });
11638         }
11639         let sequence_number = u32::from_le_bytes([bytes[4], bytes[5], bytes[6], bytes[7]]);
11640         if bytes.len() < 12 {
11641             return Err(Error::InvalidLengthError {
11642                 obj: "RangeDataNtf".to_string(),
11643                 field: "session_id".to_string(),
11644                 wanted: 12,
11645                 got: bytes.len(),
11646             });
11647         }
11648         let session_id = u32::from_le_bytes([bytes[8], bytes[9], bytes[10], bytes[11]]);
11649         if bytes.len() < 13 {
11650             return Err(Error::InvalidLengthError {
11651                 obj: "RangeDataNtf".to_string(),
11652                 field: "rcr_indicator".to_string(),
11653                 wanted: 13,
11654                 got: bytes.len(),
11655             });
11656         }
11657         let rcr_indicator = u8::from_le_bytes([bytes[12]]);
11658         if bytes.len() < 17 {
11659             return Err(Error::InvalidLengthError {
11660                 obj: "RangeDataNtf".to_string(),
11661                 field: "current_ranging_interval".to_string(),
11662                 wanted: 17,
11663                 got: bytes.len(),
11664             });
11665         }
11666         let current_ranging_interval =
11667             u32::from_le_bytes([bytes[13], bytes[14], bytes[15], bytes[16]]);
11668         if bytes.len() < 18 {
11669             return Err(Error::InvalidLengthError {
11670                 obj: "RangeDataNtf".to_string(),
11671                 field: "ranging_measurement_type".to_string(),
11672                 wanted: 18,
11673                 got: bytes.len(),
11674             });
11675         }
11676         let ranging_measurement_type = u8::from_le_bytes([bytes[17]]);
11677         let ranging_measurement_type = RangingMeasurementType::from_u8(ranging_measurement_type)
11678             .ok_or_else(|| Error::InvalidEnumValueError {
11679                 obj: "RangeDataNtf".to_string(),
11680                 field: "ranging_measurement_type".to_string(),
11681                 value: ranging_measurement_type as u64,
11682                 type_: "RangingMeasurementType".to_string(),
11683             })?;
11684         if bytes.len() < 20 {
11685             return Err(Error::InvalidLengthError {
11686                 obj: "RangeDataNtf".to_string(),
11687                 field: "mac_address_indicator".to_string(),
11688                 wanted: 20,
11689                 got: bytes.len(),
11690             });
11691         }
11692         let mac_address_indicator = u8::from_le_bytes([bytes[19]]);
11693         let mac_address_indicator = MacAddressIndicator::from_u8(mac_address_indicator)
11694             .ok_or_else(|| Error::InvalidEnumValueError {
11695                 obj: "RangeDataNtf".to_string(),
11696                 field: "mac_address_indicator".to_string(),
11697                 value: mac_address_indicator as u64,
11698                 type_: "MacAddressIndicator".to_string(),
11699             })?;
11700         let child = match (ranging_measurement_type, mac_address_indicator) {
11701             (RangingMeasurementType::TwoWay, MacAddressIndicator::ShortAddress)
11702                 if ShortMacTwoWayRangeDataNtfData::conforms(&bytes[..]) =>
11703             {
11704                 RangeDataNtfDataChild::ShortMacTwoWayRangeDataNtf(Arc::new(
11705                     ShortMacTwoWayRangeDataNtfData::parse(&bytes[..])?,
11706                 ))
11707             }
11708             (RangingMeasurementType::TwoWay, MacAddressIndicator::ExtendedAddress)
11709                 if ExtendedMacTwoWayRangeDataNtfData::conforms(&bytes[..]) =>
11710             {
11711                 RangeDataNtfDataChild::ExtendedMacTwoWayRangeDataNtf(Arc::new(
11712                     ExtendedMacTwoWayRangeDataNtfData::parse(&bytes[..])?,
11713                 ))
11714             }
11715             (_, _) => return Err(Error::InvalidPacketError),
11716         };
11717         Ok(Self {
11718             sequence_number,
11719             session_id,
11720             rcr_indicator,
11721             current_ranging_interval,
11722             ranging_measurement_type,
11723             mac_address_indicator,
11724             child,
11725         })
11726     }
write_to(&self, buffer: &mut BytesMut)11727     fn write_to(&self, buffer: &mut BytesMut) {
11728         let sequence_number = self.sequence_number;
11729         buffer[4..8].copy_from_slice(&sequence_number.to_le_bytes()[0..4]);
11730         let session_id = self.session_id;
11731         buffer[8..12].copy_from_slice(&session_id.to_le_bytes()[0..4]);
11732         let rcr_indicator = self.rcr_indicator;
11733         buffer[12..13].copy_from_slice(&rcr_indicator.to_le_bytes()[0..1]);
11734         let current_ranging_interval = self.current_ranging_interval;
11735         buffer[13..17].copy_from_slice(&current_ranging_interval.to_le_bytes()[0..4]);
11736         let ranging_measurement_type = self.ranging_measurement_type.to_u8().unwrap();
11737         buffer[17..18].copy_from_slice(&ranging_measurement_type.to_le_bytes()[0..1]);
11738         let mac_address_indicator = self.mac_address_indicator.to_u8().unwrap();
11739         buffer[19..20].copy_from_slice(&mac_address_indicator.to_le_bytes()[0..1]);
11740         match &self.child {
11741             RangeDataNtfDataChild::ShortMacTwoWayRangeDataNtf(value) => value.write_to(buffer),
11742             RangeDataNtfDataChild::ExtendedMacTwoWayRangeDataNtf(value) => value.write_to(buffer),
11743             RangeDataNtfDataChild::None => {}
11744         }
11745     }
get_total_size(&self) -> usize11746     fn get_total_size(&self) -> usize {
11747         self.get_size() + self.child.get_total_size()
11748     }
get_size(&self) -> usize11749     fn get_size(&self) -> usize {
11750         let ret = 0;
11751         let ret = ret + 24;
11752         ret
11753     }
11754 }
11755 impl Packet for RangeDataNtfPacket {
to_bytes(self) -> Bytes11756     fn to_bytes(self) -> Bytes {
11757         let mut buffer = BytesMut::new();
11758         buffer.resize(self.uci_packet.get_total_size(), 0);
11759         self.uci_packet.write_to(&mut buffer);
11760         buffer.freeze()
11761     }
to_vec(self) -> Vec<u8>11762     fn to_vec(self) -> Vec<u8> {
11763         self.to_bytes().to_vec()
11764     }
11765 }
11766 impl From<RangeDataNtfPacket> for Bytes {
from(packet: RangeDataNtfPacket) -> Self11767     fn from(packet: RangeDataNtfPacket) -> Self {
11768         packet.to_bytes()
11769     }
11770 }
11771 impl From<RangeDataNtfPacket> for Vec<u8> {
from(packet: RangeDataNtfPacket) -> Self11772     fn from(packet: RangeDataNtfPacket) -> Self {
11773         packet.to_vec()
11774     }
11775 }
11776 impl TryFrom<UciPacketPacket> for RangeDataNtfPacket {
11777     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>11778     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
11779         Self::new(value.uci_packet).map_err(TryFromError)
11780     }
11781 }
11782 impl RangeDataNtfPacket {
specialize(&self) -> RangeDataNtfChild11783     pub fn specialize(&self) -> RangeDataNtfChild {
11784         match &self.range_data_ntf.child {
11785             RangeDataNtfDataChild::ShortMacTwoWayRangeDataNtf(_) => {
11786                 RangeDataNtfChild::ShortMacTwoWayRangeDataNtf(
11787                     ShortMacTwoWayRangeDataNtfPacket::new(self.uci_packet.clone()).unwrap(),
11788                 )
11789             }
11790             RangeDataNtfDataChild::ExtendedMacTwoWayRangeDataNtf(_) => {
11791                 RangeDataNtfChild::ExtendedMacTwoWayRangeDataNtf(
11792                     ExtendedMacTwoWayRangeDataNtfPacket::new(self.uci_packet.clone()).unwrap(),
11793                 )
11794             }
11795             RangeDataNtfDataChild::None => RangeDataNtfChild::None,
11796         }
11797     }
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>11798     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
11799         let uci_packet = root;
11800         let uci_notification = match &uci_packet.child {
11801             UciPacketDataChild::UciNotification(value) => (*value).clone(),
11802             _ => return Err("inconsistent state - child was not UciNotification"),
11803         };
11804         let ranging_notification = match &uci_notification.child {
11805             UciNotificationDataChild::RangingNotification(value) => (*value).clone(),
11806             _ => return Err("inconsistent state - child was not RangingNotification"),
11807         };
11808         let range_data_ntf = match &ranging_notification.child {
11809             RangingNotificationDataChild::RangeDataNtf(value) => (*value).clone(),
11810             _ => return Err("inconsistent state - child was not RangeDataNtf"),
11811         };
11812         Ok(Self {
11813             uci_packet,
11814             uci_notification,
11815             ranging_notification,
11816             range_data_ntf,
11817         })
11818     }
get_group_id(&self) -> GroupId11819     pub fn get_group_id(&self) -> GroupId {
11820         self.uci_packet.as_ref().group_id
11821     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag11822     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
11823         self.uci_packet.as_ref().packet_boundary_flag
11824     }
get_message_type(&self) -> MessageType11825     pub fn get_message_type(&self) -> MessageType {
11826         self.uci_packet.as_ref().message_type
11827     }
get_opcode(&self) -> u811828     pub fn get_opcode(&self) -> u8 {
11829         self.uci_packet.as_ref().opcode
11830     }
get_sequence_number(&self) -> u3211831     pub fn get_sequence_number(&self) -> u32 {
11832         self.range_data_ntf.as_ref().sequence_number
11833     }
get_session_id(&self) -> u3211834     pub fn get_session_id(&self) -> u32 {
11835         self.range_data_ntf.as_ref().session_id
11836     }
get_rcr_indicator(&self) -> u811837     pub fn get_rcr_indicator(&self) -> u8 {
11838         self.range_data_ntf.as_ref().rcr_indicator
11839     }
get_current_ranging_interval(&self) -> u3211840     pub fn get_current_ranging_interval(&self) -> u32 {
11841         self.range_data_ntf.as_ref().current_ranging_interval
11842     }
get_ranging_measurement_type(&self) -> RangingMeasurementType11843     pub fn get_ranging_measurement_type(&self) -> RangingMeasurementType {
11844         self.range_data_ntf.as_ref().ranging_measurement_type
11845     }
get_mac_address_indicator(&self) -> MacAddressIndicator11846     pub fn get_mac_address_indicator(&self) -> MacAddressIndicator {
11847         self.range_data_ntf.as_ref().mac_address_indicator
11848     }
11849 }
11850 impl Into<UciPacketPacket> for RangeDataNtfPacket {
into(self) -> UciPacketPacket11851     fn into(self) -> UciPacketPacket {
11852         UciPacketPacket::new(self.uci_packet).unwrap()
11853     }
11854 }
11855 impl Into<UciNotificationPacket> for RangeDataNtfPacket {
into(self) -> UciNotificationPacket11856     fn into(self) -> UciNotificationPacket {
11857         UciNotificationPacket::new(self.uci_packet).unwrap()
11858     }
11859 }
11860 impl Into<RangingNotificationPacket> for RangeDataNtfPacket {
into(self) -> RangingNotificationPacket11861     fn into(self) -> RangingNotificationPacket {
11862         RangingNotificationPacket::new(self.uci_packet).unwrap()
11863     }
11864 }
11865 impl RangeDataNtfBuilder {
build(self) -> RangeDataNtfPacket11866     pub fn build(self) -> RangeDataNtfPacket {
11867         let range_data_ntf = Arc::new(RangeDataNtfData {
11868             sequence_number: self.sequence_number,
11869             session_id: self.session_id,
11870             rcr_indicator: self.rcr_indicator,
11871             current_ranging_interval: self.current_ranging_interval,
11872             ranging_measurement_type: self.ranging_measurement_type,
11873             mac_address_indicator: self.mac_address_indicator,
11874             child: RangeDataNtfDataChild::None,
11875         });
11876         let ranging_notification = Arc::new(RangingNotificationData {
11877             child: RangingNotificationDataChild::RangeDataNtf(range_data_ntf),
11878         });
11879         let uci_notification = Arc::new(UciNotificationData {
11880             child: UciNotificationDataChild::RangingNotification(ranging_notification),
11881         });
11882         let uci_packet = Arc::new(UciPacketData {
11883             group_id: GroupId::RangingSessionControl,
11884             packet_boundary_flag: PacketBoundaryFlag::Complete,
11885             message_type: MessageType::Notification,
11886             opcode: 0,
11887             child: UciPacketDataChild::UciNotification(uci_notification),
11888         });
11889         RangeDataNtfPacket::new(uci_packet).unwrap()
11890     }
11891 }
11892 impl Into<UciPacketPacket> for RangeDataNtfBuilder {
into(self) -> UciPacketPacket11893     fn into(self) -> UciPacketPacket {
11894         self.build().into()
11895     }
11896 }
11897 impl Into<UciNotificationPacket> for RangeDataNtfBuilder {
into(self) -> UciNotificationPacket11898     fn into(self) -> UciNotificationPacket {
11899         self.build().into()
11900     }
11901 }
11902 impl Into<RangingNotificationPacket> for RangeDataNtfBuilder {
into(self) -> RangingNotificationPacket11903     fn into(self) -> RangingNotificationPacket {
11904         self.build().into()
11905     }
11906 }
11907 
11908 #[derive(Debug)]
11909 struct ShortMacTwoWayRangeDataNtfData {
11910     two_way_ranging_measurements: Vec<ShortAddressTwoWayRangingMeasurement>,
11911 }
11912 #[derive(Debug, Clone)]
11913 pub struct ShortMacTwoWayRangeDataNtfPacket {
11914     uci_packet: Arc<UciPacketData>,
11915     uci_notification: Arc<UciNotificationData>,
11916     ranging_notification: Arc<RangingNotificationData>,
11917     range_data_ntf: Arc<RangeDataNtfData>,
11918     short_mac_two_way_range_data_ntf: Arc<ShortMacTwoWayRangeDataNtfData>,
11919 }
11920 #[derive(Debug)]
11921 pub struct ShortMacTwoWayRangeDataNtfBuilder {
11922     pub sequence_number: u32,
11923     pub session_id: u32,
11924     pub rcr_indicator: u8,
11925     pub current_ranging_interval: u32,
11926     pub two_way_ranging_measurements: Vec<ShortAddressTwoWayRangingMeasurement>,
11927 }
11928 impl ShortMacTwoWayRangeDataNtfData {
conforms(bytes: &[u8]) -> bool11929     fn conforms(bytes: &[u8]) -> bool {
11930         if bytes.len() < 29 {
11931             return false;
11932         }
11933         true
11934     }
parse(bytes: &[u8]) -> Result<Self>11935     fn parse(bytes: &[u8]) -> Result<Self> {
11936         if bytes.len() < 29 {
11937             return Err(Error::InvalidLengthError {
11938                 obj: "ShortMacTwoWayRangeDataNtf".to_string(),
11939                 field: "two_way_ranging_measurements_count".to_string(),
11940                 wanted: 29,
11941                 got: bytes.len(),
11942             });
11943         }
11944         let two_way_ranging_measurements_count = u8::from_le_bytes([bytes[28]]);
11945         let want_ = 29 + ((two_way_ranging_measurements_count as usize) * 31);
11946         if bytes.len() < want_ {
11947             return Err(Error::InvalidLengthError {
11948                 obj: "ShortMacTwoWayRangeDataNtf".to_string(),
11949                 field: "two_way_ranging_measurements".to_string(),
11950                 wanted: want_,
11951                 got: bytes.len(),
11952             });
11953         }
11954         let mut two_way_ranging_measurements: Vec<ShortAddressTwoWayRangingMeasurement> =
11955             Vec::new();
11956         let mut parsable_ = &bytes[29..];
11957         let count_ = two_way_ranging_measurements_count as usize;
11958         for _ in 0..count_ {
11959             match ShortAddressTwoWayRangingMeasurement::parse(&parsable_) {
11960                 Ok(parsed) => {
11961                     parsable_ = &parsable_[parsed.get_total_size()..];
11962                     two_way_ranging_measurements.push(parsed);
11963                 }
11964                 Err(Error::ImpossibleStructError) => break,
11965                 Err(e) => return Err(e),
11966             }
11967         }
11968         Ok(Self {
11969             two_way_ranging_measurements,
11970         })
11971     }
write_to(&self, buffer: &mut BytesMut)11972     fn write_to(&self, buffer: &mut BytesMut) {
11973         buffer[28..29]
11974             .copy_from_slice(&(self.two_way_ranging_measurements.len() as u8).to_le_bytes());
11975         let mut vec_buffer_ = &mut buffer[29..];
11976         for e_ in &self.two_way_ranging_measurements {
11977             e_.write_to(&mut vec_buffer_[0..e_.get_total_size()]);
11978             vec_buffer_ = &mut vec_buffer_[e_.get_total_size()..];
11979         }
11980     }
get_total_size(&self) -> usize11981     fn get_total_size(&self) -> usize {
11982         self.get_size()
11983     }
get_size(&self) -> usize11984     fn get_size(&self) -> usize {
11985         let ret = 0;
11986         let ret = ret + 1;
11987         let ret = ret
11988             + (self.two_way_ranging_measurements.len() * ((/* Bits: */248 + /* Dynamic: */ 0) / 8));
11989         ret
11990     }
11991 }
11992 impl Packet for ShortMacTwoWayRangeDataNtfPacket {
to_bytes(self) -> Bytes11993     fn to_bytes(self) -> Bytes {
11994         let mut buffer = BytesMut::new();
11995         buffer.resize(self.uci_packet.get_total_size(), 0);
11996         self.uci_packet.write_to(&mut buffer);
11997         buffer.freeze()
11998     }
to_vec(self) -> Vec<u8>11999     fn to_vec(self) -> Vec<u8> {
12000         self.to_bytes().to_vec()
12001     }
12002 }
12003 impl From<ShortMacTwoWayRangeDataNtfPacket> for Bytes {
from(packet: ShortMacTwoWayRangeDataNtfPacket) -> Self12004     fn from(packet: ShortMacTwoWayRangeDataNtfPacket) -> Self {
12005         packet.to_bytes()
12006     }
12007 }
12008 impl From<ShortMacTwoWayRangeDataNtfPacket> for Vec<u8> {
from(packet: ShortMacTwoWayRangeDataNtfPacket) -> Self12009     fn from(packet: ShortMacTwoWayRangeDataNtfPacket) -> Self {
12010         packet.to_vec()
12011     }
12012 }
12013 impl TryFrom<UciPacketPacket> for ShortMacTwoWayRangeDataNtfPacket {
12014     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>12015     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
12016         Self::new(value.uci_packet).map_err(TryFromError)
12017     }
12018 }
12019 impl ShortMacTwoWayRangeDataNtfPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>12020     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
12021         let uci_packet = root;
12022         let uci_notification = match &uci_packet.child {
12023             UciPacketDataChild::UciNotification(value) => (*value).clone(),
12024             _ => return Err("inconsistent state - child was not UciNotification"),
12025         };
12026         let ranging_notification = match &uci_notification.child {
12027             UciNotificationDataChild::RangingNotification(value) => (*value).clone(),
12028             _ => return Err("inconsistent state - child was not RangingNotification"),
12029         };
12030         let range_data_ntf = match &ranging_notification.child {
12031             RangingNotificationDataChild::RangeDataNtf(value) => (*value).clone(),
12032             _ => return Err("inconsistent state - child was not RangeDataNtf"),
12033         };
12034         let short_mac_two_way_range_data_ntf = match &range_data_ntf.child {
12035             RangeDataNtfDataChild::ShortMacTwoWayRangeDataNtf(value) => (*value).clone(),
12036             _ => return Err("inconsistent state - child was not ShortMacTwoWayRangeDataNtf"),
12037         };
12038         Ok(Self {
12039             uci_packet,
12040             uci_notification,
12041             ranging_notification,
12042             range_data_ntf,
12043             short_mac_two_way_range_data_ntf,
12044         })
12045     }
get_group_id(&self) -> GroupId12046     pub fn get_group_id(&self) -> GroupId {
12047         self.uci_packet.as_ref().group_id
12048     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag12049     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
12050         self.uci_packet.as_ref().packet_boundary_flag
12051     }
get_message_type(&self) -> MessageType12052     pub fn get_message_type(&self) -> MessageType {
12053         self.uci_packet.as_ref().message_type
12054     }
get_opcode(&self) -> u812055     pub fn get_opcode(&self) -> u8 {
12056         self.uci_packet.as_ref().opcode
12057     }
get_sequence_number(&self) -> u3212058     pub fn get_sequence_number(&self) -> u32 {
12059         self.range_data_ntf.as_ref().sequence_number
12060     }
get_session_id(&self) -> u3212061     pub fn get_session_id(&self) -> u32 {
12062         self.range_data_ntf.as_ref().session_id
12063     }
get_rcr_indicator(&self) -> u812064     pub fn get_rcr_indicator(&self) -> u8 {
12065         self.range_data_ntf.as_ref().rcr_indicator
12066     }
get_current_ranging_interval(&self) -> u3212067     pub fn get_current_ranging_interval(&self) -> u32 {
12068         self.range_data_ntf.as_ref().current_ranging_interval
12069     }
get_ranging_measurement_type(&self) -> RangingMeasurementType12070     pub fn get_ranging_measurement_type(&self) -> RangingMeasurementType {
12071         self.range_data_ntf.as_ref().ranging_measurement_type
12072     }
get_mac_address_indicator(&self) -> MacAddressIndicator12073     pub fn get_mac_address_indicator(&self) -> MacAddressIndicator {
12074         self.range_data_ntf.as_ref().mac_address_indicator
12075     }
get_two_way_ranging_measurements(&self) -> &Vec<ShortAddressTwoWayRangingMeasurement>12076     pub fn get_two_way_ranging_measurements(&self) -> &Vec<ShortAddressTwoWayRangingMeasurement> {
12077         &self
12078             .short_mac_two_way_range_data_ntf
12079             .as_ref()
12080             .two_way_ranging_measurements
12081     }
12082 }
12083 impl Into<UciPacketPacket> for ShortMacTwoWayRangeDataNtfPacket {
into(self) -> UciPacketPacket12084     fn into(self) -> UciPacketPacket {
12085         UciPacketPacket::new(self.uci_packet).unwrap()
12086     }
12087 }
12088 impl Into<UciNotificationPacket> for ShortMacTwoWayRangeDataNtfPacket {
into(self) -> UciNotificationPacket12089     fn into(self) -> UciNotificationPacket {
12090         UciNotificationPacket::new(self.uci_packet).unwrap()
12091     }
12092 }
12093 impl Into<RangingNotificationPacket> for ShortMacTwoWayRangeDataNtfPacket {
into(self) -> RangingNotificationPacket12094     fn into(self) -> RangingNotificationPacket {
12095         RangingNotificationPacket::new(self.uci_packet).unwrap()
12096     }
12097 }
12098 impl Into<RangeDataNtfPacket> for ShortMacTwoWayRangeDataNtfPacket {
into(self) -> RangeDataNtfPacket12099     fn into(self) -> RangeDataNtfPacket {
12100         RangeDataNtfPacket::new(self.uci_packet).unwrap()
12101     }
12102 }
12103 impl ShortMacTwoWayRangeDataNtfBuilder {
build(self) -> ShortMacTwoWayRangeDataNtfPacket12104     pub fn build(self) -> ShortMacTwoWayRangeDataNtfPacket {
12105         let short_mac_two_way_range_data_ntf = Arc::new(ShortMacTwoWayRangeDataNtfData {
12106             two_way_ranging_measurements: self.two_way_ranging_measurements,
12107         });
12108         let range_data_ntf = Arc::new(RangeDataNtfData {
12109             sequence_number: self.sequence_number,
12110             session_id: self.session_id,
12111             rcr_indicator: self.rcr_indicator,
12112             current_ranging_interval: self.current_ranging_interval,
12113             ranging_measurement_type: RangingMeasurementType::TwoWay,
12114             mac_address_indicator: MacAddressIndicator::ShortAddress,
12115             child: RangeDataNtfDataChild::ShortMacTwoWayRangeDataNtf(
12116                 short_mac_two_way_range_data_ntf,
12117             ),
12118         });
12119         let ranging_notification = Arc::new(RangingNotificationData {
12120             child: RangingNotificationDataChild::RangeDataNtf(range_data_ntf),
12121         });
12122         let uci_notification = Arc::new(UciNotificationData {
12123             child: UciNotificationDataChild::RangingNotification(ranging_notification),
12124         });
12125         let uci_packet = Arc::new(UciPacketData {
12126             group_id: GroupId::RangingSessionControl,
12127             packet_boundary_flag: PacketBoundaryFlag::Complete,
12128             message_type: MessageType::Notification,
12129             opcode: 0,
12130             child: UciPacketDataChild::UciNotification(uci_notification),
12131         });
12132         ShortMacTwoWayRangeDataNtfPacket::new(uci_packet).unwrap()
12133     }
12134 }
12135 impl Into<UciPacketPacket> for ShortMacTwoWayRangeDataNtfBuilder {
into(self) -> UciPacketPacket12136     fn into(self) -> UciPacketPacket {
12137         self.build().into()
12138     }
12139 }
12140 impl Into<UciNotificationPacket> for ShortMacTwoWayRangeDataNtfBuilder {
into(self) -> UciNotificationPacket12141     fn into(self) -> UciNotificationPacket {
12142         self.build().into()
12143     }
12144 }
12145 impl Into<RangingNotificationPacket> for ShortMacTwoWayRangeDataNtfBuilder {
into(self) -> RangingNotificationPacket12146     fn into(self) -> RangingNotificationPacket {
12147         self.build().into()
12148     }
12149 }
12150 impl Into<RangeDataNtfPacket> for ShortMacTwoWayRangeDataNtfBuilder {
into(self) -> RangeDataNtfPacket12151     fn into(self) -> RangeDataNtfPacket {
12152         self.build().into()
12153     }
12154 }
12155 macro_rules! short_mac_two_way_range_data_ntf_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
12156 #[test]
12157 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
12158 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
12159 UciPacketChild::UciNotification(uci_notification_packet) => {match uci_notification_packet.specialize() {/* (2) */
12160 UciNotificationChild::RangingNotification(ranging_notification_packet) => {match ranging_notification_packet.specialize() {/* (3) */
12161 RangingNotificationChild::RangeDataNtf(range_data_ntf_packet) => {match range_data_ntf_packet.specialize() {/* (4) */
12162 RangeDataNtfChild::ShortMacTwoWayRangeDataNtf(packet) => {let rebuilder = ShortMacTwoWayRangeDataNtfBuilder {sequence_number : packet.get_sequence_number(),session_id : packet.get_session_id(),rcr_indicator : packet.get_rcr_indicator(),current_ranging_interval : packet.get_current_ranging_interval(),two_way_ranging_measurements : packet.get_two_way_ranging_measurements().to_vec(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse short_mac_two_way_range_data_ntf
12163  {:#02x?}", range_data_ntf_packet); }}}_ => {panic!("Couldn't parse range_data_ntf
12164  {:#02x?}", ranging_notification_packet); }}}_ => {panic!("Couldn't parse ranging_notification
12165  {:#02x?}", uci_notification_packet); }}}_ => {panic!("Couldn't parse uci_notification
12166  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
12167 short_mac_two_way_range_data_ntf_builder_tests! { short_mac_two_way_range_data_ntf_builder_test_00: b"\x62\x00\x00\x19\x00\x02\x03\x04\x05\x06\x07\x08\x00\x0a\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",}
12168 
12169 #[derive(Debug)]
12170 struct ExtendedMacTwoWayRangeDataNtfData {
12171     two_way_ranging_measurements: Vec<ExtendedAddressTwoWayRangingMeasurement>,
12172 }
12173 #[derive(Debug, Clone)]
12174 pub struct ExtendedMacTwoWayRangeDataNtfPacket {
12175     uci_packet: Arc<UciPacketData>,
12176     uci_notification: Arc<UciNotificationData>,
12177     ranging_notification: Arc<RangingNotificationData>,
12178     range_data_ntf: Arc<RangeDataNtfData>,
12179     extended_mac_two_way_range_data_ntf: Arc<ExtendedMacTwoWayRangeDataNtfData>,
12180 }
12181 #[derive(Debug)]
12182 pub struct ExtendedMacTwoWayRangeDataNtfBuilder {
12183     pub sequence_number: u32,
12184     pub session_id: u32,
12185     pub rcr_indicator: u8,
12186     pub current_ranging_interval: u32,
12187     pub two_way_ranging_measurements: Vec<ExtendedAddressTwoWayRangingMeasurement>,
12188 }
12189 impl ExtendedMacTwoWayRangeDataNtfData {
conforms(bytes: &[u8]) -> bool12190     fn conforms(bytes: &[u8]) -> bool {
12191         if bytes.len() < 29 {
12192             return false;
12193         }
12194         true
12195     }
parse(bytes: &[u8]) -> Result<Self>12196     fn parse(bytes: &[u8]) -> Result<Self> {
12197         if bytes.len() < 29 {
12198             return Err(Error::InvalidLengthError {
12199                 obj: "ExtendedMacTwoWayRangeDataNtf".to_string(),
12200                 field: "two_way_ranging_measurements_count".to_string(),
12201                 wanted: 29,
12202                 got: bytes.len(),
12203             });
12204         }
12205         let two_way_ranging_measurements_count = u8::from_le_bytes([bytes[28]]);
12206         let want_ = 29 + ((two_way_ranging_measurements_count as usize) * 31);
12207         if bytes.len() < want_ {
12208             return Err(Error::InvalidLengthError {
12209                 obj: "ExtendedMacTwoWayRangeDataNtf".to_string(),
12210                 field: "two_way_ranging_measurements".to_string(),
12211                 wanted: want_,
12212                 got: bytes.len(),
12213             });
12214         }
12215         let mut two_way_ranging_measurements: Vec<ExtendedAddressTwoWayRangingMeasurement> =
12216             Vec::new();
12217         let mut parsable_ = &bytes[29..];
12218         let count_ = two_way_ranging_measurements_count as usize;
12219         for _ in 0..count_ {
12220             match ExtendedAddressTwoWayRangingMeasurement::parse(&parsable_) {
12221                 Ok(parsed) => {
12222                     parsable_ = &parsable_[parsed.get_total_size()..];
12223                     two_way_ranging_measurements.push(parsed);
12224                 }
12225                 Err(Error::ImpossibleStructError) => break,
12226                 Err(e) => return Err(e),
12227             }
12228         }
12229         Ok(Self {
12230             two_way_ranging_measurements,
12231         })
12232     }
write_to(&self, buffer: &mut BytesMut)12233     fn write_to(&self, buffer: &mut BytesMut) {
12234         buffer[28..29]
12235             .copy_from_slice(&(self.two_way_ranging_measurements.len() as u8).to_le_bytes());
12236         let mut vec_buffer_ = &mut buffer[29..];
12237         for e_ in &self.two_way_ranging_measurements {
12238             e_.write_to(&mut vec_buffer_[0..e_.get_total_size()]);
12239             vec_buffer_ = &mut vec_buffer_[e_.get_total_size()..];
12240         }
12241     }
get_total_size(&self) -> usize12242     fn get_total_size(&self) -> usize {
12243         self.get_size()
12244     }
get_size(&self) -> usize12245     fn get_size(&self) -> usize {
12246         let ret = 0;
12247         let ret = ret + 1;
12248         let ret = ret
12249             + (self.two_way_ranging_measurements.len() * ((/* Bits: */248 + /* Dynamic: */ 0) / 8));
12250         ret
12251     }
12252 }
12253 impl Packet for ExtendedMacTwoWayRangeDataNtfPacket {
to_bytes(self) -> Bytes12254     fn to_bytes(self) -> Bytes {
12255         let mut buffer = BytesMut::new();
12256         buffer.resize(self.uci_packet.get_total_size(), 0);
12257         self.uci_packet.write_to(&mut buffer);
12258         buffer.freeze()
12259     }
to_vec(self) -> Vec<u8>12260     fn to_vec(self) -> Vec<u8> {
12261         self.to_bytes().to_vec()
12262     }
12263 }
12264 impl From<ExtendedMacTwoWayRangeDataNtfPacket> for Bytes {
from(packet: ExtendedMacTwoWayRangeDataNtfPacket) -> Self12265     fn from(packet: ExtendedMacTwoWayRangeDataNtfPacket) -> Self {
12266         packet.to_bytes()
12267     }
12268 }
12269 impl From<ExtendedMacTwoWayRangeDataNtfPacket> for Vec<u8> {
from(packet: ExtendedMacTwoWayRangeDataNtfPacket) -> Self12270     fn from(packet: ExtendedMacTwoWayRangeDataNtfPacket) -> Self {
12271         packet.to_vec()
12272     }
12273 }
12274 impl TryFrom<UciPacketPacket> for ExtendedMacTwoWayRangeDataNtfPacket {
12275     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>12276     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
12277         Self::new(value.uci_packet).map_err(TryFromError)
12278     }
12279 }
12280 impl ExtendedMacTwoWayRangeDataNtfPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>12281     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
12282         let uci_packet = root;
12283         let uci_notification = match &uci_packet.child {
12284             UciPacketDataChild::UciNotification(value) => (*value).clone(),
12285             _ => return Err("inconsistent state - child was not UciNotification"),
12286         };
12287         let ranging_notification = match &uci_notification.child {
12288             UciNotificationDataChild::RangingNotification(value) => (*value).clone(),
12289             _ => return Err("inconsistent state - child was not RangingNotification"),
12290         };
12291         let range_data_ntf = match &ranging_notification.child {
12292             RangingNotificationDataChild::RangeDataNtf(value) => (*value).clone(),
12293             _ => return Err("inconsistent state - child was not RangeDataNtf"),
12294         };
12295         let extended_mac_two_way_range_data_ntf = match &range_data_ntf.child {
12296             RangeDataNtfDataChild::ExtendedMacTwoWayRangeDataNtf(value) => (*value).clone(),
12297             _ => return Err("inconsistent state - child was not ExtendedMacTwoWayRangeDataNtf"),
12298         };
12299         Ok(Self {
12300             uci_packet,
12301             uci_notification,
12302             ranging_notification,
12303             range_data_ntf,
12304             extended_mac_two_way_range_data_ntf,
12305         })
12306     }
get_group_id(&self) -> GroupId12307     pub fn get_group_id(&self) -> GroupId {
12308         self.uci_packet.as_ref().group_id
12309     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag12310     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
12311         self.uci_packet.as_ref().packet_boundary_flag
12312     }
get_message_type(&self) -> MessageType12313     pub fn get_message_type(&self) -> MessageType {
12314         self.uci_packet.as_ref().message_type
12315     }
get_opcode(&self) -> u812316     pub fn get_opcode(&self) -> u8 {
12317         self.uci_packet.as_ref().opcode
12318     }
get_sequence_number(&self) -> u3212319     pub fn get_sequence_number(&self) -> u32 {
12320         self.range_data_ntf.as_ref().sequence_number
12321     }
get_session_id(&self) -> u3212322     pub fn get_session_id(&self) -> u32 {
12323         self.range_data_ntf.as_ref().session_id
12324     }
get_rcr_indicator(&self) -> u812325     pub fn get_rcr_indicator(&self) -> u8 {
12326         self.range_data_ntf.as_ref().rcr_indicator
12327     }
get_current_ranging_interval(&self) -> u3212328     pub fn get_current_ranging_interval(&self) -> u32 {
12329         self.range_data_ntf.as_ref().current_ranging_interval
12330     }
get_ranging_measurement_type(&self) -> RangingMeasurementType12331     pub fn get_ranging_measurement_type(&self) -> RangingMeasurementType {
12332         self.range_data_ntf.as_ref().ranging_measurement_type
12333     }
get_mac_address_indicator(&self) -> MacAddressIndicator12334     pub fn get_mac_address_indicator(&self) -> MacAddressIndicator {
12335         self.range_data_ntf.as_ref().mac_address_indicator
12336     }
get_two_way_ranging_measurements( &self, ) -> &Vec<ExtendedAddressTwoWayRangingMeasurement>12337     pub fn get_two_way_ranging_measurements(
12338         &self,
12339     ) -> &Vec<ExtendedAddressTwoWayRangingMeasurement> {
12340         &self
12341             .extended_mac_two_way_range_data_ntf
12342             .as_ref()
12343             .two_way_ranging_measurements
12344     }
12345 }
12346 impl Into<UciPacketPacket> for ExtendedMacTwoWayRangeDataNtfPacket {
into(self) -> UciPacketPacket12347     fn into(self) -> UciPacketPacket {
12348         UciPacketPacket::new(self.uci_packet).unwrap()
12349     }
12350 }
12351 impl Into<UciNotificationPacket> for ExtendedMacTwoWayRangeDataNtfPacket {
into(self) -> UciNotificationPacket12352     fn into(self) -> UciNotificationPacket {
12353         UciNotificationPacket::new(self.uci_packet).unwrap()
12354     }
12355 }
12356 impl Into<RangingNotificationPacket> for ExtendedMacTwoWayRangeDataNtfPacket {
into(self) -> RangingNotificationPacket12357     fn into(self) -> RangingNotificationPacket {
12358         RangingNotificationPacket::new(self.uci_packet).unwrap()
12359     }
12360 }
12361 impl Into<RangeDataNtfPacket> for ExtendedMacTwoWayRangeDataNtfPacket {
into(self) -> RangeDataNtfPacket12362     fn into(self) -> RangeDataNtfPacket {
12363         RangeDataNtfPacket::new(self.uci_packet).unwrap()
12364     }
12365 }
12366 impl ExtendedMacTwoWayRangeDataNtfBuilder {
build(self) -> ExtendedMacTwoWayRangeDataNtfPacket12367     pub fn build(self) -> ExtendedMacTwoWayRangeDataNtfPacket {
12368         let extended_mac_two_way_range_data_ntf = Arc::new(ExtendedMacTwoWayRangeDataNtfData {
12369             two_way_ranging_measurements: self.two_way_ranging_measurements,
12370         });
12371         let range_data_ntf = Arc::new(RangeDataNtfData {
12372             sequence_number: self.sequence_number,
12373             session_id: self.session_id,
12374             rcr_indicator: self.rcr_indicator,
12375             current_ranging_interval: self.current_ranging_interval,
12376             ranging_measurement_type: RangingMeasurementType::TwoWay,
12377             mac_address_indicator: MacAddressIndicator::ExtendedAddress,
12378             child: RangeDataNtfDataChild::ExtendedMacTwoWayRangeDataNtf(
12379                 extended_mac_two_way_range_data_ntf,
12380             ),
12381         });
12382         let ranging_notification = Arc::new(RangingNotificationData {
12383             child: RangingNotificationDataChild::RangeDataNtf(range_data_ntf),
12384         });
12385         let uci_notification = Arc::new(UciNotificationData {
12386             child: UciNotificationDataChild::RangingNotification(ranging_notification),
12387         });
12388         let uci_packet = Arc::new(UciPacketData {
12389             group_id: GroupId::RangingSessionControl,
12390             packet_boundary_flag: PacketBoundaryFlag::Complete,
12391             message_type: MessageType::Notification,
12392             opcode: 0,
12393             child: UciPacketDataChild::UciNotification(uci_notification),
12394         });
12395         ExtendedMacTwoWayRangeDataNtfPacket::new(uci_packet).unwrap()
12396     }
12397 }
12398 impl Into<UciPacketPacket> for ExtendedMacTwoWayRangeDataNtfBuilder {
into(self) -> UciPacketPacket12399     fn into(self) -> UciPacketPacket {
12400         self.build().into()
12401     }
12402 }
12403 impl Into<UciNotificationPacket> for ExtendedMacTwoWayRangeDataNtfBuilder {
into(self) -> UciNotificationPacket12404     fn into(self) -> UciNotificationPacket {
12405         self.build().into()
12406     }
12407 }
12408 impl Into<RangingNotificationPacket> for ExtendedMacTwoWayRangeDataNtfBuilder {
into(self) -> RangingNotificationPacket12409     fn into(self) -> RangingNotificationPacket {
12410         self.build().into()
12411     }
12412 }
12413 impl Into<RangeDataNtfPacket> for ExtendedMacTwoWayRangeDataNtfBuilder {
into(self) -> RangeDataNtfPacket12414     fn into(self) -> RangeDataNtfPacket {
12415         self.build().into()
12416     }
12417 }
12418 macro_rules! extended_mac_two_way_range_data_ntf_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
12419 #[test]
12420 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
12421 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
12422 UciPacketChild::UciNotification(uci_notification_packet) => {match uci_notification_packet.specialize() {/* (2) */
12423 UciNotificationChild::RangingNotification(ranging_notification_packet) => {match ranging_notification_packet.specialize() {/* (3) */
12424 RangingNotificationChild::RangeDataNtf(range_data_ntf_packet) => {match range_data_ntf_packet.specialize() {/* (4) */
12425 RangeDataNtfChild::ExtendedMacTwoWayRangeDataNtf(packet) => {let rebuilder = ExtendedMacTwoWayRangeDataNtfBuilder {sequence_number : packet.get_sequence_number(),session_id : packet.get_session_id(),rcr_indicator : packet.get_rcr_indicator(),current_ranging_interval : packet.get_current_ranging_interval(),two_way_ranging_measurements : packet.get_two_way_ranging_measurements().to_vec(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse extended_mac_two_way_range_data_ntf
12426  {:#02x?}", range_data_ntf_packet); }}}_ => {panic!("Couldn't parse range_data_ntf
12427  {:#02x?}", ranging_notification_packet); }}}_ => {panic!("Couldn't parse ranging_notification
12428  {:#02x?}", uci_notification_packet); }}}_ => {panic!("Couldn't parse uci_notification
12429  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
12430 extended_mac_two_way_range_data_ntf_builder_tests! { extended_mac_two_way_range_data_ntf_builder_test_00: b"\x62\x00\x00\x19\x00\x02\x03\x04\x05\x06\x07\x08\x00\x0a\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",}
12431 
12432 #[derive(Debug)]
12433 struct RangeStopCmdData {}
12434 #[derive(Debug, Clone)]
12435 pub struct RangeStopCmdPacket {
12436     uci_packet: Arc<UciPacketData>,
12437     uci_command: Arc<UciCommandData>,
12438     ranging_command: Arc<RangingCommandData>,
12439     range_stop_cmd: Arc<RangeStopCmdData>,
12440 }
12441 #[derive(Debug)]
12442 pub struct RangeStopCmdBuilder {
12443     pub session_id: u32,
12444 }
12445 impl RangeStopCmdData {
conforms(bytes: &[u8]) -> bool12446     fn conforms(bytes: &[u8]) -> bool {
12447         if bytes.len() < 8 {
12448             return false;
12449         }
12450         true
12451     }
parse(bytes: &[u8]) -> Result<Self>12452     fn parse(bytes: &[u8]) -> Result<Self> {
12453         Ok(Self {})
12454     }
write_to(&self, buffer: &mut BytesMut)12455     fn write_to(&self, buffer: &mut BytesMut) {}
get_total_size(&self) -> usize12456     fn get_total_size(&self) -> usize {
12457         self.get_size()
12458     }
get_size(&self) -> usize12459     fn get_size(&self) -> usize {
12460         let ret = 0;
12461         ret
12462     }
12463 }
12464 impl Packet for RangeStopCmdPacket {
to_bytes(self) -> Bytes12465     fn to_bytes(self) -> Bytes {
12466         let mut buffer = BytesMut::new();
12467         buffer.resize(self.uci_packet.get_total_size(), 0);
12468         self.uci_packet.write_to(&mut buffer);
12469         buffer.freeze()
12470     }
to_vec(self) -> Vec<u8>12471     fn to_vec(self) -> Vec<u8> {
12472         self.to_bytes().to_vec()
12473     }
12474 }
12475 impl From<RangeStopCmdPacket> for Bytes {
from(packet: RangeStopCmdPacket) -> Self12476     fn from(packet: RangeStopCmdPacket) -> Self {
12477         packet.to_bytes()
12478     }
12479 }
12480 impl From<RangeStopCmdPacket> for Vec<u8> {
from(packet: RangeStopCmdPacket) -> Self12481     fn from(packet: RangeStopCmdPacket) -> Self {
12482         packet.to_vec()
12483     }
12484 }
12485 impl TryFrom<UciPacketPacket> for RangeStopCmdPacket {
12486     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>12487     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
12488         Self::new(value.uci_packet).map_err(TryFromError)
12489     }
12490 }
12491 impl RangeStopCmdPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>12492     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
12493         let uci_packet = root;
12494         let uci_command = match &uci_packet.child {
12495             UciPacketDataChild::UciCommand(value) => (*value).clone(),
12496             _ => return Err("inconsistent state - child was not UciCommand"),
12497         };
12498         let ranging_command = match &uci_command.child {
12499             UciCommandDataChild::RangingCommand(value) => (*value).clone(),
12500             _ => return Err("inconsistent state - child was not RangingCommand"),
12501         };
12502         let range_stop_cmd = match &ranging_command.child {
12503             RangingCommandDataChild::RangeStopCmd(value) => (*value).clone(),
12504             _ => return Err("inconsistent state - child was not RangeStopCmd"),
12505         };
12506         Ok(Self {
12507             uci_packet,
12508             uci_command,
12509             ranging_command,
12510             range_stop_cmd,
12511         })
12512     }
get_group_id(&self) -> GroupId12513     pub fn get_group_id(&self) -> GroupId {
12514         self.uci_packet.as_ref().group_id
12515     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag12516     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
12517         self.uci_packet.as_ref().packet_boundary_flag
12518     }
get_message_type(&self) -> MessageType12519     pub fn get_message_type(&self) -> MessageType {
12520         self.uci_packet.as_ref().message_type
12521     }
get_opcode(&self) -> u812522     pub fn get_opcode(&self) -> u8 {
12523         self.uci_packet.as_ref().opcode
12524     }
get_session_id(&self) -> u3212525     pub fn get_session_id(&self) -> u32 {
12526         self.ranging_command.as_ref().session_id
12527     }
12528 }
12529 impl Into<UciPacketPacket> for RangeStopCmdPacket {
into(self) -> UciPacketPacket12530     fn into(self) -> UciPacketPacket {
12531         UciPacketPacket::new(self.uci_packet).unwrap()
12532     }
12533 }
12534 impl Into<UciCommandPacket> for RangeStopCmdPacket {
into(self) -> UciCommandPacket12535     fn into(self) -> UciCommandPacket {
12536         UciCommandPacket::new(self.uci_packet).unwrap()
12537     }
12538 }
12539 impl Into<RangingCommandPacket> for RangeStopCmdPacket {
into(self) -> RangingCommandPacket12540     fn into(self) -> RangingCommandPacket {
12541         RangingCommandPacket::new(self.uci_packet).unwrap()
12542     }
12543 }
12544 impl RangeStopCmdBuilder {
build(self) -> RangeStopCmdPacket12545     pub fn build(self) -> RangeStopCmdPacket {
12546         let range_stop_cmd = Arc::new(RangeStopCmdData {});
12547         let ranging_command = Arc::new(RangingCommandData {
12548             session_id: self.session_id,
12549             child: RangingCommandDataChild::RangeStopCmd(range_stop_cmd),
12550         });
12551         let uci_command = Arc::new(UciCommandData {
12552             child: UciCommandDataChild::RangingCommand(ranging_command),
12553         });
12554         let uci_packet = Arc::new(UciPacketData {
12555             group_id: GroupId::RangingSessionControl,
12556             packet_boundary_flag: PacketBoundaryFlag::Complete,
12557             message_type: MessageType::Command,
12558             opcode: 1,
12559             child: UciPacketDataChild::UciCommand(uci_command),
12560         });
12561         RangeStopCmdPacket::new(uci_packet).unwrap()
12562     }
12563 }
12564 impl Into<UciPacketPacket> for RangeStopCmdBuilder {
into(self) -> UciPacketPacket12565     fn into(self) -> UciPacketPacket {
12566         self.build().into()
12567     }
12568 }
12569 impl Into<UciCommandPacket> for RangeStopCmdBuilder {
into(self) -> UciCommandPacket12570     fn into(self) -> UciCommandPacket {
12571         self.build().into()
12572     }
12573 }
12574 impl Into<RangingCommandPacket> for RangeStopCmdBuilder {
into(self) -> RangingCommandPacket12575     fn into(self) -> RangingCommandPacket {
12576         self.build().into()
12577     }
12578 }
12579 macro_rules! range_stop_cmd_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
12580 #[test]
12581 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
12582 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
12583 UciPacketChild::UciCommand(uci_command_packet) => {match uci_command_packet.specialize() {/* (2) */
12584 UciCommandChild::RangingCommand(ranging_command_packet) => {match ranging_command_packet.specialize() {/* (3) */
12585 RangingCommandChild::RangeStopCmd(packet) => {let rebuilder = RangeStopCmdBuilder {session_id : packet.get_session_id(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse range_stop_cmd
12586  {:#02x?}", ranging_command_packet); }}}_ => {panic!("Couldn't parse ranging_command
12587  {:#02x?}", uci_command_packet); }}}_ => {panic!("Couldn't parse uci_command
12588  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
12589 range_stop_cmd_builder_tests! { range_stop_cmd_builder_test_00: b"\x22\x01\x00\x04\x00\x02\x03\x04",}
12590 
12591 #[derive(Debug)]
12592 struct RangeStopRspData {
12593     status: StatusCode,
12594 }
12595 #[derive(Debug, Clone)]
12596 pub struct RangeStopRspPacket {
12597     uci_packet: Arc<UciPacketData>,
12598     uci_response: Arc<UciResponseData>,
12599     ranging_response: Arc<RangingResponseData>,
12600     range_stop_rsp: Arc<RangeStopRspData>,
12601 }
12602 #[derive(Debug)]
12603 pub struct RangeStopRspBuilder {
12604     pub status: StatusCode,
12605 }
12606 impl RangeStopRspData {
conforms(bytes: &[u8]) -> bool12607     fn conforms(bytes: &[u8]) -> bool {
12608         if bytes.len() < 5 {
12609             return false;
12610         }
12611         true
12612     }
parse(bytes: &[u8]) -> Result<Self>12613     fn parse(bytes: &[u8]) -> Result<Self> {
12614         if bytes.len() < 5 {
12615             return Err(Error::InvalidLengthError {
12616                 obj: "RangeStopRsp".to_string(),
12617                 field: "status".to_string(),
12618                 wanted: 5,
12619                 got: bytes.len(),
12620             });
12621         }
12622         let status = u8::from_le_bytes([bytes[4]]);
12623         let status = StatusCode::from_u8(status).ok_or_else(|| Error::InvalidEnumValueError {
12624             obj: "RangeStopRsp".to_string(),
12625             field: "status".to_string(),
12626             value: status as u64,
12627             type_: "StatusCode".to_string(),
12628         })?;
12629         Ok(Self { status })
12630     }
write_to(&self, buffer: &mut BytesMut)12631     fn write_to(&self, buffer: &mut BytesMut) {
12632         let status = self.status.to_u8().unwrap();
12633         buffer[4..5].copy_from_slice(&status.to_le_bytes()[0..1]);
12634     }
get_total_size(&self) -> usize12635     fn get_total_size(&self) -> usize {
12636         self.get_size()
12637     }
get_size(&self) -> usize12638     fn get_size(&self) -> usize {
12639         let ret = 0;
12640         let ret = ret + 1;
12641         ret
12642     }
12643 }
12644 impl Packet for RangeStopRspPacket {
to_bytes(self) -> Bytes12645     fn to_bytes(self) -> Bytes {
12646         let mut buffer = BytesMut::new();
12647         buffer.resize(self.uci_packet.get_total_size(), 0);
12648         self.uci_packet.write_to(&mut buffer);
12649         buffer.freeze()
12650     }
to_vec(self) -> Vec<u8>12651     fn to_vec(self) -> Vec<u8> {
12652         self.to_bytes().to_vec()
12653     }
12654 }
12655 impl From<RangeStopRspPacket> for Bytes {
from(packet: RangeStopRspPacket) -> Self12656     fn from(packet: RangeStopRspPacket) -> Self {
12657         packet.to_bytes()
12658     }
12659 }
12660 impl From<RangeStopRspPacket> for Vec<u8> {
from(packet: RangeStopRspPacket) -> Self12661     fn from(packet: RangeStopRspPacket) -> Self {
12662         packet.to_vec()
12663     }
12664 }
12665 impl TryFrom<UciPacketPacket> for RangeStopRspPacket {
12666     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>12667     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
12668         Self::new(value.uci_packet).map_err(TryFromError)
12669     }
12670 }
12671 impl RangeStopRspPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>12672     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
12673         let uci_packet = root;
12674         let uci_response = match &uci_packet.child {
12675             UciPacketDataChild::UciResponse(value) => (*value).clone(),
12676             _ => return Err("inconsistent state - child was not UciResponse"),
12677         };
12678         let ranging_response = match &uci_response.child {
12679             UciResponseDataChild::RangingResponse(value) => (*value).clone(),
12680             _ => return Err("inconsistent state - child was not RangingResponse"),
12681         };
12682         let range_stop_rsp = match &ranging_response.child {
12683             RangingResponseDataChild::RangeStopRsp(value) => (*value).clone(),
12684             _ => return Err("inconsistent state - child was not RangeStopRsp"),
12685         };
12686         Ok(Self {
12687             uci_packet,
12688             uci_response,
12689             ranging_response,
12690             range_stop_rsp,
12691         })
12692     }
get_group_id(&self) -> GroupId12693     pub fn get_group_id(&self) -> GroupId {
12694         self.uci_packet.as_ref().group_id
12695     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag12696     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
12697         self.uci_packet.as_ref().packet_boundary_flag
12698     }
get_message_type(&self) -> MessageType12699     pub fn get_message_type(&self) -> MessageType {
12700         self.uci_packet.as_ref().message_type
12701     }
get_opcode(&self) -> u812702     pub fn get_opcode(&self) -> u8 {
12703         self.uci_packet.as_ref().opcode
12704     }
get_status(&self) -> StatusCode12705     pub fn get_status(&self) -> StatusCode {
12706         self.range_stop_rsp.as_ref().status
12707     }
12708 }
12709 impl Into<UciPacketPacket> for RangeStopRspPacket {
into(self) -> UciPacketPacket12710     fn into(self) -> UciPacketPacket {
12711         UciPacketPacket::new(self.uci_packet).unwrap()
12712     }
12713 }
12714 impl Into<UciResponsePacket> for RangeStopRspPacket {
into(self) -> UciResponsePacket12715     fn into(self) -> UciResponsePacket {
12716         UciResponsePacket::new(self.uci_packet).unwrap()
12717     }
12718 }
12719 impl Into<RangingResponsePacket> for RangeStopRspPacket {
into(self) -> RangingResponsePacket12720     fn into(self) -> RangingResponsePacket {
12721         RangingResponsePacket::new(self.uci_packet).unwrap()
12722     }
12723 }
12724 impl RangeStopRspBuilder {
build(self) -> RangeStopRspPacket12725     pub fn build(self) -> RangeStopRspPacket {
12726         let range_stop_rsp = Arc::new(RangeStopRspData {
12727             status: self.status,
12728         });
12729         let ranging_response = Arc::new(RangingResponseData {
12730             child: RangingResponseDataChild::RangeStopRsp(range_stop_rsp),
12731         });
12732         let uci_response = Arc::new(UciResponseData {
12733             child: UciResponseDataChild::RangingResponse(ranging_response),
12734         });
12735         let uci_packet = Arc::new(UciPacketData {
12736             group_id: GroupId::RangingSessionControl,
12737             packet_boundary_flag: PacketBoundaryFlag::Complete,
12738             message_type: MessageType::Response,
12739             opcode: 1,
12740             child: UciPacketDataChild::UciResponse(uci_response),
12741         });
12742         RangeStopRspPacket::new(uci_packet).unwrap()
12743     }
12744 }
12745 impl Into<UciPacketPacket> for RangeStopRspBuilder {
into(self) -> UciPacketPacket12746     fn into(self) -> UciPacketPacket {
12747         self.build().into()
12748     }
12749 }
12750 impl Into<UciResponsePacket> for RangeStopRspBuilder {
into(self) -> UciResponsePacket12751     fn into(self) -> UciResponsePacket {
12752         self.build().into()
12753     }
12754 }
12755 impl Into<RangingResponsePacket> for RangeStopRspBuilder {
into(self) -> RangingResponsePacket12756     fn into(self) -> RangingResponsePacket {
12757         self.build().into()
12758     }
12759 }
12760 macro_rules! range_stop_rsp_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
12761 #[test]
12762 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
12763 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
12764 UciPacketChild::UciResponse(uci_response_packet) => {match uci_response_packet.specialize() {/* (2) */
12765 UciResponseChild::RangingResponse(ranging_response_packet) => {match ranging_response_packet.specialize() {/* (3) */
12766 RangingResponseChild::RangeStopRsp(packet) => {let rebuilder = RangeStopRspBuilder {status : packet.get_status(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse range_stop_rsp
12767  {:#02x?}", ranging_response_packet); }}}_ => {panic!("Couldn't parse ranging_response
12768  {:#02x?}", uci_response_packet); }}}_ => {panic!("Couldn't parse uci_response
12769  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
12770 range_stop_rsp_builder_tests! { range_stop_rsp_builder_test_00: b"\x42\x01\x00\x01\x00",}
12771 
12772 #[derive(Debug)]
12773 struct RangeGetRangingCountCmdData {}
12774 #[derive(Debug, Clone)]
12775 pub struct RangeGetRangingCountCmdPacket {
12776     uci_packet: Arc<UciPacketData>,
12777     uci_command: Arc<UciCommandData>,
12778     ranging_command: Arc<RangingCommandData>,
12779     range_get_ranging_count_cmd: Arc<RangeGetRangingCountCmdData>,
12780 }
12781 #[derive(Debug)]
12782 pub struct RangeGetRangingCountCmdBuilder {
12783     pub session_id: u32,
12784 }
12785 impl RangeGetRangingCountCmdData {
conforms(bytes: &[u8]) -> bool12786     fn conforms(bytes: &[u8]) -> bool {
12787         if bytes.len() < 8 {
12788             return false;
12789         }
12790         true
12791     }
parse(bytes: &[u8]) -> Result<Self>12792     fn parse(bytes: &[u8]) -> Result<Self> {
12793         Ok(Self {})
12794     }
write_to(&self, buffer: &mut BytesMut)12795     fn write_to(&self, buffer: &mut BytesMut) {}
get_total_size(&self) -> usize12796     fn get_total_size(&self) -> usize {
12797         self.get_size()
12798     }
get_size(&self) -> usize12799     fn get_size(&self) -> usize {
12800         let ret = 0;
12801         ret
12802     }
12803 }
12804 impl Packet for RangeGetRangingCountCmdPacket {
to_bytes(self) -> Bytes12805     fn to_bytes(self) -> Bytes {
12806         let mut buffer = BytesMut::new();
12807         buffer.resize(self.uci_packet.get_total_size(), 0);
12808         self.uci_packet.write_to(&mut buffer);
12809         buffer.freeze()
12810     }
to_vec(self) -> Vec<u8>12811     fn to_vec(self) -> Vec<u8> {
12812         self.to_bytes().to_vec()
12813     }
12814 }
12815 impl From<RangeGetRangingCountCmdPacket> for Bytes {
from(packet: RangeGetRangingCountCmdPacket) -> Self12816     fn from(packet: RangeGetRangingCountCmdPacket) -> Self {
12817         packet.to_bytes()
12818     }
12819 }
12820 impl From<RangeGetRangingCountCmdPacket> for Vec<u8> {
from(packet: RangeGetRangingCountCmdPacket) -> Self12821     fn from(packet: RangeGetRangingCountCmdPacket) -> Self {
12822         packet.to_vec()
12823     }
12824 }
12825 impl TryFrom<UciPacketPacket> for RangeGetRangingCountCmdPacket {
12826     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>12827     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
12828         Self::new(value.uci_packet).map_err(TryFromError)
12829     }
12830 }
12831 impl RangeGetRangingCountCmdPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>12832     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
12833         let uci_packet = root;
12834         let uci_command = match &uci_packet.child {
12835             UciPacketDataChild::UciCommand(value) => (*value).clone(),
12836             _ => return Err("inconsistent state - child was not UciCommand"),
12837         };
12838         let ranging_command = match &uci_command.child {
12839             UciCommandDataChild::RangingCommand(value) => (*value).clone(),
12840             _ => return Err("inconsistent state - child was not RangingCommand"),
12841         };
12842         let range_get_ranging_count_cmd = match &ranging_command.child {
12843             RangingCommandDataChild::RangeGetRangingCountCmd(value) => (*value).clone(),
12844             _ => return Err("inconsistent state - child was not RangeGetRangingCountCmd"),
12845         };
12846         Ok(Self {
12847             uci_packet,
12848             uci_command,
12849             ranging_command,
12850             range_get_ranging_count_cmd,
12851         })
12852     }
get_group_id(&self) -> GroupId12853     pub fn get_group_id(&self) -> GroupId {
12854         self.uci_packet.as_ref().group_id
12855     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag12856     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
12857         self.uci_packet.as_ref().packet_boundary_flag
12858     }
get_message_type(&self) -> MessageType12859     pub fn get_message_type(&self) -> MessageType {
12860         self.uci_packet.as_ref().message_type
12861     }
get_opcode(&self) -> u812862     pub fn get_opcode(&self) -> u8 {
12863         self.uci_packet.as_ref().opcode
12864     }
get_session_id(&self) -> u3212865     pub fn get_session_id(&self) -> u32 {
12866         self.ranging_command.as_ref().session_id
12867     }
12868 }
12869 impl Into<UciPacketPacket> for RangeGetRangingCountCmdPacket {
into(self) -> UciPacketPacket12870     fn into(self) -> UciPacketPacket {
12871         UciPacketPacket::new(self.uci_packet).unwrap()
12872     }
12873 }
12874 impl Into<UciCommandPacket> for RangeGetRangingCountCmdPacket {
into(self) -> UciCommandPacket12875     fn into(self) -> UciCommandPacket {
12876         UciCommandPacket::new(self.uci_packet).unwrap()
12877     }
12878 }
12879 impl Into<RangingCommandPacket> for RangeGetRangingCountCmdPacket {
into(self) -> RangingCommandPacket12880     fn into(self) -> RangingCommandPacket {
12881         RangingCommandPacket::new(self.uci_packet).unwrap()
12882     }
12883 }
12884 impl RangeGetRangingCountCmdBuilder {
build(self) -> RangeGetRangingCountCmdPacket12885     pub fn build(self) -> RangeGetRangingCountCmdPacket {
12886         let range_get_ranging_count_cmd = Arc::new(RangeGetRangingCountCmdData {});
12887         let ranging_command = Arc::new(RangingCommandData {
12888             session_id: self.session_id,
12889             child: RangingCommandDataChild::RangeGetRangingCountCmd(range_get_ranging_count_cmd),
12890         });
12891         let uci_command = Arc::new(UciCommandData {
12892             child: UciCommandDataChild::RangingCommand(ranging_command),
12893         });
12894         let uci_packet = Arc::new(UciPacketData {
12895             group_id: GroupId::RangingSessionControl,
12896             packet_boundary_flag: PacketBoundaryFlag::Complete,
12897             message_type: MessageType::Command,
12898             opcode: 3,
12899             child: UciPacketDataChild::UciCommand(uci_command),
12900         });
12901         RangeGetRangingCountCmdPacket::new(uci_packet).unwrap()
12902     }
12903 }
12904 impl Into<UciPacketPacket> for RangeGetRangingCountCmdBuilder {
into(self) -> UciPacketPacket12905     fn into(self) -> UciPacketPacket {
12906         self.build().into()
12907     }
12908 }
12909 impl Into<UciCommandPacket> for RangeGetRangingCountCmdBuilder {
into(self) -> UciCommandPacket12910     fn into(self) -> UciCommandPacket {
12911         self.build().into()
12912     }
12913 }
12914 impl Into<RangingCommandPacket> for RangeGetRangingCountCmdBuilder {
into(self) -> RangingCommandPacket12915     fn into(self) -> RangingCommandPacket {
12916         self.build().into()
12917     }
12918 }
12919 macro_rules! range_get_ranging_count_cmd_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
12920 #[test]
12921 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
12922 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
12923 UciPacketChild::UciCommand(uci_command_packet) => {match uci_command_packet.specialize() {/* (2) */
12924 UciCommandChild::RangingCommand(ranging_command_packet) => {match ranging_command_packet.specialize() {/* (3) */
12925 RangingCommandChild::RangeGetRangingCountCmd(packet) => {let rebuilder = RangeGetRangingCountCmdBuilder {session_id : packet.get_session_id(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse range_get_ranging_count_cmd
12926  {:#02x?}", ranging_command_packet); }}}_ => {panic!("Couldn't parse ranging_command
12927  {:#02x?}", uci_command_packet); }}}_ => {panic!("Couldn't parse uci_command
12928  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
12929 range_get_ranging_count_cmd_builder_tests! { range_get_ranging_count_cmd_builder_test_00: b"\x22\x03\x00\x04\x00\x02\x03\x04",}
12930 
12931 #[derive(Debug)]
12932 struct RangeGetRangingCountRspData {
12933     status: StatusCode,
12934     count: u32,
12935 }
12936 #[derive(Debug, Clone)]
12937 pub struct RangeGetRangingCountRspPacket {
12938     uci_packet: Arc<UciPacketData>,
12939     uci_response: Arc<UciResponseData>,
12940     ranging_response: Arc<RangingResponseData>,
12941     range_get_ranging_count_rsp: Arc<RangeGetRangingCountRspData>,
12942 }
12943 #[derive(Debug)]
12944 pub struct RangeGetRangingCountRspBuilder {
12945     pub status: StatusCode,
12946     pub count: u32,
12947 }
12948 impl RangeGetRangingCountRspData {
conforms(bytes: &[u8]) -> bool12949     fn conforms(bytes: &[u8]) -> bool {
12950         if bytes.len() < 9 {
12951             return false;
12952         }
12953         true
12954     }
parse(bytes: &[u8]) -> Result<Self>12955     fn parse(bytes: &[u8]) -> Result<Self> {
12956         if bytes.len() < 5 {
12957             return Err(Error::InvalidLengthError {
12958                 obj: "RangeGetRangingCountRsp".to_string(),
12959                 field: "status".to_string(),
12960                 wanted: 5,
12961                 got: bytes.len(),
12962             });
12963         }
12964         let status = u8::from_le_bytes([bytes[4]]);
12965         let status = StatusCode::from_u8(status).ok_or_else(|| Error::InvalidEnumValueError {
12966             obj: "RangeGetRangingCountRsp".to_string(),
12967             field: "status".to_string(),
12968             value: status as u64,
12969             type_: "StatusCode".to_string(),
12970         })?;
12971         if bytes.len() < 9 {
12972             return Err(Error::InvalidLengthError {
12973                 obj: "RangeGetRangingCountRsp".to_string(),
12974                 field: "count".to_string(),
12975                 wanted: 9,
12976                 got: bytes.len(),
12977             });
12978         }
12979         let count = u32::from_le_bytes([bytes[5], bytes[6], bytes[7], bytes[8]]);
12980         Ok(Self { status, count })
12981     }
write_to(&self, buffer: &mut BytesMut)12982     fn write_to(&self, buffer: &mut BytesMut) {
12983         let status = self.status.to_u8().unwrap();
12984         buffer[4..5].copy_from_slice(&status.to_le_bytes()[0..1]);
12985         let count = self.count;
12986         buffer[5..9].copy_from_slice(&count.to_le_bytes()[0..4]);
12987     }
get_total_size(&self) -> usize12988     fn get_total_size(&self) -> usize {
12989         self.get_size()
12990     }
get_size(&self) -> usize12991     fn get_size(&self) -> usize {
12992         let ret = 0;
12993         let ret = ret + 5;
12994         ret
12995     }
12996 }
12997 impl Packet for RangeGetRangingCountRspPacket {
to_bytes(self) -> Bytes12998     fn to_bytes(self) -> Bytes {
12999         let mut buffer = BytesMut::new();
13000         buffer.resize(self.uci_packet.get_total_size(), 0);
13001         self.uci_packet.write_to(&mut buffer);
13002         buffer.freeze()
13003     }
to_vec(self) -> Vec<u8>13004     fn to_vec(self) -> Vec<u8> {
13005         self.to_bytes().to_vec()
13006     }
13007 }
13008 impl From<RangeGetRangingCountRspPacket> for Bytes {
from(packet: RangeGetRangingCountRspPacket) -> Self13009     fn from(packet: RangeGetRangingCountRspPacket) -> Self {
13010         packet.to_bytes()
13011     }
13012 }
13013 impl From<RangeGetRangingCountRspPacket> for Vec<u8> {
from(packet: RangeGetRangingCountRspPacket) -> Self13014     fn from(packet: RangeGetRangingCountRspPacket) -> Self {
13015         packet.to_vec()
13016     }
13017 }
13018 impl TryFrom<UciPacketPacket> for RangeGetRangingCountRspPacket {
13019     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>13020     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
13021         Self::new(value.uci_packet).map_err(TryFromError)
13022     }
13023 }
13024 impl RangeGetRangingCountRspPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>13025     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
13026         let uci_packet = root;
13027         let uci_response = match &uci_packet.child {
13028             UciPacketDataChild::UciResponse(value) => (*value).clone(),
13029             _ => return Err("inconsistent state - child was not UciResponse"),
13030         };
13031         let ranging_response = match &uci_response.child {
13032             UciResponseDataChild::RangingResponse(value) => (*value).clone(),
13033             _ => return Err("inconsistent state - child was not RangingResponse"),
13034         };
13035         let range_get_ranging_count_rsp = match &ranging_response.child {
13036             RangingResponseDataChild::RangeGetRangingCountRsp(value) => (*value).clone(),
13037             _ => return Err("inconsistent state - child was not RangeGetRangingCountRsp"),
13038         };
13039         Ok(Self {
13040             uci_packet,
13041             uci_response,
13042             ranging_response,
13043             range_get_ranging_count_rsp,
13044         })
13045     }
get_group_id(&self) -> GroupId13046     pub fn get_group_id(&self) -> GroupId {
13047         self.uci_packet.as_ref().group_id
13048     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag13049     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
13050         self.uci_packet.as_ref().packet_boundary_flag
13051     }
get_message_type(&self) -> MessageType13052     pub fn get_message_type(&self) -> MessageType {
13053         self.uci_packet.as_ref().message_type
13054     }
get_opcode(&self) -> u813055     pub fn get_opcode(&self) -> u8 {
13056         self.uci_packet.as_ref().opcode
13057     }
get_status(&self) -> StatusCode13058     pub fn get_status(&self) -> StatusCode {
13059         self.range_get_ranging_count_rsp.as_ref().status
13060     }
get_count(&self) -> u3213061     pub fn get_count(&self) -> u32 {
13062         self.range_get_ranging_count_rsp.as_ref().count
13063     }
13064 }
13065 impl Into<UciPacketPacket> for RangeGetRangingCountRspPacket {
into(self) -> UciPacketPacket13066     fn into(self) -> UciPacketPacket {
13067         UciPacketPacket::new(self.uci_packet).unwrap()
13068     }
13069 }
13070 impl Into<UciResponsePacket> for RangeGetRangingCountRspPacket {
into(self) -> UciResponsePacket13071     fn into(self) -> UciResponsePacket {
13072         UciResponsePacket::new(self.uci_packet).unwrap()
13073     }
13074 }
13075 impl Into<RangingResponsePacket> for RangeGetRangingCountRspPacket {
into(self) -> RangingResponsePacket13076     fn into(self) -> RangingResponsePacket {
13077         RangingResponsePacket::new(self.uci_packet).unwrap()
13078     }
13079 }
13080 impl RangeGetRangingCountRspBuilder {
build(self) -> RangeGetRangingCountRspPacket13081     pub fn build(self) -> RangeGetRangingCountRspPacket {
13082         let range_get_ranging_count_rsp = Arc::new(RangeGetRangingCountRspData {
13083             status: self.status,
13084             count: self.count,
13085         });
13086         let ranging_response = Arc::new(RangingResponseData {
13087             child: RangingResponseDataChild::RangeGetRangingCountRsp(range_get_ranging_count_rsp),
13088         });
13089         let uci_response = Arc::new(UciResponseData {
13090             child: UciResponseDataChild::RangingResponse(ranging_response),
13091         });
13092         let uci_packet = Arc::new(UciPacketData {
13093             group_id: GroupId::RangingSessionControl,
13094             packet_boundary_flag: PacketBoundaryFlag::Complete,
13095             message_type: MessageType::Response,
13096             opcode: 3,
13097             child: UciPacketDataChild::UciResponse(uci_response),
13098         });
13099         RangeGetRangingCountRspPacket::new(uci_packet).unwrap()
13100     }
13101 }
13102 impl Into<UciPacketPacket> for RangeGetRangingCountRspBuilder {
into(self) -> UciPacketPacket13103     fn into(self) -> UciPacketPacket {
13104         self.build().into()
13105     }
13106 }
13107 impl Into<UciResponsePacket> for RangeGetRangingCountRspBuilder {
into(self) -> UciResponsePacket13108     fn into(self) -> UciResponsePacket {
13109         self.build().into()
13110     }
13111 }
13112 impl Into<RangingResponsePacket> for RangeGetRangingCountRspBuilder {
into(self) -> RangingResponsePacket13113     fn into(self) -> RangingResponsePacket {
13114         self.build().into()
13115     }
13116 }
13117 macro_rules! range_get_ranging_count_rsp_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
13118 #[test]
13119 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
13120 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
13121 UciPacketChild::UciResponse(uci_response_packet) => {match uci_response_packet.specialize() {/* (2) */
13122 UciResponseChild::RangingResponse(ranging_response_packet) => {match ranging_response_packet.specialize() {/* (3) */
13123 RangingResponseChild::RangeGetRangingCountRsp(packet) => {let rebuilder = RangeGetRangingCountRspBuilder {status : packet.get_status(),count : packet.get_count(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse range_get_ranging_count_rsp
13124  {:#02x?}", ranging_response_packet); }}}_ => {panic!("Couldn't parse ranging_response
13125  {:#02x?}", uci_response_packet); }}}_ => {panic!("Couldn't parse uci_response
13126  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
13127 range_get_ranging_count_rsp_builder_tests! { range_get_ranging_count_rsp_builder_test_00: b"\x42\x03\x00\x05\x00\x02\x03\x04\x05",}
13128 
13129 #[derive(Debug)]
13130 struct AndroidGetPowerStatsCmdData {}
13131 #[derive(Debug, Clone)]
13132 pub struct AndroidGetPowerStatsCmdPacket {
13133     uci_packet: Arc<UciPacketData>,
13134     uci_command: Arc<UciCommandData>,
13135     android_command: Arc<AndroidCommandData>,
13136     android_get_power_stats_cmd: Arc<AndroidGetPowerStatsCmdData>,
13137 }
13138 #[derive(Debug)]
13139 pub struct AndroidGetPowerStatsCmdBuilder {}
13140 impl AndroidGetPowerStatsCmdData {
conforms(bytes: &[u8]) -> bool13141     fn conforms(bytes: &[u8]) -> bool {
13142         if bytes.len() < 4 {
13143             return false;
13144         }
13145         true
13146     }
parse(bytes: &[u8]) -> Result<Self>13147     fn parse(bytes: &[u8]) -> Result<Self> {
13148         Ok(Self {})
13149     }
write_to(&self, buffer: &mut BytesMut)13150     fn write_to(&self, buffer: &mut BytesMut) {}
get_total_size(&self) -> usize13151     fn get_total_size(&self) -> usize {
13152         self.get_size()
13153     }
get_size(&self) -> usize13154     fn get_size(&self) -> usize {
13155         let ret = 0;
13156         ret
13157     }
13158 }
13159 impl Packet for AndroidGetPowerStatsCmdPacket {
to_bytes(self) -> Bytes13160     fn to_bytes(self) -> Bytes {
13161         let mut buffer = BytesMut::new();
13162         buffer.resize(self.uci_packet.get_total_size(), 0);
13163         self.uci_packet.write_to(&mut buffer);
13164         buffer.freeze()
13165     }
to_vec(self) -> Vec<u8>13166     fn to_vec(self) -> Vec<u8> {
13167         self.to_bytes().to_vec()
13168     }
13169 }
13170 impl From<AndroidGetPowerStatsCmdPacket> for Bytes {
from(packet: AndroidGetPowerStatsCmdPacket) -> Self13171     fn from(packet: AndroidGetPowerStatsCmdPacket) -> Self {
13172         packet.to_bytes()
13173     }
13174 }
13175 impl From<AndroidGetPowerStatsCmdPacket> for Vec<u8> {
from(packet: AndroidGetPowerStatsCmdPacket) -> Self13176     fn from(packet: AndroidGetPowerStatsCmdPacket) -> Self {
13177         packet.to_vec()
13178     }
13179 }
13180 impl TryFrom<UciPacketPacket> for AndroidGetPowerStatsCmdPacket {
13181     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>13182     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
13183         Self::new(value.uci_packet).map_err(TryFromError)
13184     }
13185 }
13186 impl AndroidGetPowerStatsCmdPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>13187     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
13188         let uci_packet = root;
13189         let uci_command = match &uci_packet.child {
13190             UciPacketDataChild::UciCommand(value) => (*value).clone(),
13191             _ => return Err("inconsistent state - child was not UciCommand"),
13192         };
13193         let android_command = match &uci_command.child {
13194             UciCommandDataChild::AndroidCommand(value) => (*value).clone(),
13195             _ => return Err("inconsistent state - child was not AndroidCommand"),
13196         };
13197         let android_get_power_stats_cmd = match &android_command.child {
13198             AndroidCommandDataChild::AndroidGetPowerStatsCmd(value) => (*value).clone(),
13199             _ => return Err("inconsistent state - child was not AndroidGetPowerStatsCmd"),
13200         };
13201         Ok(Self {
13202             uci_packet,
13203             uci_command,
13204             android_command,
13205             android_get_power_stats_cmd,
13206         })
13207     }
get_group_id(&self) -> GroupId13208     pub fn get_group_id(&self) -> GroupId {
13209         self.uci_packet.as_ref().group_id
13210     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag13211     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
13212         self.uci_packet.as_ref().packet_boundary_flag
13213     }
get_message_type(&self) -> MessageType13214     pub fn get_message_type(&self) -> MessageType {
13215         self.uci_packet.as_ref().message_type
13216     }
get_opcode(&self) -> u813217     pub fn get_opcode(&self) -> u8 {
13218         self.uci_packet.as_ref().opcode
13219     }
13220 }
13221 impl Into<UciPacketPacket> for AndroidGetPowerStatsCmdPacket {
into(self) -> UciPacketPacket13222     fn into(self) -> UciPacketPacket {
13223         UciPacketPacket::new(self.uci_packet).unwrap()
13224     }
13225 }
13226 impl Into<UciCommandPacket> for AndroidGetPowerStatsCmdPacket {
into(self) -> UciCommandPacket13227     fn into(self) -> UciCommandPacket {
13228         UciCommandPacket::new(self.uci_packet).unwrap()
13229     }
13230 }
13231 impl Into<AndroidCommandPacket> for AndroidGetPowerStatsCmdPacket {
into(self) -> AndroidCommandPacket13232     fn into(self) -> AndroidCommandPacket {
13233         AndroidCommandPacket::new(self.uci_packet).unwrap()
13234     }
13235 }
13236 impl AndroidGetPowerStatsCmdBuilder {
build(self) -> AndroidGetPowerStatsCmdPacket13237     pub fn build(self) -> AndroidGetPowerStatsCmdPacket {
13238         let android_get_power_stats_cmd = Arc::new(AndroidGetPowerStatsCmdData {});
13239         let android_command = Arc::new(AndroidCommandData {
13240             child: AndroidCommandDataChild::AndroidGetPowerStatsCmd(android_get_power_stats_cmd),
13241         });
13242         let uci_command = Arc::new(UciCommandData {
13243             child: UciCommandDataChild::AndroidCommand(android_command),
13244         });
13245         let uci_packet = Arc::new(UciPacketData {
13246             group_id: GroupId::VendorAndroid,
13247             packet_boundary_flag: PacketBoundaryFlag::Complete,
13248             message_type: MessageType::Command,
13249             opcode: 0,
13250             child: UciPacketDataChild::UciCommand(uci_command),
13251         });
13252         AndroidGetPowerStatsCmdPacket::new(uci_packet).unwrap()
13253     }
13254 }
13255 impl Into<UciPacketPacket> for AndroidGetPowerStatsCmdBuilder {
into(self) -> UciPacketPacket13256     fn into(self) -> UciPacketPacket {
13257         self.build().into()
13258     }
13259 }
13260 impl Into<UciCommandPacket> for AndroidGetPowerStatsCmdBuilder {
into(self) -> UciCommandPacket13261     fn into(self) -> UciCommandPacket {
13262         self.build().into()
13263     }
13264 }
13265 impl Into<AndroidCommandPacket> for AndroidGetPowerStatsCmdBuilder {
into(self) -> AndroidCommandPacket13266     fn into(self) -> AndroidCommandPacket {
13267         self.build().into()
13268     }
13269 }
13270 macro_rules! android_get_power_stats_cmd_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
13271 #[test]
13272 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
13273 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
13274 UciPacketChild::UciCommand(uci_command_packet) => {match uci_command_packet.specialize() {/* (2) */
13275 UciCommandChild::AndroidCommand(android_command_packet) => {match android_command_packet.specialize() {/* (3) */
13276 AndroidCommandChild::AndroidGetPowerStatsCmd(packet) => {let rebuilder = AndroidGetPowerStatsCmdBuilder {};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse android_get_power_stats_cmd
13277  {:#02x?}", android_command_packet); }}}_ => {panic!("Couldn't parse android_command
13278  {:#02x?}", uci_command_packet); }}}_ => {panic!("Couldn't parse uci_command
13279  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
13280 android_get_power_stats_cmd_builder_tests! { android_get_power_stats_cmd_builder_test_00: b"\x2e\x00\x00\x00",}
13281 
13282 #[derive(Debug)]
13283 struct AndroidGetPowerStatsRspData {
13284     stats: PowerStats,
13285 }
13286 #[derive(Debug, Clone)]
13287 pub struct AndroidGetPowerStatsRspPacket {
13288     uci_packet: Arc<UciPacketData>,
13289     uci_response: Arc<UciResponseData>,
13290     android_response: Arc<AndroidResponseData>,
13291     android_get_power_stats_rsp: Arc<AndroidGetPowerStatsRspData>,
13292 }
13293 #[derive(Debug)]
13294 pub struct AndroidGetPowerStatsRspBuilder {
13295     pub stats: PowerStats,
13296 }
13297 impl AndroidGetPowerStatsRspData {
conforms(bytes: &[u8]) -> bool13298     fn conforms(bytes: &[u8]) -> bool {
13299         if bytes.len() < 21 {
13300             return false;
13301         }
13302         if !PowerStats::conforms(&bytes[4..21]) {
13303             return false;
13304         }
13305         true
13306     }
parse(bytes: &[u8]) -> Result<Self>13307     fn parse(bytes: &[u8]) -> Result<Self> {
13308         let stats = PowerStats::parse(&bytes[4..21])?;
13309         Ok(Self { stats })
13310     }
write_to(&self, buffer: &mut BytesMut)13311     fn write_to(&self, buffer: &mut BytesMut) {
13312         let stats = &mut buffer[4..21];
13313         self.stats.write_to(stats);
13314     }
get_total_size(&self) -> usize13315     fn get_total_size(&self) -> usize {
13316         self.get_size()
13317     }
get_size(&self) -> usize13318     fn get_size(&self) -> usize {
13319         let ret = 0;
13320         let ret = ret + 17;
13321         ret
13322     }
13323 }
13324 impl Packet for AndroidGetPowerStatsRspPacket {
to_bytes(self) -> Bytes13325     fn to_bytes(self) -> Bytes {
13326         let mut buffer = BytesMut::new();
13327         buffer.resize(self.uci_packet.get_total_size(), 0);
13328         self.uci_packet.write_to(&mut buffer);
13329         buffer.freeze()
13330     }
to_vec(self) -> Vec<u8>13331     fn to_vec(self) -> Vec<u8> {
13332         self.to_bytes().to_vec()
13333     }
13334 }
13335 impl From<AndroidGetPowerStatsRspPacket> for Bytes {
from(packet: AndroidGetPowerStatsRspPacket) -> Self13336     fn from(packet: AndroidGetPowerStatsRspPacket) -> Self {
13337         packet.to_bytes()
13338     }
13339 }
13340 impl From<AndroidGetPowerStatsRspPacket> for Vec<u8> {
from(packet: AndroidGetPowerStatsRspPacket) -> Self13341     fn from(packet: AndroidGetPowerStatsRspPacket) -> Self {
13342         packet.to_vec()
13343     }
13344 }
13345 impl TryFrom<UciPacketPacket> for AndroidGetPowerStatsRspPacket {
13346     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>13347     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
13348         Self::new(value.uci_packet).map_err(TryFromError)
13349     }
13350 }
13351 impl AndroidGetPowerStatsRspPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>13352     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
13353         let uci_packet = root;
13354         let uci_response = match &uci_packet.child {
13355             UciPacketDataChild::UciResponse(value) => (*value).clone(),
13356             _ => return Err("inconsistent state - child was not UciResponse"),
13357         };
13358         let android_response = match &uci_response.child {
13359             UciResponseDataChild::AndroidResponse(value) => (*value).clone(),
13360             _ => return Err("inconsistent state - child was not AndroidResponse"),
13361         };
13362         let android_get_power_stats_rsp = match &android_response.child {
13363             AndroidResponseDataChild::AndroidGetPowerStatsRsp(value) => (*value).clone(),
13364             _ => return Err("inconsistent state - child was not AndroidGetPowerStatsRsp"),
13365         };
13366         Ok(Self {
13367             uci_packet,
13368             uci_response,
13369             android_response,
13370             android_get_power_stats_rsp,
13371         })
13372     }
get_group_id(&self) -> GroupId13373     pub fn get_group_id(&self) -> GroupId {
13374         self.uci_packet.as_ref().group_id
13375     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag13376     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
13377         self.uci_packet.as_ref().packet_boundary_flag
13378     }
get_message_type(&self) -> MessageType13379     pub fn get_message_type(&self) -> MessageType {
13380         self.uci_packet.as_ref().message_type
13381     }
get_opcode(&self) -> u813382     pub fn get_opcode(&self) -> u8 {
13383         self.uci_packet.as_ref().opcode
13384     }
get_stats(&self) -> &PowerStats13385     pub fn get_stats(&self) -> &PowerStats {
13386         &self.android_get_power_stats_rsp.as_ref().stats
13387     }
13388 }
13389 impl Into<UciPacketPacket> for AndroidGetPowerStatsRspPacket {
into(self) -> UciPacketPacket13390     fn into(self) -> UciPacketPacket {
13391         UciPacketPacket::new(self.uci_packet).unwrap()
13392     }
13393 }
13394 impl Into<UciResponsePacket> for AndroidGetPowerStatsRspPacket {
into(self) -> UciResponsePacket13395     fn into(self) -> UciResponsePacket {
13396         UciResponsePacket::new(self.uci_packet).unwrap()
13397     }
13398 }
13399 impl Into<AndroidResponsePacket> for AndroidGetPowerStatsRspPacket {
into(self) -> AndroidResponsePacket13400     fn into(self) -> AndroidResponsePacket {
13401         AndroidResponsePacket::new(self.uci_packet).unwrap()
13402     }
13403 }
13404 impl AndroidGetPowerStatsRspBuilder {
build(self) -> AndroidGetPowerStatsRspPacket13405     pub fn build(self) -> AndroidGetPowerStatsRspPacket {
13406         let android_get_power_stats_rsp =
13407             Arc::new(AndroidGetPowerStatsRspData { stats: self.stats });
13408         let android_response = Arc::new(AndroidResponseData {
13409             child: AndroidResponseDataChild::AndroidGetPowerStatsRsp(android_get_power_stats_rsp),
13410         });
13411         let uci_response = Arc::new(UciResponseData {
13412             child: UciResponseDataChild::AndroidResponse(android_response),
13413         });
13414         let uci_packet = Arc::new(UciPacketData {
13415             group_id: GroupId::VendorAndroid,
13416             packet_boundary_flag: PacketBoundaryFlag::Complete,
13417             message_type: MessageType::Response,
13418             opcode: 0,
13419             child: UciPacketDataChild::UciResponse(uci_response),
13420         });
13421         AndroidGetPowerStatsRspPacket::new(uci_packet).unwrap()
13422     }
13423 }
13424 impl Into<UciPacketPacket> for AndroidGetPowerStatsRspBuilder {
into(self) -> UciPacketPacket13425     fn into(self) -> UciPacketPacket {
13426         self.build().into()
13427     }
13428 }
13429 impl Into<UciResponsePacket> for AndroidGetPowerStatsRspBuilder {
into(self) -> UciResponsePacket13430     fn into(self) -> UciResponsePacket {
13431         self.build().into()
13432     }
13433 }
13434 impl Into<AndroidResponsePacket> for AndroidGetPowerStatsRspBuilder {
into(self) -> AndroidResponsePacket13435     fn into(self) -> AndroidResponsePacket {
13436         self.build().into()
13437     }
13438 }
13439 macro_rules! android_get_power_stats_rsp_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
13440 #[test]
13441 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
13442 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
13443 UciPacketChild::UciResponse(uci_response_packet) => {match uci_response_packet.specialize() {/* (2) */
13444 UciResponseChild::AndroidResponse(android_response_packet) => {match android_response_packet.specialize() {/* (3) */
13445 AndroidResponseChild::AndroidGetPowerStatsRsp(packet) => {let rebuilder = AndroidGetPowerStatsRspBuilder {stats : packet.get_stats().clone(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse android_get_power_stats_rsp
13446  {:#02x?}", android_response_packet); }}}_ => {panic!("Couldn't parse android_response
13447  {:#02x?}", uci_response_packet); }}}_ => {panic!("Couldn't parse uci_response
13448  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
13449 android_get_power_stats_rsp_builder_tests! { android_get_power_stats_rsp_builder_test_00: b"\x4e\x00\x00\x11\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",}
13450 
13451 #[derive(Debug)]
13452 struct AndroidSetCountryCodeCmdData {
13453     country_code: [u8; 2],
13454 }
13455 #[derive(Debug, Clone)]
13456 pub struct AndroidSetCountryCodeCmdPacket {
13457     uci_packet: Arc<UciPacketData>,
13458     uci_command: Arc<UciCommandData>,
13459     android_command: Arc<AndroidCommandData>,
13460     android_set_country_code_cmd: Arc<AndroidSetCountryCodeCmdData>,
13461 }
13462 #[derive(Debug)]
13463 pub struct AndroidSetCountryCodeCmdBuilder {
13464     pub country_code: [u8; 2],
13465 }
13466 impl AndroidSetCountryCodeCmdData {
conforms(bytes: &[u8]) -> bool13467     fn conforms(bytes: &[u8]) -> bool {
13468         if bytes.len() < 6 {
13469             return false;
13470         }
13471         true
13472     }
parse(bytes: &[u8]) -> Result<Self>13473     fn parse(bytes: &[u8]) -> Result<Self> {
13474         if bytes.len() < 6 {
13475             return Err(Error::InvalidLengthError {
13476                 obj: "AndroidSetCountryCodeCmd".to_string(),
13477                 field: "country_code".to_string(),
13478                 wanted: 6,
13479                 got: bytes.len(),
13480             });
13481         }
13482         let country_code = bytes[4..6]
13483             .try_into()
13484             .map_err(|_| Error::InvalidPacketError)?;
13485         Ok(Self { country_code })
13486     }
write_to(&self, buffer: &mut BytesMut)13487     fn write_to(&self, buffer: &mut BytesMut) {
13488         &buffer[4..6].copy_from_slice(&self.country_code);
13489     }
get_total_size(&self) -> usize13490     fn get_total_size(&self) -> usize {
13491         self.get_size()
13492     }
get_size(&self) -> usize13493     fn get_size(&self) -> usize {
13494         let ret = 0;
13495         let ret = ret + 2;
13496         ret
13497     }
13498 }
13499 impl Packet for AndroidSetCountryCodeCmdPacket {
to_bytes(self) -> Bytes13500     fn to_bytes(self) -> Bytes {
13501         let mut buffer = BytesMut::new();
13502         buffer.resize(self.uci_packet.get_total_size(), 0);
13503         self.uci_packet.write_to(&mut buffer);
13504         buffer.freeze()
13505     }
to_vec(self) -> Vec<u8>13506     fn to_vec(self) -> Vec<u8> {
13507         self.to_bytes().to_vec()
13508     }
13509 }
13510 impl From<AndroidSetCountryCodeCmdPacket> for Bytes {
from(packet: AndroidSetCountryCodeCmdPacket) -> Self13511     fn from(packet: AndroidSetCountryCodeCmdPacket) -> Self {
13512         packet.to_bytes()
13513     }
13514 }
13515 impl From<AndroidSetCountryCodeCmdPacket> for Vec<u8> {
from(packet: AndroidSetCountryCodeCmdPacket) -> Self13516     fn from(packet: AndroidSetCountryCodeCmdPacket) -> Self {
13517         packet.to_vec()
13518     }
13519 }
13520 impl TryFrom<UciPacketPacket> for AndroidSetCountryCodeCmdPacket {
13521     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>13522     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
13523         Self::new(value.uci_packet).map_err(TryFromError)
13524     }
13525 }
13526 impl AndroidSetCountryCodeCmdPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>13527     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
13528         let uci_packet = root;
13529         let uci_command = match &uci_packet.child {
13530             UciPacketDataChild::UciCommand(value) => (*value).clone(),
13531             _ => return Err("inconsistent state - child was not UciCommand"),
13532         };
13533         let android_command = match &uci_command.child {
13534             UciCommandDataChild::AndroidCommand(value) => (*value).clone(),
13535             _ => return Err("inconsistent state - child was not AndroidCommand"),
13536         };
13537         let android_set_country_code_cmd = match &android_command.child {
13538             AndroidCommandDataChild::AndroidSetCountryCodeCmd(value) => (*value).clone(),
13539             _ => return Err("inconsistent state - child was not AndroidSetCountryCodeCmd"),
13540         };
13541         Ok(Self {
13542             uci_packet,
13543             uci_command,
13544             android_command,
13545             android_set_country_code_cmd,
13546         })
13547     }
get_group_id(&self) -> GroupId13548     pub fn get_group_id(&self) -> GroupId {
13549         self.uci_packet.as_ref().group_id
13550     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag13551     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
13552         self.uci_packet.as_ref().packet_boundary_flag
13553     }
get_message_type(&self) -> MessageType13554     pub fn get_message_type(&self) -> MessageType {
13555         self.uci_packet.as_ref().message_type
13556     }
get_opcode(&self) -> u813557     pub fn get_opcode(&self) -> u8 {
13558         self.uci_packet.as_ref().opcode
13559     }
get_country_code(&self) -> &[u8; 2]13560     pub fn get_country_code(&self) -> &[u8; 2] {
13561         &self.android_set_country_code_cmd.as_ref().country_code
13562     }
13563 }
13564 impl Into<UciPacketPacket> for AndroidSetCountryCodeCmdPacket {
into(self) -> UciPacketPacket13565     fn into(self) -> UciPacketPacket {
13566         UciPacketPacket::new(self.uci_packet).unwrap()
13567     }
13568 }
13569 impl Into<UciCommandPacket> for AndroidSetCountryCodeCmdPacket {
into(self) -> UciCommandPacket13570     fn into(self) -> UciCommandPacket {
13571         UciCommandPacket::new(self.uci_packet).unwrap()
13572     }
13573 }
13574 impl Into<AndroidCommandPacket> for AndroidSetCountryCodeCmdPacket {
into(self) -> AndroidCommandPacket13575     fn into(self) -> AndroidCommandPacket {
13576         AndroidCommandPacket::new(self.uci_packet).unwrap()
13577     }
13578 }
13579 impl AndroidSetCountryCodeCmdBuilder {
build(self) -> AndroidSetCountryCodeCmdPacket13580     pub fn build(self) -> AndroidSetCountryCodeCmdPacket {
13581         let android_set_country_code_cmd = Arc::new(AndroidSetCountryCodeCmdData {
13582             country_code: self.country_code,
13583         });
13584         let android_command = Arc::new(AndroidCommandData {
13585             child: AndroidCommandDataChild::AndroidSetCountryCodeCmd(android_set_country_code_cmd),
13586         });
13587         let uci_command = Arc::new(UciCommandData {
13588             child: UciCommandDataChild::AndroidCommand(android_command),
13589         });
13590         let uci_packet = Arc::new(UciPacketData {
13591             group_id: GroupId::VendorAndroid,
13592             packet_boundary_flag: PacketBoundaryFlag::Complete,
13593             message_type: MessageType::Command,
13594             opcode: 1,
13595             child: UciPacketDataChild::UciCommand(uci_command),
13596         });
13597         AndroidSetCountryCodeCmdPacket::new(uci_packet).unwrap()
13598     }
13599 }
13600 impl Into<UciPacketPacket> for AndroidSetCountryCodeCmdBuilder {
into(self) -> UciPacketPacket13601     fn into(self) -> UciPacketPacket {
13602         self.build().into()
13603     }
13604 }
13605 impl Into<UciCommandPacket> for AndroidSetCountryCodeCmdBuilder {
into(self) -> UciCommandPacket13606     fn into(self) -> UciCommandPacket {
13607         self.build().into()
13608     }
13609 }
13610 impl Into<AndroidCommandPacket> for AndroidSetCountryCodeCmdBuilder {
into(self) -> AndroidCommandPacket13611     fn into(self) -> AndroidCommandPacket {
13612         self.build().into()
13613     }
13614 }
13615 macro_rules! android_set_country_code_cmd_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
13616 #[test]
13617 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
13618 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
13619 UciPacketChild::UciCommand(uci_command_packet) => {match uci_command_packet.specialize() {/* (2) */
13620 UciCommandChild::AndroidCommand(android_command_packet) => {match android_command_packet.specialize() {/* (3) */
13621 AndroidCommandChild::AndroidSetCountryCodeCmd(packet) => {let rebuilder = AndroidSetCountryCodeCmdBuilder {country_code : packet.get_country_code().clone(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse android_set_country_code_cmd
13622  {:#02x?}", android_command_packet); }}}_ => {panic!("Couldn't parse android_command
13623  {:#02x?}", uci_command_packet); }}}_ => {panic!("Couldn't parse uci_command
13624  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
13625 android_set_country_code_cmd_builder_tests! { android_set_country_code_cmd_builder_test_00: b"\x2e\x01\x00\x02\x55\x53",}
13626 
13627 #[derive(Debug)]
13628 struct AndroidSetCountryCodeRspData {
13629     status: StatusCode,
13630 }
13631 #[derive(Debug, Clone)]
13632 pub struct AndroidSetCountryCodeRspPacket {
13633     uci_packet: Arc<UciPacketData>,
13634     uci_response: Arc<UciResponseData>,
13635     android_response: Arc<AndroidResponseData>,
13636     android_set_country_code_rsp: Arc<AndroidSetCountryCodeRspData>,
13637 }
13638 #[derive(Debug)]
13639 pub struct AndroidSetCountryCodeRspBuilder {
13640     pub status: StatusCode,
13641 }
13642 impl AndroidSetCountryCodeRspData {
conforms(bytes: &[u8]) -> bool13643     fn conforms(bytes: &[u8]) -> bool {
13644         if bytes.len() < 5 {
13645             return false;
13646         }
13647         true
13648     }
parse(bytes: &[u8]) -> Result<Self>13649     fn parse(bytes: &[u8]) -> Result<Self> {
13650         if bytes.len() < 5 {
13651             return Err(Error::InvalidLengthError {
13652                 obj: "AndroidSetCountryCodeRsp".to_string(),
13653                 field: "status".to_string(),
13654                 wanted: 5,
13655                 got: bytes.len(),
13656             });
13657         }
13658         let status = u8::from_le_bytes([bytes[4]]);
13659         let status = StatusCode::from_u8(status).ok_or_else(|| Error::InvalidEnumValueError {
13660             obj: "AndroidSetCountryCodeRsp".to_string(),
13661             field: "status".to_string(),
13662             value: status as u64,
13663             type_: "StatusCode".to_string(),
13664         })?;
13665         Ok(Self { status })
13666     }
write_to(&self, buffer: &mut BytesMut)13667     fn write_to(&self, buffer: &mut BytesMut) {
13668         let status = self.status.to_u8().unwrap();
13669         buffer[4..5].copy_from_slice(&status.to_le_bytes()[0..1]);
13670     }
get_total_size(&self) -> usize13671     fn get_total_size(&self) -> usize {
13672         self.get_size()
13673     }
get_size(&self) -> usize13674     fn get_size(&self) -> usize {
13675         let ret = 0;
13676         let ret = ret + 1;
13677         ret
13678     }
13679 }
13680 impl Packet for AndroidSetCountryCodeRspPacket {
to_bytes(self) -> Bytes13681     fn to_bytes(self) -> Bytes {
13682         let mut buffer = BytesMut::new();
13683         buffer.resize(self.uci_packet.get_total_size(), 0);
13684         self.uci_packet.write_to(&mut buffer);
13685         buffer.freeze()
13686     }
to_vec(self) -> Vec<u8>13687     fn to_vec(self) -> Vec<u8> {
13688         self.to_bytes().to_vec()
13689     }
13690 }
13691 impl From<AndroidSetCountryCodeRspPacket> for Bytes {
from(packet: AndroidSetCountryCodeRspPacket) -> Self13692     fn from(packet: AndroidSetCountryCodeRspPacket) -> Self {
13693         packet.to_bytes()
13694     }
13695 }
13696 impl From<AndroidSetCountryCodeRspPacket> for Vec<u8> {
from(packet: AndroidSetCountryCodeRspPacket) -> Self13697     fn from(packet: AndroidSetCountryCodeRspPacket) -> Self {
13698         packet.to_vec()
13699     }
13700 }
13701 impl TryFrom<UciPacketPacket> for AndroidSetCountryCodeRspPacket {
13702     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>13703     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
13704         Self::new(value.uci_packet).map_err(TryFromError)
13705     }
13706 }
13707 impl AndroidSetCountryCodeRspPacket {
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>13708     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
13709         let uci_packet = root;
13710         let uci_response = match &uci_packet.child {
13711             UciPacketDataChild::UciResponse(value) => (*value).clone(),
13712             _ => return Err("inconsistent state - child was not UciResponse"),
13713         };
13714         let android_response = match &uci_response.child {
13715             UciResponseDataChild::AndroidResponse(value) => (*value).clone(),
13716             _ => return Err("inconsistent state - child was not AndroidResponse"),
13717         };
13718         let android_set_country_code_rsp = match &android_response.child {
13719             AndroidResponseDataChild::AndroidSetCountryCodeRsp(value) => (*value).clone(),
13720             _ => return Err("inconsistent state - child was not AndroidSetCountryCodeRsp"),
13721         };
13722         Ok(Self {
13723             uci_packet,
13724             uci_response,
13725             android_response,
13726             android_set_country_code_rsp,
13727         })
13728     }
get_group_id(&self) -> GroupId13729     pub fn get_group_id(&self) -> GroupId {
13730         self.uci_packet.as_ref().group_id
13731     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag13732     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
13733         self.uci_packet.as_ref().packet_boundary_flag
13734     }
get_message_type(&self) -> MessageType13735     pub fn get_message_type(&self) -> MessageType {
13736         self.uci_packet.as_ref().message_type
13737     }
get_opcode(&self) -> u813738     pub fn get_opcode(&self) -> u8 {
13739         self.uci_packet.as_ref().opcode
13740     }
get_status(&self) -> StatusCode13741     pub fn get_status(&self) -> StatusCode {
13742         self.android_set_country_code_rsp.as_ref().status
13743     }
13744 }
13745 impl Into<UciPacketPacket> for AndroidSetCountryCodeRspPacket {
into(self) -> UciPacketPacket13746     fn into(self) -> UciPacketPacket {
13747         UciPacketPacket::new(self.uci_packet).unwrap()
13748     }
13749 }
13750 impl Into<UciResponsePacket> for AndroidSetCountryCodeRspPacket {
into(self) -> UciResponsePacket13751     fn into(self) -> UciResponsePacket {
13752         UciResponsePacket::new(self.uci_packet).unwrap()
13753     }
13754 }
13755 impl Into<AndroidResponsePacket> for AndroidSetCountryCodeRspPacket {
into(self) -> AndroidResponsePacket13756     fn into(self) -> AndroidResponsePacket {
13757         AndroidResponsePacket::new(self.uci_packet).unwrap()
13758     }
13759 }
13760 impl AndroidSetCountryCodeRspBuilder {
build(self) -> AndroidSetCountryCodeRspPacket13761     pub fn build(self) -> AndroidSetCountryCodeRspPacket {
13762         let android_set_country_code_rsp = Arc::new(AndroidSetCountryCodeRspData {
13763             status: self.status,
13764         });
13765         let android_response = Arc::new(AndroidResponseData {
13766             child: AndroidResponseDataChild::AndroidSetCountryCodeRsp(android_set_country_code_rsp),
13767         });
13768         let uci_response = Arc::new(UciResponseData {
13769             child: UciResponseDataChild::AndroidResponse(android_response),
13770         });
13771         let uci_packet = Arc::new(UciPacketData {
13772             group_id: GroupId::VendorAndroid,
13773             packet_boundary_flag: PacketBoundaryFlag::Complete,
13774             message_type: MessageType::Response,
13775             opcode: 1,
13776             child: UciPacketDataChild::UciResponse(uci_response),
13777         });
13778         AndroidSetCountryCodeRspPacket::new(uci_packet).unwrap()
13779     }
13780 }
13781 impl Into<UciPacketPacket> for AndroidSetCountryCodeRspBuilder {
into(self) -> UciPacketPacket13782     fn into(self) -> UciPacketPacket {
13783         self.build().into()
13784     }
13785 }
13786 impl Into<UciResponsePacket> for AndroidSetCountryCodeRspBuilder {
into(self) -> UciResponsePacket13787     fn into(self) -> UciResponsePacket {
13788         self.build().into()
13789     }
13790 }
13791 impl Into<AndroidResponsePacket> for AndroidSetCountryCodeRspBuilder {
into(self) -> AndroidResponsePacket13792     fn into(self) -> AndroidResponsePacket {
13793         self.build().into()
13794     }
13795 }
13796 macro_rules! android_set_country_code_rsp_builder_tests { ($($name:ident: $byte_string:expr,)*) => {$(
13797 #[test]
13798 pub fn $name() { let raw_bytes = $byte_string;/* (0) */
13799 match UciPacketPacket::parse(raw_bytes) {Ok(uci_packet_packet) => {match uci_packet_packet.specialize() {/* (1) */
13800 UciPacketChild::UciResponse(uci_response_packet) => {match uci_response_packet.specialize() {/* (2) */
13801 UciResponseChild::AndroidResponse(android_response_packet) => {match android_response_packet.specialize() {/* (3) */
13802 AndroidResponseChild::AndroidSetCountryCodeRsp(packet) => {let rebuilder = AndroidSetCountryCodeRspBuilder {status : packet.get_status(),};let rebuilder_base : UciPacketPacket = rebuilder.into();let rebuilder_bytes : &[u8] = &rebuilder_base.to_bytes();assert_eq!(rebuilder_bytes, raw_bytes);}_ => {panic!("Couldn't parse android_set_country_code_rsp
13803  {:#02x?}", android_response_packet); }}}_ => {panic!("Couldn't parse android_response
13804  {:#02x?}", uci_response_packet); }}}_ => {panic!("Couldn't parse uci_response
13805  {:#02x?}", uci_packet_packet); }}},Err(e) => panic!("could not parse UciPacket: {:?} {:02x?}", e, raw_bytes),}})*}}
13806 android_set_country_code_rsp_builder_tests! { android_set_country_code_rsp_builder_test_00: b"\x4e\x01\x00\x01\x00",}
13807 
13808 #[derive(Debug)]
13809 enum UciVendor_A_CommandDataChild {
13810     Payload(Bytes),
13811     None,
13812 }
13813 impl UciVendor_A_CommandDataChild {
get_total_size(&self) -> usize13814     fn get_total_size(&self) -> usize {
13815         match self {
13816             UciVendor_A_CommandDataChild::Payload(p) => p.len(),
13817             UciVendor_A_CommandDataChild::None => 0,
13818         }
13819     }
13820 }
13821 #[derive(Debug)]
13822 pub enum UciVendor_A_CommandChild {
13823     Payload(Bytes),
13824     None,
13825 }
13826 #[derive(Debug)]
13827 struct UciVendor_A_CommandData {
13828     child: UciVendor_A_CommandDataChild,
13829 }
13830 #[derive(Debug, Clone)]
13831 pub struct UciVendor_A_CommandPacket {
13832     uci_packet: Arc<UciPacketData>,
13833     uci_command: Arc<UciCommandData>,
13834     uci_vendor__a__command: Arc<UciVendor_A_CommandData>,
13835 }
13836 #[derive(Debug)]
13837 pub struct UciVendor_A_CommandBuilder {
13838     pub opcode: u8,
13839     pub payload: Option<Bytes>,
13840 }
13841 impl UciVendor_A_CommandData {
conforms(bytes: &[u8]) -> bool13842     fn conforms(bytes: &[u8]) -> bool {
13843         if bytes.len() < 4 {
13844             return false;
13845         }
13846         true
13847     }
parse(bytes: &[u8]) -> Result<Self>13848     fn parse(bytes: &[u8]) -> Result<Self> {
13849         let payload: Vec<u8> = bytes[4..].into();
13850         let child = if payload.len() > 0 {
13851             UciVendor_A_CommandDataChild::Payload(Bytes::from(payload))
13852         } else {
13853             UciVendor_A_CommandDataChild::None
13854         };
13855         Ok(Self { child })
13856     }
write_to(&self, buffer: &mut BytesMut)13857     fn write_to(&self, buffer: &mut BytesMut) {
13858         match &self.child {
13859             UciVendor_A_CommandDataChild::Payload(p) => buffer[4..].copy_from_slice(&p[..]),
13860             UciVendor_A_CommandDataChild::None => {}
13861         }
13862     }
get_total_size(&self) -> usize13863     fn get_total_size(&self) -> usize {
13864         self.get_size() + self.child.get_total_size()
13865     }
get_size(&self) -> usize13866     fn get_size(&self) -> usize {
13867         let ret = 0;
13868         ret
13869     }
13870 }
13871 impl Packet for UciVendor_A_CommandPacket {
to_bytes(self) -> Bytes13872     fn to_bytes(self) -> Bytes {
13873         let mut buffer = BytesMut::new();
13874         buffer.resize(self.uci_packet.get_total_size(), 0);
13875         self.uci_packet.write_to(&mut buffer);
13876         buffer.freeze()
13877     }
to_vec(self) -> Vec<u8>13878     fn to_vec(self) -> Vec<u8> {
13879         self.to_bytes().to_vec()
13880     }
13881 }
13882 impl From<UciVendor_A_CommandPacket> for Bytes {
from(packet: UciVendor_A_CommandPacket) -> Self13883     fn from(packet: UciVendor_A_CommandPacket) -> Self {
13884         packet.to_bytes()
13885     }
13886 }
13887 impl From<UciVendor_A_CommandPacket> for Vec<u8> {
from(packet: UciVendor_A_CommandPacket) -> Self13888     fn from(packet: UciVendor_A_CommandPacket) -> Self {
13889         packet.to_vec()
13890     }
13891 }
13892 impl TryFrom<UciPacketPacket> for UciVendor_A_CommandPacket {
13893     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>13894     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
13895         Self::new(value.uci_packet).map_err(TryFromError)
13896     }
13897 }
13898 impl UciVendor_A_CommandPacket {
specialize(&self) -> UciVendor_A_CommandChild13899     pub fn specialize(&self) -> UciVendor_A_CommandChild {
13900         match &self.uci_vendor__a__command.child {
13901             UciVendor_A_CommandDataChild::Payload(p) => {
13902                 UciVendor_A_CommandChild::Payload(p.clone())
13903             }
13904             UciVendor_A_CommandDataChild::None => UciVendor_A_CommandChild::None,
13905         }
13906     }
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>13907     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
13908         let uci_packet = root;
13909         let uci_command = match &uci_packet.child {
13910             UciPacketDataChild::UciCommand(value) => (*value).clone(),
13911             _ => return Err("inconsistent state - child was not UciCommand"),
13912         };
13913         let uci_vendor__a__command = match &uci_command.child {
13914             UciCommandDataChild::UciVendor_A_Command(value) => (*value).clone(),
13915             _ => return Err("inconsistent state - child was not UciVendor_A_Command"),
13916         };
13917         Ok(Self {
13918             uci_packet,
13919             uci_command,
13920             uci_vendor__a__command,
13921         })
13922     }
get_group_id(&self) -> GroupId13923     pub fn get_group_id(&self) -> GroupId {
13924         self.uci_packet.as_ref().group_id
13925     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag13926     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
13927         self.uci_packet.as_ref().packet_boundary_flag
13928     }
get_message_type(&self) -> MessageType13929     pub fn get_message_type(&self) -> MessageType {
13930         self.uci_packet.as_ref().message_type
13931     }
get_opcode(&self) -> u813932     pub fn get_opcode(&self) -> u8 {
13933         self.uci_packet.as_ref().opcode
13934     }
13935 }
13936 impl Into<UciPacketPacket> for UciVendor_A_CommandPacket {
into(self) -> UciPacketPacket13937     fn into(self) -> UciPacketPacket {
13938         UciPacketPacket::new(self.uci_packet).unwrap()
13939     }
13940 }
13941 impl Into<UciCommandPacket> for UciVendor_A_CommandPacket {
into(self) -> UciCommandPacket13942     fn into(self) -> UciCommandPacket {
13943         UciCommandPacket::new(self.uci_packet).unwrap()
13944     }
13945 }
13946 impl UciVendor_A_CommandBuilder {
build(self) -> UciVendor_A_CommandPacket13947     pub fn build(self) -> UciVendor_A_CommandPacket {
13948         let uci_vendor__a__command = Arc::new(UciVendor_A_CommandData {
13949             child: match self.payload {
13950                 None => UciVendor_A_CommandDataChild::None,
13951                 Some(bytes) => UciVendor_A_CommandDataChild::Payload(bytes),
13952             },
13953         });
13954         let uci_command = Arc::new(UciCommandData {
13955             child: UciCommandDataChild::UciVendor_A_Command(uci_vendor__a__command),
13956         });
13957         let uci_packet = Arc::new(UciPacketData {
13958             group_id: GroupId::VendorReservedA,
13959             packet_boundary_flag: PacketBoundaryFlag::Complete,
13960             message_type: MessageType::Command,
13961             opcode: self.opcode,
13962             child: UciPacketDataChild::UciCommand(uci_command),
13963         });
13964         UciVendor_A_CommandPacket::new(uci_packet).unwrap()
13965     }
13966 }
13967 impl Into<UciPacketPacket> for UciVendor_A_CommandBuilder {
into(self) -> UciPacketPacket13968     fn into(self) -> UciPacketPacket {
13969         self.build().into()
13970     }
13971 }
13972 impl Into<UciCommandPacket> for UciVendor_A_CommandBuilder {
into(self) -> UciCommandPacket13973     fn into(self) -> UciCommandPacket {
13974         self.build().into()
13975     }
13976 }
13977 
13978 #[derive(Debug)]
13979 enum UciVendor_B_CommandDataChild {
13980     Payload(Bytes),
13981     None,
13982 }
13983 impl UciVendor_B_CommandDataChild {
get_total_size(&self) -> usize13984     fn get_total_size(&self) -> usize {
13985         match self {
13986             UciVendor_B_CommandDataChild::Payload(p) => p.len(),
13987             UciVendor_B_CommandDataChild::None => 0,
13988         }
13989     }
13990 }
13991 #[derive(Debug)]
13992 pub enum UciVendor_B_CommandChild {
13993     Payload(Bytes),
13994     None,
13995 }
13996 #[derive(Debug)]
13997 struct UciVendor_B_CommandData {
13998     child: UciVendor_B_CommandDataChild,
13999 }
14000 #[derive(Debug, Clone)]
14001 pub struct UciVendor_B_CommandPacket {
14002     uci_packet: Arc<UciPacketData>,
14003     uci_command: Arc<UciCommandData>,
14004     uci_vendor__b__command: Arc<UciVendor_B_CommandData>,
14005 }
14006 #[derive(Debug)]
14007 pub struct UciVendor_B_CommandBuilder {
14008     pub opcode: u8,
14009     pub payload: Option<Bytes>,
14010 }
14011 impl UciVendor_B_CommandData {
conforms(bytes: &[u8]) -> bool14012     fn conforms(bytes: &[u8]) -> bool {
14013         if bytes.len() < 4 {
14014             return false;
14015         }
14016         true
14017     }
parse(bytes: &[u8]) -> Result<Self>14018     fn parse(bytes: &[u8]) -> Result<Self> {
14019         let payload: Vec<u8> = bytes[4..].into();
14020         let child = if payload.len() > 0 {
14021             UciVendor_B_CommandDataChild::Payload(Bytes::from(payload))
14022         } else {
14023             UciVendor_B_CommandDataChild::None
14024         };
14025         Ok(Self { child })
14026     }
write_to(&self, buffer: &mut BytesMut)14027     fn write_to(&self, buffer: &mut BytesMut) {
14028         match &self.child {
14029             UciVendor_B_CommandDataChild::Payload(p) => buffer[4..].copy_from_slice(&p[..]),
14030             UciVendor_B_CommandDataChild::None => {}
14031         }
14032     }
get_total_size(&self) -> usize14033     fn get_total_size(&self) -> usize {
14034         self.get_size() + self.child.get_total_size()
14035     }
get_size(&self) -> usize14036     fn get_size(&self) -> usize {
14037         let ret = 0;
14038         ret
14039     }
14040 }
14041 impl Packet for UciVendor_B_CommandPacket {
to_bytes(self) -> Bytes14042     fn to_bytes(self) -> Bytes {
14043         let mut buffer = BytesMut::new();
14044         buffer.resize(self.uci_packet.get_total_size(), 0);
14045         self.uci_packet.write_to(&mut buffer);
14046         buffer.freeze()
14047     }
to_vec(self) -> Vec<u8>14048     fn to_vec(self) -> Vec<u8> {
14049         self.to_bytes().to_vec()
14050     }
14051 }
14052 impl From<UciVendor_B_CommandPacket> for Bytes {
from(packet: UciVendor_B_CommandPacket) -> Self14053     fn from(packet: UciVendor_B_CommandPacket) -> Self {
14054         packet.to_bytes()
14055     }
14056 }
14057 impl From<UciVendor_B_CommandPacket> for Vec<u8> {
from(packet: UciVendor_B_CommandPacket) -> Self14058     fn from(packet: UciVendor_B_CommandPacket) -> Self {
14059         packet.to_vec()
14060     }
14061 }
14062 impl TryFrom<UciPacketPacket> for UciVendor_B_CommandPacket {
14063     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>14064     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
14065         Self::new(value.uci_packet).map_err(TryFromError)
14066     }
14067 }
14068 impl UciVendor_B_CommandPacket {
specialize(&self) -> UciVendor_B_CommandChild14069     pub fn specialize(&self) -> UciVendor_B_CommandChild {
14070         match &self.uci_vendor__b__command.child {
14071             UciVendor_B_CommandDataChild::Payload(p) => {
14072                 UciVendor_B_CommandChild::Payload(p.clone())
14073             }
14074             UciVendor_B_CommandDataChild::None => UciVendor_B_CommandChild::None,
14075         }
14076     }
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>14077     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
14078         let uci_packet = root;
14079         let uci_command = match &uci_packet.child {
14080             UciPacketDataChild::UciCommand(value) => (*value).clone(),
14081             _ => return Err("inconsistent state - child was not UciCommand"),
14082         };
14083         let uci_vendor__b__command = match &uci_command.child {
14084             UciCommandDataChild::UciVendor_B_Command(value) => (*value).clone(),
14085             _ => return Err("inconsistent state - child was not UciVendor_B_Command"),
14086         };
14087         Ok(Self {
14088             uci_packet,
14089             uci_command,
14090             uci_vendor__b__command,
14091         })
14092     }
get_group_id(&self) -> GroupId14093     pub fn get_group_id(&self) -> GroupId {
14094         self.uci_packet.as_ref().group_id
14095     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag14096     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
14097         self.uci_packet.as_ref().packet_boundary_flag
14098     }
get_message_type(&self) -> MessageType14099     pub fn get_message_type(&self) -> MessageType {
14100         self.uci_packet.as_ref().message_type
14101     }
get_opcode(&self) -> u814102     pub fn get_opcode(&self) -> u8 {
14103         self.uci_packet.as_ref().opcode
14104     }
14105 }
14106 impl Into<UciPacketPacket> for UciVendor_B_CommandPacket {
into(self) -> UciPacketPacket14107     fn into(self) -> UciPacketPacket {
14108         UciPacketPacket::new(self.uci_packet).unwrap()
14109     }
14110 }
14111 impl Into<UciCommandPacket> for UciVendor_B_CommandPacket {
into(self) -> UciCommandPacket14112     fn into(self) -> UciCommandPacket {
14113         UciCommandPacket::new(self.uci_packet).unwrap()
14114     }
14115 }
14116 impl UciVendor_B_CommandBuilder {
build(self) -> UciVendor_B_CommandPacket14117     pub fn build(self) -> UciVendor_B_CommandPacket {
14118         let uci_vendor__b__command = Arc::new(UciVendor_B_CommandData {
14119             child: match self.payload {
14120                 None => UciVendor_B_CommandDataChild::None,
14121                 Some(bytes) => UciVendor_B_CommandDataChild::Payload(bytes),
14122             },
14123         });
14124         let uci_command = Arc::new(UciCommandData {
14125             child: UciCommandDataChild::UciVendor_B_Command(uci_vendor__b__command),
14126         });
14127         let uci_packet = Arc::new(UciPacketData {
14128             group_id: GroupId::VendorReservedB,
14129             packet_boundary_flag: PacketBoundaryFlag::Complete,
14130             message_type: MessageType::Command,
14131             opcode: self.opcode,
14132             child: UciPacketDataChild::UciCommand(uci_command),
14133         });
14134         UciVendor_B_CommandPacket::new(uci_packet).unwrap()
14135     }
14136 }
14137 impl Into<UciPacketPacket> for UciVendor_B_CommandBuilder {
into(self) -> UciPacketPacket14138     fn into(self) -> UciPacketPacket {
14139         self.build().into()
14140     }
14141 }
14142 impl Into<UciCommandPacket> for UciVendor_B_CommandBuilder {
into(self) -> UciCommandPacket14143     fn into(self) -> UciCommandPacket {
14144         self.build().into()
14145     }
14146 }
14147 
14148 #[derive(Debug)]
14149 enum UciVendor_E_CommandDataChild {
14150     Payload(Bytes),
14151     None,
14152 }
14153 impl UciVendor_E_CommandDataChild {
get_total_size(&self) -> usize14154     fn get_total_size(&self) -> usize {
14155         match self {
14156             UciVendor_E_CommandDataChild::Payload(p) => p.len(),
14157             UciVendor_E_CommandDataChild::None => 0,
14158         }
14159     }
14160 }
14161 #[derive(Debug)]
14162 pub enum UciVendor_E_CommandChild {
14163     Payload(Bytes),
14164     None,
14165 }
14166 #[derive(Debug)]
14167 struct UciVendor_E_CommandData {
14168     child: UciVendor_E_CommandDataChild,
14169 }
14170 #[derive(Debug, Clone)]
14171 pub struct UciVendor_E_CommandPacket {
14172     uci_packet: Arc<UciPacketData>,
14173     uci_command: Arc<UciCommandData>,
14174     uci_vendor__e__command: Arc<UciVendor_E_CommandData>,
14175 }
14176 #[derive(Debug)]
14177 pub struct UciVendor_E_CommandBuilder {
14178     pub opcode: u8,
14179     pub payload: Option<Bytes>,
14180 }
14181 impl UciVendor_E_CommandData {
conforms(bytes: &[u8]) -> bool14182     fn conforms(bytes: &[u8]) -> bool {
14183         if bytes.len() < 4 {
14184             return false;
14185         }
14186         true
14187     }
parse(bytes: &[u8]) -> Result<Self>14188     fn parse(bytes: &[u8]) -> Result<Self> {
14189         let payload: Vec<u8> = bytes[4..].into();
14190         let child = if payload.len() > 0 {
14191             UciVendor_E_CommandDataChild::Payload(Bytes::from(payload))
14192         } else {
14193             UciVendor_E_CommandDataChild::None
14194         };
14195         Ok(Self { child })
14196     }
write_to(&self, buffer: &mut BytesMut)14197     fn write_to(&self, buffer: &mut BytesMut) {
14198         match &self.child {
14199             UciVendor_E_CommandDataChild::Payload(p) => buffer[4..].copy_from_slice(&p[..]),
14200             UciVendor_E_CommandDataChild::None => {}
14201         }
14202     }
get_total_size(&self) -> usize14203     fn get_total_size(&self) -> usize {
14204         self.get_size() + self.child.get_total_size()
14205     }
get_size(&self) -> usize14206     fn get_size(&self) -> usize {
14207         let ret = 0;
14208         ret
14209     }
14210 }
14211 impl Packet for UciVendor_E_CommandPacket {
to_bytes(self) -> Bytes14212     fn to_bytes(self) -> Bytes {
14213         let mut buffer = BytesMut::new();
14214         buffer.resize(self.uci_packet.get_total_size(), 0);
14215         self.uci_packet.write_to(&mut buffer);
14216         buffer.freeze()
14217     }
to_vec(self) -> Vec<u8>14218     fn to_vec(self) -> Vec<u8> {
14219         self.to_bytes().to_vec()
14220     }
14221 }
14222 impl From<UciVendor_E_CommandPacket> for Bytes {
from(packet: UciVendor_E_CommandPacket) -> Self14223     fn from(packet: UciVendor_E_CommandPacket) -> Self {
14224         packet.to_bytes()
14225     }
14226 }
14227 impl From<UciVendor_E_CommandPacket> for Vec<u8> {
from(packet: UciVendor_E_CommandPacket) -> Self14228     fn from(packet: UciVendor_E_CommandPacket) -> Self {
14229         packet.to_vec()
14230     }
14231 }
14232 impl TryFrom<UciPacketPacket> for UciVendor_E_CommandPacket {
14233     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>14234     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
14235         Self::new(value.uci_packet).map_err(TryFromError)
14236     }
14237 }
14238 impl UciVendor_E_CommandPacket {
specialize(&self) -> UciVendor_E_CommandChild14239     pub fn specialize(&self) -> UciVendor_E_CommandChild {
14240         match &self.uci_vendor__e__command.child {
14241             UciVendor_E_CommandDataChild::Payload(p) => {
14242                 UciVendor_E_CommandChild::Payload(p.clone())
14243             }
14244             UciVendor_E_CommandDataChild::None => UciVendor_E_CommandChild::None,
14245         }
14246     }
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>14247     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
14248         let uci_packet = root;
14249         let uci_command = match &uci_packet.child {
14250             UciPacketDataChild::UciCommand(value) => (*value).clone(),
14251             _ => return Err("inconsistent state - child was not UciCommand"),
14252         };
14253         let uci_vendor__e__command = match &uci_command.child {
14254             UciCommandDataChild::UciVendor_E_Command(value) => (*value).clone(),
14255             _ => return Err("inconsistent state - child was not UciVendor_E_Command"),
14256         };
14257         Ok(Self {
14258             uci_packet,
14259             uci_command,
14260             uci_vendor__e__command,
14261         })
14262     }
get_group_id(&self) -> GroupId14263     pub fn get_group_id(&self) -> GroupId {
14264         self.uci_packet.as_ref().group_id
14265     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag14266     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
14267         self.uci_packet.as_ref().packet_boundary_flag
14268     }
get_message_type(&self) -> MessageType14269     pub fn get_message_type(&self) -> MessageType {
14270         self.uci_packet.as_ref().message_type
14271     }
get_opcode(&self) -> u814272     pub fn get_opcode(&self) -> u8 {
14273         self.uci_packet.as_ref().opcode
14274     }
14275 }
14276 impl Into<UciPacketPacket> for UciVendor_E_CommandPacket {
into(self) -> UciPacketPacket14277     fn into(self) -> UciPacketPacket {
14278         UciPacketPacket::new(self.uci_packet).unwrap()
14279     }
14280 }
14281 impl Into<UciCommandPacket> for UciVendor_E_CommandPacket {
into(self) -> UciCommandPacket14282     fn into(self) -> UciCommandPacket {
14283         UciCommandPacket::new(self.uci_packet).unwrap()
14284     }
14285 }
14286 impl UciVendor_E_CommandBuilder {
build(self) -> UciVendor_E_CommandPacket14287     pub fn build(self) -> UciVendor_E_CommandPacket {
14288         let uci_vendor__e__command = Arc::new(UciVendor_E_CommandData {
14289             child: match self.payload {
14290                 None => UciVendor_E_CommandDataChild::None,
14291                 Some(bytes) => UciVendor_E_CommandDataChild::Payload(bytes),
14292             },
14293         });
14294         let uci_command = Arc::new(UciCommandData {
14295             child: UciCommandDataChild::UciVendor_E_Command(uci_vendor__e__command),
14296         });
14297         let uci_packet = Arc::new(UciPacketData {
14298             group_id: GroupId::VendorReservedE,
14299             packet_boundary_flag: PacketBoundaryFlag::Complete,
14300             message_type: MessageType::Command,
14301             opcode: self.opcode,
14302             child: UciPacketDataChild::UciCommand(uci_command),
14303         });
14304         UciVendor_E_CommandPacket::new(uci_packet).unwrap()
14305     }
14306 }
14307 impl Into<UciPacketPacket> for UciVendor_E_CommandBuilder {
into(self) -> UciPacketPacket14308     fn into(self) -> UciPacketPacket {
14309         self.build().into()
14310     }
14311 }
14312 impl Into<UciCommandPacket> for UciVendor_E_CommandBuilder {
into(self) -> UciCommandPacket14313     fn into(self) -> UciCommandPacket {
14314         self.build().into()
14315     }
14316 }
14317 
14318 #[derive(Debug)]
14319 enum UciVendor_F_CommandDataChild {
14320     Payload(Bytes),
14321     None,
14322 }
14323 impl UciVendor_F_CommandDataChild {
get_total_size(&self) -> usize14324     fn get_total_size(&self) -> usize {
14325         match self {
14326             UciVendor_F_CommandDataChild::Payload(p) => p.len(),
14327             UciVendor_F_CommandDataChild::None => 0,
14328         }
14329     }
14330 }
14331 #[derive(Debug)]
14332 pub enum UciVendor_F_CommandChild {
14333     Payload(Bytes),
14334     None,
14335 }
14336 #[derive(Debug)]
14337 struct UciVendor_F_CommandData {
14338     child: UciVendor_F_CommandDataChild,
14339 }
14340 #[derive(Debug, Clone)]
14341 pub struct UciVendor_F_CommandPacket {
14342     uci_packet: Arc<UciPacketData>,
14343     uci_command: Arc<UciCommandData>,
14344     uci_vendor__f__command: Arc<UciVendor_F_CommandData>,
14345 }
14346 #[derive(Debug)]
14347 pub struct UciVendor_F_CommandBuilder {
14348     pub opcode: u8,
14349     pub payload: Option<Bytes>,
14350 }
14351 impl UciVendor_F_CommandData {
conforms(bytes: &[u8]) -> bool14352     fn conforms(bytes: &[u8]) -> bool {
14353         if bytes.len() < 4 {
14354             return false;
14355         }
14356         true
14357     }
parse(bytes: &[u8]) -> Result<Self>14358     fn parse(bytes: &[u8]) -> Result<Self> {
14359         let payload: Vec<u8> = bytes[4..].into();
14360         let child = if payload.len() > 0 {
14361             UciVendor_F_CommandDataChild::Payload(Bytes::from(payload))
14362         } else {
14363             UciVendor_F_CommandDataChild::None
14364         };
14365         Ok(Self { child })
14366     }
write_to(&self, buffer: &mut BytesMut)14367     fn write_to(&self, buffer: &mut BytesMut) {
14368         match &self.child {
14369             UciVendor_F_CommandDataChild::Payload(p) => buffer[4..].copy_from_slice(&p[..]),
14370             UciVendor_F_CommandDataChild::None => {}
14371         }
14372     }
get_total_size(&self) -> usize14373     fn get_total_size(&self) -> usize {
14374         self.get_size() + self.child.get_total_size()
14375     }
get_size(&self) -> usize14376     fn get_size(&self) -> usize {
14377         let ret = 0;
14378         ret
14379     }
14380 }
14381 impl Packet for UciVendor_F_CommandPacket {
to_bytes(self) -> Bytes14382     fn to_bytes(self) -> Bytes {
14383         let mut buffer = BytesMut::new();
14384         buffer.resize(self.uci_packet.get_total_size(), 0);
14385         self.uci_packet.write_to(&mut buffer);
14386         buffer.freeze()
14387     }
to_vec(self) -> Vec<u8>14388     fn to_vec(self) -> Vec<u8> {
14389         self.to_bytes().to_vec()
14390     }
14391 }
14392 impl From<UciVendor_F_CommandPacket> for Bytes {
from(packet: UciVendor_F_CommandPacket) -> Self14393     fn from(packet: UciVendor_F_CommandPacket) -> Self {
14394         packet.to_bytes()
14395     }
14396 }
14397 impl From<UciVendor_F_CommandPacket> for Vec<u8> {
from(packet: UciVendor_F_CommandPacket) -> Self14398     fn from(packet: UciVendor_F_CommandPacket) -> Self {
14399         packet.to_vec()
14400     }
14401 }
14402 impl TryFrom<UciPacketPacket> for UciVendor_F_CommandPacket {
14403     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>14404     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
14405         Self::new(value.uci_packet).map_err(TryFromError)
14406     }
14407 }
14408 impl UciVendor_F_CommandPacket {
specialize(&self) -> UciVendor_F_CommandChild14409     pub fn specialize(&self) -> UciVendor_F_CommandChild {
14410         match &self.uci_vendor__f__command.child {
14411             UciVendor_F_CommandDataChild::Payload(p) => {
14412                 UciVendor_F_CommandChild::Payload(p.clone())
14413             }
14414             UciVendor_F_CommandDataChild::None => UciVendor_F_CommandChild::None,
14415         }
14416     }
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>14417     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
14418         let uci_packet = root;
14419         let uci_command = match &uci_packet.child {
14420             UciPacketDataChild::UciCommand(value) => (*value).clone(),
14421             _ => return Err("inconsistent state - child was not UciCommand"),
14422         };
14423         let uci_vendor__f__command = match &uci_command.child {
14424             UciCommandDataChild::UciVendor_F_Command(value) => (*value).clone(),
14425             _ => return Err("inconsistent state - child was not UciVendor_F_Command"),
14426         };
14427         Ok(Self {
14428             uci_packet,
14429             uci_command,
14430             uci_vendor__f__command,
14431         })
14432     }
get_group_id(&self) -> GroupId14433     pub fn get_group_id(&self) -> GroupId {
14434         self.uci_packet.as_ref().group_id
14435     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag14436     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
14437         self.uci_packet.as_ref().packet_boundary_flag
14438     }
get_message_type(&self) -> MessageType14439     pub fn get_message_type(&self) -> MessageType {
14440         self.uci_packet.as_ref().message_type
14441     }
get_opcode(&self) -> u814442     pub fn get_opcode(&self) -> u8 {
14443         self.uci_packet.as_ref().opcode
14444     }
14445 }
14446 impl Into<UciPacketPacket> for UciVendor_F_CommandPacket {
into(self) -> UciPacketPacket14447     fn into(self) -> UciPacketPacket {
14448         UciPacketPacket::new(self.uci_packet).unwrap()
14449     }
14450 }
14451 impl Into<UciCommandPacket> for UciVendor_F_CommandPacket {
into(self) -> UciCommandPacket14452     fn into(self) -> UciCommandPacket {
14453         UciCommandPacket::new(self.uci_packet).unwrap()
14454     }
14455 }
14456 impl UciVendor_F_CommandBuilder {
build(self) -> UciVendor_F_CommandPacket14457     pub fn build(self) -> UciVendor_F_CommandPacket {
14458         let uci_vendor__f__command = Arc::new(UciVendor_F_CommandData {
14459             child: match self.payload {
14460                 None => UciVendor_F_CommandDataChild::None,
14461                 Some(bytes) => UciVendor_F_CommandDataChild::Payload(bytes),
14462             },
14463         });
14464         let uci_command = Arc::new(UciCommandData {
14465             child: UciCommandDataChild::UciVendor_F_Command(uci_vendor__f__command),
14466         });
14467         let uci_packet = Arc::new(UciPacketData {
14468             group_id: GroupId::VendorReservedF,
14469             packet_boundary_flag: PacketBoundaryFlag::Complete,
14470             message_type: MessageType::Command,
14471             opcode: self.opcode,
14472             child: UciPacketDataChild::UciCommand(uci_command),
14473         });
14474         UciVendor_F_CommandPacket::new(uci_packet).unwrap()
14475     }
14476 }
14477 impl Into<UciPacketPacket> for UciVendor_F_CommandBuilder {
into(self) -> UciPacketPacket14478     fn into(self) -> UciPacketPacket {
14479         self.build().into()
14480     }
14481 }
14482 impl Into<UciCommandPacket> for UciVendor_F_CommandBuilder {
into(self) -> UciCommandPacket14483     fn into(self) -> UciCommandPacket {
14484         self.build().into()
14485     }
14486 }
14487 
14488 #[derive(Debug)]
14489 enum UciVendor_A_ResponseDataChild {
14490     Payload(Bytes),
14491     None,
14492 }
14493 impl UciVendor_A_ResponseDataChild {
get_total_size(&self) -> usize14494     fn get_total_size(&self) -> usize {
14495         match self {
14496             UciVendor_A_ResponseDataChild::Payload(p) => p.len(),
14497             UciVendor_A_ResponseDataChild::None => 0,
14498         }
14499     }
14500 }
14501 #[derive(Debug)]
14502 pub enum UciVendor_A_ResponseChild {
14503     Payload(Bytes),
14504     None,
14505 }
14506 #[derive(Debug)]
14507 struct UciVendor_A_ResponseData {
14508     child: UciVendor_A_ResponseDataChild,
14509 }
14510 #[derive(Debug, Clone)]
14511 pub struct UciVendor_A_ResponsePacket {
14512     uci_packet: Arc<UciPacketData>,
14513     uci_response: Arc<UciResponseData>,
14514     uci_vendor__a__response: Arc<UciVendor_A_ResponseData>,
14515 }
14516 #[derive(Debug)]
14517 pub struct UciVendor_A_ResponseBuilder {
14518     pub opcode: u8,
14519     pub payload: Option<Bytes>,
14520 }
14521 impl UciVendor_A_ResponseData {
conforms(bytes: &[u8]) -> bool14522     fn conforms(bytes: &[u8]) -> bool {
14523         if bytes.len() < 4 {
14524             return false;
14525         }
14526         true
14527     }
parse(bytes: &[u8]) -> Result<Self>14528     fn parse(bytes: &[u8]) -> Result<Self> {
14529         let payload: Vec<u8> = bytes[4..].into();
14530         let child = if payload.len() > 0 {
14531             UciVendor_A_ResponseDataChild::Payload(Bytes::from(payload))
14532         } else {
14533             UciVendor_A_ResponseDataChild::None
14534         };
14535         Ok(Self { child })
14536     }
write_to(&self, buffer: &mut BytesMut)14537     fn write_to(&self, buffer: &mut BytesMut) {
14538         match &self.child {
14539             UciVendor_A_ResponseDataChild::Payload(p) => buffer[4..].copy_from_slice(&p[..]),
14540             UciVendor_A_ResponseDataChild::None => {}
14541         }
14542     }
get_total_size(&self) -> usize14543     fn get_total_size(&self) -> usize {
14544         self.get_size() + self.child.get_total_size()
14545     }
get_size(&self) -> usize14546     fn get_size(&self) -> usize {
14547         let ret = 0;
14548         ret
14549     }
14550 }
14551 impl Packet for UciVendor_A_ResponsePacket {
to_bytes(self) -> Bytes14552     fn to_bytes(self) -> Bytes {
14553         let mut buffer = BytesMut::new();
14554         buffer.resize(self.uci_packet.get_total_size(), 0);
14555         self.uci_packet.write_to(&mut buffer);
14556         buffer.freeze()
14557     }
to_vec(self) -> Vec<u8>14558     fn to_vec(self) -> Vec<u8> {
14559         self.to_bytes().to_vec()
14560     }
14561 }
14562 impl From<UciVendor_A_ResponsePacket> for Bytes {
from(packet: UciVendor_A_ResponsePacket) -> Self14563     fn from(packet: UciVendor_A_ResponsePacket) -> Self {
14564         packet.to_bytes()
14565     }
14566 }
14567 impl From<UciVendor_A_ResponsePacket> for Vec<u8> {
from(packet: UciVendor_A_ResponsePacket) -> Self14568     fn from(packet: UciVendor_A_ResponsePacket) -> Self {
14569         packet.to_vec()
14570     }
14571 }
14572 impl TryFrom<UciPacketPacket> for UciVendor_A_ResponsePacket {
14573     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>14574     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
14575         Self::new(value.uci_packet).map_err(TryFromError)
14576     }
14577 }
14578 impl UciVendor_A_ResponsePacket {
specialize(&self) -> UciVendor_A_ResponseChild14579     pub fn specialize(&self) -> UciVendor_A_ResponseChild {
14580         match &self.uci_vendor__a__response.child {
14581             UciVendor_A_ResponseDataChild::Payload(p) => {
14582                 UciVendor_A_ResponseChild::Payload(p.clone())
14583             }
14584             UciVendor_A_ResponseDataChild::None => UciVendor_A_ResponseChild::None,
14585         }
14586     }
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>14587     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
14588         let uci_packet = root;
14589         let uci_response = match &uci_packet.child {
14590             UciPacketDataChild::UciResponse(value) => (*value).clone(),
14591             _ => return Err("inconsistent state - child was not UciResponse"),
14592         };
14593         let uci_vendor__a__response = match &uci_response.child {
14594             UciResponseDataChild::UciVendor_A_Response(value) => (*value).clone(),
14595             _ => return Err("inconsistent state - child was not UciVendor_A_Response"),
14596         };
14597         Ok(Self {
14598             uci_packet,
14599             uci_response,
14600             uci_vendor__a__response,
14601         })
14602     }
get_group_id(&self) -> GroupId14603     pub fn get_group_id(&self) -> GroupId {
14604         self.uci_packet.as_ref().group_id
14605     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag14606     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
14607         self.uci_packet.as_ref().packet_boundary_flag
14608     }
get_message_type(&self) -> MessageType14609     pub fn get_message_type(&self) -> MessageType {
14610         self.uci_packet.as_ref().message_type
14611     }
get_opcode(&self) -> u814612     pub fn get_opcode(&self) -> u8 {
14613         self.uci_packet.as_ref().opcode
14614     }
14615 }
14616 impl Into<UciPacketPacket> for UciVendor_A_ResponsePacket {
into(self) -> UciPacketPacket14617     fn into(self) -> UciPacketPacket {
14618         UciPacketPacket::new(self.uci_packet).unwrap()
14619     }
14620 }
14621 impl Into<UciResponsePacket> for UciVendor_A_ResponsePacket {
into(self) -> UciResponsePacket14622     fn into(self) -> UciResponsePacket {
14623         UciResponsePacket::new(self.uci_packet).unwrap()
14624     }
14625 }
14626 impl UciVendor_A_ResponseBuilder {
build(self) -> UciVendor_A_ResponsePacket14627     pub fn build(self) -> UciVendor_A_ResponsePacket {
14628         let uci_vendor__a__response = Arc::new(UciVendor_A_ResponseData {
14629             child: match self.payload {
14630                 None => UciVendor_A_ResponseDataChild::None,
14631                 Some(bytes) => UciVendor_A_ResponseDataChild::Payload(bytes),
14632             },
14633         });
14634         let uci_response = Arc::new(UciResponseData {
14635             child: UciResponseDataChild::UciVendor_A_Response(uci_vendor__a__response),
14636         });
14637         let uci_packet = Arc::new(UciPacketData {
14638             group_id: GroupId::VendorReservedA,
14639             packet_boundary_flag: PacketBoundaryFlag::Complete,
14640             message_type: MessageType::Response,
14641             opcode: self.opcode,
14642             child: UciPacketDataChild::UciResponse(uci_response),
14643         });
14644         UciVendor_A_ResponsePacket::new(uci_packet).unwrap()
14645     }
14646 }
14647 impl Into<UciPacketPacket> for UciVendor_A_ResponseBuilder {
into(self) -> UciPacketPacket14648     fn into(self) -> UciPacketPacket {
14649         self.build().into()
14650     }
14651 }
14652 impl Into<UciResponsePacket> for UciVendor_A_ResponseBuilder {
into(self) -> UciResponsePacket14653     fn into(self) -> UciResponsePacket {
14654         self.build().into()
14655     }
14656 }
14657 
14658 #[derive(Debug)]
14659 enum UciVendor_B_ResponseDataChild {
14660     Payload(Bytes),
14661     None,
14662 }
14663 impl UciVendor_B_ResponseDataChild {
get_total_size(&self) -> usize14664     fn get_total_size(&self) -> usize {
14665         match self {
14666             UciVendor_B_ResponseDataChild::Payload(p) => p.len(),
14667             UciVendor_B_ResponseDataChild::None => 0,
14668         }
14669     }
14670 }
14671 #[derive(Debug)]
14672 pub enum UciVendor_B_ResponseChild {
14673     Payload(Bytes),
14674     None,
14675 }
14676 #[derive(Debug)]
14677 struct UciVendor_B_ResponseData {
14678     child: UciVendor_B_ResponseDataChild,
14679 }
14680 #[derive(Debug, Clone)]
14681 pub struct UciVendor_B_ResponsePacket {
14682     uci_packet: Arc<UciPacketData>,
14683     uci_response: Arc<UciResponseData>,
14684     uci_vendor__b__response: Arc<UciVendor_B_ResponseData>,
14685 }
14686 #[derive(Debug)]
14687 pub struct UciVendor_B_ResponseBuilder {
14688     pub opcode: u8,
14689     pub payload: Option<Bytes>,
14690 }
14691 impl UciVendor_B_ResponseData {
conforms(bytes: &[u8]) -> bool14692     fn conforms(bytes: &[u8]) -> bool {
14693         if bytes.len() < 4 {
14694             return false;
14695         }
14696         true
14697     }
parse(bytes: &[u8]) -> Result<Self>14698     fn parse(bytes: &[u8]) -> Result<Self> {
14699         let payload: Vec<u8> = bytes[4..].into();
14700         let child = if payload.len() > 0 {
14701             UciVendor_B_ResponseDataChild::Payload(Bytes::from(payload))
14702         } else {
14703             UciVendor_B_ResponseDataChild::None
14704         };
14705         Ok(Self { child })
14706     }
write_to(&self, buffer: &mut BytesMut)14707     fn write_to(&self, buffer: &mut BytesMut) {
14708         match &self.child {
14709             UciVendor_B_ResponseDataChild::Payload(p) => buffer[4..].copy_from_slice(&p[..]),
14710             UciVendor_B_ResponseDataChild::None => {}
14711         }
14712     }
get_total_size(&self) -> usize14713     fn get_total_size(&self) -> usize {
14714         self.get_size() + self.child.get_total_size()
14715     }
get_size(&self) -> usize14716     fn get_size(&self) -> usize {
14717         let ret = 0;
14718         ret
14719     }
14720 }
14721 impl Packet for UciVendor_B_ResponsePacket {
to_bytes(self) -> Bytes14722     fn to_bytes(self) -> Bytes {
14723         let mut buffer = BytesMut::new();
14724         buffer.resize(self.uci_packet.get_total_size(), 0);
14725         self.uci_packet.write_to(&mut buffer);
14726         buffer.freeze()
14727     }
to_vec(self) -> Vec<u8>14728     fn to_vec(self) -> Vec<u8> {
14729         self.to_bytes().to_vec()
14730     }
14731 }
14732 impl From<UciVendor_B_ResponsePacket> for Bytes {
from(packet: UciVendor_B_ResponsePacket) -> Self14733     fn from(packet: UciVendor_B_ResponsePacket) -> Self {
14734         packet.to_bytes()
14735     }
14736 }
14737 impl From<UciVendor_B_ResponsePacket> for Vec<u8> {
from(packet: UciVendor_B_ResponsePacket) -> Self14738     fn from(packet: UciVendor_B_ResponsePacket) -> Self {
14739         packet.to_vec()
14740     }
14741 }
14742 impl TryFrom<UciPacketPacket> for UciVendor_B_ResponsePacket {
14743     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>14744     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
14745         Self::new(value.uci_packet).map_err(TryFromError)
14746     }
14747 }
14748 impl UciVendor_B_ResponsePacket {
specialize(&self) -> UciVendor_B_ResponseChild14749     pub fn specialize(&self) -> UciVendor_B_ResponseChild {
14750         match &self.uci_vendor__b__response.child {
14751             UciVendor_B_ResponseDataChild::Payload(p) => {
14752                 UciVendor_B_ResponseChild::Payload(p.clone())
14753             }
14754             UciVendor_B_ResponseDataChild::None => UciVendor_B_ResponseChild::None,
14755         }
14756     }
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>14757     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
14758         let uci_packet = root;
14759         let uci_response = match &uci_packet.child {
14760             UciPacketDataChild::UciResponse(value) => (*value).clone(),
14761             _ => return Err("inconsistent state - child was not UciResponse"),
14762         };
14763         let uci_vendor__b__response = match &uci_response.child {
14764             UciResponseDataChild::UciVendor_B_Response(value) => (*value).clone(),
14765             _ => return Err("inconsistent state - child was not UciVendor_B_Response"),
14766         };
14767         Ok(Self {
14768             uci_packet,
14769             uci_response,
14770             uci_vendor__b__response,
14771         })
14772     }
get_group_id(&self) -> GroupId14773     pub fn get_group_id(&self) -> GroupId {
14774         self.uci_packet.as_ref().group_id
14775     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag14776     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
14777         self.uci_packet.as_ref().packet_boundary_flag
14778     }
get_message_type(&self) -> MessageType14779     pub fn get_message_type(&self) -> MessageType {
14780         self.uci_packet.as_ref().message_type
14781     }
get_opcode(&self) -> u814782     pub fn get_opcode(&self) -> u8 {
14783         self.uci_packet.as_ref().opcode
14784     }
14785 }
14786 impl Into<UciPacketPacket> for UciVendor_B_ResponsePacket {
into(self) -> UciPacketPacket14787     fn into(self) -> UciPacketPacket {
14788         UciPacketPacket::new(self.uci_packet).unwrap()
14789     }
14790 }
14791 impl Into<UciResponsePacket> for UciVendor_B_ResponsePacket {
into(self) -> UciResponsePacket14792     fn into(self) -> UciResponsePacket {
14793         UciResponsePacket::new(self.uci_packet).unwrap()
14794     }
14795 }
14796 impl UciVendor_B_ResponseBuilder {
build(self) -> UciVendor_B_ResponsePacket14797     pub fn build(self) -> UciVendor_B_ResponsePacket {
14798         let uci_vendor__b__response = Arc::new(UciVendor_B_ResponseData {
14799             child: match self.payload {
14800                 None => UciVendor_B_ResponseDataChild::None,
14801                 Some(bytes) => UciVendor_B_ResponseDataChild::Payload(bytes),
14802             },
14803         });
14804         let uci_response = Arc::new(UciResponseData {
14805             child: UciResponseDataChild::UciVendor_B_Response(uci_vendor__b__response),
14806         });
14807         let uci_packet = Arc::new(UciPacketData {
14808             group_id: GroupId::VendorReservedB,
14809             packet_boundary_flag: PacketBoundaryFlag::Complete,
14810             message_type: MessageType::Response,
14811             opcode: self.opcode,
14812             child: UciPacketDataChild::UciResponse(uci_response),
14813         });
14814         UciVendor_B_ResponsePacket::new(uci_packet).unwrap()
14815     }
14816 }
14817 impl Into<UciPacketPacket> for UciVendor_B_ResponseBuilder {
into(self) -> UciPacketPacket14818     fn into(self) -> UciPacketPacket {
14819         self.build().into()
14820     }
14821 }
14822 impl Into<UciResponsePacket> for UciVendor_B_ResponseBuilder {
into(self) -> UciResponsePacket14823     fn into(self) -> UciResponsePacket {
14824         self.build().into()
14825     }
14826 }
14827 
14828 #[derive(Debug)]
14829 enum UciVendor_E_ResponseDataChild {
14830     Payload(Bytes),
14831     None,
14832 }
14833 impl UciVendor_E_ResponseDataChild {
get_total_size(&self) -> usize14834     fn get_total_size(&self) -> usize {
14835         match self {
14836             UciVendor_E_ResponseDataChild::Payload(p) => p.len(),
14837             UciVendor_E_ResponseDataChild::None => 0,
14838         }
14839     }
14840 }
14841 #[derive(Debug)]
14842 pub enum UciVendor_E_ResponseChild {
14843     Payload(Bytes),
14844     None,
14845 }
14846 #[derive(Debug)]
14847 struct UciVendor_E_ResponseData {
14848     child: UciVendor_E_ResponseDataChild,
14849 }
14850 #[derive(Debug, Clone)]
14851 pub struct UciVendor_E_ResponsePacket {
14852     uci_packet: Arc<UciPacketData>,
14853     uci_response: Arc<UciResponseData>,
14854     uci_vendor__e__response: Arc<UciVendor_E_ResponseData>,
14855 }
14856 #[derive(Debug)]
14857 pub struct UciVendor_E_ResponseBuilder {
14858     pub opcode: u8,
14859     pub payload: Option<Bytes>,
14860 }
14861 impl UciVendor_E_ResponseData {
conforms(bytes: &[u8]) -> bool14862     fn conforms(bytes: &[u8]) -> bool {
14863         if bytes.len() < 4 {
14864             return false;
14865         }
14866         true
14867     }
parse(bytes: &[u8]) -> Result<Self>14868     fn parse(bytes: &[u8]) -> Result<Self> {
14869         let payload: Vec<u8> = bytes[4..].into();
14870         let child = if payload.len() > 0 {
14871             UciVendor_E_ResponseDataChild::Payload(Bytes::from(payload))
14872         } else {
14873             UciVendor_E_ResponseDataChild::None
14874         };
14875         Ok(Self { child })
14876     }
write_to(&self, buffer: &mut BytesMut)14877     fn write_to(&self, buffer: &mut BytesMut) {
14878         match &self.child {
14879             UciVendor_E_ResponseDataChild::Payload(p) => buffer[4..].copy_from_slice(&p[..]),
14880             UciVendor_E_ResponseDataChild::None => {}
14881         }
14882     }
get_total_size(&self) -> usize14883     fn get_total_size(&self) -> usize {
14884         self.get_size() + self.child.get_total_size()
14885     }
get_size(&self) -> usize14886     fn get_size(&self) -> usize {
14887         let ret = 0;
14888         ret
14889     }
14890 }
14891 impl Packet for UciVendor_E_ResponsePacket {
to_bytes(self) -> Bytes14892     fn to_bytes(self) -> Bytes {
14893         let mut buffer = BytesMut::new();
14894         buffer.resize(self.uci_packet.get_total_size(), 0);
14895         self.uci_packet.write_to(&mut buffer);
14896         buffer.freeze()
14897     }
to_vec(self) -> Vec<u8>14898     fn to_vec(self) -> Vec<u8> {
14899         self.to_bytes().to_vec()
14900     }
14901 }
14902 impl From<UciVendor_E_ResponsePacket> for Bytes {
from(packet: UciVendor_E_ResponsePacket) -> Self14903     fn from(packet: UciVendor_E_ResponsePacket) -> Self {
14904         packet.to_bytes()
14905     }
14906 }
14907 impl From<UciVendor_E_ResponsePacket> for Vec<u8> {
from(packet: UciVendor_E_ResponsePacket) -> Self14908     fn from(packet: UciVendor_E_ResponsePacket) -> Self {
14909         packet.to_vec()
14910     }
14911 }
14912 impl TryFrom<UciPacketPacket> for UciVendor_E_ResponsePacket {
14913     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>14914     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
14915         Self::new(value.uci_packet).map_err(TryFromError)
14916     }
14917 }
14918 impl UciVendor_E_ResponsePacket {
specialize(&self) -> UciVendor_E_ResponseChild14919     pub fn specialize(&self) -> UciVendor_E_ResponseChild {
14920         match &self.uci_vendor__e__response.child {
14921             UciVendor_E_ResponseDataChild::Payload(p) => {
14922                 UciVendor_E_ResponseChild::Payload(p.clone())
14923             }
14924             UciVendor_E_ResponseDataChild::None => UciVendor_E_ResponseChild::None,
14925         }
14926     }
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>14927     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
14928         let uci_packet = root;
14929         let uci_response = match &uci_packet.child {
14930             UciPacketDataChild::UciResponse(value) => (*value).clone(),
14931             _ => return Err("inconsistent state - child was not UciResponse"),
14932         };
14933         let uci_vendor__e__response = match &uci_response.child {
14934             UciResponseDataChild::UciVendor_E_Response(value) => (*value).clone(),
14935             _ => return Err("inconsistent state - child was not UciVendor_E_Response"),
14936         };
14937         Ok(Self {
14938             uci_packet,
14939             uci_response,
14940             uci_vendor__e__response,
14941         })
14942     }
get_group_id(&self) -> GroupId14943     pub fn get_group_id(&self) -> GroupId {
14944         self.uci_packet.as_ref().group_id
14945     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag14946     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
14947         self.uci_packet.as_ref().packet_boundary_flag
14948     }
get_message_type(&self) -> MessageType14949     pub fn get_message_type(&self) -> MessageType {
14950         self.uci_packet.as_ref().message_type
14951     }
get_opcode(&self) -> u814952     pub fn get_opcode(&self) -> u8 {
14953         self.uci_packet.as_ref().opcode
14954     }
14955 }
14956 impl Into<UciPacketPacket> for UciVendor_E_ResponsePacket {
into(self) -> UciPacketPacket14957     fn into(self) -> UciPacketPacket {
14958         UciPacketPacket::new(self.uci_packet).unwrap()
14959     }
14960 }
14961 impl Into<UciResponsePacket> for UciVendor_E_ResponsePacket {
into(self) -> UciResponsePacket14962     fn into(self) -> UciResponsePacket {
14963         UciResponsePacket::new(self.uci_packet).unwrap()
14964     }
14965 }
14966 impl UciVendor_E_ResponseBuilder {
build(self) -> UciVendor_E_ResponsePacket14967     pub fn build(self) -> UciVendor_E_ResponsePacket {
14968         let uci_vendor__e__response = Arc::new(UciVendor_E_ResponseData {
14969             child: match self.payload {
14970                 None => UciVendor_E_ResponseDataChild::None,
14971                 Some(bytes) => UciVendor_E_ResponseDataChild::Payload(bytes),
14972             },
14973         });
14974         let uci_response = Arc::new(UciResponseData {
14975             child: UciResponseDataChild::UciVendor_E_Response(uci_vendor__e__response),
14976         });
14977         let uci_packet = Arc::new(UciPacketData {
14978             group_id: GroupId::VendorReservedE,
14979             packet_boundary_flag: PacketBoundaryFlag::Complete,
14980             message_type: MessageType::Response,
14981             opcode: self.opcode,
14982             child: UciPacketDataChild::UciResponse(uci_response),
14983         });
14984         UciVendor_E_ResponsePacket::new(uci_packet).unwrap()
14985     }
14986 }
14987 impl Into<UciPacketPacket> for UciVendor_E_ResponseBuilder {
into(self) -> UciPacketPacket14988     fn into(self) -> UciPacketPacket {
14989         self.build().into()
14990     }
14991 }
14992 impl Into<UciResponsePacket> for UciVendor_E_ResponseBuilder {
into(self) -> UciResponsePacket14993     fn into(self) -> UciResponsePacket {
14994         self.build().into()
14995     }
14996 }
14997 
14998 #[derive(Debug)]
14999 enum UciVendor_F_ResponseDataChild {
15000     Payload(Bytes),
15001     None,
15002 }
15003 impl UciVendor_F_ResponseDataChild {
get_total_size(&self) -> usize15004     fn get_total_size(&self) -> usize {
15005         match self {
15006             UciVendor_F_ResponseDataChild::Payload(p) => p.len(),
15007             UciVendor_F_ResponseDataChild::None => 0,
15008         }
15009     }
15010 }
15011 #[derive(Debug)]
15012 pub enum UciVendor_F_ResponseChild {
15013     Payload(Bytes),
15014     None,
15015 }
15016 #[derive(Debug)]
15017 struct UciVendor_F_ResponseData {
15018     child: UciVendor_F_ResponseDataChild,
15019 }
15020 #[derive(Debug, Clone)]
15021 pub struct UciVendor_F_ResponsePacket {
15022     uci_packet: Arc<UciPacketData>,
15023     uci_response: Arc<UciResponseData>,
15024     uci_vendor__f__response: Arc<UciVendor_F_ResponseData>,
15025 }
15026 #[derive(Debug)]
15027 pub struct UciVendor_F_ResponseBuilder {
15028     pub opcode: u8,
15029     pub payload: Option<Bytes>,
15030 }
15031 impl UciVendor_F_ResponseData {
conforms(bytes: &[u8]) -> bool15032     fn conforms(bytes: &[u8]) -> bool {
15033         if bytes.len() < 4 {
15034             return false;
15035         }
15036         true
15037     }
parse(bytes: &[u8]) -> Result<Self>15038     fn parse(bytes: &[u8]) -> Result<Self> {
15039         let payload: Vec<u8> = bytes[4..].into();
15040         let child = if payload.len() > 0 {
15041             UciVendor_F_ResponseDataChild::Payload(Bytes::from(payload))
15042         } else {
15043             UciVendor_F_ResponseDataChild::None
15044         };
15045         Ok(Self { child })
15046     }
write_to(&self, buffer: &mut BytesMut)15047     fn write_to(&self, buffer: &mut BytesMut) {
15048         match &self.child {
15049             UciVendor_F_ResponseDataChild::Payload(p) => buffer[4..].copy_from_slice(&p[..]),
15050             UciVendor_F_ResponseDataChild::None => {}
15051         }
15052     }
get_total_size(&self) -> usize15053     fn get_total_size(&self) -> usize {
15054         self.get_size() + self.child.get_total_size()
15055     }
get_size(&self) -> usize15056     fn get_size(&self) -> usize {
15057         let ret = 0;
15058         ret
15059     }
15060 }
15061 impl Packet for UciVendor_F_ResponsePacket {
to_bytes(self) -> Bytes15062     fn to_bytes(self) -> Bytes {
15063         let mut buffer = BytesMut::new();
15064         buffer.resize(self.uci_packet.get_total_size(), 0);
15065         self.uci_packet.write_to(&mut buffer);
15066         buffer.freeze()
15067     }
to_vec(self) -> Vec<u8>15068     fn to_vec(self) -> Vec<u8> {
15069         self.to_bytes().to_vec()
15070     }
15071 }
15072 impl From<UciVendor_F_ResponsePacket> for Bytes {
from(packet: UciVendor_F_ResponsePacket) -> Self15073     fn from(packet: UciVendor_F_ResponsePacket) -> Self {
15074         packet.to_bytes()
15075     }
15076 }
15077 impl From<UciVendor_F_ResponsePacket> for Vec<u8> {
from(packet: UciVendor_F_ResponsePacket) -> Self15078     fn from(packet: UciVendor_F_ResponsePacket) -> Self {
15079         packet.to_vec()
15080     }
15081 }
15082 impl TryFrom<UciPacketPacket> for UciVendor_F_ResponsePacket {
15083     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>15084     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
15085         Self::new(value.uci_packet).map_err(TryFromError)
15086     }
15087 }
15088 impl UciVendor_F_ResponsePacket {
specialize(&self) -> UciVendor_F_ResponseChild15089     pub fn specialize(&self) -> UciVendor_F_ResponseChild {
15090         match &self.uci_vendor__f__response.child {
15091             UciVendor_F_ResponseDataChild::Payload(p) => {
15092                 UciVendor_F_ResponseChild::Payload(p.clone())
15093             }
15094             UciVendor_F_ResponseDataChild::None => UciVendor_F_ResponseChild::None,
15095         }
15096     }
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>15097     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
15098         let uci_packet = root;
15099         let uci_response = match &uci_packet.child {
15100             UciPacketDataChild::UciResponse(value) => (*value).clone(),
15101             _ => return Err("inconsistent state - child was not UciResponse"),
15102         };
15103         let uci_vendor__f__response = match &uci_response.child {
15104             UciResponseDataChild::UciVendor_F_Response(value) => (*value).clone(),
15105             _ => return Err("inconsistent state - child was not UciVendor_F_Response"),
15106         };
15107         Ok(Self {
15108             uci_packet,
15109             uci_response,
15110             uci_vendor__f__response,
15111         })
15112     }
get_group_id(&self) -> GroupId15113     pub fn get_group_id(&self) -> GroupId {
15114         self.uci_packet.as_ref().group_id
15115     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag15116     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
15117         self.uci_packet.as_ref().packet_boundary_flag
15118     }
get_message_type(&self) -> MessageType15119     pub fn get_message_type(&self) -> MessageType {
15120         self.uci_packet.as_ref().message_type
15121     }
get_opcode(&self) -> u815122     pub fn get_opcode(&self) -> u8 {
15123         self.uci_packet.as_ref().opcode
15124     }
15125 }
15126 impl Into<UciPacketPacket> for UciVendor_F_ResponsePacket {
into(self) -> UciPacketPacket15127     fn into(self) -> UciPacketPacket {
15128         UciPacketPacket::new(self.uci_packet).unwrap()
15129     }
15130 }
15131 impl Into<UciResponsePacket> for UciVendor_F_ResponsePacket {
into(self) -> UciResponsePacket15132     fn into(self) -> UciResponsePacket {
15133         UciResponsePacket::new(self.uci_packet).unwrap()
15134     }
15135 }
15136 impl UciVendor_F_ResponseBuilder {
build(self) -> UciVendor_F_ResponsePacket15137     pub fn build(self) -> UciVendor_F_ResponsePacket {
15138         let uci_vendor__f__response = Arc::new(UciVendor_F_ResponseData {
15139             child: match self.payload {
15140                 None => UciVendor_F_ResponseDataChild::None,
15141                 Some(bytes) => UciVendor_F_ResponseDataChild::Payload(bytes),
15142             },
15143         });
15144         let uci_response = Arc::new(UciResponseData {
15145             child: UciResponseDataChild::UciVendor_F_Response(uci_vendor__f__response),
15146         });
15147         let uci_packet = Arc::new(UciPacketData {
15148             group_id: GroupId::VendorReservedF,
15149             packet_boundary_flag: PacketBoundaryFlag::Complete,
15150             message_type: MessageType::Response,
15151             opcode: self.opcode,
15152             child: UciPacketDataChild::UciResponse(uci_response),
15153         });
15154         UciVendor_F_ResponsePacket::new(uci_packet).unwrap()
15155     }
15156 }
15157 impl Into<UciPacketPacket> for UciVendor_F_ResponseBuilder {
into(self) -> UciPacketPacket15158     fn into(self) -> UciPacketPacket {
15159         self.build().into()
15160     }
15161 }
15162 impl Into<UciResponsePacket> for UciVendor_F_ResponseBuilder {
into(self) -> UciResponsePacket15163     fn into(self) -> UciResponsePacket {
15164         self.build().into()
15165     }
15166 }
15167 
15168 #[derive(Debug)]
15169 enum UciVendor_A_NotificationDataChild {
15170     Payload(Bytes),
15171     None,
15172 }
15173 impl UciVendor_A_NotificationDataChild {
get_total_size(&self) -> usize15174     fn get_total_size(&self) -> usize {
15175         match self {
15176             UciVendor_A_NotificationDataChild::Payload(p) => p.len(),
15177             UciVendor_A_NotificationDataChild::None => 0,
15178         }
15179     }
15180 }
15181 #[derive(Debug)]
15182 pub enum UciVendor_A_NotificationChild {
15183     Payload(Bytes),
15184     None,
15185 }
15186 #[derive(Debug)]
15187 struct UciVendor_A_NotificationData {
15188     child: UciVendor_A_NotificationDataChild,
15189 }
15190 #[derive(Debug, Clone)]
15191 pub struct UciVendor_A_NotificationPacket {
15192     uci_packet: Arc<UciPacketData>,
15193     uci_notification: Arc<UciNotificationData>,
15194     uci_vendor__a__notification: Arc<UciVendor_A_NotificationData>,
15195 }
15196 #[derive(Debug)]
15197 pub struct UciVendor_A_NotificationBuilder {
15198     pub opcode: u8,
15199     pub payload: Option<Bytes>,
15200 }
15201 impl UciVendor_A_NotificationData {
conforms(bytes: &[u8]) -> bool15202     fn conforms(bytes: &[u8]) -> bool {
15203         if bytes.len() < 4 {
15204             return false;
15205         }
15206         true
15207     }
parse(bytes: &[u8]) -> Result<Self>15208     fn parse(bytes: &[u8]) -> Result<Self> {
15209         let payload: Vec<u8> = bytes[4..].into();
15210         let child = if payload.len() > 0 {
15211             UciVendor_A_NotificationDataChild::Payload(Bytes::from(payload))
15212         } else {
15213             UciVendor_A_NotificationDataChild::None
15214         };
15215         Ok(Self { child })
15216     }
write_to(&self, buffer: &mut BytesMut)15217     fn write_to(&self, buffer: &mut BytesMut) {
15218         match &self.child {
15219             UciVendor_A_NotificationDataChild::Payload(p) => buffer[4..].copy_from_slice(&p[..]),
15220             UciVendor_A_NotificationDataChild::None => {}
15221         }
15222     }
get_total_size(&self) -> usize15223     fn get_total_size(&self) -> usize {
15224         self.get_size() + self.child.get_total_size()
15225     }
get_size(&self) -> usize15226     fn get_size(&self) -> usize {
15227         let ret = 0;
15228         ret
15229     }
15230 }
15231 impl Packet for UciVendor_A_NotificationPacket {
to_bytes(self) -> Bytes15232     fn to_bytes(self) -> Bytes {
15233         let mut buffer = BytesMut::new();
15234         buffer.resize(self.uci_packet.get_total_size(), 0);
15235         self.uci_packet.write_to(&mut buffer);
15236         buffer.freeze()
15237     }
to_vec(self) -> Vec<u8>15238     fn to_vec(self) -> Vec<u8> {
15239         self.to_bytes().to_vec()
15240     }
15241 }
15242 impl From<UciVendor_A_NotificationPacket> for Bytes {
from(packet: UciVendor_A_NotificationPacket) -> Self15243     fn from(packet: UciVendor_A_NotificationPacket) -> Self {
15244         packet.to_bytes()
15245     }
15246 }
15247 impl From<UciVendor_A_NotificationPacket> for Vec<u8> {
from(packet: UciVendor_A_NotificationPacket) -> Self15248     fn from(packet: UciVendor_A_NotificationPacket) -> Self {
15249         packet.to_vec()
15250     }
15251 }
15252 impl TryFrom<UciPacketPacket> for UciVendor_A_NotificationPacket {
15253     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>15254     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
15255         Self::new(value.uci_packet).map_err(TryFromError)
15256     }
15257 }
15258 impl UciVendor_A_NotificationPacket {
specialize(&self) -> UciVendor_A_NotificationChild15259     pub fn specialize(&self) -> UciVendor_A_NotificationChild {
15260         match &self.uci_vendor__a__notification.child {
15261             UciVendor_A_NotificationDataChild::Payload(p) => {
15262                 UciVendor_A_NotificationChild::Payload(p.clone())
15263             }
15264             UciVendor_A_NotificationDataChild::None => UciVendor_A_NotificationChild::None,
15265         }
15266     }
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>15267     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
15268         let uci_packet = root;
15269         let uci_notification = match &uci_packet.child {
15270             UciPacketDataChild::UciNotification(value) => (*value).clone(),
15271             _ => return Err("inconsistent state - child was not UciNotification"),
15272         };
15273         let uci_vendor__a__notification = match &uci_notification.child {
15274             UciNotificationDataChild::UciVendor_A_Notification(value) => (*value).clone(),
15275             _ => return Err("inconsistent state - child was not UciVendor_A_Notification"),
15276         };
15277         Ok(Self {
15278             uci_packet,
15279             uci_notification,
15280             uci_vendor__a__notification,
15281         })
15282     }
get_group_id(&self) -> GroupId15283     pub fn get_group_id(&self) -> GroupId {
15284         self.uci_packet.as_ref().group_id
15285     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag15286     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
15287         self.uci_packet.as_ref().packet_boundary_flag
15288     }
get_message_type(&self) -> MessageType15289     pub fn get_message_type(&self) -> MessageType {
15290         self.uci_packet.as_ref().message_type
15291     }
get_opcode(&self) -> u815292     pub fn get_opcode(&self) -> u8 {
15293         self.uci_packet.as_ref().opcode
15294     }
15295 }
15296 impl Into<UciPacketPacket> for UciVendor_A_NotificationPacket {
into(self) -> UciPacketPacket15297     fn into(self) -> UciPacketPacket {
15298         UciPacketPacket::new(self.uci_packet).unwrap()
15299     }
15300 }
15301 impl Into<UciNotificationPacket> for UciVendor_A_NotificationPacket {
into(self) -> UciNotificationPacket15302     fn into(self) -> UciNotificationPacket {
15303         UciNotificationPacket::new(self.uci_packet).unwrap()
15304     }
15305 }
15306 impl UciVendor_A_NotificationBuilder {
build(self) -> UciVendor_A_NotificationPacket15307     pub fn build(self) -> UciVendor_A_NotificationPacket {
15308         let uci_vendor__a__notification = Arc::new(UciVendor_A_NotificationData {
15309             child: match self.payload {
15310                 None => UciVendor_A_NotificationDataChild::None,
15311                 Some(bytes) => UciVendor_A_NotificationDataChild::Payload(bytes),
15312             },
15313         });
15314         let uci_notification = Arc::new(UciNotificationData {
15315             child: UciNotificationDataChild::UciVendor_A_Notification(uci_vendor__a__notification),
15316         });
15317         let uci_packet = Arc::new(UciPacketData {
15318             group_id: GroupId::VendorReservedA,
15319             packet_boundary_flag: PacketBoundaryFlag::Complete,
15320             message_type: MessageType::Notification,
15321             opcode: self.opcode,
15322             child: UciPacketDataChild::UciNotification(uci_notification),
15323         });
15324         UciVendor_A_NotificationPacket::new(uci_packet).unwrap()
15325     }
15326 }
15327 impl Into<UciPacketPacket> for UciVendor_A_NotificationBuilder {
into(self) -> UciPacketPacket15328     fn into(self) -> UciPacketPacket {
15329         self.build().into()
15330     }
15331 }
15332 impl Into<UciNotificationPacket> for UciVendor_A_NotificationBuilder {
into(self) -> UciNotificationPacket15333     fn into(self) -> UciNotificationPacket {
15334         self.build().into()
15335     }
15336 }
15337 
15338 #[derive(Debug)]
15339 enum UciVendor_B_NotificationDataChild {
15340     Payload(Bytes),
15341     None,
15342 }
15343 impl UciVendor_B_NotificationDataChild {
get_total_size(&self) -> usize15344     fn get_total_size(&self) -> usize {
15345         match self {
15346             UciVendor_B_NotificationDataChild::Payload(p) => p.len(),
15347             UciVendor_B_NotificationDataChild::None => 0,
15348         }
15349     }
15350 }
15351 #[derive(Debug)]
15352 pub enum UciVendor_B_NotificationChild {
15353     Payload(Bytes),
15354     None,
15355 }
15356 #[derive(Debug)]
15357 struct UciVendor_B_NotificationData {
15358     child: UciVendor_B_NotificationDataChild,
15359 }
15360 #[derive(Debug, Clone)]
15361 pub struct UciVendor_B_NotificationPacket {
15362     uci_packet: Arc<UciPacketData>,
15363     uci_notification: Arc<UciNotificationData>,
15364     uci_vendor__b__notification: Arc<UciVendor_B_NotificationData>,
15365 }
15366 #[derive(Debug)]
15367 pub struct UciVendor_B_NotificationBuilder {
15368     pub opcode: u8,
15369     pub payload: Option<Bytes>,
15370 }
15371 impl UciVendor_B_NotificationData {
conforms(bytes: &[u8]) -> bool15372     fn conforms(bytes: &[u8]) -> bool {
15373         if bytes.len() < 4 {
15374             return false;
15375         }
15376         true
15377     }
parse(bytes: &[u8]) -> Result<Self>15378     fn parse(bytes: &[u8]) -> Result<Self> {
15379         let payload: Vec<u8> = bytes[4..].into();
15380         let child = if payload.len() > 0 {
15381             UciVendor_B_NotificationDataChild::Payload(Bytes::from(payload))
15382         } else {
15383             UciVendor_B_NotificationDataChild::None
15384         };
15385         Ok(Self { child })
15386     }
write_to(&self, buffer: &mut BytesMut)15387     fn write_to(&self, buffer: &mut BytesMut) {
15388         match &self.child {
15389             UciVendor_B_NotificationDataChild::Payload(p) => buffer[4..].copy_from_slice(&p[..]),
15390             UciVendor_B_NotificationDataChild::None => {}
15391         }
15392     }
get_total_size(&self) -> usize15393     fn get_total_size(&self) -> usize {
15394         self.get_size() + self.child.get_total_size()
15395     }
get_size(&self) -> usize15396     fn get_size(&self) -> usize {
15397         let ret = 0;
15398         ret
15399     }
15400 }
15401 impl Packet for UciVendor_B_NotificationPacket {
to_bytes(self) -> Bytes15402     fn to_bytes(self) -> Bytes {
15403         let mut buffer = BytesMut::new();
15404         buffer.resize(self.uci_packet.get_total_size(), 0);
15405         self.uci_packet.write_to(&mut buffer);
15406         buffer.freeze()
15407     }
to_vec(self) -> Vec<u8>15408     fn to_vec(self) -> Vec<u8> {
15409         self.to_bytes().to_vec()
15410     }
15411 }
15412 impl From<UciVendor_B_NotificationPacket> for Bytes {
from(packet: UciVendor_B_NotificationPacket) -> Self15413     fn from(packet: UciVendor_B_NotificationPacket) -> Self {
15414         packet.to_bytes()
15415     }
15416 }
15417 impl From<UciVendor_B_NotificationPacket> for Vec<u8> {
from(packet: UciVendor_B_NotificationPacket) -> Self15418     fn from(packet: UciVendor_B_NotificationPacket) -> Self {
15419         packet.to_vec()
15420     }
15421 }
15422 impl TryFrom<UciPacketPacket> for UciVendor_B_NotificationPacket {
15423     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>15424     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
15425         Self::new(value.uci_packet).map_err(TryFromError)
15426     }
15427 }
15428 impl UciVendor_B_NotificationPacket {
specialize(&self) -> UciVendor_B_NotificationChild15429     pub fn specialize(&self) -> UciVendor_B_NotificationChild {
15430         match &self.uci_vendor__b__notification.child {
15431             UciVendor_B_NotificationDataChild::Payload(p) => {
15432                 UciVendor_B_NotificationChild::Payload(p.clone())
15433             }
15434             UciVendor_B_NotificationDataChild::None => UciVendor_B_NotificationChild::None,
15435         }
15436     }
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>15437     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
15438         let uci_packet = root;
15439         let uci_notification = match &uci_packet.child {
15440             UciPacketDataChild::UciNotification(value) => (*value).clone(),
15441             _ => return Err("inconsistent state - child was not UciNotification"),
15442         };
15443         let uci_vendor__b__notification = match &uci_notification.child {
15444             UciNotificationDataChild::UciVendor_B_Notification(value) => (*value).clone(),
15445             _ => return Err("inconsistent state - child was not UciVendor_B_Notification"),
15446         };
15447         Ok(Self {
15448             uci_packet,
15449             uci_notification,
15450             uci_vendor__b__notification,
15451         })
15452     }
get_group_id(&self) -> GroupId15453     pub fn get_group_id(&self) -> GroupId {
15454         self.uci_packet.as_ref().group_id
15455     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag15456     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
15457         self.uci_packet.as_ref().packet_boundary_flag
15458     }
get_message_type(&self) -> MessageType15459     pub fn get_message_type(&self) -> MessageType {
15460         self.uci_packet.as_ref().message_type
15461     }
get_opcode(&self) -> u815462     pub fn get_opcode(&self) -> u8 {
15463         self.uci_packet.as_ref().opcode
15464     }
15465 }
15466 impl Into<UciPacketPacket> for UciVendor_B_NotificationPacket {
into(self) -> UciPacketPacket15467     fn into(self) -> UciPacketPacket {
15468         UciPacketPacket::new(self.uci_packet).unwrap()
15469     }
15470 }
15471 impl Into<UciNotificationPacket> for UciVendor_B_NotificationPacket {
into(self) -> UciNotificationPacket15472     fn into(self) -> UciNotificationPacket {
15473         UciNotificationPacket::new(self.uci_packet).unwrap()
15474     }
15475 }
15476 impl UciVendor_B_NotificationBuilder {
build(self) -> UciVendor_B_NotificationPacket15477     pub fn build(self) -> UciVendor_B_NotificationPacket {
15478         let uci_vendor__b__notification = Arc::new(UciVendor_B_NotificationData {
15479             child: match self.payload {
15480                 None => UciVendor_B_NotificationDataChild::None,
15481                 Some(bytes) => UciVendor_B_NotificationDataChild::Payload(bytes),
15482             },
15483         });
15484         let uci_notification = Arc::new(UciNotificationData {
15485             child: UciNotificationDataChild::UciVendor_B_Notification(uci_vendor__b__notification),
15486         });
15487         let uci_packet = Arc::new(UciPacketData {
15488             group_id: GroupId::VendorReservedB,
15489             packet_boundary_flag: PacketBoundaryFlag::Complete,
15490             message_type: MessageType::Notification,
15491             opcode: self.opcode,
15492             child: UciPacketDataChild::UciNotification(uci_notification),
15493         });
15494         UciVendor_B_NotificationPacket::new(uci_packet).unwrap()
15495     }
15496 }
15497 impl Into<UciPacketPacket> for UciVendor_B_NotificationBuilder {
into(self) -> UciPacketPacket15498     fn into(self) -> UciPacketPacket {
15499         self.build().into()
15500     }
15501 }
15502 impl Into<UciNotificationPacket> for UciVendor_B_NotificationBuilder {
into(self) -> UciNotificationPacket15503     fn into(self) -> UciNotificationPacket {
15504         self.build().into()
15505     }
15506 }
15507 
15508 #[derive(Debug)]
15509 enum UciVendor_E_NotificationDataChild {
15510     Payload(Bytes),
15511     None,
15512 }
15513 impl UciVendor_E_NotificationDataChild {
get_total_size(&self) -> usize15514     fn get_total_size(&self) -> usize {
15515         match self {
15516             UciVendor_E_NotificationDataChild::Payload(p) => p.len(),
15517             UciVendor_E_NotificationDataChild::None => 0,
15518         }
15519     }
15520 }
15521 #[derive(Debug)]
15522 pub enum UciVendor_E_NotificationChild {
15523     Payload(Bytes),
15524     None,
15525 }
15526 #[derive(Debug)]
15527 struct UciVendor_E_NotificationData {
15528     child: UciVendor_E_NotificationDataChild,
15529 }
15530 #[derive(Debug, Clone)]
15531 pub struct UciVendor_E_NotificationPacket {
15532     uci_packet: Arc<UciPacketData>,
15533     uci_notification: Arc<UciNotificationData>,
15534     uci_vendor__e__notification: Arc<UciVendor_E_NotificationData>,
15535 }
15536 #[derive(Debug)]
15537 pub struct UciVendor_E_NotificationBuilder {
15538     pub opcode: u8,
15539     pub payload: Option<Bytes>,
15540 }
15541 impl UciVendor_E_NotificationData {
conforms(bytes: &[u8]) -> bool15542     fn conforms(bytes: &[u8]) -> bool {
15543         if bytes.len() < 4 {
15544             return false;
15545         }
15546         true
15547     }
parse(bytes: &[u8]) -> Result<Self>15548     fn parse(bytes: &[u8]) -> Result<Self> {
15549         let payload: Vec<u8> = bytes[4..].into();
15550         let child = if payload.len() > 0 {
15551             UciVendor_E_NotificationDataChild::Payload(Bytes::from(payload))
15552         } else {
15553             UciVendor_E_NotificationDataChild::None
15554         };
15555         Ok(Self { child })
15556     }
write_to(&self, buffer: &mut BytesMut)15557     fn write_to(&self, buffer: &mut BytesMut) {
15558         match &self.child {
15559             UciVendor_E_NotificationDataChild::Payload(p) => buffer[4..].copy_from_slice(&p[..]),
15560             UciVendor_E_NotificationDataChild::None => {}
15561         }
15562     }
get_total_size(&self) -> usize15563     fn get_total_size(&self) -> usize {
15564         self.get_size() + self.child.get_total_size()
15565     }
get_size(&self) -> usize15566     fn get_size(&self) -> usize {
15567         let ret = 0;
15568         ret
15569     }
15570 }
15571 impl Packet for UciVendor_E_NotificationPacket {
to_bytes(self) -> Bytes15572     fn to_bytes(self) -> Bytes {
15573         let mut buffer = BytesMut::new();
15574         buffer.resize(self.uci_packet.get_total_size(), 0);
15575         self.uci_packet.write_to(&mut buffer);
15576         buffer.freeze()
15577     }
to_vec(self) -> Vec<u8>15578     fn to_vec(self) -> Vec<u8> {
15579         self.to_bytes().to_vec()
15580     }
15581 }
15582 impl From<UciVendor_E_NotificationPacket> for Bytes {
from(packet: UciVendor_E_NotificationPacket) -> Self15583     fn from(packet: UciVendor_E_NotificationPacket) -> Self {
15584         packet.to_bytes()
15585     }
15586 }
15587 impl From<UciVendor_E_NotificationPacket> for Vec<u8> {
from(packet: UciVendor_E_NotificationPacket) -> Self15588     fn from(packet: UciVendor_E_NotificationPacket) -> Self {
15589         packet.to_vec()
15590     }
15591 }
15592 impl TryFrom<UciPacketPacket> for UciVendor_E_NotificationPacket {
15593     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>15594     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
15595         Self::new(value.uci_packet).map_err(TryFromError)
15596     }
15597 }
15598 impl UciVendor_E_NotificationPacket {
specialize(&self) -> UciVendor_E_NotificationChild15599     pub fn specialize(&self) -> UciVendor_E_NotificationChild {
15600         match &self.uci_vendor__e__notification.child {
15601             UciVendor_E_NotificationDataChild::Payload(p) => {
15602                 UciVendor_E_NotificationChild::Payload(p.clone())
15603             }
15604             UciVendor_E_NotificationDataChild::None => UciVendor_E_NotificationChild::None,
15605         }
15606     }
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>15607     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
15608         let uci_packet = root;
15609         let uci_notification = match &uci_packet.child {
15610             UciPacketDataChild::UciNotification(value) => (*value).clone(),
15611             _ => return Err("inconsistent state - child was not UciNotification"),
15612         };
15613         let uci_vendor__e__notification = match &uci_notification.child {
15614             UciNotificationDataChild::UciVendor_E_Notification(value) => (*value).clone(),
15615             _ => return Err("inconsistent state - child was not UciVendor_E_Notification"),
15616         };
15617         Ok(Self {
15618             uci_packet,
15619             uci_notification,
15620             uci_vendor__e__notification,
15621         })
15622     }
get_group_id(&self) -> GroupId15623     pub fn get_group_id(&self) -> GroupId {
15624         self.uci_packet.as_ref().group_id
15625     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag15626     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
15627         self.uci_packet.as_ref().packet_boundary_flag
15628     }
get_message_type(&self) -> MessageType15629     pub fn get_message_type(&self) -> MessageType {
15630         self.uci_packet.as_ref().message_type
15631     }
get_opcode(&self) -> u815632     pub fn get_opcode(&self) -> u8 {
15633         self.uci_packet.as_ref().opcode
15634     }
15635 }
15636 impl Into<UciPacketPacket> for UciVendor_E_NotificationPacket {
into(self) -> UciPacketPacket15637     fn into(self) -> UciPacketPacket {
15638         UciPacketPacket::new(self.uci_packet).unwrap()
15639     }
15640 }
15641 impl Into<UciNotificationPacket> for UciVendor_E_NotificationPacket {
into(self) -> UciNotificationPacket15642     fn into(self) -> UciNotificationPacket {
15643         UciNotificationPacket::new(self.uci_packet).unwrap()
15644     }
15645 }
15646 impl UciVendor_E_NotificationBuilder {
build(self) -> UciVendor_E_NotificationPacket15647     pub fn build(self) -> UciVendor_E_NotificationPacket {
15648         let uci_vendor__e__notification = Arc::new(UciVendor_E_NotificationData {
15649             child: match self.payload {
15650                 None => UciVendor_E_NotificationDataChild::None,
15651                 Some(bytes) => UciVendor_E_NotificationDataChild::Payload(bytes),
15652             },
15653         });
15654         let uci_notification = Arc::new(UciNotificationData {
15655             child: UciNotificationDataChild::UciVendor_E_Notification(uci_vendor__e__notification),
15656         });
15657         let uci_packet = Arc::new(UciPacketData {
15658             group_id: GroupId::VendorReservedE,
15659             packet_boundary_flag: PacketBoundaryFlag::Complete,
15660             message_type: MessageType::Notification,
15661             opcode: self.opcode,
15662             child: UciPacketDataChild::UciNotification(uci_notification),
15663         });
15664         UciVendor_E_NotificationPacket::new(uci_packet).unwrap()
15665     }
15666 }
15667 impl Into<UciPacketPacket> for UciVendor_E_NotificationBuilder {
into(self) -> UciPacketPacket15668     fn into(self) -> UciPacketPacket {
15669         self.build().into()
15670     }
15671 }
15672 impl Into<UciNotificationPacket> for UciVendor_E_NotificationBuilder {
into(self) -> UciNotificationPacket15673     fn into(self) -> UciNotificationPacket {
15674         self.build().into()
15675     }
15676 }
15677 
15678 #[derive(Debug)]
15679 enum UciVendor_F_NotificationDataChild {
15680     Payload(Bytes),
15681     None,
15682 }
15683 impl UciVendor_F_NotificationDataChild {
get_total_size(&self) -> usize15684     fn get_total_size(&self) -> usize {
15685         match self {
15686             UciVendor_F_NotificationDataChild::Payload(p) => p.len(),
15687             UciVendor_F_NotificationDataChild::None => 0,
15688         }
15689     }
15690 }
15691 #[derive(Debug)]
15692 pub enum UciVendor_F_NotificationChild {
15693     Payload(Bytes),
15694     None,
15695 }
15696 #[derive(Debug)]
15697 struct UciVendor_F_NotificationData {
15698     child: UciVendor_F_NotificationDataChild,
15699 }
15700 #[derive(Debug, Clone)]
15701 pub struct UciVendor_F_NotificationPacket {
15702     uci_packet: Arc<UciPacketData>,
15703     uci_notification: Arc<UciNotificationData>,
15704     uci_vendor__f__notification: Arc<UciVendor_F_NotificationData>,
15705 }
15706 #[derive(Debug)]
15707 pub struct UciVendor_F_NotificationBuilder {
15708     pub opcode: u8,
15709     pub payload: Option<Bytes>,
15710 }
15711 impl UciVendor_F_NotificationData {
conforms(bytes: &[u8]) -> bool15712     fn conforms(bytes: &[u8]) -> bool {
15713         if bytes.len() < 4 {
15714             return false;
15715         }
15716         true
15717     }
parse(bytes: &[u8]) -> Result<Self>15718     fn parse(bytes: &[u8]) -> Result<Self> {
15719         let payload: Vec<u8> = bytes[4..].into();
15720         let child = if payload.len() > 0 {
15721             UciVendor_F_NotificationDataChild::Payload(Bytes::from(payload))
15722         } else {
15723             UciVendor_F_NotificationDataChild::None
15724         };
15725         Ok(Self { child })
15726     }
write_to(&self, buffer: &mut BytesMut)15727     fn write_to(&self, buffer: &mut BytesMut) {
15728         match &self.child {
15729             UciVendor_F_NotificationDataChild::Payload(p) => buffer[4..].copy_from_slice(&p[..]),
15730             UciVendor_F_NotificationDataChild::None => {}
15731         }
15732     }
get_total_size(&self) -> usize15733     fn get_total_size(&self) -> usize {
15734         self.get_size() + self.child.get_total_size()
15735     }
get_size(&self) -> usize15736     fn get_size(&self) -> usize {
15737         let ret = 0;
15738         ret
15739     }
15740 }
15741 impl Packet for UciVendor_F_NotificationPacket {
to_bytes(self) -> Bytes15742     fn to_bytes(self) -> Bytes {
15743         let mut buffer = BytesMut::new();
15744         buffer.resize(self.uci_packet.get_total_size(), 0);
15745         self.uci_packet.write_to(&mut buffer);
15746         buffer.freeze()
15747     }
to_vec(self) -> Vec<u8>15748     fn to_vec(self) -> Vec<u8> {
15749         self.to_bytes().to_vec()
15750     }
15751 }
15752 impl From<UciVendor_F_NotificationPacket> for Bytes {
from(packet: UciVendor_F_NotificationPacket) -> Self15753     fn from(packet: UciVendor_F_NotificationPacket) -> Self {
15754         packet.to_bytes()
15755     }
15756 }
15757 impl From<UciVendor_F_NotificationPacket> for Vec<u8> {
from(packet: UciVendor_F_NotificationPacket) -> Self15758     fn from(packet: UciVendor_F_NotificationPacket) -> Self {
15759         packet.to_vec()
15760     }
15761 }
15762 impl TryFrom<UciPacketPacket> for UciVendor_F_NotificationPacket {
15763     type Error = TryFromError;
try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error>15764     fn try_from(value: UciPacketPacket) -> std::result::Result<Self, Self::Error> {
15765         Self::new(value.uci_packet).map_err(TryFromError)
15766     }
15767 }
15768 impl UciVendor_F_NotificationPacket {
specialize(&self) -> UciVendor_F_NotificationChild15769     pub fn specialize(&self) -> UciVendor_F_NotificationChild {
15770         match &self.uci_vendor__f__notification.child {
15771             UciVendor_F_NotificationDataChild::Payload(p) => {
15772                 UciVendor_F_NotificationChild::Payload(p.clone())
15773             }
15774             UciVendor_F_NotificationDataChild::None => UciVendor_F_NotificationChild::None,
15775         }
15776     }
new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str>15777     fn new(root: Arc<UciPacketData>) -> std::result::Result<Self, &'static str> {
15778         let uci_packet = root;
15779         let uci_notification = match &uci_packet.child {
15780             UciPacketDataChild::UciNotification(value) => (*value).clone(),
15781             _ => return Err("inconsistent state - child was not UciNotification"),
15782         };
15783         let uci_vendor__f__notification = match &uci_notification.child {
15784             UciNotificationDataChild::UciVendor_F_Notification(value) => (*value).clone(),
15785             _ => return Err("inconsistent state - child was not UciVendor_F_Notification"),
15786         };
15787         Ok(Self {
15788             uci_packet,
15789             uci_notification,
15790             uci_vendor__f__notification,
15791         })
15792     }
get_group_id(&self) -> GroupId15793     pub fn get_group_id(&self) -> GroupId {
15794         self.uci_packet.as_ref().group_id
15795     }
get_packet_boundary_flag(&self) -> PacketBoundaryFlag15796     pub fn get_packet_boundary_flag(&self) -> PacketBoundaryFlag {
15797         self.uci_packet.as_ref().packet_boundary_flag
15798     }
get_message_type(&self) -> MessageType15799     pub fn get_message_type(&self) -> MessageType {
15800         self.uci_packet.as_ref().message_type
15801     }
get_opcode(&self) -> u815802     pub fn get_opcode(&self) -> u8 {
15803         self.uci_packet.as_ref().opcode
15804     }
15805 }
15806 impl Into<UciPacketPacket> for UciVendor_F_NotificationPacket {
into(self) -> UciPacketPacket15807     fn into(self) -> UciPacketPacket {
15808         UciPacketPacket::new(self.uci_packet).unwrap()
15809     }
15810 }
15811 impl Into<UciNotificationPacket> for UciVendor_F_NotificationPacket {
into(self) -> UciNotificationPacket15812     fn into(self) -> UciNotificationPacket {
15813         UciNotificationPacket::new(self.uci_packet).unwrap()
15814     }
15815 }
15816 impl UciVendor_F_NotificationBuilder {
build(self) -> UciVendor_F_NotificationPacket15817     pub fn build(self) -> UciVendor_F_NotificationPacket {
15818         let uci_vendor__f__notification = Arc::new(UciVendor_F_NotificationData {
15819             child: match self.payload {
15820                 None => UciVendor_F_NotificationDataChild::None,
15821                 Some(bytes) => UciVendor_F_NotificationDataChild::Payload(bytes),
15822             },
15823         });
15824         let uci_notification = Arc::new(UciNotificationData {
15825             child: UciNotificationDataChild::UciVendor_F_Notification(uci_vendor__f__notification),
15826         });
15827         let uci_packet = Arc::new(UciPacketData {
15828             group_id: GroupId::VendorReservedF,
15829             packet_boundary_flag: PacketBoundaryFlag::Complete,
15830             message_type: MessageType::Notification,
15831             opcode: self.opcode,
15832             child: UciPacketDataChild::UciNotification(uci_notification),
15833         });
15834         UciVendor_F_NotificationPacket::new(uci_packet).unwrap()
15835     }
15836 }
15837 impl Into<UciPacketPacket> for UciVendor_F_NotificationBuilder {
into(self) -> UciPacketPacket15838     fn into(self) -> UciPacketPacket {
15839         self.build().into()
15840     }
15841 }
15842 impl Into<UciNotificationPacket> for UciVendor_F_NotificationBuilder {
into(self) -> UciNotificationPacket15843     fn into(self) -> UciNotificationPacket {
15844         self.build().into()
15845     }
15846 }
15847