mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-23 23:34:28 +00:00
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
|
||||
# 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 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
|
||||
|
Loading…
Reference in New Issue
Block a user