Skip to content

Commit

Permalink
protoprint: when sorting elements, first value must be zero in proto3…
Browse files Browse the repository at this point in the history
… file(#582)
  • Loading branch information
japersik authored Nov 2, 2023
1 parent e429ee6 commit 5d00292
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion desc/protoprint/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -2137,11 +2137,20 @@ func (a elementAddrs) Less(i, j int) bool {
return vi.GetNumber() < vj.GetNumber()

case *desc.EnumValueDescriptor:
// enum values ordered by number then name
// enum values ordered by number then name,
// but first value number must be 0 in proto3
vj := dj.(*desc.EnumValueDescriptor)
if vi.GetNumber() == vj.GetNumber() {
return vi.GetName() < vj.GetName()
}
if vi.GetFile().IsProto3() {
if vj.GetNumber() == 0 {
return false
}
if vi.GetNumber() == 0 {
return true
}
}
return vi.GetNumber() < vj.GetNumber()

case *descriptorpb.DescriptorProto_ExtensionRange:
Expand Down

0 comments on commit 5d00292

Please sign in to comment.