lschmierer / sacn

Project moved to: https://github.com/RustLight/sacn
Apache License 2.0
12 stars 5 forks source link

Flatten packet parsing #14

Closed lschmierer closed 6 years ago

lschmierer commented 6 years ago

Currently, on no_std hardware, we always allocate the maximum possible packet size on the heap. This is not very efficient.

Handle nested PDUs as simple &[u8] slices.

trait Pdu {
    fn vector(&self) -> u32;

    fn pack(&self, buf: &[u8]) -> Result<(), PackError> {
        ...
    }

    fn pack_header(&self, buf: &[u8]) -> Result<(), PackError>;

    fn pack_data(&self, buf: &[u8]) -> Result<(), PackError>;

    fn len(&self) -> usize {
        ...
    }

    fn vector_len(&self) -> usize;

    fn header_len(&self) -> usize;

    fn data_len(&self) -> usize;
}
lschmierer commented 6 years ago

This makes all very complicated and the API inerergonomic. Also, a packet size of 1144 bytes (about 1 kB) does not seem too bad.