Skip to content

Utility to render uint64_t as number (not string) when serializing protobuf message (e.g. from Struct) #10411

@dio

Description

@dio

Since the movement on removing rapidjson as a dependency here: #4705. We prefer to use protobuf way of serializing objects to JSON strings. Most of the time we choose to use protobuf Struct. The issue with protobuf Struct is how it holds number value, it only supports double. When we want to hold uint64_t we need to statically cast that into a double. The problem is when we serialize it, through protobuf MessageToJsonString it is possible for that value to be rendered in scientific notation as reported in: #9341 (comment). This is due to how protobuf's strutil renders double: https://github.com/protocolbuffers/protobuf/blob/422053f3bcb39cac483d2769e936c473e7c8bcdb/src/google/protobuf/stubs/strutil.cc#L1248-L1290. We can create a new message structure with uint64 field, but MessageToJsonString strictly follows json proto3 spec which renders uint64 to string only: protocolbuffers/protobuf#5015 (comment).

Per #9341 should we keep it as a string, however: openzipkin/zipkin-go#161, seems like uint64 is final for zipkin? Or we are OK to have a "patch" in our codebase on that part: #10400? Or going down to introduce control on how protobuf renders unit64_t/double.

cc. @junr03 @htuch

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions