1
0
mirror of https://github.com/danog/tl-schema.git synced 2024-11-30 04:19:47 +01:00

Improve converter

This commit is contained in:
Viktor Oreshkin 2017-07-03 11:28:47 +03:00
parent 007afbbf9a
commit b9e946ab84

View File

@ -94,18 +94,16 @@ class TLTokenTL(TLToken):
@staticmethod
def dump(inst):
"""
Prints prepending zeroes in crc
and two spaces in case of empty params
so output is slightly different from telegram's schemas
but still correct
"""
return '{name}#{crc} {params} = {result};'.format(
name=inst.name,
crc=str(binascii.b2a_hex(struct.pack('>i', inst.crc)), encoding='ascii'),
crc=TLTokenTL.crc2hex(inst.crc),
params=' '.join('{name}:{type}'.format(**param) for param in inst.params),
result=inst.result
)
).replace(' ', ' ')
@staticmethod
def crc2hex(crc: int):
return str(binascii.b2a_hex(struct.pack('>i', crc)), encoding='ascii').lstrip('0')
def __repr__(self):
return self.dump(self)