use snafu::{OptionExt as _, ResultExt as _};
use tracing::instrument;
use crate::types::{
FromBytes, NotEnoughBytes, ParseError, ParseTimeTag, SizedSlice, ToBytes,
information_elements::{Dpi, SelectExecute, Spi},
quality_descriptors::Qos,
time::{Cp16Time2a, Cp56Time2a},
};
#[derive(Debug, Clone, Eq, PartialEq, Default, Copy)]
#[repr(u8)]
pub enum Qu {
#[default]
Unspecified,
ShortPulse,
LongPulse,
Persistent,
Other(u8),
}
impl Qu {
#[must_use]
pub const fn from_byte(byte: u8) -> Self {
match byte {
0 => Qu::Unspecified,
1 => Qu::ShortPulse,
2 => Qu::LongPulse,
3 => Qu::Persistent,
_ => Qu::Other(byte),
}
}
#[must_use]
pub const fn to_byte(self) -> u8 {
match self {
Qu::Unspecified => 0,
Qu::ShortPulse => 1,
Qu::LongPulse => 2,
Qu::Persistent => 3,
Qu::Other(byte) => byte,
}
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct Sco {
pub se: SelectExecute,
pub qu: Qu,
pub scs: Spi,
}
impl Sco {
#[must_use]
pub const fn from_byte(byte: u8) -> Self {
let se = SelectExecute::from_bool(byte & 0b1000_0000 != 0);
let qu = Qu::from_byte(byte & 0b0111_1100 >> 2);
let scs = Spi::from_byte(byte & 0b0000_0001);
Sco { se, qu, scs }
}
#[must_use]
pub const fn to_byte(&self) -> u8 {
let mut byte: u8 = 0;
byte |= (self.se as u8) << 7;
byte |= self.qu.to_byte() << 2;
byte |= self.scs as u8;
byte
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct Dco {
pub se: SelectExecute,
pub qu: Qu,
pub dcs: Dpi,
}
impl Dco {
#[must_use]
pub const fn from_byte(byte: u8) -> Self {
let se = SelectExecute::from_bool(byte & 0b1000_0000 != 0);
let qu = Qu::from_byte(byte & 0b0111_1100 >> 2);
let dcs = Dpi::from_byte(byte & 0b0000_0011);
Dco { se, qu, dcs }
}
#[must_use]
pub const fn to_byte(&self) -> u8 {
let mut byte: u8 = 0;
byte |= (self.se as u8) << 7;
byte |= self.qu.to_byte() << 2;
byte |= self.dcs as u8;
byte
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default, Copy)]
#[repr(u8)]
pub enum Rcs {
#[default]
None = 0,
Decrement = 1,
Increment = 2,
Invalid = 3,
}
impl Rcs {
#[must_use]
pub const fn from_byte(byte: u8) -> Self {
match byte {
0 => Rcs::None,
1 => Rcs::Decrement,
2 => Rcs::Increment,
_ => Rcs::Invalid,
}
}
#[must_use]
pub const fn to_byte(self) -> u8 {
match self {
Rcs::None => 0,
Rcs::Decrement => 1,
Rcs::Increment => 2,
Rcs::Invalid => 3,
}
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct Rco {
pub se: SelectExecute,
pub qu: Qu,
pub rcs: Rcs,
}
impl Rco {
#[must_use]
pub const fn from_byte(byte: u8) -> Self {
let se = SelectExecute::from_bool(byte & 0b1000_0000 != 0);
let qu = Qu::from_byte(byte & 0b0111_1100 >> 2);
let rcs = Rcs::from_byte(byte & 0b0000_0011);
Rco { se, qu, rcs }
}
#[must_use]
pub const fn to_byte(&self) -> u8 {
let mut byte: u8 = 0;
byte |= (self.se as u8) << 7;
byte |= self.qu.to_byte() << 2;
byte |= self.rcs as u8;
byte
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default, Copy)]
#[repr(u8)]
pub enum Qoi {
#[default]
Unused,
Global,
Group1,
Group2,
Group3,
Group4,
Group5,
Group6,
Group7,
Group8,
Group9,
Group10,
Group11,
Group12,
Group13,
Group14,
Group15,
Group16,
Other(u8),
}
impl Qoi {
#[must_use]
pub const fn from_byte(byte: u8) -> Self {
match byte {
0 => Qoi::Unused,
20 => Qoi::Global,
21 => Qoi::Group1,
22 => Qoi::Group2,
23 => Qoi::Group3,
24 => Qoi::Group4,
25 => Qoi::Group5,
26 => Qoi::Group6,
27 => Qoi::Group7,
28 => Qoi::Group8,
29 => Qoi::Group9,
30 => Qoi::Group10,
31 => Qoi::Group11,
32 => Qoi::Group12,
33 => Qoi::Group13,
34 => Qoi::Group14,
35 => Qoi::Group15,
36 => Qoi::Group16,
_ => Qoi::Other(byte),
}
}
#[must_use]
pub const fn to_byte(self) -> u8 {
match self {
Qoi::Unused => 0,
Qoi::Global => 20,
Qoi::Group1 => 21,
Qoi::Group2 => 22,
Qoi::Group3 => 23,
Qoi::Group4 => 24,
Qoi::Group5 => 25,
Qoi::Group6 => 26,
Qoi::Group7 => 27,
Qoi::Group8 => 28,
Qoi::Group9 => 29,
Qoi::Group10 => 30,
Qoi::Group11 => 31,
Qoi::Group12 => 32,
Qoi::Group13 => 33,
Qoi::Group14 => 34,
Qoi::Group15 => 35,
Qoi::Group16 => 36,
Qoi::Other(byte) => byte,
}
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default, Copy)]
#[repr(u8)]
pub enum Frz {
#[default]
Read = 0,
Freeze = 1,
FreezeAndReset = 2,
Reset = 3,
}
impl Frz {
#[must_use]
pub const fn from_byte(byte: u8) -> Self {
match byte {
0 => Frz::Read,
1 => Frz::Freeze,
2 => Frz::FreezeAndReset,
_ => Frz::Reset,
}
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default, Copy)]
#[repr(u8)]
pub enum Rqt {
#[default]
None,
ReqCo1,
ReqCo2,
ReqCo3,
ReqCo4,
ReqCoGen,
Other(u8),
}
impl Rqt {
#[must_use]
pub const fn from_byte(byte: u8) -> Self {
match byte {
0 => Rqt::None,
1 => Rqt::ReqCo1,
2 => Rqt::ReqCo2,
3 => Rqt::ReqCo3,
4 => Rqt::ReqCo4,
5 => Rqt::ReqCoGen,
_ => Rqt::Other(byte),
}
}
#[must_use]
pub const fn to_byte(self) -> u8 {
match self {
Rqt::None => 0,
Rqt::ReqCo1 => 1,
Rqt::ReqCo2 => 2,
Rqt::ReqCo3 => 3,
Rqt::ReqCo4 => 4,
Rqt::ReqCoGen => 5,
Rqt::Other(byte) => byte,
}
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default, Copy)]
#[repr(u8)]
pub enum Qrp {
#[default]
Unused,
General,
TtEvents,
Other(u8),
}
impl Qrp {
#[must_use]
pub const fn from_byte(byte: u8) -> Self {
match byte {
0 => Qrp::Unused,
1 => Qrp::General,
2 => Qrp::TtEvents,
_ => Qrp::Other(byte),
}
}
#[must_use]
pub const fn to_byte(self) -> u8 {
match self {
Qrp::Unused => 0,
Qrp::General => 1,
Qrp::TtEvents => 2,
Qrp::Other(byte) => byte,
}
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct CScNa1 {
pub sco: Sco,
}
impl FromBytes for CScNa1 {
#[instrument]
fn from_bytes(bytes: &[u8]) -> Result<Self, ParseError> {
let sco = Sco::from_byte(*bytes.first().context(NotEnoughBytes)?);
Ok(Self { sco })
}
}
impl ToBytes for CScNa1 {
#[instrument]
fn to_bytes(&self, buffer: &mut Vec<u8>) -> Result<(), ParseError> {
buffer.push(self.sco.to_byte());
Ok(())
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct CdcNa1 {
pub dco: Dco,
}
impl FromBytes for CdcNa1 {
#[instrument]
fn from_bytes(bytes: &[u8]) -> Result<Self, ParseError> {
let dco = Dco::from_byte(*bytes.first().context(NotEnoughBytes)?);
Ok(Self { dco })
}
}
impl ToBytes for CdcNa1 {
#[instrument]
fn to_bytes(&self, buffer: &mut Vec<u8>) -> Result<(), ParseError> {
buffer.push(self.dco.to_byte());
Ok(())
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct CrcNa1 {
pub rco: Rco,
}
impl FromBytes for CrcNa1 {
#[instrument]
fn from_bytes(bytes: &[u8]) -> Result<Self, ParseError> {
let rco = Rco::from_byte(*bytes.first().context(NotEnoughBytes)?);
Ok(Self { rco })
}
}
impl ToBytes for CrcNa1 {
#[instrument]
fn to_bytes(&self, buffer: &mut Vec<u8>) -> Result<(), ParseError> {
buffer.push(self.rco.to_byte());
Ok(())
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct CSeNa1 {
pub nva: u16,
pub qos: Qos,
}
impl FromBytes for CSeNa1 {
#[instrument]
fn from_bytes(bytes: &[u8]) -> Result<Self, ParseError> {
let nva = u16::from_le_bytes(*bytes.first_chunk::<2>().context(NotEnoughBytes)?);
let qos = Qos::from_byte(*bytes.get(2).context(NotEnoughBytes)?);
Ok(Self { nva, qos })
}
}
impl ToBytes for CSeNa1 {
#[instrument]
fn to_bytes(&self, buffer: &mut Vec<u8>) -> Result<(), ParseError> {
buffer.extend_from_slice(&self.nva.to_le_bytes());
buffer.push(self.qos.to_byte());
Ok(())
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct CSeNb1 {
pub sva: u16,
pub qos: Qos,
}
impl FromBytes for CSeNb1 {
#[instrument]
fn from_bytes(bytes: &[u8]) -> Result<Self, ParseError> {
let sva = u16::from_le_bytes(*bytes.first_chunk::<2>().context(NotEnoughBytes)?);
let qos = Qos::from_byte(*bytes.get(2).context(NotEnoughBytes)?);
Ok(Self { sva, qos })
}
}
impl ToBytes for CSeNb1 {
#[instrument]
fn to_bytes(&self, buffer: &mut Vec<u8>) -> Result<(), ParseError> {
buffer.extend_from_slice(&self.sva.to_le_bytes());
buffer.push(self.qos.to_byte());
Ok(())
}
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct CSeNc1 {
pub value: f32,
pub qos: Qos,
}
impl FromBytes for CSeNc1 {
#[instrument]
fn from_bytes(bytes: &[u8]) -> Result<Self, ParseError> {
let value = f32::from_le_bytes(*bytes.first_chunk::<4>().context(NotEnoughBytes)?);
let qos = Qos::from_byte(*bytes.get(4).context(NotEnoughBytes)?);
Ok(Self { value, qos })
}
}
impl ToBytes for CSeNc1 {
#[instrument]
fn to_bytes(&self, buffer: &mut Vec<u8>) -> Result<(), ParseError> {
buffer.extend_from_slice(&self.value.to_le_bytes());
buffer.push(self.qos.to_byte());
Ok(())
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct CBoNa1 {
pub bsi: u32,
}
impl FromBytes for CBoNa1 {
#[instrument]
fn from_bytes(bytes: &[u8]) -> Result<Self, ParseError> {
let bsi = u32::from_le_bytes(*bytes.first_chunk::<4>().context(NotEnoughBytes)?);
Ok(Self { bsi })
}
}
impl ToBytes for CBoNa1 {
#[instrument]
fn to_bytes(&self, buffer: &mut Vec<u8>) -> Result<(), ParseError> {
buffer.extend_from_slice(&self.bsi.to_le_bytes());
Ok(())
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct CScTa1 {
pub sco: Sco,
pub time: Cp56Time2a,
}
impl FromBytes for CScTa1 {
#[instrument]
fn from_bytes(bytes: &[u8]) -> Result<Self, ParseError> {
let sco = Sco::from_byte(*bytes.first().context(NotEnoughBytes)?);
let time = Cp56Time2a::from_bytes(
bytes.get(1..8).context(NotEnoughBytes)?.try_into().context(SizedSlice)?,
)
.context(ParseTimeTag)?;
Ok(Self { sco, time })
}
}
impl ToBytes for CScTa1 {
#[instrument]
fn to_bytes(&self, buffer: &mut Vec<u8>) -> Result<(), ParseError> {
buffer.push(self.sco.to_byte());
buffer.extend_from_slice(&self.time.to_bytes());
Ok(())
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct CdcTa1 {
pub dco: Dco,
pub time: Cp56Time2a,
}
impl FromBytes for CdcTa1 {
#[instrument]
fn from_bytes(bytes: &[u8]) -> Result<Self, ParseError> {
let dco = Dco::from_byte(*bytes.first().context(NotEnoughBytes)?);
let time = Cp56Time2a::from_bytes(
bytes.get(1..8).context(NotEnoughBytes)?.try_into().context(SizedSlice)?,
)
.context(ParseTimeTag)?;
Ok(Self { dco, time })
}
}
impl ToBytes for CdcTa1 {
#[instrument]
fn to_bytes(&self, buffer: &mut Vec<u8>) -> Result<(), ParseError> {
buffer.push(self.dco.to_byte());
buffer.extend_from_slice(&self.time.to_bytes());
Ok(())
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct CrcTa1 {
pub rco: Rco,
pub time: Cp56Time2a,
}
impl FromBytes for CrcTa1 {
#[instrument]
fn from_bytes(bytes: &[u8]) -> Result<Self, ParseError> {
let rco = Rco::from_byte(*bytes.first().context(NotEnoughBytes)?);
let time = Cp56Time2a::from_bytes(
bytes.get(1..8).context(NotEnoughBytes)?.try_into().context(SizedSlice)?,
)
.context(ParseTimeTag)?;
Ok(Self { rco, time })
}
}
impl ToBytes for CrcTa1 {
#[instrument]
fn to_bytes(&self, buffer: &mut Vec<u8>) -> Result<(), ParseError> {
buffer.push(self.rco.to_byte());
buffer.extend_from_slice(&self.time.to_bytes());
Ok(())
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct CSeTa1 {
pub nva: u16,
pub qos: Qos,
pub time: Cp56Time2a,
}
impl FromBytes for CSeTa1 {
#[instrument]
fn from_bytes(bytes: &[u8]) -> Result<Self, ParseError> {
let nva = u16::from_le_bytes(*bytes.first_chunk::<2>().context(NotEnoughBytes)?);
let qos = Qos::from_byte(*bytes.get(2).context(NotEnoughBytes)?);
let time = Cp56Time2a::from_bytes(
bytes.get(3..10).context(NotEnoughBytes)?.try_into().context(SizedSlice)?,
)
.context(ParseTimeTag)?;
Ok(Self { nva, qos, time })
}
}
impl ToBytes for CSeTa1 {
#[instrument]
fn to_bytes(&self, buffer: &mut Vec<u8>) -> Result<(), ParseError> {
buffer.extend_from_slice(&self.nva.to_le_bytes());
buffer.push(self.qos.to_byte());
buffer.extend_from_slice(&self.time.to_bytes());
Ok(())
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct CSeTb1 {
pub sva: u16,
pub qos: Qos,
pub time: Cp56Time2a,
}
impl FromBytes for CSeTb1 {
#[instrument]
fn from_bytes(bytes: &[u8]) -> Result<Self, ParseError> {
let sva = u16::from_le_bytes(*bytes.first_chunk::<2>().context(NotEnoughBytes)?);
let qos = Qos::from_byte(*bytes.get(2).context(NotEnoughBytes)?);
let time = Cp56Time2a::from_bytes(
bytes.get(3..10).context(NotEnoughBytes)?.try_into().context(SizedSlice)?,
)
.context(ParseTimeTag)?;
Ok(Self { sva, qos, time })
}
}
impl ToBytes for CSeTb1 {
#[instrument]
fn to_bytes(&self, buffer: &mut Vec<u8>) -> Result<(), ParseError> {
buffer.extend_from_slice(&self.sva.to_le_bytes());
buffer.push(self.qos.to_byte());
buffer.extend_from_slice(&self.time.to_bytes());
Ok(())
}
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct CSeTc1 {
pub value: f32,
pub qos: Qos,
pub time: Cp56Time2a,
}
impl FromBytes for CSeTc1 {
#[instrument]
fn from_bytes(bytes: &[u8]) -> Result<Self, ParseError> {
let value = f32::from_le_bytes(*bytes.first_chunk::<4>().context(NotEnoughBytes)?);
let qos = Qos::from_byte(*bytes.get(4).context(NotEnoughBytes)?);
let time = Cp56Time2a::from_bytes(
bytes.get(5..12).context(NotEnoughBytes)?.try_into().context(SizedSlice)?,
)
.context(ParseTimeTag)?;
Ok(Self { value, qos, time })
}
}
impl ToBytes for CSeTc1 {
#[instrument]
fn to_bytes(&self, buffer: &mut Vec<u8>) -> Result<(), ParseError> {
buffer.extend_from_slice(&self.value.to_le_bytes());
buffer.push(self.qos.to_byte());
buffer.extend_from_slice(&self.time.to_bytes());
Ok(())
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct CBoTa1 {
pub bsi: u32,
pub time: Cp56Time2a,
}
impl FromBytes for CBoTa1 {
#[instrument]
fn from_bytes(bytes: &[u8]) -> Result<Self, ParseError> {
let (bsi_bytes, time_bytes) = bytes.split_at(4);
let bsi = u32::from_le_bytes(*bsi_bytes.first_chunk::<4>().context(NotEnoughBytes)?);
let time = Cp56Time2a::from_bytes(time_bytes.try_into().context(SizedSlice)?)
.context(ParseTimeTag)?;
Ok(Self { bsi, time })
}
}
impl ToBytes for CBoTa1 {
#[instrument]
fn to_bytes(&self, buffer: &mut Vec<u8>) -> Result<(), ParseError> {
buffer.extend_from_slice(&self.bsi.to_le_bytes());
buffer.extend_from_slice(&self.time.to_bytes());
Ok(())
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct CIcNa1 {
pub qoi: Qoi,
}
impl FromBytes for CIcNa1 {
#[instrument]
fn from_bytes(bytes: &[u8]) -> Result<Self, ParseError> {
let qoi = Qoi::from_byte(*bytes.first().context(NotEnoughBytes)?);
Ok(Self { qoi })
}
}
impl ToBytes for CIcNa1 {
#[instrument]
fn to_bytes(&self, buffer: &mut Vec<u8>) -> Result<(), ParseError> {
buffer.push(self.qoi.to_byte());
Ok(())
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct CCiNa1 {
pub rqt: Rqt,
pub frz: Frz,
}
impl FromBytes for CCiNa1 {
#[instrument]
fn from_bytes(bytes: &[u8]) -> Result<Self, ParseError> {
let byte = *bytes.first().context(NotEnoughBytes)?;
let rqt = Rqt::from_byte(byte & 0b0011_1111);
let frz = Frz::from_byte(byte >> 6);
Ok(Self { rqt, frz })
}
}
impl ToBytes for CCiNa1 {
#[instrument]
fn to_bytes(&self, buffer: &mut Vec<u8>) -> Result<(), ParseError> {
let mut byte: u8 = 0;
byte |= self.rqt.to_byte() & 0b0011_1111;
byte |= (self.frz as u8) << 6;
buffer.push(byte);
Ok(())
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct CRdNa1 {
}
impl FromBytes for CRdNa1 {
#[instrument]
fn from_bytes(_: &[u8]) -> Result<Self, ParseError> {
Ok(Self {})
}
}
impl ToBytes for CRdNa1 {
#[instrument]
fn to_bytes(&self, buffer: &mut Vec<u8>) -> Result<(), ParseError> {
Ok(())
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct CCsNa1 {
pub time: Cp56Time2a,
}
impl FromBytes for CCsNa1 {
#[instrument]
fn from_bytes(bytes: &[u8]) -> Result<Self, ParseError> {
let time = Cp56Time2a::from_bytes(bytes.first_chunk::<7>().context(NotEnoughBytes)?)
.context(ParseTimeTag)?;
Ok(Self { time })
}
}
impl ToBytes for CCsNa1 {
#[instrument]
fn to_bytes(&self, buffer: &mut Vec<u8>) -> Result<(), ParseError> {
buffer.extend_from_slice(&self.time.to_bytes());
Ok(())
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct CTsNa1 {
pub tsc: u16,
}
impl FromBytes for CTsNa1 {
#[instrument]
fn from_bytes(bytes: &[u8]) -> Result<Self, ParseError> {
let tsc = u16::from_le_bytes(*bytes.first_chunk::<2>().context(NotEnoughBytes)?);
Ok(Self { tsc })
}
}
impl ToBytes for CTsNa1 {
#[instrument]
fn to_bytes(&self, buffer: &mut Vec<u8>) -> Result<(), ParseError> {
buffer.extend_from_slice(&self.tsc.to_le_bytes());
Ok(())
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct CRpNa1 {
pub qrp: Qrp,
}
impl FromBytes for CRpNa1 {
#[instrument]
fn from_bytes(bytes: &[u8]) -> Result<Self, ParseError> {
let qrp = Qrp::from_byte(*bytes.first().context(NotEnoughBytes)?);
Ok(Self { qrp })
}
}
impl ToBytes for CRpNa1 {
#[instrument]
fn to_bytes(&self, buffer: &mut Vec<u8>) -> Result<(), ParseError> {
buffer.push(self.qrp.to_byte());
Ok(())
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct CCdNa1 {
pub delay: Cp16Time2a,
}
impl FromBytes for CCdNa1 {
#[instrument]
fn from_bytes(bytes: &[u8]) -> Result<Self, ParseError> {
let delay = Cp16Time2a::from_bytes(*bytes.first_chunk::<2>().context(NotEnoughBytes)?)
.context(ParseTimeTag)?;
Ok(Self { delay })
}
}
impl ToBytes for CCdNa1 {
#[instrument]
fn to_bytes(&self, buffer: &mut Vec<u8>) -> Result<(), ParseError> {
buffer.extend_from_slice(&self.delay.to_bytes());
Ok(())
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct CTsTa1 {
pub tsc: u16,
pub time: Cp56Time2a,
}
impl FromBytes for CTsTa1 {
#[instrument]
fn from_bytes(bytes: &[u8]) -> Result<Self, ParseError> {
let (tsc_bytes, time_bytes) = bytes.split_at(2);
let tsc = u16::from_le_bytes(tsc_bytes.try_into().context(SizedSlice)?);
let time = Cp56Time2a::from_bytes(time_bytes.try_into().context(SizedSlice)?)
.context(ParseTimeTag)?;
Ok(Self { tsc, time })
}
}
impl ToBytes for CTsTa1 {
#[instrument]
fn to_bytes(&self, buffer: &mut Vec<u8>) -> Result<(), ParseError> {
buffer.extend_from_slice(&self.tsc.to_le_bytes());
buffer.extend_from_slice(&self.time.to_bytes());
Ok(())
}
}