Packing python bools as tw net bools just works
python handles bools more like the ints 0 and 1 and those are exactly the values the teeworlds network protocol expects I can totally see this breaking in python4 or a new mypy version maybe one day a ``get_bool()`` could make sense also for readability but for now this should be stable as long as the tests pass
This commit is contained in:
parent
f1d562f25f
commit
3b93a6bba2
|
@ -471,7 +471,7 @@ def pack_field(member: NetMessageMemberJson) -> str:
|
|||
packer = 'int'
|
||||
elif member['type']['kind'] in ('int32', 'tick'):
|
||||
packer = 'int'
|
||||
elif member['type']['kind'] == 'boolean': # TODO: can we back True and False as int?
|
||||
elif member['type']['kind'] == 'boolean':
|
||||
packer = 'int'
|
||||
elif member['type']['kind'] == 'tune_param':
|
||||
packer = 'int'
|
||||
|
|
|
@ -11,6 +11,19 @@ def test_unpack_ints_and_strings() -> None:
|
|||
assert u.get_str() == 'foo'
|
||||
assert u.get_str() == 'bar'
|
||||
|
||||
def test_pack_bools() -> None:
|
||||
assert pack_int(False) == b'\x00'
|
||||
assert pack_int(True) == b'\x01'
|
||||
|
||||
assert pack_int(0) == b'\x00'
|
||||
assert pack_int(1) == b'\x01'
|
||||
|
||||
def test_unpack_bools() -> None:
|
||||
data: bytes = b'\x00\x01'
|
||||
u = Unpacker(data)
|
||||
assert (u.get_int() == 1) is False
|
||||
assert (u.get_int() == 1) is True
|
||||
|
||||
def test_simple_repack() -> None:
|
||||
data: bytes = pack_str('hello world')
|
||||
assert data == b'hello world\x00'
|
||||
|
|
Loading…
Reference in a new issue