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

Seek/Peek support #4

Open
vhdirk opened this issue Oct 17, 2024 · 1 comment
Open

Seek/Peek support #4

vhdirk opened this issue Oct 17, 2024 · 1 comment

Comments

@vhdirk
Copy link

vhdirk commented Oct 17, 2024

My weird protocol has a 'operation' structure like this:

struct SomeOperation {
   #[protocol(bits=1)]
   b7: u8,
   #[protocol(bits=1)]
   b6: u8,

   #[protocol(bits=6)]
   opcode: u8,

  # more data fields as defined by 'SomeOperation'
   data: SomeOperationData,
}

At first glance, you would think that opcode would define how data should be parsed. And that's mostly true, were it not for the small but very annoying detail that the 2 first bits (b7 and b6) are actually part of data. Depending on opcode, b7 and b6 might be 2 independent variables, but they may as well be one 2 bit field.

So to parse this particular operation, I need to skip 2 bits, read the opcode and then rewind the reader. Or succinctly, just peek at bits 5 through 0. And the reverse when serializing the whole thing again.

It would be quite cool (yet probably quite confusing) to just read the opcode, rewind, and read the whole thing again, jumping over the bits that have already been read before.

Any ideas ? :)

@wojciech-graj
Copy link
Owner

Seeking and peeking are unfortunately out of the question, as I'm limited by the capabilities of bitstream_io, and their BitReader can't perform such operations.

The best solution would probably be to manually implement ProtocolRead and ProtocolWrite on SomeOperationData.

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

No branches or pull requests

2 participants