usb-device icon indicating copy to clipboard operation
usb-device copied to clipboard

Add a tool for writing descriptors with lengths not known at compile time

Open electroCutie opened this issue 5 years ago • 1 comments

This is meant to be a starting point for #45

electroCutie avatar Oct 17 '20 08:10 electroCutie

Hi, thanks for the PR and sorry for the late reply!

I wonder if this couldn't be done a bit more simply with just a few extra methods in DescriptorWriter, something along the lines of:

    /// Returns a mark for the current byte position
    fn pos(&self) -> Mark { /* ... */ }

    /// Write raw bytes to the descriptor
    fn write_raw(&self, data: &[u8]) -> Result {
        self.write_raw_at(data, self.pos())
    }

    /// Write raw bytes to the descriptor at a previously marked location
    fn write_raw_at(&self, data: &[u8], pos: &Mark) -> Result { /* ... */ }

Mark would be a simple wrapper type for a usize that also supports subtraction for finding out the length of something. This would allow for any weird descriptors that may not encode length as a single byte, or perhaps want to write length - 1 or something like that.

mvirkkunen avatar Mar 13 '21 17:03 mvirkkunen