Source File
order.go
Belonging Package
google.golang.org/protobuf/internal/order
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package order
import (
)
// FieldOrder specifies the ordering to visit message fields.
// It is a function that reports whether x is ordered before y.
type FieldOrder func(x, y protoreflect.FieldDescriptor) bool
var (
// AnyFieldOrder specifies no specific field ordering.
AnyFieldOrder FieldOrder = nil
// LegacyFieldOrder sorts fields in the same ordering as emitted by
// wire serialization in the github.com/golang/protobuf implementation.
LegacyFieldOrder FieldOrder = func(, protoreflect.FieldDescriptor) bool {
, := .ContainingOneof(), .ContainingOneof()
:= func( protoreflect.OneofDescriptor) bool {
return != nil && !.IsSynthetic()
}
// Extension fields sort before non-extension fields.
if .IsExtension() != .IsExtension() {
return .IsExtension() && !.IsExtension()
}
// Fields not within a oneof sort before those within a oneof.
if () != () {
return !() && ()
}
// Fields in disjoint oneof sets are sorted by declaration index.
if != nil && != nil && != {
return .Index() < .Index()
}
// Fields sorted by field number.
return .Number() < .Number()
}
// NumberFieldOrder sorts fields by their field number.
NumberFieldOrder FieldOrder = func(, protoreflect.FieldDescriptor) bool {
return .Number() < .Number()
}
// IndexNameFieldOrder sorts non-extension fields before extension fields.
// Non-extensions are sorted according to their declaration index.
// Extensions are sorted according to their full name.
IndexNameFieldOrder FieldOrder = func(, protoreflect.FieldDescriptor) bool {
// Non-extension fields sort before extension fields.
if .IsExtension() != .IsExtension() {
return !.IsExtension() && .IsExtension()
}
// Extensions sorted by fullname.
if .IsExtension() && .IsExtension() {
return .FullName() < .FullName()
}
// Non-extensions sorted by declaration index.
return .Index() < .Index()
}
)
// KeyOrder specifies the ordering to visit map entries.
// It is a function that reports whether x is ordered before y.
type KeyOrder func(x, y protoreflect.MapKey) bool
var (
// AnyKeyOrder specifies no specific key ordering.
AnyKeyOrder KeyOrder = nil
// GenericKeyOrder sorts false before true, numeric keys in ascending order,
// and strings in lexicographical ordering according to UTF-8 codepoints.
GenericKeyOrder KeyOrder = func(, protoreflect.MapKey) bool {
switch .Interface().(type) {
case bool:
return !.Bool() && .Bool()
case int32, int64:
return .Int() < .Int()
case uint32, uint64:
return .Uint() < .Uint()
case string:
return .String() < .String()
default:
panic("invalid map key type")
}
}
)
The pages are generated with Golds v0.4.9. (GOOS=linux GOARCH=amd64)