Skip to content
Permalink
Browse files

Remove a cast to usize and use the new safe usize::from_be_bytes

Introduced in rust 1.32.0
  • Loading branch information...
lopopolo committed Jan 27, 2019
1 parent 7a7354c commit 2263c8087c1feba5dd1395d30d2f7a5636f46f26
Showing with 6 additions and 3 deletions.
  1. +6 −3 cast-client/src/codec.rs
@@ -104,10 +104,13 @@ impl CastMessage {
if src.len() < CAST_MESSAGE_HEADER_LENGTH {
return None;
}
let header = src.split_to(4);
let header = src.split_to(CAST_MESSAGE_HEADER_LENGTH);
let length = {
let mut header = header.into_buf();
header.get_u32_be() as usize
let mut bytes: [u8; 8] = Default::default();
for (i, byte) in header.into_buf().bytes().iter().enumerate() {
bytes[i + CAST_MESSAGE_HEADER_LENGTH] = *byte;
}
usize::from_be_bytes(bytes)
};
if length > CAST_MESSAGE_PROTOBUF_MAX_LENGTH {
panic!("CastMessageCodec decoder received message of length {}, which is larger than the max message length of {}", length, CAST_MESSAGE_PROTOBUF_MAX_LENGTH);

0 comments on commit 2263c80

Please sign in to comment.
You can’t perform that action at this time.