Make generated .to_bytes() more readable

This commit is contained in:
Lonami Exo 2017-09-29 13:00:22 +02:00
parent 195bba6f21
commit 76d14b2dd9

View File

@ -300,15 +300,17 @@ class TLGenerator:
# Write the .to_bytes() function # Write the .to_bytes() function
builder.writeln('def to_bytes(self):') builder.writeln('def to_bytes(self):')
builder.write("return b''.join((") builder.writeln("return b''.join((")
builder.current_indent += 1
# First constructor code, we already know its bytes # First constructor code, we already know its bytes
builder.write('{},'.format(repr(struct.pack('<I', tlobject.id)))) builder.writeln('{},'.format(repr(struct.pack('<I', tlobject.id))))
for arg in tlobject.args: for arg in tlobject.args:
if TLGenerator.write_to_bytes(builder, arg, tlobject.args): if TLGenerator.write_to_bytes(builder, arg, tlobject.args):
builder.write(',') builder.writeln(',')
builder.current_indent -= 1
builder.writeln('))') builder.writeln('))')
builder.end_block() builder.end_block()