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

serialize_i64 not writing an int64 msgpack type when value fits into something smaller #326

Open
edgimar opened this issue Feb 10, 2023 · 2 comments

Comments

@edgimar
Copy link

edgimar commented Feb 10, 2023

I am trying to use [serde(serialize_with = "myfunc")] to serialize a std::time::Duration type, where myfunc is defined as:

fn myfunc<S>(duration: &std::time::Duration, serializer: S) -> Result<S::Ok, S::Error>
where
    S: Serializer,
{
    serializer.serialize_i64(duration.as_millis() as i64)
}

When I attempt to serialize the struct with a Duration value of 256 using to_vec_named(), the serialized msgpack contains [cd, 1, 0] for the value.

@kornelski
Copy link
Collaborator

This is intentional since 23f9b31

@edgimar
Copy link
Author

edgimar commented Feb 11, 2023

Couldn't this "most effective" behavior be made an option? There are some cases where one wants to explicitly encode with a specific type.

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

No branches or pull requests

2 participants