[go: up one dir, main page]

Skip to content

Possible wrong implementation of `truncated_length`

Following this issue: mavio#1 (closed)

    fn truncated_length(slice: &[u8]) -> usize {
        let n: usize = slice.len();
        // Assume that all elements are zeros
        let mut num_non_zero = 0usize;
        // Seek from the end to start
        for i in 1..=n {
            // Stop when non-zero element is found
            if slice[n - i] != 0u8 {
                num_non_zero = n - i + 1;
                break;
            }
        }

        num_non_zero
    }

this does not follow MAVLink specification as described here: https://mavlink.io/en/guide/serialization.html#payload_truncation

The first byte of the payload is never truncated, even if the payload consists entirely of zeros.

this function might return 0 which will then create an empty payload.bytes() which does not match expected payload_length (1)