open_dis_rust/
simulation_management_with_reliability.rs

1//     open-dis-rust - Rust implementation of the IEEE 1278.1-2012 Distributed Interactive
2//                     Simulation (DIS) application protocol
3//     Copyright (C) 2025 Cameron Howell
4//
5//     Licensed under the BSD 2-Clause License
6
7//! The Simulation Management with Reliability (SIMAN-R) protocol family
8
9use crate::{
10    common::{
11        GenericHeader, SerializedLength,
12        data_types::{
13            ClockTime,
14            datum_records::{FixedDatumRecord, VariableDatumRecord},
15            entity_id::EntityId,
16            record_specification::RecordSpecification,
17        },
18        enums::{
19            AcknowledgeFlag, AcknowledgeResponseFlag, ActionResponseRequestStatus, EventType,
20            FrozenBehavior, PduType, ProtocolFamily, Reason, RecordQueryREventType,
21            RequiredReliabilityService, VariableRecordTypes,
22        },
23        pdu::Pdu,
24        pdu_header::PduHeader,
25    },
26    define_pdu,
27};
28
29define_pdu! {
30    #[derive(Debug)]
31    /// Implemented according to IEEE 1278.1-2012 §7.11.2
32    pub struct CreateEntityReliablePdu {
33        header: PduHeader,
34        pdu_type: PduType::CreateEntityReliable,
35        protocol_family: ProtocolFamily::SimulationManagementWithReliability,
36        fields: {
37            pub originating_entity_id: EntityId,
38            pub receiving_entity_id: EntityId,
39            pub required_reliability_service: RequiredReliabilityService,
40            padding: u8,
41            padding2: u16,
42            pub request_id: u32,
43        }
44    }
45}
46
47define_pdu! {
48    #[derive(Debug)]
49    /// Implemented according to IEEE 1278.1-2012 §7.11.3
50    pub struct RemoveEntityReliablePdu {
51        header: PduHeader,
52        pdu_type: PduType::RemoveEntityReliable,
53        protocol_family: ProtocolFamily::SimulationManagementWithReliability,
54        fields: {
55            pub originating_entity_id: EntityId,
56            pub receiving_entity_id: EntityId,
57            pub required_reliability_service: RequiredReliabilityService,
58            padding: u8,
59            padding2: u16,
60            pub request_id: u32,
61        }
62    }
63}
64
65define_pdu! {
66    #[derive(Debug)]
67    /// Implemented according to IEEE 1278.1-2012 §7.11.4
68    pub struct StartResumeReliablePdu {
69        header: PduHeader,
70        pdu_type: PduType::StartResumeReliable,
71        protocol_family: ProtocolFamily::SimulationManagementWithReliability,
72        fields: {
73            pub originating_entity_id: EntityId,
74            pub receiving_entity_id: EntityId,
75            pub real_world_time: ClockTime,
76            pub simulation_time: ClockTime,
77            pub required_reliability_service: RequiredReliabilityService,
78            padding: u8,
79            padding2: u16,
80            pub request_id: u32,
81        }
82    }
83}
84
85define_pdu! {
86    #[derive(Debug)]
87    /// Implemented according to IEEE 1278.1-2012 §7.11.5
88    pub struct StopFreezeReliablePdu {
89        header: PduHeader,
90        pdu_type: PduType::StopFreezeReliable,
91        protocol_family: ProtocolFamily::SimulationManagementWithReliability,
92        fields: {
93            pub originating_entity_id: EntityId,
94            pub receiving_entity_id: EntityId,
95            pub real_world_time: ClockTime,
96            pub reason: Reason,
97            pub frozen_behavior: FrozenBehavior,
98            pub required_reliability_service: u8,
99            padding: u8,
100            pub request_id: u32,
101        }
102    }
103}
104
105define_pdu! {
106    #[derive(Debug)]
107    /// Implemented according to IEEE 1278.1-2012 §7.11.6
108    pub struct AcknowledgeReliablePdu {
109        header: PduHeader,
110        pdu_type: PduType::AcknowledgeReliable,
111        protocol_family: ProtocolFamily::SimulationManagementWithReliability,
112        fields: {
113            pub originating_entity_id: EntityId,
114            pub receiving_entity_id: EntityId,
115            pub acknowledge_flag: AcknowledgeFlag,
116            pub response_flag: AcknowledgeResponseFlag,
117            pub request_id: u32,
118        }
119    }
120}
121
122define_pdu! {
123    #[derive(Debug)]
124    /// Implemented according to IEEE 1278.1-2012 §7.11.7
125    pub struct ActionRequestReliablePdu {
126        header: PduHeader,
127        pdu_type: PduType::ActionRequestReliable,
128        protocol_family: ProtocolFamily::SimulationManagementWithReliability,
129        fields: {
130            pub originating_entity_id: EntityId,
131            pub receiving_entity_id: EntityId,
132            pub required_reliability_service: RequiredReliabilityService,
133            padding: u8,
134            padding2: u16,
135            pub request_id: u32,
136            pub action_id: u32,
137            padding3: u32,
138            pub number_of_fixed_datum_records: u32,
139            pub number_of_variable_datum_records: u32,
140            pub fixed_datum_records: Vec<FixedDatumRecord>,
141            pub variable_datum_records: Vec<VariableDatumRecord>,
142        }
143    }
144}
145
146define_pdu! {
147    #[derive(Debug)]
148    /// Implemented according to IEEE 1278.1-2012 §7.11.8
149    pub struct ActionResponseReliablePdu {
150        header: PduHeader,
151        pdu_type: PduType::ActionResponseReliable,
152        protocol_family: ProtocolFamily::SimulationManagementWithReliability,
153        fields: {
154            pub originating_entity_id: EntityId,
155            pub receiving_entity_id: EntityId,
156            pub request_id: u32,
157            pub request_status: ActionResponseRequestStatus,
158            pub number_of_fixed_datum_records: u32,
159            pub number_of_variable_datum_records: u32,
160            pub fixed_datum_records: Vec<FixedDatumRecord>,
161            pub variable_datum_records: Vec<VariableDatumRecord>,
162        }
163    }
164}
165
166define_pdu! {
167    #[derive(Debug)]
168    /// Implemented according to IEEE 1278.1-2012 §7.11.9
169    pub struct DataQueryReliablePdu {
170        header: PduHeader,
171        pdu_type: PduType::DataQueryReliable,
172        protocol_family: ProtocolFamily::SimulationManagementWithReliability,
173        fields: {
174            pub originating_entity_id: EntityId,
175            pub receiving_entity_id: EntityId,
176            pub required_reliability_service: RequiredReliabilityService,
177            padding: u8,
178            padding2: u16,
179            pub request_id: u32,
180            pub time_interval: u32,
181            pub number_of_fixed_datum_records: u32,
182            pub number_of_variable_datum_records: u32,
183            pub fixed_datum_ids: Vec<VariableRecordTypes>,
184            pub variable_datum_ids: Vec<VariableRecordTypes>,
185        }
186    }
187}
188
189define_pdu! {
190    #[derive(Debug)]
191    /// Implemented according to IEEE 1278.1-2012 §7.11.10
192    pub struct SetDataReliablePdu {
193        header: PduHeader,
194        pdu_type: PduType::SetDataReliable,
195        protocol_family: ProtocolFamily::SimulationManagementWithReliability,
196        fields: {
197            pub originating_entity_id: EntityId,
198            pub receiving_entity_id: EntityId,
199            pub required_reliability_service: RequiredReliabilityService,
200            padding: u8,
201            padding2: u16,
202            pub request_id: u32,
203            pub number_of_fixed_datum_records: u32,
204            pub number_of_variable_datum_records: u32,
205            pub fixed_datum_records: Vec<FixedDatumRecord>,
206            pub variable_datum_records: Vec<VariableDatumRecord>,
207        }
208    }
209}
210
211define_pdu! {
212    #[derive(Debug)]
213    /// Implemented according to IEEE 1278.1-2012 §7.11.11
214    pub struct DataReliablePdu {
215        header: PduHeader,
216        pdu_type: PduType::DataReliable,
217        protocol_family: ProtocolFamily::SimulationManagementWithReliability,
218        fields: {
219            pub originating_entity_id: EntityId,
220            pub receiving_entity_id: EntityId,
221            pub request_id: u32,
222            pub required_reliability_service: RequiredReliabilityService,
223            padding: u8,
224            padding2: u16,
225            pub number_of_fixed_datum_records: u32,
226            pub number_of_variable_datum_records: u32,
227            pub fixed_datum_records: Vec<FixedDatumRecord>,
228            pub variable_datum_records: Vec<VariableDatumRecord>,
229        }
230    }
231}
232
233define_pdu! {
234    #[derive(Debug)]
235    /// Implemented according to IEEE 1278.1-2012 §7.11.12
236    pub struct EventReportReliablePdu {
237        header: PduHeader,
238        pdu_type: PduType::EventReportReliable,
239        protocol_family: ProtocolFamily::SimulationManagementWithReliability,
240        fields: {
241            pub originating_entity_id: EntityId,
242            pub receiving_entity_id: EntityId,
243            pub event_type: EventType,
244            padding: u32,
245            pub number_of_fixed_datum_records: u32,
246            pub number_of_variable_datum_records: u32,
247            pub fixed_datum_records: Vec<FixedDatumRecord>,
248            pub variable_datum_records: Vec<VariableDatumRecord>,
249        }
250    }
251}
252
253define_pdu! {
254    #[derive(Debug)]
255    /// Implemented according to IEEE 1278.1-2012 §7.11.13
256    pub struct CommentReliablePdu {
257        header: PduHeader,
258        pdu_type: PduType::CommentReliable,
259        protocol_family: ProtocolFamily::SimulationManagementWithReliability,
260        fields: {
261            pub originating_entity_id: EntityId,
262            pub receiving_entity_id: EntityId,
263            pub number_of_fixed_datum_records: u32,
264            pub number_of_variable_datum_records: u32,
265            pub fixed_datum_records: Vec<FixedDatumRecord>,
266            pub variable_datum_records: Vec<VariableDatumRecord>,
267        }
268    }
269}
270
271define_pdu! {
272    #[derive(Debug)]
273    /// Implemented according to IEEE 1278.1-2012 §7.11.14
274    pub struct RecordQueryReliablePdu {
275        header: PduHeader,
276        pdu_type: PduType::RecordQueryReliable,
277        protocol_family: ProtocolFamily::SimulationManagementWithReliability,
278        fields: {
279            pub originating_entity_id: EntityId,
280            pub receiving_entity_id: EntityId,
281            pub request_id: u32,
282            pub required_reliability_service: RequiredReliabilityService,
283            padding: u8,
284            pub event_type: RecordQueryREventType,
285            pub time: u32,
286            pub number_of_records: u32,
287            pub record_ids: Vec<u32>,
288        }
289    }
290}
291
292define_pdu! {
293    #[derive(Debug)]
294    /// Implemented according to IEEE 1278.1-2012 §7.11.15
295    pub struct SetRecordReliablePdu {
296        header: PduHeader,
297        pdu_type: PduType::SetRecordReliable,
298        protocol_family: ProtocolFamily::SimulationManagementWithReliability,
299        fields: {
300            pub originating_entity_id: EntityId,
301            pub receiving_entity_id: EntityId,
302            pub request_id: u32,
303            pub required_reliability_service: RequiredReliabilityService,
304            padding: u8,
305            padding2: u16,
306            padding3: u32,
307            pub record_sets: RecordSpecification,
308        }
309    }
310}
311
312#[cfg(test)]
313mod tests {
314    use super::*;
315    use crate::common::{constants::BITS_PER_BYTE, pdu::Pdu};
316    use bytes::BytesMut;
317
318    mod create_entity_reliable_pdu_tests {
319        use super::*;
320
321        #[test]
322        fn cast_to_any() {
323            let pdu = CreateEntityReliablePdu::new();
324            let any_pdu = pdu.as_any();
325
326            assert!(any_pdu.is::<CreateEntityReliablePdu>());
327        }
328
329        #[test]
330        fn serialize_then_deserialize() {
331            let mut pdu = CreateEntityReliablePdu::new();
332            let mut serialize_buf = BytesMut::new();
333            let _ = pdu.serialize(&mut serialize_buf);
334
335            let mut deserialize_buf = serialize_buf.freeze();
336            let new_pdu =
337                CreateEntityReliablePdu::deserialize(&mut deserialize_buf).unwrap_or_default();
338            assert_eq!(new_pdu.header, pdu.header);
339        }
340
341        #[test]
342        fn check_default_pdu_length() {
343            const DEFAULT_LENGTH: u16 = 256 / BITS_PER_BYTE;
344            let pdu = CreateEntityReliablePdu::new();
345            assert_eq!(pdu.header().length, DEFAULT_LENGTH);
346        }
347    }
348
349    mod remove_entity_reliable_pdu_tests {
350        use super::*;
351
352        #[test]
353        fn cast_to_any() {
354            let pdu = RemoveEntityReliablePdu::new();
355            let any_pdu = pdu.as_any();
356
357            assert!(any_pdu.is::<RemoveEntityReliablePdu>());
358        }
359
360        #[test]
361        fn serialize_then_deserialize() {
362            let mut pdu = RemoveEntityReliablePdu::new();
363            let mut serialize_buf = BytesMut::new();
364            let _ = pdu.serialize(&mut serialize_buf);
365
366            let mut deserialize_buf = serialize_buf.freeze();
367            let new_pdu =
368                RemoveEntityReliablePdu::deserialize(&mut deserialize_buf).unwrap_or_default();
369            assert_eq!(new_pdu.header, pdu.header);
370        }
371
372        #[test]
373        fn check_default_pdu_length() {
374            const DEFAULT_LENGTH: u16 = 256 / BITS_PER_BYTE;
375            let pdu = RemoveEntityReliablePdu::new();
376            assert_eq!(pdu.header().length, DEFAULT_LENGTH);
377        }
378    }
379
380    mod start_resume_reliable_pdu_tests {
381        use super::*;
382
383        #[test]
384        fn cast_to_any() {
385            let pdu = StartResumeReliablePdu::new();
386            let any_pdu = pdu.as_any();
387
388            assert!(any_pdu.is::<StartResumeReliablePdu>());
389        }
390
391        #[test]
392        fn serialize_then_deserialize() {
393            let mut pdu = StartResumeReliablePdu::new();
394            let mut serialize_buf = BytesMut::new();
395            let _ = pdu.serialize(&mut serialize_buf);
396
397            let mut deserialize_buf = serialize_buf.freeze();
398            let new_pdu =
399                StartResumeReliablePdu::deserialize(&mut deserialize_buf).unwrap_or_default();
400            assert_eq!(new_pdu.header, pdu.header);
401        }
402
403        #[test]
404        fn check_default_pdu_length() {
405            const DEFAULT_LENGTH: u16 = 384 / BITS_PER_BYTE;
406            let pdu = StartResumeReliablePdu::new();
407            assert_eq!(pdu.header().length, DEFAULT_LENGTH);
408        }
409    }
410
411    mod stop_freeze_reliable_pdu_tests {
412        use super::*;
413
414        #[test]
415        fn cast_to_any() {
416            let pdu = StopFreezeReliablePdu::new();
417            let any_pdu = pdu.as_any();
418
419            assert!(any_pdu.is::<StopFreezeReliablePdu>());
420        }
421
422        #[test]
423        fn serialize_then_deserialize() {
424            let mut pdu = StopFreezeReliablePdu::new();
425            let mut serialize_buf = BytesMut::new();
426            let _ = pdu.serialize(&mut serialize_buf);
427
428            let mut deserialize_buf = serialize_buf.freeze();
429            let new_pdu =
430                StopFreezeReliablePdu::deserialize(&mut deserialize_buf).unwrap_or_default();
431            assert_eq!(new_pdu.header, pdu.header);
432        }
433
434        #[test]
435        fn check_default_pdu_length() {
436            const DEFAULT_LENGTH: u16 = 320 / BITS_PER_BYTE;
437            let pdu = StopFreezeReliablePdu::new();
438            assert_eq!(pdu.header().length, DEFAULT_LENGTH);
439        }
440    }
441
442    mod acknowledge_reliable_pdu_tests {
443        use super::*;
444        #[test]
445        fn cast_to_any() {
446            let pdu = AcknowledgeReliablePdu::new();
447            let any_pdu = pdu.as_any();
448
449            assert!(any_pdu.is::<AcknowledgeReliablePdu>());
450        }
451
452        #[test]
453        fn serialize_then_deserialize() {
454            let mut pdu = AcknowledgeReliablePdu::new();
455            let mut serialize_buf = BytesMut::new();
456            let _ = pdu.serialize(&mut serialize_buf);
457
458            let mut deserialize_buf = serialize_buf.freeze();
459            let new_pdu =
460                AcknowledgeReliablePdu::deserialize(&mut deserialize_buf).unwrap_or_default();
461            assert_eq!(new_pdu.header, pdu.header);
462        }
463
464        #[test]
465        fn check_default_pdu_length() {
466            const DEFAULT_LENGTH: u16 = 256 / BITS_PER_BYTE;
467            let pdu = AcknowledgeReliablePdu::new();
468            assert_eq!(pdu.header().length, DEFAULT_LENGTH);
469        }
470    }
471
472    mod action_request_reliable_pdu_tests {
473        use super::*;
474
475        #[test]
476        fn cast_to_any() {
477            let pdu = ActionRequestReliablePdu::new();
478            let any_pdu = pdu.as_any();
479
480            assert!(any_pdu.is::<ActionRequestReliablePdu>());
481        }
482
483        #[test]
484        fn serialize_then_deserialize() {
485            let mut pdu = ActionRequestReliablePdu::new();
486            let mut serialize_buf = BytesMut::new();
487            let _ = pdu.serialize(&mut serialize_buf);
488
489            let mut deserialize_buf = serialize_buf.freeze();
490            let new_pdu =
491                ActionRequestReliablePdu::deserialize(&mut deserialize_buf).unwrap_or_default();
492            assert_eq!(new_pdu.header, pdu.header);
493        }
494
495        #[test]
496        fn check_default_pdu_length() {
497            const DEFAULT_LENGTH: u16 = 384 / BITS_PER_BYTE;
498            let pdu = ActionRequestReliablePdu::new();
499            assert_eq!(pdu.header().length, DEFAULT_LENGTH);
500        }
501    }
502
503    mod action_response_reliable_pdu_tests {
504        use super::*;
505
506        #[test]
507        fn cast_to_any() {
508            let pdu = ActionResponseReliablePdu::new();
509            let any_pdu = pdu.as_any();
510
511            assert!(any_pdu.is::<ActionResponseReliablePdu>());
512        }
513
514        #[test]
515        fn serialize_then_deserialize() {
516            let mut pdu = ActionResponseReliablePdu::new();
517            let mut serialize_buf = BytesMut::new();
518            let _ = pdu.serialize(&mut serialize_buf);
519
520            let mut deserialize_buf = serialize_buf.freeze();
521            let new_pdu =
522                ActionResponseReliablePdu::deserialize(&mut deserialize_buf).unwrap_or_default();
523            assert_eq!(new_pdu.header, pdu.header);
524        }
525
526        #[test]
527        fn check_default_pdu_length() {
528            const DEFAULT_LENGTH: u16 = 320 / BITS_PER_BYTE;
529            let pdu = ActionResponseReliablePdu::new();
530            assert_eq!(pdu.header().length, DEFAULT_LENGTH);
531        }
532    }
533
534    mod data_query_reliable_pdu_tests {
535        use super::*;
536
537        #[test]
538        fn cast_to_any() {
539            let pdu = DataQueryReliablePdu::new();
540            let any_pdu = pdu.as_any();
541
542            assert!(any_pdu.is::<DataQueryReliablePdu>());
543        }
544
545        #[test]
546        fn serialize_then_deserialize() {
547            let mut pdu = DataQueryReliablePdu::new();
548            let mut serialize_buf = BytesMut::new();
549            let _ = pdu.serialize(&mut serialize_buf);
550
551            let mut deserialize_buf = serialize_buf.freeze();
552            let new_pdu =
553                DataQueryReliablePdu::deserialize(&mut deserialize_buf).unwrap_or_default();
554            assert_eq!(new_pdu.header, pdu.header);
555        }
556
557        #[test]
558        fn check_default_pdu_length() {
559            const DEFAULT_LENGTH: u16 = 352 / BITS_PER_BYTE;
560            let pdu = DataQueryReliablePdu::new();
561            assert_eq!(pdu.header().length, DEFAULT_LENGTH);
562        }
563    }
564
565    mod set_data_reliable_pdu_tests {
566        use super::*;
567
568        #[test]
569        fn cast_to_any() {
570            let pdu = SetDataReliablePdu::new();
571            let any_pdu = pdu.as_any();
572
573            assert!(any_pdu.is::<SetDataReliablePdu>());
574        }
575
576        #[test]
577        fn serialize_then_deserialize() {
578            let mut pdu = SetDataReliablePdu::new();
579            let mut serialize_buf = BytesMut::new();
580            let _ = pdu.serialize(&mut serialize_buf);
581
582            let mut deserialize_buf = serialize_buf.freeze();
583            let new_pdu = SetDataReliablePdu::deserialize(&mut deserialize_buf).unwrap_or_default();
584            assert_eq!(new_pdu.header, pdu.header);
585        }
586
587        #[test]
588        fn check_default_pdu_length() {
589            const DEFAULT_LENGTH: u16 = 320 / BITS_PER_BYTE;
590            let pdu = SetDataReliablePdu::new();
591            assert_eq!(pdu.header().length, DEFAULT_LENGTH);
592        }
593    }
594
595    mod data_reliable_pdu_tests {
596        use super::*;
597
598        #[test]
599        fn cast_to_any() {
600            let pdu = DataReliablePdu::new();
601            let any_pdu = pdu.as_any();
602
603            assert!(any_pdu.is::<DataReliablePdu>());
604        }
605
606        #[test]
607        fn serialize_then_deserialize() {
608            let mut pdu = DataReliablePdu::new();
609            let mut serialize_buf = BytesMut::new();
610            let _ = pdu.serialize(&mut serialize_buf);
611
612            let mut deserialize_buf = serialize_buf.freeze();
613            let new_pdu = DataReliablePdu::deserialize(&mut deserialize_buf).unwrap_or_default();
614            assert_eq!(new_pdu.header, pdu.header);
615        }
616
617        #[test]
618        fn check_default_pdu_length() {
619            const DEFAULT_LENGTH: u16 = 320 / BITS_PER_BYTE;
620            let pdu = DataReliablePdu::new();
621            assert_eq!(pdu.header().length, DEFAULT_LENGTH);
622        }
623    }
624
625    mod event_report_reliable_pdu_tests {
626        use super::*;
627
628        #[test]
629        fn cast_to_any() {
630            let pdu = EventReportReliablePdu::new();
631            let any_pdu = pdu.as_any();
632
633            assert!(any_pdu.is::<EventReportReliablePdu>());
634        }
635
636        #[test]
637        fn serialize_then_deserialize() {
638            let mut pdu = EventReportReliablePdu::new();
639            let mut serialize_buf = BytesMut::new();
640            let _ = pdu.serialize(&mut serialize_buf);
641
642            let mut deserialize_buf = serialize_buf.freeze();
643            let new_pdu =
644                EventReportReliablePdu::deserialize(&mut deserialize_buf).unwrap_or_default();
645            assert_eq!(new_pdu.header, pdu.header);
646        }
647
648        #[test]
649        fn check_default_pdu_length() {
650            const DEFAULT_LENGTH: u16 = 320 / BITS_PER_BYTE;
651            let pdu = EventReportReliablePdu::new();
652            assert_eq!(pdu.header().length, DEFAULT_LENGTH);
653        }
654    }
655
656    mod comment_reliable_pdu_tests {
657        use super::*;
658
659        #[test]
660        fn cast_to_any() {
661            let pdu = CommentReliablePdu::new();
662            let any_pdu = pdu.as_any();
663
664            assert!(any_pdu.is::<CommentReliablePdu>());
665        }
666
667        #[test]
668        fn serialize_then_deserialize() {
669            let mut pdu = CommentReliablePdu::new();
670            let mut serialize_buf = BytesMut::new();
671            let _ = pdu.serialize(&mut serialize_buf);
672
673            let mut deserialize_buf = serialize_buf.freeze();
674            let new_pdu = CommentReliablePdu::deserialize(&mut deserialize_buf).unwrap_or_default();
675            assert_eq!(new_pdu.header, pdu.header);
676        }
677
678        #[test]
679        fn check_default_pdu_length() {
680            const DEFAULT_LENGTH: u16 = 256 / BITS_PER_BYTE;
681            let pdu = CommentReliablePdu::new();
682            assert_eq!(pdu.header().length, DEFAULT_LENGTH);
683        }
684    }
685
686    mod record_query_reliable_pdu_tests {
687        use super::*;
688
689        #[test]
690        fn cast_to_any() {
691            let pdu = RecordQueryReliablePdu::new();
692            let any_pdu = pdu.as_any();
693
694            assert!(any_pdu.is::<RecordQueryReliablePdu>());
695        }
696
697        #[test]
698        fn serialize_then_deserialize() {
699            let mut pdu = RecordQueryReliablePdu::new();
700            let mut serialize_buf = BytesMut::new();
701            let _ = pdu.serialize(&mut serialize_buf);
702
703            let mut deserialize_buf = serialize_buf.freeze();
704            let new_pdu =
705                RecordQueryReliablePdu::deserialize(&mut deserialize_buf).unwrap_or_default();
706            assert_eq!(new_pdu.header, pdu.header);
707        }
708
709        #[test]
710        fn check_default_pdu_length() {
711            const DEFAULT_LENGTH: u16 = 320 / BITS_PER_BYTE;
712            let pdu = RecordQueryReliablePdu::new();
713            assert_eq!(pdu.header().length, DEFAULT_LENGTH);
714        }
715    }
716
717    mod set_record_reliable_pdu_tests {
718        use super::*;
719
720        #[test]
721        fn cast_to_any() {
722            let pdu = SetRecordReliablePdu::new();
723            let any_pdu = pdu.as_any();
724
725            assert!(any_pdu.is::<SetRecordReliablePdu>());
726        }
727
728        #[test]
729        fn serialize_then_deserialize() {
730            let mut pdu = SetRecordReliablePdu::new();
731            let mut serialize_buf = BytesMut::new();
732            let _ = pdu.serialize(&mut serialize_buf);
733
734            let mut deserialize_buf = serialize_buf.freeze();
735            let new_pdu =
736                SetRecordReliablePdu::deserialize(&mut deserialize_buf).unwrap_or_default();
737            assert_eq!(new_pdu.header, pdu.header);
738        }
739
740        #[test]
741        fn check_default_pdu_length() {
742            const DEFAULT_LENGTH: u16 = 320 / BITS_PER_BYTE;
743            let pdu = SetRecordReliablePdu::new();
744            assert_eq!(pdu.header().length, DEFAULT_LENGTH);
745        }
746    }
747}