Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[protoprint] Enum sorting fix in proto3 #582

Merged
merged 3 commits into from
Nov 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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