From 730965e22cd50b5b840ae2b6b894dae64533bccd Mon Sep 17 00:00:00 2001 From: alemidev Date: Sat, 4 Dec 2021 02:12:14 +0100 Subject: [PATCH] move TrailingByteArray up --- aiocraft/mc/types.py | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/aiocraft/mc/types.py b/aiocraft/mc/types.py index ad22d4b..844a51d 100644 --- a/aiocraft/mc/types.py +++ b/aiocraft/mc/types.py @@ -21,6 +21,18 @@ class Type(object): def read(cls, buffer:io.BytesIO) -> Any: return struct.unpack(cls._fmt, buffer.read(cls._size))[0] +class TrailingByteArray(Type): + _pytype : type = bytes + + @classmethod + def write(cls, data:bytes, buffer:io.BytesIO): + if data: + buffer.write(data) + + @classmethod + def read(cls, buffer:io.BytesIO) -> bytes: + return buffer.read() + class Boolean(Type): _pytype : type = bool _size : int = 1 @@ -126,6 +138,16 @@ class VarLong(VarInt): _pytype : type = int _size = 10 +class EntityMetadata(TrailingByteArray): + # TODO + pass + +class Slot(TrailingByteArray): + _pytype : type = bytes + # TODO + pass + + class Maybe(Type): # TODO better name without _t : Class[Type] = TrailingByteArray _pytype : type = bytes @@ -259,24 +281,3 @@ class UUID(Type): def read(cls, buffer:io.BytesIO) -> uuid.UUID: return uuid.UUID(int=int.from_bytes(buffer.read(cls._size), 'big')) -class TrailingByteArray(Type): - _pytype : type = bytes - - @classmethod - def write(cls, data:bytes, buffer:io.BytesIO): - if data: - buffer.write(data) - - @classmethod - def read(cls, buffer:io.BytesIO) -> bytes: - return buffer.read() - -class EntityMetadata(TrailingByteArray): - # TODO - pass - -class Slot(TrailingByteArray): - _pytype : type = bytes - # TODO - pass -