本文整理匯總了Golang中github.com/gogo/protobuf/protoc-gen-gogo/descriptor.DescriptorProto.GetField方法的典型用法代碼示例。如果您正苦於以下問題:Golang DescriptorProto.GetField方法的具體用法?Golang DescriptorProto.GetField怎麽用?Golang DescriptorProto.GetField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gogo/protobuf/protoc-gen-gogo/descriptor.DescriptorProto
的用法示例。
在下文中一共展示了DescriptorProto.GetField方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getFieldNumber
func getFieldNumber(descriptorSet *descriptor.FileDescriptorSet, rootPkg string, rootMsg string, msg *descriptor.DescriptorProto, fieldNum int32) *descriptor.FieldDescriptorProto {
for _, f := range msg.GetField() {
if f.GetNumber() == fieldNum {
return f
}
}
if !msg.IsExtendable() {
return nil
}
extendee := "." + rootPkg + "." + rootMsg
for _, file := range descriptorSet.GetFile() {
for _, ext := range file.GetExtension() {
if strings.Map(dotToUnderscore, file.GetPackage()) == strings.Map(dotToUnderscore, rootPkg) {
if !(ext.GetExtendee() == rootMsg || ext.GetExtendee() == extendee) {
continue
}
} else {
if ext.GetExtendee() != extendee {
continue
}
}
if ext.GetNumber() == fieldNum {
return ext
}
}
}
return nil
}
示例2: newMsg
func newMsg(desc protoparser.DescMap, protomsg *descriptor.DescriptorProto) *msg {
msg := &msg{make(map[string]fieldEncoder)}
for _, f := range protomsg.GetField() {
fieldEnc := newFieldEncoder(desc, f)
msg.fieldEncoders[f.GetName()] = fieldEnc
}
return msg
}
示例3: BuilderMap
func BuilderMap(visited map[string]struct{}, fieldname string, repeated bool, msg *descriptor.DescriptorProto, fileDescriptorSet *descriptor.FileDescriptorSet) []string {
s := []string{`"` + typ(fieldname, repeated, msg) + `": build` + typ(fieldname, repeated, msg) + `(emptyIfNull(null)),`}
for _, f := range msg.GetField() {
if !f.IsMessage() {
continue
}
fieldMsg := getMessage(f, fileDescriptorSet)
if _, ok := visited[msg.GetName()+"."+f.GetName()]; !ok {
visited[msg.GetName()+"."+f.GetName()] = struct{}{}
s = append(s, BuilderMap(visited, f.GetName(), f.IsRepeated(), fieldMsg, fileDescriptorSet)...)
}
}
return s
}
示例4: Builder
func Builder(visited map[string]struct{}, root bool, fieldname string, repeated bool, msg *descriptor.DescriptorProto, fileDescriptorSet *descriptor.FileDescriptorSet, proto3 bool, buildField FieldBuilder) string {
s := []string{`function build` + typ(fieldname, repeated, msg) + `(json) {`}
if repeated {
s = append(s, `var s = '<div class="node" type="`+typ(fieldname, repeated, msg)+`" fieldname="`+fieldname+`" repeated="true">';`)
} else {
s = append(s, `if (json == undefined) {
return "";
}
`)
s = append(s, `var s = '<div class="node" type="`+typ(fieldname, repeated, msg)+`" fieldname="`+fieldname+`" repeated="false">';`)
}
if !root {
s = append(s, `s += '<div class="row"><div class="col-sm-2">'`)
s = append(s, `s += '<a href="#" class="del-child btn btn-danger btn-xs" role="button" fieldname="`+fieldname+`">Remove</a>'`)
s = append(s, `s += '</div><div class="col-sm-10">'`)
s = append(s, `s += '<label class="heading">`+fieldname+`</label>'`)
s = append(s, `s += '</div></div>'`)
}
ms := []string{}
for _, f := range msg.GetField() {
if f.IsMessage() {
fieldMsg := getMessage(f, fileDescriptorSet)
if _, ok := visited[msg.GetName()+"."+f.GetName()]; !ok {
visited[msg.GetName()+"."+f.GetName()] = struct{}{}
ms = append(ms, Builder(visited, false, f.GetName(), f.IsRepeated(), fieldMsg, fileDescriptorSet, proto3, buildField))
}
}
s = append(s, buildField(fileDescriptorSet, msg, f, proto3))
}
if root {
s = append(s, `
s += '</div>';
var node = $(s);
activateLinks(node);
return node;
}`)
} else {
s = append(s, `
s += '</div>';
return s;
}`)
}
f := strings.Join(s, "\n")
ms = append(ms, f)
return strings.Join(ms, "\n\n")
}
示例5: visit
func (this *descMap) visit(pkgName string, msg *descriptor.DescriptorProto) error {
if _, ok := this.msgToField[msg]; ok {
return nil
}
fields := msg.GetField()
if msg.HasExtension() {
exts := this.findExts(pkgName, msg.GetName())
fields = append(fields, exts...)
}
for i, f := range fields {
if _, ok := this.msgToField[msg]; !ok {
this.msgToField[msg] = make(map[uint64]*descriptor.FieldDescriptorProto)
}
this.msgToField[msg][f.GetKeyUint64()] = fields[i]
if f.GetType() == descriptor.FieldDescriptorProto_TYPE_MESSAGE {
newPkgName, newMsgName := this.desc.FindMessage(pkgName, msg.GetName(), f.GetName())
if len(newMsgName) == 0 {
return &errUnknown{pkgName + "." + msg.GetName() + "." + f.GetName()}
}
newMsg := this.desc.GetMessage(newPkgName, newMsgName)
if newMsg == nil {
return &errUnknown{newPkgName + "." + newMsgName}
}
this.fieldToMsg[fields[i]] = newMsg
if _, ok := this.msgToField[newMsg]; ok {
continue
}
if err := this.visit(newPkgName, newMsg); err != nil {
return err
}
}
}
for i := range msg.GetNestedType() {
if err := this.visit(pkgName, msg.GetNestedType()[i]); err != nil {
return err
}
}
return nil
}