fix(codecs): Fix framing handling of long frames (#10568)
* fix(codecs): Fix framing handling of long frames Previously it would return `Ok(None)` when a frame longer than `max_length` was encountered, but the `tokio_codec::Decoder` specifies: ``` If an entire frame is available, then this instance will remove those bytes from the buffer provided and return them as a decoded frame. Note that removing bytes from the provided buffer doesn't always necessarily copy the bytes, so this should be an efficient operation in most circumstances. If the bytes look valid, but a frame isn't fully available yet, then Ok(None) is returned. This indicates to the Framed instance that it needs to read some more bytes before calling this method again. Note that the bytes provided may be empty. If a previous call to decode consumed all the bytes in the buffer then decode will be called again until it returns Ok(None), indicating that more bytes need to be read. ``` That is, it should only return `Ok(None)` if it hit the end of the buffer without reading a full frame. As a reference, consider the implementation of `tokio_codec::LinesCodec` which, when discarding, discards until it can find the next frame before returning (granted it behaves slightly differently by returning an error, first, when it hits a line that is too long where we just warn). Signed-off-by: Jesse Szwedko <jesse@szwedko.me> * PRfeedback Signed-off-by: Jesse Szwedko <jesse@szwedko.me>
J
Jesse Szwedko committed
4c8abf34f6f4d185a97976efd9298148929973d2
Parent: e14acc7
Committed by GitHub <noreply@github.com>
on 12/23/2021, 2:48:14 AM