Find new way to not deal with struct messages

This commit is contained in:
Artemis Tosini 2024-08-28 01:49:36 +00:00
parent a02ce7a0f5
commit 07d4a5d9b4
Signed by: artemist
GPG key ID: EE5227935FE3FF18
3 changed files with 21 additions and 7 deletions

View file

@ -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);
}
}

View file

@ -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..];
}

View file

@ -29,6 +29,7 @@
];
RUST_SRC_PATH = "${rustPackages.rustPlatform.rustLibSrc}";
RUST_LOG = "debug,vapored=trace,vapore-client=trace";
RUST_BACKTRACE = "1";
};
formatter = pkgs.nixfmt-rfc-style;