Faster Object deserialization (~3x)
This commit is contained in:
parent
33263e9ce6
commit
7374c10afd
@ -15,3 +15,12 @@
|
|||||||
#
|
#
|
||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# 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)
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from importlib import import_module
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from json import JSONEncoder, dumps
|
from json import JSONEncoder, dumps
|
||||||
|
|
||||||
@ -26,16 +25,11 @@ from ..all import objects
|
|||||||
|
|
||||||
|
|
||||||
class Object:
|
class Object:
|
||||||
|
all = {}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def read(b: BytesIO, *args):
|
def read(b: BytesIO, *args):
|
||||||
id = int.from_bytes(b.read(4), "little")
|
return Object.all[int.from_bytes(b.read(4), "little")].read(b, *args)
|
||||||
name = objects.get(id)
|
|
||||||
path, name = name.rsplit(".", 1)
|
|
||||||
|
|
||||||
return getattr(
|
|
||||||
import_module("pyrogram.api." + path),
|
|
||||||
name
|
|
||||||
).read(b, *args)
|
|
||||||
|
|
||||||
def write(self, *args) -> bytes:
|
def write(self, *args) -> bytes:
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user