From 7f3e58b7e6e943f4ba2d3fa833017cb63e1a63cb Mon Sep 17 00:00:00 2001 From: alemidev Date: Fri, 12 Nov 2021 01:38:32 +0100 Subject: [PATCH] impl integer byte array --- aiocraft/mc/mctypes.py | 24 ++++++++++++++++++------ compiler/proto.py | 6 +++++- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/aiocraft/mc/mctypes.py b/aiocraft/mc/mctypes.py index ba40449..a31a0fa 100644 --- a/aiocraft/mc/mctypes.py +++ b/aiocraft/mc/mctypes.py @@ -165,13 +165,29 @@ class ByteArray(Type): length = VarInt.read(buffer) return buffer.read(length) +class IntegerByteArray(Type): + _pytype : type = bytes + + @classmethod + def write(cls, data:bytes, buffer:io.BytesIO): + Int.write(len(data), buffer) + buffer.write(data) + + @classmethod + def read(cls, buffer:io.BytesIO) -> bytes: + length = Int.read(buffer) + return buffer.read(length) + class Chat(String): _pytype : type = str - pass class Identifier(String): _pytype : type = str - pass + +class Angle(Type): + _pytype : type = int + _size : int = 1 + _fmt : str = ">b" class EntityMetadata(Type): _pytype : type = bytes @@ -198,10 +214,6 @@ class Position(Type): # TODO pass -class Angle(Type): - _pytype : type = bytes - # TODO - pass class UUID(Type): _pytype : type = bytes diff --git a/compiler/proto.py b/compiler/proto.py index 389e1f8..17907f8 100644 --- a/compiler/proto.py +++ b/compiler/proto.py @@ -55,7 +55,11 @@ def mctype(slot_type:Any) -> Type: if isinstance(slot_type, list): name = slot_type[0] if name == "buffer": - return ByteArray + data = slot_type[1] + if data["countType"] == "varint": + return ByteArray + elif data["countType"] == "integer": + return IntegerByteArray # TODO composite data types return TrailingByteArray