Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

electroCutie
Copy link

This is meant to be a starting point for #45

@mvirkkunen
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants