Skip to content

Conversation

@minlux
Copy link

@minlux minlux commented Dec 13, 2025

This PR adds a packet for the Nack (84 XX) command, to zvt.
This packet/command is somehow special, as it has not a fixed INSTR byte. Instead of INSTR the packets 2nd byte is the error code of the Nack.
The respective traits for serialization and deserialization are hand written, instead of generated using the Zvt macro, to deal with this speciality.

Signed-off-by: Manuel Heiß <manuel-heiss@gmx.de>

/// Specialized impl for Nack with ADPU serialization
/// This impl overrides the default behavior to use `code` as the INSTR byte
impl zvt_builder::ZvtSerializerImpl<zvt_builder::length::Adpu, zvt_builder::encoding::Default, zvt_builder::encoding::BigEndian> for Nack {
Copy link
Contributor

@dorezyuk dorezyuk Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

puh I'm not sure - from what i see we would fall into

impl<T> ZvtSerializer for T
where
    Self: ZvtCommand
        + ZvtSerializerImpl<length::Adpu, encoding::Default, encoding::BigEndian>
        + ZvtSerializerImpl,
    encoding::Default: encoding::Encoding<Self>,
{
    fn zvt_serialize(&self) -> Vec<u8> {
        // Find a more elegant way to express this.
        let tag: Tag = encoding::BigEndian::decode(&[Self::CLASS, Self::INSTR])
            .unwrap()
            .0;
        <Self as ZvtSerializerImpl<length::Adpu, encoding::Default, encoding::BigEndian>>::serialize_tagged(self, Some(tag))
    }

    fn zvt_deserialize(bytes: &[u8]) -> ZVTResult<(Self, &[u8])> {
        let tag: Tag = encoding::BigEndian::decode(&[Self::CLASS, Self::INSTR])
            .unwrap()
            .0;
        <Self as ZvtSerializerImpl<length::Adpu, encoding::Default, encoding::BigEndian>>::deserialize_tagged(bytes, Some(tag))
    }
}
```... 

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think I would to the following

pub struct Nack {
    error: u8
}

impl zvt_builder::encoding::Encoding<Nack> for zvt_builder::encoding::Default {
    fn decode(_bytes: &[u8]) -> zvt_builder::ZVTResult<(Nack, &[u8])> {
        Err(zvt_builder::ZVTError::NonImplemented)
    }

    fn encode(_input: &Nack) -> Vec<u8> {
        vec![]
    }
}

impl zvt_builder::ZvtSerializerImpl for Nack {
    fn serialize_tagged(&self, tag: Option<zvt_builder::Tag>) -> Vec<u8> {
        todo!()
    }

    fn deserialize_tagged(mut bytes: &[u8], tag: Option<zvt_builder::Tag>) -> zvt_builder::ZVTResult<(Self, &[u8])> {
        todo!()
    }
}

impl zvt_builder::ZvtSerializer for Nack {
    fn zvt_serialize(&self) -> Vec<u8> {
        // here goes the real impl
        todo!()
    }

    fn zvt_deserialize(bytes: &[u8]) -> zvt_builder::ZVTResult<(Self, &[u8])> {
        // here goes the real impl
        todo!()
    }
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want me to change the implementation as you proposed?
Or are you going to integrate it as you said?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you do :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants