https://kotlinlang.org logo
#serialization
Title
# serialization
h

Huy Tâm

02/28/2024, 6:54 AM
Hi, I have a scenario about decoding and encoding protobuf unit test. here is proto data: e802058203061001200128018a0500 have tags: 45, 48, and 81.
Copy code
@Serializable
class TestProtoBuf {
 @ProtoNumber(number = 45)
 val id: UInt? = null
 @ProtoNumber(number = 48)
 val otherValue: OtherValue? 
}

@Test
fun testProto() {
  val data = "e802058203061001200128018a0500"
  val result = ProtoBuf.decodeFromHexString<TestProtoBuf>(data)
  val dataAfterSerialize = ProtoBuf.encodeToHexString(result)

  assertEquals(expected = data, actual = dataAfterSerialize)
}
When I decode with “e802058203061001200128018a0500" and encode back to a string. The dataAfterSerialize equals “e80205820306100120012801”, can see “8a0500" is removed. So how can I keep unknown field data in dataAfterSerialize?
2 Views