-
Notifications
You must be signed in to change notification settings - Fork 180
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
Improve bytes #1174
Improve bytes #1174
Conversation
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.
I really love the changes 👍
zenoh/src/api/bytes.rs
Outdated
@@ -2345,75 +2925,54 @@ mod tests { | |||
hm.insert(0, 0); | |||
hm.insert(1, 1); | |||
println!("Serialize:\t{:?}", hm); | |||
let p = ZBytes::from_iter(hm.clone().drain()); | |||
let p = ZBytes::from(hm.clone()); |
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.
I love it. It's easier to use and understandable now.
} | ||
|
||
// Tuple (a, b, c) | ||
macro_rules! impl_tuple3 { |
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.
I guess the reason we use macro instead of inline here is type issue, right?
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.
Correct and trait recursiveness...
} | ||
} | ||
|
||
// HashMap |
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.
Do you think we can provide something similar for Vec? Now we only support Vec<u8>
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.
Unfortunately not. Rust does not support serialization and Vec<u8>
should have a special treatment compared to Vec<T> where ZSerde: Serialize<T>
.
An iterator of T
is serialized in this way:
- Serialize
T
as standalone - Write length of serialized
T
into final buffer - Append serialized
T
This allows to iterate over the elements T
because we know where the serialized T
starts and end.
u8
is a special case of T
where we do not want to prepend the serialized length but just copy everything.
But in order to treat it differently, we need specialization in Rust... which is not supported :(
@evshary could you please review this PR? |
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.
LGTM for adding more specific int/uint type in encoding
HashMap
char
Encoding
foru8
,u16
,u32
,u64
,u128
,i8
,i16
,i32
,i64
,i128
,f32
,f64