-
Notifications
You must be signed in to change notification settings - Fork 10
Zvt: Add nack packet/command #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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 { |
There was a problem hiding this comment.
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))
}
}
```... There was a problem hiding this comment.
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!()
}
}
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you do :)
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.