本文整理匯總了Golang中github.com/gogo/protobuf/protoc-gen-gogo/descriptor.FileDescriptorSet.GetEnum方法的典型用法代碼示例。如果您正苦於以下問題:Golang FileDescriptorSet.GetEnum方法的具體用法?Golang FileDescriptorSet.GetEnum怎麽用?Golang FileDescriptorSet.GetEnum使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gogo/protobuf/protoc-gen-gogo/descriptor.FileDescriptorSet
的用法示例。
在下文中一共展示了FileDescriptorSet.GetEnum方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: new
func new(rootPackage string, rootMessage string, descSet *descriptor.FileDescriptorSet, path string) (*fdesc, error) {
fieldpaths := strings.Split(path, ".")
keys := make([]uint64, len(fieldpaths))
fields := make([]*descriptor.FieldDescriptorProto, len(fieldpaths))
curPackage := rootPackage
curMessage := rootMessage
last := len(fieldpaths) - 1
var fieldDesc *descriptor.FieldDescriptorProto
for i, f := range fieldpaths {
fieldName := f
fieldDesc = descSet.GetField(curPackage, curMessage, fieldName)
if fieldDesc == nil {
curPackage, fieldDesc = descSet.FindExtension(curPackage, curMessage, fieldName)
if fieldDesc == nil {
return nil, &errChild{fieldName: fieldName, pkg: curPackage, msg: curMessage}
}
typeNames := strings.Split(fieldDesc.GetTypeName(), ".")
curMessage = fieldDesc.GetTypeName()
if len(typeNames) > 1 {
curPackage = typeNames[1]
curMessage = typeNames[2]
}
fieldKey := fieldDesc.GetKeyUint64()
keys[i] = fieldKey
fields[i] = fieldDesc
} else {
fieldKey := fieldDesc.GetKeyUint64()
if fieldDesc.IsMessage() {
curPackage, curMessage = descSet.FindMessage(curPackage, curMessage, fieldName)
} else if i != last {
return nil, &errMessage{fieldName}
}
keys[i] = fieldKey
fields[i] = fieldDesc
}
}
fd := &fdesc{curPackage, curMessage, fields, fieldDesc, keys, 0}
if fieldDesc.GetType() == descriptor.FieldDescriptorProto_TYPE_ENUM {
typeNames := strings.Split(fieldDesc.GetTypeName(), ".")
enumMessage := fieldDesc.GetTypeName()
enumPackage := curPackage
if len(typeNames) > 1 {
enumPackage = typeNames[1]
enumMessage = typeNames[2]
}
enum := descSet.GetEnum(enumPackage, enumMessage)
if enum == nil {
return nil, &errChild{fieldName: fieldDesc.GetName(), pkg: enumPackage, msg: enumMessage}
}
for _, v := range enum.GetValue() {
if v.GetNumber() < fd.firstEnumValue {
fd.firstEnumValue = v.GetNumber()
}
}
}
return fd, nil
}
示例2: getEnum
func getEnum(fileDescriptorSet *descriptor.FileDescriptorSet, f *descriptor.FieldDescriptorProto) *descriptor.EnumDescriptorProto {
typeNames := strings.Split(f.GetTypeName(), ".")
return fileDescriptorSet.GetEnum(typeNames[1], typeNames[2])
}