Find new way to not deal with struct messages
This commit is contained in:
parent
a02ce7a0f5
commit
07d4a5d9b4
|
@ -181,7 +181,8 @@ impl Context {
|
|||
if let Poll::Ready(maybe_message) = self.as_mut().socket.poll_next_unpin(cx) {
|
||||
let message = maybe_message.ok_or_eyre("Socket was closed while trying to recieve")?;
|
||||
if let Err(err) = self.as_mut().handle_receive(message) {
|
||||
log::warn!("Got error while processing message: {}", err);
|
||||
log::warn!("Got error while processing message: {:?}", err);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,8 +28,6 @@ impl<T: protobuf::Message> CMProtoBufMessage<T> {
|
|||
self.header.write_to_vec(&mut out)?;
|
||||
self.body.write_to_vec(&mut out)?;
|
||||
|
||||
log::trace!("Serialized message: {}", hex::encode(&out));
|
||||
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
|
@ -55,7 +53,10 @@ pub struct CMRawProtoBufMessage {
|
|||
impl CMRawProtoBufMessage {
|
||||
pub fn try_parse(binary: &[u8]) -> eyre::Result<Self> {
|
||||
if binary.len() < 8 {
|
||||
eyre::bail!("Message too short for type");
|
||||
eyre::bail!(
|
||||
"Message too short for type (need 8 bytes, was {} bytes)",
|
||||
binary.len()
|
||||
);
|
||||
}
|
||||
let raw_action = u32::from_le_bytes(binary[0..4].try_into().unwrap()) & !0x8000_0000;
|
||||
let action = EMsg::from_i32(raw_action as i32)
|
||||
|
@ -64,7 +65,11 @@ impl CMRawProtoBufMessage {
|
|||
let header_length = u32::from_le_bytes(binary[4..8].try_into().unwrap());
|
||||
let header_end = 8 + header_length as usize;
|
||||
if binary.len() < header_end {
|
||||
eyre::bail!("Message too short for header")
|
||||
eyre::bail!(
|
||||
"Message too short for header (need {}, was {})",
|
||||
header_end,
|
||||
binary.len()
|
||||
)
|
||||
}
|
||||
|
||||
let header = CMsgProtoBufHeader::parse_from_bytes(&binary[8..header_end])?;
|
||||
|
@ -113,10 +118,17 @@ impl CMRawProtoBufMessage {
|
|||
let full_length = u32::from_le_bytes(body[0..4].try_into().unwrap());
|
||||
let message_end = 4 + full_length as usize;
|
||||
if body.len() < message_end {
|
||||
eyre::bail!("sub-message too short")
|
||||
eyre::bail!(
|
||||
"sub-message too short (need {}, got {})",
|
||||
message_end,
|
||||
body.len()
|
||||
)
|
||||
}
|
||||
|
||||
items.push(Self::try_parse(&body[4..message_end])?);
|
||||
match Self::try_parse(&body[4..message_end]) {
|
||||
Ok(msg) => items.push(msg),
|
||||
Err(err) => log::warn!("Failed to parse sub-message: {:?}", err),
|
||||
}
|
||||
|
||||
body = &body[message_end..];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue