mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-24 08:22:59 +01:00
Merge pull request #328 from xfix/remove-some-uses-of-unsafe-from-frame-message
Remove some uses of unsafe from Frame::message
This commit is contained in:
commit
c427fd1241
@ -1,5 +1,5 @@
|
|||||||
#![cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
|
#![cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
|
||||||
use byteorder::{BigEndian, ByteOrder, NetworkEndian};
|
use byteorder::{ByteOrder, NetworkEndian};
|
||||||
use bytes::{BufMut, Bytes, BytesMut};
|
use bytes::{BufMut, Bytes, BytesMut};
|
||||||
use futures::{Async, Poll, Stream};
|
use futures::{Async, Poll, Stream};
|
||||||
use rand;
|
use rand;
|
||||||
@ -312,20 +312,12 @@ impl Frame {
|
|||||||
} else if payload_len <= 65_535 {
|
} else if payload_len <= 65_535 {
|
||||||
let mut buf = BytesMut::with_capacity(p_len + 4);
|
let mut buf = BytesMut::with_capacity(p_len + 4);
|
||||||
buf.put_slice(&[one, two | 126]);
|
buf.put_slice(&[one, two | 126]);
|
||||||
{
|
buf.put_u16_be(payload_len as u16);
|
||||||
let buf_mut = unsafe { buf.bytes_mut() };
|
|
||||||
BigEndian::write_u16(&mut buf_mut[..2], payload_len as u16);
|
|
||||||
}
|
|
||||||
unsafe { buf.advance_mut(2) };
|
|
||||||
buf
|
buf
|
||||||
} else {
|
} else {
|
||||||
let mut buf = BytesMut::with_capacity(p_len + 10);
|
let mut buf = BytesMut::with_capacity(p_len + 10);
|
||||||
buf.put_slice(&[one, two | 127]);
|
buf.put_slice(&[one, two | 127]);
|
||||||
{
|
buf.put_u64_be(payload_len as u64);
|
||||||
let buf_mut = unsafe { buf.bytes_mut() };
|
|
||||||
BigEndian::write_u64(&mut buf_mut[..8], payload_len as u64);
|
|
||||||
}
|
|
||||||
unsafe { buf.advance_mut(8) };
|
|
||||||
buf
|
buf
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user