impl integer byte array
This commit is contained in:
parent
d6aec8cfad
commit
7f3e58b7e6
2 changed files with 23 additions and 7 deletions
|
@ -165,13 +165,29 @@ class ByteArray(Type):
|
||||||
length = VarInt.read(buffer)
|
length = VarInt.read(buffer)
|
||||||
return buffer.read(length)
|
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):
|
class Chat(String):
|
||||||
_pytype : type = str
|
_pytype : type = str
|
||||||
pass
|
|
||||||
|
|
||||||
class Identifier(String):
|
class Identifier(String):
|
||||||
_pytype : type = str
|
_pytype : type = str
|
||||||
pass
|
|
||||||
|
class Angle(Type):
|
||||||
|
_pytype : type = int
|
||||||
|
_size : int = 1
|
||||||
|
_fmt : str = ">b"
|
||||||
|
|
||||||
class EntityMetadata(Type):
|
class EntityMetadata(Type):
|
||||||
_pytype : type = bytes
|
_pytype : type = bytes
|
||||||
|
@ -198,10 +214,6 @@ class Position(Type):
|
||||||
# TODO
|
# TODO
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class Angle(Type):
|
|
||||||
_pytype : type = bytes
|
|
||||||
# TODO
|
|
||||||
pass
|
|
||||||
|
|
||||||
class UUID(Type):
|
class UUID(Type):
|
||||||
_pytype : type = bytes
|
_pytype : type = bytes
|
||||||
|
|
|
@ -55,7 +55,11 @@ def mctype(slot_type:Any) -> Type:
|
||||||
if isinstance(slot_type, list):
|
if isinstance(slot_type, list):
|
||||||
name = slot_type[0]
|
name = slot_type[0]
|
||||||
if name == "buffer":
|
if name == "buffer":
|
||||||
|
data = slot_type[1]
|
||||||
|
if data["countType"] == "varint":
|
||||||
return ByteArray
|
return ByteArray
|
||||||
|
elif data["countType"] == "integer":
|
||||||
|
return IntegerByteArray
|
||||||
# TODO composite data types
|
# TODO composite data types
|
||||||
return TrailingByteArray
|
return TrailingByteArray
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue