-
Notifications
You must be signed in to change notification settings - Fork 254
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
Allow decoding Events containing BitVecs #408
Conversation
I wonder whether it's worth trying to simplify the decode logic; if bitvec contains its byte length, I could just ignore the order and store things entirely since I no longer need to try and re-encode it (I haven't checked yet, but should do so before committing to this). |
I had a look into the encode impl and reworked the handling to cover more cases and not care about ordering |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
decode_and_consume_type(type_id, &self.metadata.runtime_metadata().types, input)?; | ||
// count how many bytes were consumed based on remaining length: | ||
let consumed_len = all_bytes.len() - input.len(); | ||
// move those consumed bytes to the output vec unaltered: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, much more efficient 💪
|
||
// Given a type Id and a type registry, attempt to consume the bytes | ||
// corresponding to that type from our input. | ||
fn decode_and_consume_type( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: If we are happy and merge this, we could create a new "good first issue" to review the tests, perhaps adding some like the bitvec ones to test this method more specifically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this would be a good method to unit test
|
||
// We just need to consume the correct number of bytes. Roughly, we encode this | ||
// as a Compact<u32> length, and then a slice of T of that length, where T is the | ||
// bit store type. So, we ignore the bit order and only care that the bit store type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// bit store type. So, we ignore the bit order and only care that the bit store type | |
// bit store type. We ignore the bit order and only care that the bit store type |
@@ -404,6 +449,19 @@ mod tests { | |||
EventsDecoder::<DefaultConfig>::new(metadata) | |||
} | |||
|
|||
fn decode_and_consume_type_consumes_all_bytes< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
* Handle bitvec decoding * clippy * rework bitvec decoding; don't care about order and can handle other store primitives * cargo fmt
Also a little refactoring to make it easier to test the core decode logic, and remove the need to re-encode.
closes #405