breese / trial.protocol

Network wire protocols
11 stars 4 forks source link

Generator for real numbers shouldn't print the fractional part if there is none #66

Open vinipsmaker opened 1 year ago

vinipsmaker commented 1 year ago

So, I'm developing a Telegram client and I'm using this lib: https://core.telegram.org/tdlib

What I learnt is that a few applications (including tdlib) will reject JSON messages if they include the fractional part (even if it's all zeros). Here's the reply I get from the previous application when sending one of such requests:

{"code":400.000000000000,"@type":"error","message":"Failed to parse JSON object as TDLib request: Can't parse \"559815.000000000\" as an integer"}

So I guess Trial.Protocol's generator needs to detect such patterns and omit the fractional part if it's going to be all zeroes. Otherwise this class of applications will not work.

For my case I can (and will) use a workaround. However I think it's important for Trial.Protocol to up its game, so I'm reporting this issue.

breese commented 1 year ago

Sounds like broken applications. JSON has no distinction between integer and floating-point numbers.

vinipsmaker commented 1 year ago

JSON has no distinction between integer and floating-point numbers.

That is true. However Trial.Protocol still is generating lots of extraneous unneeded textual output.

breese commented 1 year ago

Good point. The floating-point formatting is Trial.Protocol is rather primitive.