I recently tried working with Teloxide and noticed that the library doesn’t have a convenient built-in way to serialize/deserialize callback data.

So I decided to try an approach based on binary serialization of an enum followed by base64 encoding. I liked this solution for several reasons:

  • There’s no need to manually implement serialization/deserialization for each callback variant-it’s enough to implement the conversion for the enum once.
  • It’s fast and reasonably efficient in terms of size.
  • The callback data becomes unreadable to humans (it would normally look something like do_something_1341), which provides a small barrier to reverse engineering.

I ended up packaging this approach into a Rust library called easy_callback.

I’d appreciate any feedback or suggestions.

1 post - 1 participant

Read full topic