aboutsummaryrefslogtreecommitdiff
path: root/src/protocol.rs
diff options
context:
space:
mode:
authorJoey Sacchini <joey@sacchini.net>2020-10-02 12:46:46 -0400
committerJoey Sacchini <joey@sacchini.net>2020-10-02 12:46:46 -0400
commit9b9aa681d3bcf41a22291dff5d243b5fbb108339 (patch)
tree08ee19d486f2b444ac25b462c01ce32679dc0c15 /src/protocol.rs
parentb3e6c71ddcd554e0ef350b93feda8a8eb0de76ab (diff)
downloadmcproto-rs-9b9aa681d3bcf41a22291dff5d243b5fbb108339.tar.gz
mcproto-rs-9b9aa681d3bcf41a22291dff5d243b5fbb108339.tar.bz2
mcproto-rs-9b9aa681d3bcf41a22291dff5d243b5fbb108339.zip
fix random generation and make raw packet accept a borrowed slice
Diffstat (limited to 'src/protocol.rs')
-rw-r--r--src/protocol.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/protocol.rs b/src/protocol.rs
index d3a9af0..98b9740 100644
--- a/src/protocol.rs
+++ b/src/protocol.rs
@@ -30,7 +30,7 @@ impl<T: Clone + fmt::Debug + PartialEq + Serialize> PacketIdentifier for T {}
pub trait Packet<I: PacketIdentifier>: Serialize {
fn id(&self) -> I;
- fn mc_deserialize(raw: RawPacket<I>) -> Result<Self, PacketErr>;
+ fn mc_deserialize(raw: RawPacket<'_, I>) -> Result<Self, PacketErr>;
}
pub enum PacketErr {
@@ -57,9 +57,9 @@ impl fmt::Debug for PacketErr {
impl std::error::Error for PacketErr {}
#[derive(Debug, Clone, PartialEq)]
-pub struct RawPacket<I> {
+pub struct RawPacket<'a, I> {
pub id: I,
- pub data: Vec<u8>,
+ pub data: &'a[u8],
}
pub trait ProtocolType: Serialize + Deserialize {}
@@ -200,7 +200,7 @@ macro_rules! define_protocol {
use crate::Deserialize;
let id = raw.id;
- let data = raw.data.as_slice();
+ let data = raw.data;
match (id.id, id.state, id.direction) {
$(($id, $state, $direction) => Ok($nam($body::mc_deserialize(data).map_err(DeserializeFailed)?.value))),*,