Skip to content

String successfully parses bytes buffer #363

@russellmcc

Description

@russellmcc

I have a pre-existing msgpack schema that I tried to encode in rmp-serde like this:

#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
#[serde(untagged)]
pub enum Value {
    Numeric(f32),
    String(String),
    #[serde(with = "serde_bytes")]
    Bytes(Vec<u8>),
    Bool(bool),
}

However, if I use rmp-serde to decode a buffer that happens to contain valid utf-8, like

{
    "m": "set",
    "path": "ui-state",
    "value": {
        "type": "Buffer",
        "data": [
            97
        ]
    }
}

(base64 g6Fto3NldKRwYXRoqHVpLXN0YXRlpXZhbHVlxAFh), I get a String, but I actually wanted a Bytes. It would be nice if there were some sort of strictness annotation that would make this behave as intended.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions