diff --git a/telethon_generator/parser/tl_object.py b/telethon_generator/parser/tl_object.py index fdcf5450..600cc9a1 100755 --- a/telethon_generator/parser/tl_object.py +++ b/telethon_generator/parser/tl_object.py @@ -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) diff --git a/telethon_generator/tl_generator.py b/telethon_generator/tl_generator.py index 66a9a663..80975702 100755 --- a/telethon_generator/tl_generator.py +++ b/telethon_generator/tl_generator.py @@ -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))