mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-25 10:53:44 +03:00
Distinguish between vector type and constructor (fix #81)
This commit is contained in:
parent
b84641023a
commit
c4447bf226
|
@ -159,8 +159,14 @@ class TLArg:
|
|||
vector_match = re.match(r'vector<(\w+)>', self.type, re.IGNORECASE)
|
||||
if vector_match:
|
||||
self.is_vector = True
|
||||
self.type = vector_match.group(
|
||||
1) # Update the type to match the one inside the vector
|
||||
|
||||
# If the type's first letter is not uppercase, then
|
||||
# it is a constructor and we use (read/write) its ID
|
||||
# as pinpointed on issue #81.
|
||||
self.use_vector_id = self.type[0] == 'V'
|
||||
|
||||
# Update the type to match the one inside the vector
|
||||
self.type = vector_match.group(1)
|
||||
|
||||
# The name may contain "date" in it, if this is the case and the type is "int",
|
||||
# we can safely assume that this should be treated as a "date" object.
|
||||
|
@ -179,7 +185,10 @@ class TLArg:
|
|||
real_type = '#'
|
||||
|
||||
if self.is_vector:
|
||||
real_type = 'Vector<{}>'.format(real_type)
|
||||
if self.use_vector_id:
|
||||
real_type = 'Vector<{}>'.format(real_type)
|
||||
else:
|
||||
real_type = 'vector<{}>'.format(real_type)
|
||||
|
||||
if self.is_generic:
|
||||
real_type = '!{}'.format(real_type)
|
||||
|
|
|
@ -311,8 +311,10 @@ class TLGenerator:
|
|||
builder.writeln('if {}:'.format(name))
|
||||
|
||||
if arg.is_vector:
|
||||
builder.writeln(
|
||||
"writer.write_int(0x1cb5c415, signed=False) # Vector's constructor ID")
|
||||
if arg.use_vector_id:
|
||||
builder.writeln(
|
||||
"writer.write_int(0x1cb5c415, signed=False) # Vector's constructor ID")
|
||||
|
||||
builder.writeln('writer.write_int(len({}))'.format(name))
|
||||
builder.writeln('for {}_item in {}:'.format(arg.name, name))
|
||||
# Temporary disable .is_vector, not to enter this if again
|
||||
|
@ -405,7 +407,9 @@ class TLGenerator:
|
|||
arg.is_flag = False
|
||||
|
||||
if arg.is_vector:
|
||||
builder.writeln("reader.read_int() # Vector's constructor ID")
|
||||
if arg.use_vector_id:
|
||||
builder.writeln("reader.read_int() # Vector's constructor ID")
|
||||
|
||||
builder.writeln('{} = [] # Initialize an empty list'.format(name))
|
||||
builder.writeln('{}_len = reader.read_int()'.format(arg.name))
|
||||
builder.writeln('for _ in range({}_len):'.format(arg.name))
|
||||
|
|
Loading…
Reference in New Issue
Block a user