本文整理汇总了Golang中code/google/com/p/gogoprotobuf/protoc-gen-gogo/descriptor.FileDescriptorSet.FindExtension方法的典型用法代码示例。如果您正苦于以下问题:Golang FileDescriptorSet.FindExtension方法的具体用法?Golang FileDescriptorSet.FindExtension怎么用?Golang FileDescriptorSet.FindExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类code/google/com/p/gogoprotobuf/protoc-gen-gogo/descriptor.FileDescriptorSet
的用法示例。
在下文中一共展示了FileDescriptorSet.FindExtension方法的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: Collapse
//Collapses a proto fieldpath into a go fieldpath. They are different if some of the fields in the fieldpath have been embedded.
func Collapse(rootPkg string, rootMsg string, path string, descriptorSet *descriptor.FileDescriptorSet) (string, error) {
msg := descriptorSet.GetMessage(rootPkg, rootMsg)
if msg == nil {
return "", &errUndefined{rootPkg, rootMsg, path}
}
paths := strings.Split(path, ".")
if len(paths) == 0 {
return "", &errUndefined{rootPkg, rootMsg, path}
}
if len(paths) == 1 {
return path, nil
}
for _, f := range msg.GetField() {
if f.GetName() != paths[0] {
continue
}
if f.IsMessage() {
newRootPkg, newRootMsg := descriptorSet.FindMessage(rootPkg, rootMsg, f.GetName())
if len(newRootPkg) == 0 || len(newRootMsg) == 0 {
return "", &errUndefined{rootPkg, rootMsg, path}
}
newPath, err := Collapse(newRootPkg, newRootMsg, strings.Join(paths[1:], "."), descriptorSet)
if err != nil {
return "", err
}
if gogoproto.IsEmbed(f) {
return newPath, nil
} else {
return paths[0] + "." + newPath, nil
}
}
}
if msg.IsExtendable() {
newRootPkg, f := descriptorSet.FindExtension(rootPkg, rootMsg, paths[0])
if f == nil {
return "", &errUndefined{rootPkg, rootMsg, path}
}
typeName := f.GetTypeName()
typeNames := strings.Split(typeName, ".")
newRootMsg := typeName
if len(typeNames) > 1 {
newRootMsg = typeNames[len(typeNames)-1]
}
newPath, err := Collapse(newRootPkg, newRootMsg, strings.Join(paths[1:], "."), descriptorSet)
if err != nil {
return "", err
}
if gogoproto.IsEmbed(f) {
return newPath, nil
} else {
return paths[0] + "." + newPath, nil
}
}
return "", nil
}