diff options
| author | mat <github@matdoes.dev> | 2022-09-07 22:12:16 -0500 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-09-07 22:12:16 -0500 |
| commit | 98000f800f31c85c7bbf121b116047137b503c49 (patch) | |
| tree | 720e21b59e1b10eed6e66b6ace06714407d68f54 | |
| parent | ec316e02cd7d86829614ec1c0b7e3edadad103c5 (diff) | |
| download | azalea-drasl-98000f800f31c85c7bbf121b116047137b503c49.tar.xz | |
why am i getting a varint error
| -rw-r--r-- | azalea-buf/src/read.rs | 10 | ||||
| -rwxr-xr-x | azalea-chat/src/component.rs | 2 | ||||
| -rw-r--r-- | azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs | 14 |
3 files changed, 17 insertions, 9 deletions
diff --git a/azalea-buf/src/read.rs b/azalea-buf/src/read.rs index 045dcd4f..78c858e4 100644 --- a/azalea-buf/src/read.rs +++ b/azalea-buf/src/read.rs @@ -64,13 +64,10 @@ pub async fn read_varint_async( let mut buffer = [0]; let mut ans = 0; for i in 0..5 { - reader - .read_exact(&mut buffer) - .await - .map_err(|_| BufReadError::InvalidVarInt)?; + reader.read_exact(&mut buffer).await?; ans |= ((buffer[0] & 0b0111_1111) as i32) << (7 * i); if buffer[0] & 0b1000_0000 == 0 { - return Ok(ans); + break; } } Ok(ans) @@ -103,8 +100,7 @@ impl McBufVarReadable for i32 { let mut buffer = [0]; let mut ans = 0; for i in 0..5 { - buf.read_exact(&mut buffer) - .map_err(|_| BufReadError::InvalidVarInt)?; + buf.read_exact(&mut buffer)?; ans |= ((buffer[0] & 0b0111_1111) as i32) << (7 * i); if buffer[0] & 0b1000_0000 == 0 { break; diff --git a/azalea-chat/src/component.rs b/azalea-chat/src/component.rs index caf50b0a..6cf1ec09 100755 --- a/azalea-chat/src/component.rs +++ b/azalea-chat/src/component.rs @@ -182,7 +182,7 @@ impl<'de> Deserialize<'de> for Component { "keybind text components aren't yet supported", )); } else { - let nbt = if let Some(nbt) = json.get("nbt") { + let _nbt = if let Some(nbt) = json.get("nbt") { nbt } else { return Err(de::Error::custom( diff --git a/azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs index 7192f88a..5d3bdd23 100644 --- a/azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs @@ -14,7 +14,7 @@ pub struct ClientboundPlayerChatPacket { pub chat_type: ChatTypeBound, } -#[derive(Copy, Clone, Debug, McBuf)] +#[derive(Copy, Clone, Debug, McBuf, PartialEq, Eq)] pub enum ChatType { Chat = 0, SayCommand = 1, @@ -115,3 +115,15 @@ impl McBufWritable for FilterMask { Ok(()) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_chat_type() { + let chat_type_enum = ChatType::read_from(&mut &[0x06][..]).unwrap(); + assert_eq!(chat_type_enum, ChatType::EmoteCommand); + assert!(ChatType::read_from(&mut &[0x07][..]).is_err()); + } +} |
