kotlinx.serialization icon indicating copy to clipboard operation
kotlinx.serialization copied to clipboard

Support preserving unknown fields in ProtoBuf format

Open xiaozhikang0916 opened this issue 1 year ago • 4 comments

Introducing new annotation @ProtoUnknownFields and built-in type ProtoMessage, to store any fields with proto ids that are undefined in current message class.

In my understanding, both ktx-serialization and protocol buffer are designed in strong typing, all messages used in code should be well defined in kt class or proto message. Therefore I would like to keep ProtoMessage and ProtoField minimun published. Not like JsonObject in json format, users cannot retrieve detailed data from it.

Close #2655

xiaozhikang0916 avatar Nov 18 '24 04:11 xiaozhikang0916

@sandwwraith Hi, please take a look here?

xiaozhikang0916 avatar Nov 18 '24 04:11 xiaozhikang0916

@xiaozhikang0916 Sure, when I'll have time

sandwwraith avatar Nov 22 '24 17:11 sandwwraith

@pdvrieze Actually I don't want to decode the protobuf wire data into a tree-structure type like what JsonObject do, neither provide retreiving method of the content.

The raw content in protobuf wire data is quite ambiguous that, you can even not possible to tell whether a VARINT 1 is 1 or -1 or true, or tell a LEN field is string or sub-message. The only way to parse wire data content correctly and explictly is to parse with message definition, or with a concrete type in kotlin.

Base on it, ProtoMessage here is not designed for retrieving content from undefined fields, but for holding it only.

xiaozhikang0916 avatar Nov 26 '24 06:11 xiaozhikang0916

Any progress about it? We have plan on upgrading Kotlin and serialization runtime version, and it would be great if we can have this functionality in near future.

xiaozhikang0916 avatar Mar 06 '25 16:03 xiaozhikang0916