1use rsomeip_bytes::{Buf, BufMut, Deserialize, DeserializeError, Serialize, SerializeError};
6
7macro_rules! impl_basic_type {
13 ($name:ident, $repr:ty, $getter:ident, $fmt:literal) => {
14 impl $name {
15 #[doc=concat!("Creates a new [`", stringify!($name), "`] with the given `value`.")]
16 #[doc=concat!("use rsomeip_proto::", stringify!($name), ";")]
21 #[doc=concat!("let value = ", stringify!($name), "::new(1 as ", stringify!($repr), ");")]
23 #[doc=concat!("assert_eq!(value.", stringify!($getter), "(), 1 as ", stringify!($repr), ");")]
24 #[inline]
26 #[must_use]
27 pub const fn new(value: $repr) -> Self {
28 Self(value)
29 }
30
31 #[doc=concat!("Returns the [`", stringify!($repr), "`] representation of this [`", stringify!($name), "`].")]
32 #[doc=concat!("use rsomeip_proto::", stringify!($name), ";")]
37 #[doc=concat!("let value = ", stringify!($name), "::new(1 as ", stringify!($repr), ");")]
39 #[doc=concat!("assert_eq!(value.", stringify!($getter), "(), 1 as ", stringify!($repr), ");")]
40 #[inline]
42 #[must_use]
43 pub const fn $getter(self) -> $repr {
44 self.0
45 }
46 }
47
48 impl From<$repr> for $name {
49 fn from(value: $repr) -> Self {
50 Self::new(value)
51 }
52 }
53
54 impl From<$name> for $repr {
55 fn from(value: $name) -> Self {
56 value.0
57 }
58 }
59
60 impl rsomeip_bytes::Serialize for $name {
61 fn serialize(&self, buffer: &mut impl BufMut) -> Result<usize, rsomeip_bytes::SerializeError> {
62 self.0.serialize(buffer)
63 }
64
65 fn size_hint(&self) -> usize {
66 self.0.size_hint()
67 }
68 }
69
70 impl rsomeip_bytes::Deserialize for $name {
71 type Output = Self;
72
73 fn deserialize(buffer: &mut impl Buf) -> Result<Self::Output, rsomeip_bytes::DeserializeError> {
74 <$repr>::deserialize(buffer).map(Self::new)
75 }
76 }
77
78 impl ::std::fmt::Display for $name {
79 fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
80 write!(f, $fmt, self.0)
81 }
82 }
83 };
84}
85
86macro_rules! impl_basic_type_u16 {
87 ($name:ident) => {
88 impl_basic_type!($name, u16, as_u16, "{:04x?}");
89 };
90}
91
92macro_rules! impl_basic_type_u8 {
93 ($name:ident) => {
94 impl_basic_type!($name, u8, as_u8, "{:02x?}");
95 };
96}
97
98#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
105pub struct ServiceId(u16);
106
107impl_basic_type_u16!(ServiceId);
108
109#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
127pub struct MethodId(u16);
128
129impl_basic_type_u16!(MethodId);
130
131#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
135pub struct MessageId {
136 pub service: ServiceId,
138 pub method: MethodId,
140}
141
142impl MessageId {
143 #[inline]
155 #[must_use]
156 pub const fn new(service: ServiceId, method: MethodId) -> Self {
157 Self { service, method }
158 }
159
160 #[inline]
171 #[must_use]
172 pub const fn with_service(mut self, value: ServiceId) -> Self {
173 self.service = value;
174 self
175 }
176
177 #[inline]
188 #[must_use]
189 pub const fn with_method(mut self, value: MethodId) -> Self {
190 self.method = value;
191 self
192 }
193
194 #[inline]
206 #[must_use]
207 pub const fn from_u32(value: u32) -> Self {
208 let service = ServiceId::new((value >> 16) as u16);
209 let method = MethodId::new((value & 0xffff) as u16);
210 Self::new(service, method)
211 }
212
213 #[inline]
224 #[must_use]
225 pub const fn as_u32(self) -> u32 {
226 let service = (self.service.as_u16() as u32) << 16;
227 service | (self.method.as_u16() as u32)
228 }
229}
230
231impl From<u32> for MessageId {
232 fn from(value: u32) -> Self {
233 Self::from_u32(value)
234 }
235}
236
237impl From<MessageId> for u32 {
238 fn from(value: MessageId) -> Self {
239 value.as_u32()
240 }
241}
242
243impl Serialize for MessageId {
244 fn serialize(&self, buffer: &mut impl BufMut) -> Result<usize, SerializeError> {
245 self.as_u32().serialize(buffer)
246 }
247
248 fn size_hint(&self) -> usize {
249 size_of::<u32>()
250 }
251}
252
253impl Deserialize for MessageId {
254 type Output = Self;
255
256 fn deserialize(buffer: &mut impl Buf) -> Result<Self::Output, DeserializeError> {
257 u32::deserialize(buffer).map(Self::from_u32)
258 }
259}
260
261impl std::fmt::Display for MessageId {
262 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
275 write!(f, "{}.{}", self.service, self.method)
276 }
277}
278
279#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
285pub struct ClientId(u16);
286
287impl_basic_type_u16!(ClientId);
288
289impl ClientId {
290 #[inline]
302 #[must_use]
303 pub const fn prefix(&self) -> u8 {
304 self.0.to_be_bytes()[0]
305 }
306
307 #[inline]
319 #[must_use]
320 pub const fn with_prefix(mut self, prefix: u8) -> Self {
321 self.0 |= (prefix as u16) << 8;
322 self
323 }
324}
325
326#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
346pub struct SessionId(u16);
347
348impl_basic_type_u16!(SessionId);
349
350impl SessionId {
351 pub const DISABLED: Self = Self::new(0);
353
354 pub const ENABLED: Self = Self::new(1);
356
357 #[inline]
370 #[must_use]
371 pub const fn is_enabled(self) -> bool {
372 self.0 > 0
373 }
374
375 #[expect(clippy::return_self_not_must_use)]
389 pub const fn increment(&mut self) -> Self {
390 let old = self.0;
391 self.0 = match old.wrapping_add(1) {
392 0 => 1,
393 x => x,
394 };
395 Self::new(old)
396 }
397}
398
399#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
403pub struct RequestId {
404 pub client: ClientId,
406 pub session: SessionId,
408}
409
410impl RequestId {
411 #[inline]
423 #[must_use]
424 pub const fn new(client: ClientId, session: SessionId) -> Self {
425 Self { client, session }
426 }
427
428 #[inline]
439 #[must_use]
440 pub const fn with_client(mut self, value: ClientId) -> Self {
441 self.client = value;
442 self
443 }
444
445 #[inline]
456 #[must_use]
457 pub const fn with_session(mut self, value: SessionId) -> Self {
458 self.session = value;
459 self
460 }
461
462 #[must_use]
474 pub const fn from_u32(value: u32) -> Self {
475 let client = ClientId::new((value >> 16) as u16);
476 let session = SessionId::new((value & 0xffff) as u16);
477 Self::new(client, session)
478 }
479
480 #[must_use]
491 pub const fn as_u32(self) -> u32 {
492 let client = (self.client.as_u16() as u32) << 16;
493 client | (self.session.as_u16() as u32)
494 }
495}
496
497impl From<u32> for RequestId {
498 fn from(value: u32) -> Self {
499 Self::from_u32(value)
500 }
501}
502
503impl From<RequestId> for u32 {
504 fn from(value: RequestId) -> Self {
505 value.as_u32()
506 }
507}
508
509impl Serialize for RequestId {
510 fn serialize(&self, buffer: &mut impl BufMut) -> Result<usize, SerializeError> {
511 self.as_u32().serialize(buffer)
512 }
513
514 fn size_hint(&self) -> usize {
515 size_of::<u32>()
516 }
517}
518
519impl Deserialize for RequestId {
520 type Output = Self;
521
522 fn deserialize(buffer: &mut impl Buf) -> Result<Self::Output, DeserializeError> {
523 u32::deserialize(buffer).map(Self::from_u32)
524 }
525}
526
527impl std::fmt::Display for RequestId {
528 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
541 write!(f, "{}.{}", self.client, self.session)
542 }
543}
544
545#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
547pub struct ProtocolVersion(u8);
548
549impl_basic_type_u8!(ProtocolVersion);
550
551#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
563pub struct InterfaceVersion(u8);
564
565impl_basic_type_u8!(InterfaceVersion);
566
567#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
569pub struct MessageTypeField(u8);
570
571impl_basic_type_u8!(MessageTypeField);
572
573impl MessageTypeField {
574 pub const TP_FLAG: u8 = 0x20;
576
577 pub const ALL_FLAGS: u8 = Self::TP_FLAG;
579
580 #[inline]
591 #[must_use]
592 pub const fn is_tp(&self) -> bool {
593 self.0 & Self::TP_FLAG == Self::TP_FLAG
594 }
595
596 #[inline]
607 #[must_use]
608 pub const fn flags(self) -> u8 {
609 self.0 & Self::ALL_FLAGS
610 }
611
612 #[inline]
627 #[must_use]
628 pub const fn with_flags(mut self, flags: u8, enabled: bool) -> Self {
629 if enabled {
630 self.0 |= flags;
631 } else {
632 self.0 &= !flags;
633 }
634 self
635 }
636
637 #[inline]
650 #[must_use]
651 pub const fn as_type(self) -> MessageType {
652 MessageType::from_u8(self.0 & !Self::ALL_FLAGS)
653 }
654
655 #[inline]
666 #[must_use]
667 pub const fn from_type(value: MessageType) -> Self {
668 Self::new(value.as_u8())
669 }
670}
671
672#[non_exhaustive]
677#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
678pub enum MessageType {
679 #[default]
681 Request,
682 RequestNoReturn,
684 Notification,
686 Response,
688 Error,
690 Unknown(u8),
692}
693
694impl MessageType {
695 #[inline]
697 #[must_use]
698 pub const fn from_u8(value: u8) -> Self {
699 match value {
700 0x00 => Self::Request,
701 0x01 => Self::RequestNoReturn,
702 0x02 => Self::Notification,
703 0x80 => Self::Response,
704 0x81 => Self::Error,
705 x => Self::Unknown(x),
706 }
707 }
708
709 #[inline]
711 #[must_use]
712 pub const fn as_u8(self) -> u8 {
713 match self {
714 Self::Request => 0x00,
715 Self::RequestNoReturn => 0x01,
716 Self::Notification => 0x02,
717 Self::Response => 0x80,
718 Self::Error => 0x81,
719 Self::Unknown(x) => x,
720 }
721 }
722}
723
724impl From<u8> for MessageType {
725 fn from(value: u8) -> Self {
726 Self::from_u8(value)
727 }
728}
729
730impl From<MessageType> for u8 {
731 fn from(value: MessageType) -> Self {
732 value.as_u8()
733 }
734}
735
736impl Serialize for MessageType {
737 fn serialize(&self, buffer: &mut impl BufMut) -> Result<usize, SerializeError> {
738 u8::from(*self).serialize(buffer)
739 }
740
741 fn size_hint(&self) -> usize {
742 size_of::<u8>()
743 }
744}
745
746impl Deserialize for MessageType {
747 type Output = Self;
748
749 fn deserialize(buffer: &mut impl Buf) -> Result<Self::Output, DeserializeError> {
750 u8::deserialize(buffer).map(Self::from)
751 }
752}
753
754impl std::fmt::Display for MessageType {
755 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
765 write!(f, "{self:?}")
766 }
767}
768
769#[non_exhaustive]
771#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
772pub enum ReturnCode {
773 #[default]
775 Ok,
776 NotOk,
778 UnknownService,
780 UnknownMethod,
782 NotReady,
784 NotReachable,
786 Timeout,
788 WrongProtocolVersion,
790 WrongInterfaceVersion,
792 MalformedMessage,
794 WrongMessageType,
796 E2eRepeated,
798 E2eWrongSequence,
800 E2e,
802 E2eNotAvailable,
804 E2eNoNewData,
806 Reserved(u8),
808 Other(u8),
810}
811
812impl From<u8> for ReturnCode {
813 fn from(value: u8) -> Self {
814 match value {
815 0x00 => Self::Ok,
816 0x01 => Self::NotOk,
817 0x02 => Self::UnknownService,
818 0x03 => Self::UnknownMethod,
819 0x04 => Self::NotReady,
820 0x05 => Self::NotReachable,
821 0x06 => Self::Timeout,
822 0x07 => Self::WrongProtocolVersion,
823 0x08 => Self::WrongInterfaceVersion,
824 0x09 => Self::MalformedMessage,
825 0x0a => Self::WrongMessageType,
826 0x0b => Self::E2eRepeated,
827 0x0c => Self::E2eWrongSequence,
828 0x0d => Self::E2e,
829 0x0e => Self::E2eNotAvailable,
830 0x0f => Self::E2eNoNewData,
831 n if (0x10..=0x5e).contains(&n) => Self::Reserved(n),
832 n => Self::Other(n),
833 }
834 }
835}
836
837impl From<ReturnCode> for u8 {
838 fn from(value: ReturnCode) -> Self {
839 match value {
840 ReturnCode::Ok => 0x00,
841 ReturnCode::NotOk => 0x01,
842 ReturnCode::UnknownService => 0x02,
843 ReturnCode::UnknownMethod => 0x03,
844 ReturnCode::NotReady => 0x04,
845 ReturnCode::NotReachable => 0x05,
846 ReturnCode::Timeout => 0x06,
847 ReturnCode::WrongProtocolVersion => 0x07,
848 ReturnCode::WrongInterfaceVersion => 0x08,
849 ReturnCode::MalformedMessage => 0x09,
850 ReturnCode::WrongMessageType => 0x0a,
851 ReturnCode::E2eRepeated => 0x0b,
852 ReturnCode::E2eWrongSequence => 0x0c,
853 ReturnCode::E2e => 0x0d,
854 ReturnCode::E2eNotAvailable => 0x0e,
855 ReturnCode::E2eNoNewData => 0x0f,
856 ReturnCode::Reserved(x) | ReturnCode::Other(x) => x,
857 }
858 }
859}
860
861impl Serialize for ReturnCode {
862 fn serialize(&self, buffer: &mut impl BufMut) -> Result<usize, SerializeError> {
863 u8::from(*self).serialize(buffer)
864 }
865
866 fn size_hint(&self) -> usize {
867 size_of::<u8>()
868 }
869}
870
871impl Deserialize for ReturnCode {
872 type Output = Self;
873
874 fn deserialize(buffer: &mut impl Buf) -> Result<Self::Output, DeserializeError> {
875 u8::deserialize(buffer).map(Self::from)
876 }
877}
878
879impl std::fmt::Display for ReturnCode {
880 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
890 write!(f, "{self:?}")
891 }
892}
893
894#[cfg(test)]
895mod tests {
896 use super::*;
897 use rsomeip_bytes::{Bytes, BytesMut};
898
899 macro_rules! test_new_type_serialization {
901 ($name:ty, $repr:ty, $ser_test_name:ident, $de_test_name:ident) => {
902 #[test]
903 fn $ser_test_name() {
904 let value = <$name>::from(<$repr>::MAX);
905 let mut buffer = BytesMut::new();
906 assert_eq!(value.size_hint(), size_of::<$repr>());
907 assert_eq!(value.serialize(&mut buffer), Ok(size_of::<$repr>()));
908 assert_eq!(buffer[..], <$repr>::MAX.to_be_bytes()[..]);
909 }
910
911 #[test]
912 fn $de_test_name() {
913 let mut buffer = Bytes::copy_from_slice(&(<$repr>::MAX).to_be_bytes()[..]);
914 let value =
915 <$name>::deserialize(&mut buffer).expect("should deserialize the value");
916 assert_eq!(<$repr>::from(value), <$repr>::MAX);
917 }
918 };
919 }
920
921 test_new_type_serialization!(
922 ServiceId,
923 u16,
924 service_id_is_serializable,
925 service_id_is_deserializable
926 );
927 test_new_type_serialization!(
928 MethodId,
929 u16,
930 method_id_is_serializable,
931 method_id_is_deserializable
932 );
933 test_new_type_serialization!(
934 MessageId,
935 u32,
936 message_id_is_serializable,
937 message_id_is_deserializable
938 );
939 test_new_type_serialization!(
940 ClientId,
941 u16,
942 client_id_is_serializable,
943 client_id_is_deserializable
944 );
945 test_new_type_serialization!(
946 SessionId,
947 u16,
948 session_id_is_serializable,
949 session_id_is_deserializable
950 );
951 test_new_type_serialization!(
952 RequestId,
953 u32,
954 request_id_is_serializable,
955 request_id_is_deserializable
956 );
957 test_new_type_serialization!(
958 ProtocolVersion,
959 u8,
960 protocol_version_is_serializable,
961 protocol_version_is_deserializable
962 );
963 test_new_type_serialization!(
964 InterfaceVersion,
965 u8,
966 interface_version_is_serializable,
967 interface_version_is_deserializable
968 );
969 test_new_type_serialization!(
970 MessageType,
971 u8,
972 message_type_is_serializable,
973 message_type_is_deserializable
974 );
975 test_new_type_serialization!(
976 MessageTypeField,
977 u8,
978 message_type_field_is_serializable,
979 message_type_field_is_deserializable
980 );
981 test_new_type_serialization!(
982 ReturnCode,
983 u8,
984 return_code_is_serializable,
985 return_code_is_deserializable
986 );
987
988 #[test]
989 fn message_id_converts_from_u32() {
990 let message_id = MessageId::from(0x1234_5678_u32);
991 assert_eq!(message_id.service.as_u16(), 0x1234);
992 assert_eq!(message_id.method.as_u16(), 0x5678);
993 }
994
995 #[test]
996 fn message_id_converts_to_u32() {
997 let service = ServiceId::new(0x1234);
998 let method = MethodId::new(0x5678);
999 assert_eq!(u32::from(MessageId::new(service, method)), 0x1234_5678_u32);
1000 }
1001
1002 #[test]
1003 fn request_id_converts_from_u32() {
1004 let request_id = RequestId::from(0x1234_5678_u32);
1005 assert_eq!(request_id.client.as_u16(), 0x1234);
1006 assert_eq!(request_id.session.as_u16(), 0x5678);
1007 }
1008
1009 #[test]
1010 fn request_id_converts_to_u32() {
1011 let client = ClientId::new(0x1234);
1012 let session = SessionId::new(0x5678);
1013 assert_eq!(u32::from(RequestId::new(client, session)), 0x1234_5678_u32);
1014 }
1015
1016 #[test]
1017 fn is_session_handling_enabled() {
1018 assert!(!SessionId::DISABLED.is_enabled());
1019 assert!(SessionId::ENABLED.is_enabled());
1020 }
1021
1022 #[test]
1023 fn session_id_wraps_to_1() {
1024 let mut session = SessionId::new(0xffff);
1025 assert_eq!(session.increment().as_u16(), 0xffff);
1026 assert_eq!(session.as_u16(), 1);
1027 }
1028
1029 #[test]
1030 fn message_type_converts_from_u8() {
1031 assert_eq!(MessageType::from(0x00), MessageType::Request);
1032 assert_eq!(MessageType::from(0x01), MessageType::RequestNoReturn);
1033 assert_eq!(MessageType::from(0x02), MessageType::Notification);
1034 assert_eq!(MessageType::from(0x80), MessageType::Response);
1035 assert_eq!(MessageType::from(0x81), MessageType::Error);
1036 (u8::MIN..=u8::MAX)
1037 .filter(|x| ![0x00, 0x01, 0x02, 0x80, 0x81, 0x20, 0x21, 0x22, 0xa0, 0xa1].contains(x))
1038 .for_each(|x| {
1039 assert_eq!(MessageType::Unknown(x), MessageType::from(x));
1040 });
1041 }
1042
1043 #[test]
1044 fn message_type_converts_to_u8() {
1045 assert_eq!(0x00, u8::from(MessageType::Request));
1046 assert_eq!(0x01, u8::from(MessageType::RequestNoReturn));
1047 assert_eq!(0x02, u8::from(MessageType::Notification));
1048 assert_eq!(0x80, u8::from(MessageType::Response));
1049 assert_eq!(0x81, u8::from(MessageType::Error));
1050 (u8::MIN..=u8::MAX)
1051 .filter(|x| ![0x00, 0x01, 0x02, 0x80, 0x81, 0x20, 0x21, 0x22, 0xa0, 0xa1].contains(x))
1052 .for_each(|x| {
1053 assert_eq!(u8::from(MessageType::Unknown(x)), x);
1054 });
1055 }
1056
1057 #[test]
1058 fn return_code_converts_from_u8() {
1059 assert_eq!(ReturnCode::from(0x00), ReturnCode::Ok);
1060 assert_eq!(ReturnCode::from(0x01), ReturnCode::NotOk);
1061 assert_eq!(ReturnCode::from(0x02), ReturnCode::UnknownService);
1062 assert_eq!(ReturnCode::from(0x03), ReturnCode::UnknownMethod);
1063 assert_eq!(ReturnCode::from(0x04), ReturnCode::NotReady);
1064 assert_eq!(ReturnCode::from(0x05), ReturnCode::NotReachable);
1065 assert_eq!(ReturnCode::from(0x06), ReturnCode::Timeout);
1066 assert_eq!(ReturnCode::from(0x07), ReturnCode::WrongProtocolVersion);
1067 assert_eq!(ReturnCode::from(0x08), ReturnCode::WrongInterfaceVersion);
1068 assert_eq!(ReturnCode::from(0x09), ReturnCode::MalformedMessage);
1069 assert_eq!(ReturnCode::from(0x0a), ReturnCode::WrongMessageType);
1070 assert_eq!(ReturnCode::from(0x0b), ReturnCode::E2eRepeated);
1071 assert_eq!(ReturnCode::from(0x0c), ReturnCode::E2eWrongSequence);
1072 assert_eq!(ReturnCode::from(0x0d), ReturnCode::E2e);
1073 assert_eq!(ReturnCode::from(0x0e), ReturnCode::E2eNotAvailable);
1074 assert_eq!(ReturnCode::from(0x0f), ReturnCode::E2eNoNewData);
1075 (0x10..=0x5e).for_each(|x| assert_eq!(ReturnCode::Reserved(x), ReturnCode::from(x)));
1076 (0x5f..=u8::MAX).for_each(|x| assert_eq!(ReturnCode::Other(x), ReturnCode::from(x)));
1077 }
1078
1079 #[test]
1080 fn return_code_converts_to_u8() {
1081 assert_eq!(0x00, u8::from(ReturnCode::Ok));
1082 assert_eq!(0x01, u8::from(ReturnCode::NotOk));
1083 assert_eq!(0x02, u8::from(ReturnCode::UnknownService));
1084 assert_eq!(0x03, u8::from(ReturnCode::UnknownMethod));
1085 assert_eq!(0x04, u8::from(ReturnCode::NotReady));
1086 assert_eq!(0x05, u8::from(ReturnCode::NotReachable));
1087 assert_eq!(0x06, u8::from(ReturnCode::Timeout));
1088 assert_eq!(0x07, u8::from(ReturnCode::WrongProtocolVersion));
1089 assert_eq!(0x08, u8::from(ReturnCode::WrongInterfaceVersion));
1090 assert_eq!(0x09, u8::from(ReturnCode::MalformedMessage));
1091 assert_eq!(0x0a, u8::from(ReturnCode::WrongMessageType));
1092 assert_eq!(0x0b, u8::from(ReturnCode::E2eRepeated));
1093 assert_eq!(0x0c, u8::from(ReturnCode::E2eWrongSequence));
1094 assert_eq!(0x0d, u8::from(ReturnCode::E2e));
1095 assert_eq!(0x0e, u8::from(ReturnCode::E2eNotAvailable));
1096 assert_eq!(0x0f, u8::from(ReturnCode::E2eNoNewData));
1097 (0x10..=0x5e).for_each(|x| assert_eq!(u8::from(ReturnCode::Reserved(x)), x));
1098 (0x5f..=u8::MAX).for_each(|x| assert_eq!(u8::from(ReturnCode::Other(x)), x));
1099 }
1100}