-
Notifications
You must be signed in to change notification settings - Fork 111
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 serde support for tl_types. #277
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,10 @@ fn write_struct<W: Write>( | |
writeln!(file, "{indent}#[derive(Debug)]")?; | ||
} | ||
|
||
if config.impl_serde{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here. |
||
writeln!(file, "{indent}#[derive(serde_derive::Serialize, serde_derive::Deserialize)]")?; | ||
} | ||
|
||
writeln!(file, "{indent}#[derive(Clone, PartialEq)]")?; | ||
write!( | ||
file, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,8 @@ | |
//! * `tl-mtproto`: generates code for the `mtproto.tl`. | ||
//! Only useful for low-level libraries. | ||
//! | ||
//! * `impl-serde`: generates code for serde support | ||
//! | ||
//! [`types`]: types/index.html | ||
//! [`functions`]: functions/index.html | ||
//! [`RemoteCall`]: trait.RemoteCall.html | ||
|
@@ -84,19 +86,24 @@ pub use deserialize::{Cursor, Deserializable}; | |
pub use generated::{enums, functions, name_for_id, types, LAYER}; | ||
pub use serialize::Serializable; | ||
|
||
#[cfg(feature = "impl-serde")] | ||
use serde_derive::{Deserialize, Serialize}; | ||
|
||
/// This struct represents the concrete type of a vector, that is, | ||
/// `vector` as opposed to the type `Vector`. This bare type is less | ||
/// common, so instead of creating a enum for `Vector` wrapping `vector` | ||
/// as Rust's `Vec` (as we would do with auto-generated code), | ||
/// a new-type for `vector` is used instead. | ||
#[cfg_attr(feature = "impl-serde", derive(Serialize, Deserialize))] | ||
#[derive(Clone, Debug, PartialEq)] | ||
pub struct RawVec<T>(pub Vec<T>); | ||
|
||
/// This struct represents an unparsed blob, which should not be deserialized | ||
/// as a bytes string. Used by functions returning generic objects which pass | ||
/// the underlying result without any modification or interpretation. | ||
#[cfg_attr(feature = "impl-serde", derive(Serialize, Deserialize))] | ||
#[derive(Clone, Debug, PartialEq)] | ||
pub struct Blob(pub Vec<u8>); | ||
pub struct Blob(#[cfg_attr(feature = "impl-serde", serde(with = "serde_bytes"))] pub Vec<u8>); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Help needed.I am not formiliar with tl proto. Is there any other structure that store bytes in .tl definition files? All bytes-like properties need marked by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, Might be good to write a |
||
|
||
impl From<Vec<u8>> for Blob { | ||
fn from(value: Vec<u8>) -> Self { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting is going to complain here.