mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-01-24 08:14:14 +03:00
Fix generated __bytes__ failing with flag indicator but no flags
Likely since the code was ported to get rid of the BinaryWriter, since the flag calculation was inlined. Some types (only channelMessages as of layer 71) had a flag indicator but no flag arguments, so the calculation of which were not None failed. This special case is now handled correctly.
This commit is contained in:
parent
af08d59cb7
commit
2f28050cac
|
@ -491,11 +491,15 @@ class TLGenerator:
|
|||
|
||||
elif arg.flag_indicator:
|
||||
# Calculate the flags with those items which are not None
|
||||
builder.write("struct.pack('<I', {})".format(
|
||||
' | '.join('({} if {} else 0)'.format(
|
||||
1 << flag.flag_index, 'self.{}'.format(flag.name)
|
||||
) for flag in args if flag.is_flag)
|
||||
))
|
||||
if not any(f.is_flag for f in args):
|
||||
# There's a flag indicator, but no flag arguments so it's 0
|
||||
builder.write(r"b'\0\0\0\0'")
|
||||
else:
|
||||
builder.write("struct.pack('<I', {})".format(
|
||||
' | '.join('({} if {} else 0)'.format(
|
||||
1 << flag.flag_index, 'self.{}'.format(flag.name)
|
||||
) for flag in args if flag.is_flag)
|
||||
))
|
||||
|
||||
elif 'int' == arg.type:
|
||||
# struct.pack is around 4 times faster than int.to_bytes
|
||||
|
|
Loading…
Reference in New Issue
Block a user