Closed henriqueqc closed 2 years ago
Just realized that an enum could be used to solve that particular case.
I'm not averse to it, but I'm not going to tackle it any time soon. PRs are welcome, if you (or anyone reading) wants to add validations. In general, a custom codec with a post-encoder
fn is probably the place to add ad hoc validation.
Closing for now.
Is there a way to add validations to the data being decoded?
When using decode-stream with aleph it could be useful to be able to disconnect the client when it sends a field that we are not expecting.
For example, a protocol might define a SFD (start frame delimiter) field and expect it to be a 0x2 uchar. If the client sends something other than 0x2 we may want to disconnect the client instead of trying to decode the rest of the stream, as it is probably garbage, or we may choose to drop the data until we find a SFD.
What do you think of these use cases?