Minecraft bedrock support (#7)

* Added needed ground stuff

* Minecraft bedrock support!

* Documentation acknowledgements!

* Added utf8_le_undended test, some docs and modified master_querant

* Modified query function to comply with the others

Before: game query -> protocol query (get port or default port)
After: game query (get port or default port) -> protocol query

* Modified md files
This commit is contained in:
CosminPerRam 2022-12-05 18:47:35 +02:00 committed by GitHub
parent ae14e37e60
commit 91f8bbb9fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 319 additions and 107 deletions

View file

@ -98,6 +98,19 @@ pub mod buffer {
Ok(value)
}
pub fn get_string_utf8_le_unended(buf: &[u8], pos: &mut usize) -> GDResult<String> {
let sub_buf = &buf[*pos..];
if sub_buf.len() == 0 {
return Err(GDError::PacketUnderflow("Unexpectedly short packet for getting an utf8 LE string.".to_string()));
}
let value = std::str::from_utf8(&sub_buf)
.map_err(|_| GDError::PacketBad("Badly formatted utf8 LE string.".to_string()))?.to_string();
*pos += value.len();
Ok(value)
}
pub fn get_string_utf16_be(buf: &[u8], pos: &mut usize) -> GDResult<String> {
let sub_buf = &buf[*pos..];
if sub_buf.len() == 0 {
@ -199,6 +212,16 @@ mod tests {
assert_eq!(pos, 6);
}
#[test]
fn get_string_utf8_le_unended_test() {
let data = [72, 101, 108, 108, 111];
let mut pos = 0;
assert_eq!(buffer::get_string_utf8_le_unended(&data, &mut pos).unwrap(), "Hello");
assert_eq!(pos, 5);
assert!(buffer::get_string_utf8_le_unended(&data, &mut pos).is_err());
assert_eq!(pos, 5);
}
#[test]
fn get_string_utf16_be_test() {
let data = [0x00, 0x48, 0x00, 0x65, 0x00, 0x6c, 0x00, 0x6c, 0x00, 0x6f];