From c1c5c5d18a65b88bb9dc71e3eb063e6235c6fdc0 Mon Sep 17 00:00:00 2001 From: Anton Grigoryev Date: Thu, 12 Mar 2015 01:52:26 +0300 Subject: [PATCH] testing.py works please test it :) --- mtproto.py | 54 +++++++++++++++++++++++++++--------------------------- testing.py | 21 +++++++-------------- 2 files changed, 34 insertions(+), 41 deletions(-) diff --git a/mtproto.py b/mtproto.py index 7584062c..468339b5 100644 --- a/mtproto.py +++ b/mtproto.py @@ -24,36 +24,38 @@ def vis(bs): print(" ".join(["%02X" % b for b in bs[(i+1)*symbols_in_one_line:]])+"\n") # for last line +class TlConstructor: + def __init__(self, json_dict): + self.id = int(json_dict['id']) + self.type = json_dict['type'] + self.predicate = json_dict['predicate'] + self.params = [] + # case of vector + for param in json_dict['params']: + if param['type'] == "Vector": + param['type'] = "Vector t" + param['subtype'] = "long" + else: + param['subtype'] = None + self.params.append(param) + + class TL: def __init__(self): with open("TL_schema.JSON", 'r') as f: - TL_dict = json.load(f) + TL_dict = json.load(f) - self.methods = TL_dict['methods'] self.constructors = TL_dict['constructors'] - - self.func_dict_id = {} - self.func_dict_name = {} - self.obj_dict_id = {} - self.obj_dict_name = {} + self.constructor_id = {} + self.constructor_type = {} # Read constructors for elem in self.constructors: - z = TlElement(elem) - self.func_dict_id = {} + z = TlConstructor(elem) + self.constructor_id[z.id] = z + self.constructor_type[z.type] = z - def serialize(self, type_, data): - # 1. Type constructor ID - # 2. type costructor params - - # Bare types - if type_ == 'string': - assert isinstance(data, str) - struct.pack("