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

added btree_map support to prost-serde #79

Closed
wants to merge 1 commit into from

Conversation

siennathesane
Copy link
Contributor

This fixes a hidden bug where users can use btree_map=. in protoc-gen-prost but it would break when uses with protoc-gen-prost-serde. Now users can use it in both places. I tested it with a complex workspace with buf and it worked as intended.

Example from generated code, see metadata__:

struct GeneratedVisitor;
impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
    type Value = ErrorInfo;

    fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        formatter.write_str("struct google.rpc.ErrorInfo")
    }

    fn visit_map<V>(self, mut map: V) -> std::result::Result<ErrorInfo, V::Error>
    where
        V: serde::de::MapAccess<'de>,
    {
        let mut reason__ = None;
        let mut domain__ = None;
        let mut metadata__ = None;
        while let Some(k) = map.next_key()? {
            match k {
                GeneratedField::Reason => {
                    if reason__.is_some() {
                        return Err(serde::de::Error::duplicate_field("reason"));
                    }
                    reason__ = Some(map.next_value()?);
                }
                GeneratedField::Domain => {
                    if domain__.is_some() {
                        return Err(serde::de::Error::duplicate_field("domain"));
                    }
                    domain__ = Some(map.next_value()?);
                }
                GeneratedField::Metadata => {
                    if metadata__.is_some() {
                        return Err(serde::de::Error::duplicate_field("metadata"));
                    }
                    metadata__ =
                        Some(map.next_value::<std::collections::BTreeMap<_, _>>()?);
                }
            }
        }
        Ok(ErrorInfo {
            reason: reason__.unwrap_or_default(),
            domain: domain__.unwrap_or_default(),
            metadata: metadata__.unwrap_or_default(),
        })
    }
}

@siennathesane
Copy link
Contributor Author

Shouldn't CI have run after you approved it?

@neoeinstein
Copy link
Owner

Not sure why this never built, but I've now merged this in, and it should go out with the updates to prost, pbjson, and tonic.

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

Successfully merging this pull request may close these issues.

2 participants