Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for older layer Objects #43

Closed
4l1fe opened this issue Apr 4, 2018 · 4 comments
Closed

Add support for older layer Objects #43

4l1fe opened this issue Apr 4, 2018 · 4 comments

Comments

@4l1fe
Copy link

4l1fe commented Apr 4, 2018

Now i examine the library functionality and have a need to store some objects in a DB.
So they are not similar and i wanna just dump them to bytes to store as is for further using.

For example:

pyrogram.api.types.contact.Contact
pyrogram.api.types.user.User
pyrogram.api.types.chat_forbidden.ChatForbidden
pyrogram.api.types.dialog.Dialog

Are there any pitfalls?

@delivrance
Copy link
Member

Weird use case, but yeah is surely possible. Any Pyrogram Object (both types and functions) can be serialized using the .write() method. You get a bytes string which can be loaded again using Object.read(b) (b must be a BytesIO object), from pyrogram.api.core.Object.

The only downside would be versioning. New layer updates could modify the types/functions schema and you won't be able to load old objects with the updated library. This can be handled by saving the layer number as well in your DB, but Pyrogram currently lacks support for older layers.

@4l1fe
Copy link
Author

4l1fe commented Apr 4, 2018

I understand about versioning that makes sense. Thx much for your advice.

Why do i use this approach? because i don't know clearly how to use lot of functions, types(i/ve been learning it) but i need to save accounts data now. Don't lost it. And in the future i'll extract info what i'm intrested in from objects

@4l1fe 4l1fe closed this as completed Apr 4, 2018
@delivrance
Copy link
Member

All the latest functions and types are coming straight from the official Telegram clients schema, but they aren't documented at all. Fortunately, the names are descriptive enough to get an idea of what they do.

Anyway, it turns out that this approach is actually used by the official Android app: it saves raw messages plus the layer number and loads them again when needed using the correct schema.

I'll flag this as enhancement. Maybe we could add support for old layers someday, but for now this is a low priority. Thanks for the suggestion ^^

@delivrance delivrance reopened this Apr 4, 2018
@delivrance delivrance changed the title Are objects pickable? Add support for older layer Objects Apr 4, 2018
@delivrance
Copy link
Member

This is unlikely to happen. Closing for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants