Source File
legacy_enum.go
Belonging Package
google.golang.org/protobuf/internal/impl
package impl
import (
pref
)
func ( pref.EnumDescriptor) string {
var string
:= string(.FullName())
if := .ParentFile(); != nil {
= string(.Package())
= strings.TrimPrefix(, +".")
}
if == "" {
return strs.GoCamelCase()
}
return + "." + strs.GoCamelCase()
}
func ( reflect.Value) pref.Enum {
:= legacyLoadEnumType(.Type())
return .New(pref.EnumNumber(.Int()))
}
var legacyEnumTypeCache sync.Map // map[reflect.Type]protoreflect.EnumType
if , := legacyEnumTypeCache.Load(); {
return .(pref.EnumType)
}
var pref.EnumType
:= LegacyLoadEnumDesc()
= &legacyEnumType{
desc: ,
goType: ,
}
if , := legacyEnumTypeCache.LoadOrStore(, ); {
return .(pref.EnumType)
}
return
}
type legacyEnumType struct {
desc pref.EnumDescriptor
goType reflect.Type
m sync.Map // map[protoreflect.EnumNumber]proto.Enum
}
func ( *legacyEnumType) ( pref.EnumNumber) pref.Enum {
if , := .m.Load(); {
return .(pref.Enum)
}
:= &legacyEnumWrapper{num: , pbTyp: , goTyp: .goType}
.m.Store(, )
return
}
func ( *legacyEnumType) () pref.EnumDescriptor {
return .desc
}
type legacyEnumWrapper struct {
num pref.EnumNumber
pbTyp pref.EnumType
goTyp reflect.Type
}
func ( *legacyEnumWrapper) () pref.EnumDescriptor {
return .pbTyp.Descriptor()
}
func ( *legacyEnumWrapper) () pref.EnumType {
return .pbTyp
}
func ( *legacyEnumWrapper) () pref.EnumNumber {
return .num
}
func ( *legacyEnumWrapper) () pref.Enum {
return
}
func ( *legacyEnumWrapper) () interface{} {
:= reflect.New(.goTyp).Elem()
.SetInt(int64(.num))
return .Interface()
}
var (
_ pref.Enum = (*legacyEnumWrapper)(nil)
_ unwrapper = (*legacyEnumWrapper)(nil)
)
var legacyEnumDescCache sync.Map // map[reflect.Type]protoreflect.EnumDescriptor
if , := legacyEnumDescCache.Load(); {
return .(pref.EnumDescriptor)
}
:= reflect.Zero().Interface()
if , := .(pref.Enum); {
panic(fmt.Sprintf("%v already implements proto.Enum", ))
}
, := .(enumV1)
if ! {
return aberrantLoadEnumDesc()
}
, := .EnumDescriptor()
var pref.EnumDescriptor
if len() == 1 {
= legacyLoadFileDesc().Enums().Get([0])
} else {
:= legacyLoadFileDesc().Messages().Get([0])
for , := range [1 : len()-1] {
= .Messages().Get()
}
= .Enums().Get([len()-1])
}
if , := legacyEnumDescCache.LoadOrStore(, ); {
return .(protoreflect.EnumDescriptor)
}
return
}
var aberrantEnumDescCache sync.Map // map[reflect.Type]protoreflect.EnumDescriptor
if , := aberrantEnumDescCache.Load(); {
return .(pref.EnumDescriptor)
}
if , := aberrantEnumDescCache.LoadOrStore(, ); {
return .(pref.EnumDescriptor)
}
return
}
func ( reflect.Type) pref.FullName {
:= func( rune) rune {
switch {
case == '/':
return '.'
case 'a' <= && <= 'z', 'A' <= && <= 'Z', '0' <= && <= '9':
return
default:
return '_'
}
}
:= strings.Map(, .PkgPath())
:= strings.Map(, .Name())
if == "" {
= fmt.Sprintf("UnknownX%X", reflect.ValueOf().Pointer())
}
:= append(strings.Split(, "."), )
for , := range {
if == "" || ('0' <= [0] && [0] <= '9') {
[] = "x" +
}
}
return pref.FullName(strings.Join(, "."))
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |