impl integer byte array

This commit is contained in:
əlemi 2021-11-12 01:38:32 +01:00
parent d6aec8cfad
commit 7f3e58b7e6
2 changed files with 23 additions and 7 deletions

View file

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

View file

@ -55,7 +55,11 @@ def mctype(slot_type:Any) -> Type:
if isinstance(slot_type, list):
name = slot_type[0]
if name == "buffer":
data = slot_type[1]
if data["countType"] == "varint":
return ByteArray
elif data["countType"] == "integer":
return IntegerByteArray
# TODO composite data types
return TrailingByteArray