Add `try_from_bytes_incomplete` method to handle Protocol 300 transmissions that may contain extra trailing bytes. This improves robustness when parsing messages from unreliable sources or when dealing with partial data.
The original `try_from_bytes` method remains strict, while the new method provides a more lenient parsing option for cases where strict validation isn't required. Also added a TODO comment for future validation of message length.
Changed FromBytesError::InvalidBytes to take ownership of the byte slice by converting it to Vec<u8>. This removes the lifetime parameter from the enum, simplifying the API and preventing potential lifetime-related issues. The change ensures that error instances can be freely moved and stored without borrowing constraints.
Refactored Protocol300Transmission parsing to provide more detailed error information when encountering invalid byte sequences. Changed the error variant from `InvalidByte` to `InvalidBytes` which now includes the problematic byte slice, enabling better debugging. Updated the match arm to capture the byte slice as `b` instead of using a wildcard, and modified the error logging to reflect these changes. The lifetime parameter was added to the `FromBytesError` enum to support the byte slice reference.
Add a new method to calculate the byte length of Protocol300Transmission
variants without converting to bytes. The method returns:
- 1 byte for control characters (Ack, Enq, Eot, Nack)
- 3 bytes for Init
- telegram_length + 3 bytes for Message
Include comprehensive unit tests for all transmission variants to ensure
correct length calculation.