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

Can JSON decoder be loose on constraints about float? #364

Open
junaid1460 opened this issue Nov 30, 2023 · 3 comments
Open

Can JSON decoder be loose on constraints about float? #364

junaid1460 opened this issue Nov 30, 2023 · 3 comments
Labels
Kind:Needs More Info Needs more information to investigate.

Comments

@junaid1460
Copy link

junaid1460 commented Nov 30, 2023

Most JSON encoders just wrap 1.0 to 1, while protobuf gives good enough code generation, can we cast 1 -> 1.0 for floats and doubles?

The alternate solution is to use FloatValue and DoubleValue, that feels like just more work for no reason

@whatyouhide whatyouhide changed the title Can json decoder be loose on constraints about float ? Can JSON decoder be loose on constraints about float? Nov 30, 2023
@whatyouhide
Copy link
Collaborator

@junaid1460 thanks for the report! Do you know what other Protobuf libraries (for other languages) do in these cases?

@whatyouhide whatyouhide added the Kind:Needs More Info Needs more information to investigate. label May 11, 2024
@junaid1460
Copy link
Author

We've been using protobuf in dart/flutter its json decoder just automatically handles 1 and spits out 1.0.

eg:

// 1
{"value": 1} 

// 2
{"value": 2.3}
message Resp {
    float value;
}

when we parse 1 with Resp it should just take it as float.

@whatyouhide
Copy link
Collaborator

Gotcha, what do decoders for Ruby and Python do for example?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Kind:Needs More Info Needs more information to investigate.
Projects
None yet
Development

No branches or pull requests

2 participants