Open curiousmindflow opened 2 years ago
I'm curious if anyone has gotten this to work. I'm not sure that it's possible for a complex set of messages.
I'm attempting to add serde to the librespot_protocol
protos. This worked perfectly with the previous serde feature. Here's about where I gave up:
impl protobuf_codegen::CustomizeCallback for AddSerde {
fn message(&self, _message: &MessageDescriptor) -> Customize {
Customize::default().before("#[derive(::serde::Serialize, ::serde::Deserialize)]")
}
fn enumeration(&self, _enum: &EnumDescriptor) -> Customize {
Customize::default().before("#[derive(::serde::Serialize, ::serde::Deserialize)]")
}
fn field(&self, field: &FieldDescriptor) -> Customize {
if field.proto().type_() == Type::TYPE_ENUM {
if field.is_singular() {
// singular optional enums
if field.proto().proto3_optional()
|| field.proto().descriptor_dyn().file_descriptor().syntax() == Syntax::Proto2
&& field.proto().label() == Label::LABEL_OPTIONAL
{
Customize::default()
.before(
"#[serde(serialize_with = \"crate::optional_serialize_enum_or_unknown\", deserialize_with = \"crate::optional_deserialize_enum_or_unknown\")]")
} else {
// singular required enums
Customize::default()
.before(
"#[serde(serialize_with = \"crate::serialize_enum_or_unknown\", deserialize_with = \"crate::deserialize_enum_or_unknown\")]")
}
} else {
// repeated enums
Customize::default()
.before(
"#[serde(serialize_with = \"crate::vec_serialize_enum_or_unknown\", deserialize_with = \"crate::vec_deserialize_enum_or_unknown\")]")
}
} else if field.proto().type_() == Type::TYPE_MESSAGE && field.is_singular() {
// messages
Customize::default().before("#[serde(with = \"crate::MessageFieldDef\")]")
} else {
Customize::default()
}
}
fn special_field(&self, _message: &MessageDescriptor, _field: &str) -> Customize {
Customize::default().before("#[serde(skip)]")
}
// fn oneof(&self, _oneof: &OneofDescriptor) -> Customize {
// todo!("other issues note this may also be necessary")
// }
}
@GeorgeHahn did you ever managed to get it working? Have a challenging case myself and am running into issues for a message oneof groups
field and two fields of type MessageField<T>
... If you have any suggestions or references that would be awesome!
Nope, I'm stranded on version 2 of the library.
Hmm... I didn't even try version 2, but guess I'm doomed to do the same 😉
Thanks for your reply!!
Hello,
I have a .proto that rely on two other .proto, aka submessage. I need the corresponding generated .rs struct to be Serialize and Deserialize. For simple messages, it works already, but for message with submessage i have errors.
Here are the messages: