Open korken89 opened 4 years ago
The issue I see with a "footer flavor" is that there is no way to push the footer before COBS finishes.
One could extend the COBS flavor to have an optional "generate footer" that is None
in the normal case, and if there is something to generate a footer it will be pushed before the finalization of COBS, but then one would have to add so the deserialization returns an optional footer.
An alternative is to implement Hash for it as such:
#[derive(Hash, Serialize, Deserialize)]
pub enum Message {
/// ...
}
#[derive(Serialize, Deserialize)]
struct Packet {
msg: Message,
crc: u16,
}
And fill the CRC with a suitably implemented Hasher
.
I'm necromancing this issue because I am also looking for similar functionality. I'm not really familiar with Postcard at this time, so this might not be a good idea: My approach would be a CRC flavour that wraps COBS. Dropping the flavour object could/would write the computed CRC with its "last breath" to the COBS flavour - although a more elegant solution would be to expose the end of the message to the flavours.
What is the current recommended way to serialize/deserialize with a footer? With this I mean, in my usecase, I want to append a CRC to the end of the buffer and each byte being serialized should also go through the CRC calculation. Currently if I serialize with a flavor I cannot append the CRC manually as it can for example have been encoded with COBS.
Let's say I want something like this: