# -*- coding: utf-8 -*- """ Created on Tue Sep 2 19:26:15 2014 @author: agrigoryev """ from binascii import crc32 from datetime import datetime import io import json import socket import struct def vis(bs): """ Function to visualize byte streams. Split into bytes, print to console. :param bs: BYTE STRING """ symbols_in_one_line = 8 n = len(bs) // symbols_in_one_line for i in range(n): print(" ".join(["%02X" % b for b in bs[i*symbols_in_one_line:(i+1)*symbols_in_one_line]])) # for every 8 symbols line print(" ".join(["%02X" % b for b in bs[(i+1)*symbols_in_one_line:]])+"\n") # for last line class TL: def __init__(self): with open("TL_schema.JSON", 'r') as 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 = {} # Read constructors for elem in self.constructors: z = TlElement(elem) self.func_dict_id = {} def serialize(self, type_, data): # 1. Type constructor ID # 2. type costructor params # Bare types if type_ == 'string': assert isinstance(data, str) struct.pack(">') vis(message) # Sending message visualisation to console data = self.header_unencrypted(message) + message step1 = struct.pack(' 0: # if we have smth. in the socket packet_length = struct.unpack("