Faster Object deserialization (~3x)

This commit is contained in:
Dan 2017-12-11 11:35:38 +01:00
parent 33263e9ce6
commit 7374c10afd
2 changed files with 12 additions and 9 deletions

View File

@ -15,3 +15,12 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from importlib import import_module
from .all import objects
from .core.object import Object
for k, v in objects.items():
path, name = v.rsplit(".", 1)
Object.all[k] = getattr(import_module("pyrogram.api." + path), name)

View File

@ -18,7 +18,6 @@
from collections import OrderedDict
from datetime import datetime
from importlib import import_module
from io import BytesIO
from json import JSONEncoder, dumps
@ -26,16 +25,11 @@ from ..all import objects
class Object:
all = {}
@staticmethod
def read(b: BytesIO, *args):
id = int.from_bytes(b.read(4), "little")
name = objects.get(id)
path, name = name.rsplit(".", 1)
return getattr(
import_module("pyrogram.api." + path),
name
).read(b, *args)
return Object.all[int.from_bytes(b.read(4), "little")].read(b, *args)
def write(self, *args) -> bytes:
pass