test_codec

Function test_codec 

Source
pub fn test_codec<D: Codec + PartialEq + Debug>(
    encoded_bytes: &[u8],
    v: &D,
) -> Result<(), Error>
Expand description

Comprehensively tests a codec implementation with both valid and corrupted data.

This function performs several checks:

  1. Encodes the value and verifies it matches the expected bytes
  2. Decodes the encoded bytes and verifies it matches the original value
  3. Tests error handling by corrupting each byte and ensuring decode fails

§Arguments

  • encoded_bytes - The expected encoded representation
  • v - The value to test encoding/decoding

§Returns

Ok(()) if all tests pass, io::Error if any encoding/decoding operation fails