4 ms·
One option not mentioned in this article is use of unknown fields [1] (e.g. C++ documentation is at [2]). Rather than changing the types of the field from a mes
by quietbritishjim 4y ago
One option not mentioned in this article is use of unknown fields [1] (e.g. C++ documentation is at [2]). Rather than changing the types of the field from a message to bytes, simply remove them altogether:
message Metric {
// MetricDescriptor metric_descriptor = 1;
// Resource resource = 2;
repeated Int64TimeSeries int64_timeseries = 3;
}
When then message is deserialised, those will be placed in a separate binary buffer, which is used directly when reserialising. It even works for other types of field. Originally this functionality was lost in the transition from proto2 to proto3 but was added back a long time ago now.
This feels like a cleaner solution to me as it's what this feature is really intended for.
[1] https://developers.google.com/protocol-buffers/docs/proto3#unknowns https://developers.google.com/protocol-buffers/docs/proto3#u...
[2] https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.unknown_field_set https://developers.google.com/protocol-buffers/docs/referenc...