Skip to content

[ProtoBuf] Should we check duplicating of proto id? #2653

@xiaozhikang0916

Description

@xiaozhikang0916

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions