Change Ping and Pong payloads to Bytes

Fixes Issue #1049
This commit is contained in:
Patrick Himmelmann 2019-09-06 14:14:52 +02:00
parent c9400456f6
commit e374f3c97c
1 changed files with 10 additions and 10 deletions

View File

@ -13,9 +13,9 @@ pub enum Message {
/// Binary message /// Binary message
Binary(Bytes), Binary(Bytes),
/// Ping message /// Ping message
Ping(String), Ping(Bytes),
/// Pong message /// Pong message
Pong(String), Pong(Bytes),
/// Close message with optional reason /// Close message with optional reason
Close(Option<CloseReason>), Close(Option<CloseReason>),
/// No-op. Useful for actix-net services /// No-op. Useful for actix-net services
@ -30,9 +30,9 @@ pub enum Frame {
/// Binary frame /// Binary frame
Binary(Option<BytesMut>), Binary(Option<BytesMut>),
/// Ping message /// Ping message
Ping(String), Ping(Bytes),
/// Pong message /// Pong message
Pong(String), Pong(Bytes),
/// Close message with optional reason /// Close message with optional reason
Close(Option<CloseReason>), Close(Option<CloseReason>),
} }
@ -119,17 +119,17 @@ impl Decoder for Codec {
} }
} }
OpCode::Ping => { OpCode::Ping => {
if let Some(ref pl) = payload { if let Some(pl) = payload {
Ok(Some(Frame::Ping(String::from_utf8_lossy(pl).into()))) Ok(Some(Frame::Ping(pl.into())))
} else { } else {
Ok(Some(Frame::Ping(String::new()))) Ok(Some(Frame::Ping(Bytes::new())))
} }
} }
OpCode::Pong => { OpCode::Pong => {
if let Some(ref pl) = payload { if let Some(pl) = payload {
Ok(Some(Frame::Pong(String::from_utf8_lossy(pl).into()))) Ok(Some(Frame::Pong(pl.into())))
} else { } else {
Ok(Some(Frame::Pong(String::new()))) Ok(Some(Frame::Pong(Bytes::new())))
} }
} }
OpCode::Binary => Ok(Some(Frame::Binary(payload))), OpCode::Binary => Ok(Some(Frame::Binary(payload))),