-
Notifications
You must be signed in to change notification settings - Fork 658
Closed
Labels
Description
Right now the ProtoBuf
format allow duplicating proto ids in one message, e.g.
@Serializable
data class MessageWithDuplicateId(
@ProtoNumber(3) val s: String,
@ProtoNumber(3) val d: Int
)
ProtoBuf.encodeToHexString(MessageWithDuplicateId("foo", 42))
// 1a03666f6f182a
// 3:LEN {"foo"} 3:VARINT 42
is a valid definition in this lib, and can be serialized into wire.
But when decoding from the same wire data will just throw message complaining wrong wire type.
Intent
IMO we should check that all proto ids should be unique, as described in the Protocol Buffer Documentation, before any deserializing and serializing happens.
With this check, developers can find out what is wrong ( or what will be wrong ) more easily, especially in messages with one-of properties (in #2546), whose ids may be in different classes.
bcmedeiros