usb-device
usb-device copied to clipboard
Add a tool for writing descriptors with lengths not known at compile time
This is meant to be a starting point for #45
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.