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

Feature request: serde support #276

Open
RuofengX opened this issue Oct 16, 2024 · 5 comments
Open

Feature request: serde support #276

RuofengX opened this issue Oct 16, 2024 · 5 comments

Comments

@RuofengX
Copy link

I am using this awesome crate in my actual work to gather some useful information from open chats and bots.

I want to save the data to database or just simple json-string, like

  • grammers_client::types::chat::Chat
  • grammers_tl_types::types::Message
  • etc.

I found this project seems doesn't support serde, am I right? And if it really not support, why? I noticed that telegram has it's own bytecode ser&de function, but serde is the in-facts standard in rust language. Using serde framework will make this project more flexible.

@Lonami
Copy link
Owner

Lonami commented Oct 16, 2024

I'm okay adding it behind a feature gate. If you're willing to send a PR, you would need to modify the generator to emit the derive, but I suppose that would be enough.

Be warned though, it's a lot of generated code, and I suspect serde will bloat it even further, which is why I've avoided it so far.

And of course appreciate the compliments :)

@RuofengX
Copy link
Author

RuofengX commented Oct 17, 2024

Thanks for reply.

I didn't notice such structure is generated. Is that done by grammers-tl-gen?
I am looking into grammers-tl-gen module, it works like macros but it directly generate code files. How it works?

@Lonami
Copy link
Owner

Lonami commented Oct 17, 2024

The generator is used by grammers-tl-types' build.rs script.

@RuofengX
Copy link
Author

How often does build.rs run? Is it just a oneshot task? Or does telegram official often change the tl schema?

So is it possible to simply add #[derive(Serialize, Deserialized)] in generated files?

@Lonami
Copy link
Owner

Lonami commented Oct 18, 2024

build.rs runs when its crate or the dependencies of its crate change. So changing the api.tl, the generator, or the types package itself, should cause it to re-run.

telegram official often change the tl schema

Pretty regularly, yes. But grabbing the latest api.tl is a manual task.

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

No branches or pull requests

2 participants