We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
bytes
Vec<u8>
Protobuf bytes should be deserialized to base64 strings.
Right now all Vec<_> are deserialized as they are. The Vec<u8> case should be handled differently.
Vec<_>
The text was updated successfully, but these errors were encountered:
My quick-fix is to use Serde field attributes.
pub fn base64_to_bytes<'de, D>(deserializer: D) -> Result<Vec<u8>, D::Error> where D: Deserializer<'de>, { let value: Option<&str> = Deserialize::deserialize(deserializer)?; Ok(match value { Some(value) => base64::decode(value).map_err(D::Error::custom)?, None => vec![], }) } /// Serialize bytes to base64 string. pub fn bytes_to_base64<S>(bytes: &[u8], serializer: S) -> Result<S::Ok, S::Error> where S: Serializer, { serializer.serialize_str(&base64::encode(bytes)) }
And then,
#[serde( serialize_with = "bytes_to_base64", deserialize_with = "base64_to_bytes" )] pub bytes: ::prost::alloc::vec::Vec<u8>,
Sorry, something went wrong.
I found serde_with which can be used with field_attributes for data: ::prost::alloc::vec::Vec<u8>.
serde_with
field_attributes
data: ::prost::alloc::vec::Vec<u8>
config.field_attribute("data", "#[serde(with = \"serde_with::As::<serde_with::base64::Base64>\")]");
or for repeated_data: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec<u8>>
repeated_data: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec<u8>>
config.field_attribute("repeated_data", "#[serde(with = \"serde_with::As::<Vec<serde_with::base64::Base64>>\")]");
No branches or pull requests
Protobuf
bytes
should be deserialized to base64 strings.Right now all
Vec<_>
are deserialized as they are. TheVec<u8>
case should be handled differently.The text was updated successfully, but these errors were encountered: