Skip to content

Conversation

@minlux
Copy link

@minlux minlux commented Dec 13, 2025

This PR adds a module "commands" with an enum for all zvt commands.
This enum can be used to to simplify reception - see example below.

This PR also adds a new attribute zvt_instr_any for the ZvtEnum macro.
When this attribute is added to an command enum, the respective match arm, generated by the ZvtEnum macro evaluates only the packet's CLASS byte, and ignores the INSTR byte.
It was mainly created for the Nack packet, where the INSTR is the actual error code - and can be any value.

The following example shows the usage of Commands enum to receive any zvt packet:

match transport.read_packet::<zvt::commands::Command>().await {
    Ok(packet) => {
        let result = match packet {
            zvt::commands::Command::Registration(reg) => {
                handle_registration(&mut transport, reg).await
            }
            zvt::commands::Command::Authorization(auth) => {
                handle_authorization(&mut transport, auth).await
            }
            zvt::commands::Command::Nack(nack) => {
                handle_nack(&mut transport, nack).await
            }

Note: The enum, already contains commands for the Authorization and Nack packet - which are provided in my other PRs :-)

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

i'm not sure if i get it - what is the use case of the enum? Would we use it in the sequences or do you have something else in mind

@minlux
Copy link
Author

minlux commented Jan 25, 2026

I implemented a terminal simulator. The snippet from above is used there.
So the purpose of the command enum is (as mentioned) to simplify reception.

Useful for all kind of zvt "server".

I also have a websocket to zvt proxy, that uses that enum.

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