Closed b2soft closed 5 months ago
There is a case of a missing case msgpack::type::FLOAT32:
in ConvertToJSON
.
There is a case of a missing
case msgpack::type::FLOAT32:
inConvertToJSON
.
Probably, that is the case. At least FLOAT32 and FLOAT may be encoded as Double. But we have only IsDouble
, to keep from json conversion it's needed to add some float getter as well:
https://github.com/citizenfx/fivem/blob/master/code/client/shared/MsgpackJson.h#L36C26-L36C26
Float getter/setter were added only after this PR in rapidjson https://github.com/Tencent/rapidjson/issues/341
Trying to round-trip float32's may lead some to backwards compatibility problems. Some care, if possible, will be required.
The missing msgpack::type::FLOAT32
in ConvertToJSON
is a bug regardless.
I think FLOAT32/float can be treated as double and returned as double safely. It will not break any backward compatibility issues (because floats did not work) and would not affect new code, if you continue using doubles
The Problem
I'm trying to use modern way of returning data from C# Client to NUI, utilizing result(object) call. For some reason
float
values are not serialized and equal null at NUI side.Reproduce code
Possible problem
When I tested different types:
float _a, double _b, int _c, long _d, string _e, bool _f
, it seems like only float is not converted correctlyI observed, that value of this
result
is serialized first to JSON, and then to MessagePack. https://github.com/citizenfx/fivem/blob/81fd97f8ee7def9f89fb2aafa99a13aadc045d10/code/components/nui-resources/src/ResourceUICallbacks.cpp#L23 Possibly, JSON part serializesfloats
wrong.Workaround
For now I have 2 workarounds:
double
everywhere instead offloat
result(JsonConvert.SerializeObject(new { ok = true, speed = vehicleSpeed }));