nurtex-codec 1.2.0

Library for serializing types from the Minecraft protocol.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::Buffer;

impl Buffer for bool {
  fn read_buf(buffer: &mut std::io::Cursor<&[u8]>) -> Option<Self> {
    let byte = u8::read_buf(buffer)?;

    if byte > 1 {
      return None;
    }

    Some(byte != 0)
  }

  fn write_buf(&self, buffer: &mut impl std::io::Write) -> std::io::Result<()> {
    let byte = u8::from(*self);
    byte.write_buf(buffer)
  }
}