1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 14:26:04 +00:00

why am i getting a varint error

This commit is contained in:
mat 2022-09-07 22:12:16 -05:00
parent ec316e02cd
commit 98000f800f
3 changed files with 17 additions and 9 deletions

View file

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

View file

@ -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(

View file

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