protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

Can JSON decoder be loose on constraints about float?

Open junaid1460 opened this issue 1 year ago • 3 comments

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

junaid1460 avatar Nov 30 '23 05:11 junaid1460

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

whatyouhide avatar May 11 '24 21:05 whatyouhide

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.

junaid1460 avatar May 25 '24 09:05 junaid1460

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

whatyouhide avatar May 25 '24 21:05 whatyouhide