-
Notifications
You must be signed in to change notification settings - Fork 14
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
Deserialize branch #374
Deserialize branch #374
Conversation
4532b3c
to
bc06503
Compare
313cae7
to
9fa4827
Compare
bc06503
to
c626577
Compare
9fa4827
to
4c9f31b
Compare
c626577
to
73fac9b
Compare
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.
Approved with nits
@@ -368,96 +372,7 @@ impl Storable for Node { | |||
|
|||
match meta_raw.as_deref()[TRIE_HASH_LEN + 1].try_into()? { | |||
NodeTypeId::Branch => { | |||
// TODO: add path |
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.
nit: This TODO seems relevant still, but it was deleted.
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.
Will go away shortly
offset: addr, | ||
size: ENCODED_CHILD_LEN_SIZE, | ||
})? | ||
.as_deref()[0] as u64; |
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.
nit: this will get a clippy exception due to unhandled panic once we add the clippy rules. Maybe:
.as_deref()[0] as u64; | |
.as_deref().get(0).ok_or(...)? as u64; |
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.
🤔 this could also be solved with a macro. We should be casting to an array and using from_be_bytes
such that we can make the size any valid numeric type. I'll add a comment to #396
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.
|
||
addr += ENCODED_CHILD_LEN_SIZE as usize; | ||
|
||
if len == 0 { |
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.
nit: clearer if this and the prior statement were reversed. Perhaps increase addr before setting and testing len.
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.
To go along with your comment about the macro, every time we get a view, we should automatically advance the address. I created #396 to address this
|
||
let node = BranchNode { | ||
// TODO: add path | ||
// path: Vec::new().into(), |
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.
nit: Is this comment wrong? This assumes that all branch nodes have no data.
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.
Will go away shortly
|
||
let raw_len = { | ||
let mut buf = [0; DATA_LEN_SIZE]; | ||
cursor.read_exact(&mut buf)?; |
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.
nit (DRY): identical code could be refactored into a macro, maybe:
macro_rules! read_data {
($cursor:expr, $type:ty) => {{
let mut buf = [0u8; std::mem::size_of::<$type>()];
$cursor.read_exact(&mut buf)?;
<$type>::from_le_bytes(buf)
}};
}
Then, at the callsite, you can do all the manipulation:
*child = Some(read_data!(cursor, usize))
.filter(|addr| *addr != 0)
.map(DiskAddress::from);
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.
|
||
let node = BranchNode { | ||
// TODO: add path | ||
// path: Vec::new().into(), |
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.
nit: this line can be removed with the TODO above?
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.
Will go away shortly
73fac9b
to
e6e7cf7
Compare
Delegate branch deserialization to the branch-module.