本文整理匯總了Golang中github.com/gogo/protobuf/protoc-gen-gogo/descriptor.FileDescriptorSet.FindExtensionByFieldNumber方法的典型用法代碼示例。如果您正苦於以下問題:Golang FileDescriptorSet.FindExtensionByFieldNumber方法的具體用法?Golang FileDescriptorSet.FindExtensionByFieldNumber怎麽用?Golang FileDescriptorSet.FindExtensionByFieldNumber使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gogo/protobuf/protoc-gen-gogo/descriptor.FileDescriptorSet
的用法示例。
在下文中一共展示了FileDescriptorSet.FindExtensionByFieldNumber方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ToString
//.........這裏部分代碼省略.........
w.String(`}` + "\n")
break
} else {
w.tab()
w.String(f.GetName() + `:`)
var m int
var err error
switch f.GetType() {
case descriptor.FieldDescriptorProto_TYPE_DOUBLE:
m, err = DecFloat64(buf, offset, w)
case descriptor.FieldDescriptorProto_TYPE_FLOAT:
m, err = DecFloat32(buf, offset, w)
case descriptor.FieldDescriptorProto_TYPE_INT64:
m, err = DecInt64(buf, offset, w)
case descriptor.FieldDescriptorProto_TYPE_UINT64:
m, err = DecUint64(buf, offset, w)
case descriptor.FieldDescriptorProto_TYPE_INT32:
m, err = DecInt32(buf, offset, w)
case descriptor.FieldDescriptorProto_TYPE_FIXED64:
m, err = DecFixed64(buf, offset, w)
case descriptor.FieldDescriptorProto_TYPE_FIXED32:
m, err = DecFixed32(buf, offset, w)
case descriptor.FieldDescriptorProto_TYPE_BOOL:
m, err = DecBool(buf, offset, w)
case descriptor.FieldDescriptorProto_TYPE_STRING:
m, err = DecString(buf, offset, w)
case descriptor.FieldDescriptorProto_TYPE_GROUP:
panic("not implemented")
case descriptor.FieldDescriptorProto_TYPE_BYTES:
m, err = DecBytes(buf, offset, w)
case descriptor.FieldDescriptorProto_TYPE_UINT32:
m, err = DecUint32(buf, offset, w)
case descriptor.FieldDescriptorProto_TYPE_ENUM:
m, err = DecInt32(buf, offset, w)
case descriptor.FieldDescriptorProto_TYPE_SFIXED32:
m, err = DecSfixed32(buf, offset, w)
case descriptor.FieldDescriptorProto_TYPE_SFIXED64:
m, err = DecSfixed64(buf, offset, w)
case descriptor.FieldDescriptorProto_TYPE_SINT32:
m, err = DecSint32(buf, offset, w)
case descriptor.FieldDescriptorProto_TYPE_SINT64:
m, err = DecSint64(buf, offset, w)
default:
panic("unreachable")
}
offset += m
if err != nil {
panic(err)
}
w.String(",\n")
break
}
}
if !found {
for _, extRange := range msg.GetExtensionRange() {
if extRange.GetStart() <= fieldNum && fieldNum <= extRange.GetEnd() {
found = true
break
}
}
w.tab()
offset -= n
nn, err := protoSkip(buf[offset:])
if err != nil {
panic(err)
}
if !found {
w.String("XXX_unrecognized:")
} else {
w.String("XXX_extensions:")
extPkg, ext := desc.FindExtensionByFieldNumber(messagePkg, messageName, fieldNum)
if ext != nil && ext.IsMessage() {
names := strings.Split(ext.GetTypeName(), ".")
if len(names) == 3 {
_, nnn, err := decodeVarint(buf, offset+n)
if err != nil {
panic(err)
}
w.tab()
w.String(extPkg + "." + names[2] + `:{` + "\n")
err = ToString(extPkg, names[2], desc, "", buf[offset+n+nnn:offset+nn], tabs+1, writer)
if err != nil {
return err
}
offset += nn
w.tab()
w.String(`}` + "\n")
break
} else {
panic(ext.GetTypeName())
}
}
}
w.Bytes(buf[offset : offset+nn])
w.String("\n")
offset += nn
}
}
return nil
}