Replies: 2 comments
-
In case you want to hardwire the lengths of the message payload based on the command, a function might come in handy:
This version does not excplicitely store the length of the array in the byte stream, as it is always fixed based on the command. Regarding the length you can indeed do something like that. There is a lengthof operator (see https://zserio.org/doc/ZserioLanguageOverview.html#lengthof-operator). At the moment there is no way to extend the generated code by anything that you would put in the schema. But of course you can manually inject code after code generation to do so. We know of projects that do something similar in a post-schema-generation step. |
Beta Was this translation helpful? Give feedback.
-
Unfortunately, unions are not designed for this. Actually, unions are auto choices. To compute the checksum in the footer, it will be necessary to serialize message in the two steps. The first step will serialize the header and the payload, the second one will serialize everything or maybe only the checksum. It is not nice but it will work. Example:
Templates could simplify things a little bit:
|
Beta Was this translation helpful? Give feedback.
-
I would like to use zserio to generate code for an existing communication protocol. I think my protocol has some fairly common characteristics (a type-length-value format), but I haven't been able to find a zserio example that reaches this level of complexity. Can anyone guide me in the right direction?
Here are two example messages in this protocol:
Notice that the messages have common headers (command, length) and footers (checksum). Since my actual header and footer formats are more complex, I would like to share those definitions between messages. I believe that would look like this:
But I am not sure how to express these details to the zserio generator:
After the generator runs, I would like clients to be able to write Python code like this:
Questions
Header.length = sizeof(payload)
.Beta Was this translation helpful? Give feedback.
All reactions