本文整理汇总了Golang中github.com/pixty/gogoprotobuf/protoc-gen-gogo/descriptor.FieldDescriptorProto.IsMessage方法的典型用法代码示例。如果您正苦于以下问题:Golang FieldDescriptorProto.IsMessage方法的具体用法?Golang FieldDescriptorProto.IsMessage怎么用?Golang FieldDescriptorProto.IsMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pixty/gogoprotobuf/protoc-gen-gogo/descriptor.FieldDescriptorProto
的用法示例。
在下文中一共展示了FieldDescriptorProto.IsMessage方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: hasLoop
func (p *plugin) hasLoop(field *descriptor.FieldDescriptorProto, visited []*generator.Descriptor, excludes []*generator.Descriptor) *generator.Descriptor {
if field.IsMessage() || p.IsGroup(field) {
fieldMessage := p.ObjectNamed(field.GetTypeName()).(*generator.Descriptor)
fieldTypeName := generator.CamelCaseSlice(fieldMessage.TypeName())
for _, message := range visited {
messageTypeName := generator.CamelCaseSlice(message.TypeName())
if fieldTypeName == messageTypeName {
for _, e := range excludes {
if fieldTypeName == generator.CamelCaseSlice(e.TypeName()) {
return nil
}
}
return fieldMessage
}
}
for _, f := range fieldMessage.Field {
visited = append(visited, fieldMessage)
loopTo := p.hasLoop(f, visited, excludes)
if loopTo != nil {
return loopTo
}
}
}
return nil
}
示例2: 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
}
示例3: GetMap
func GetMap(file *descriptor.FileDescriptorProto, field *descriptor.FieldDescriptorProto) *descriptor.DescriptorProto {
if !field.IsMessage() {
return nil
}
typeName := field.GetTypeName()
if strings.Contains(typeName, "Map") && !strings.HasSuffix(typeName, "Entry") {
typeName += "." + CamelCase(field.GetName()) + "Entry"
}
ts := strings.Split(typeName, ".")
if len(ts) == 1 {
return file.GetMessage(typeName)
}
newTypeName := strings.Join(ts[2:], ".")
return file.GetMessage(newTypeName)
}
示例4: GenerateField
func (p *plugin) GenerateField(file *generator.FileDescriptor, message *generator.Descriptor, field *descriptor.FieldDescriptorProto) {
proto3 := gogoproto.IsProto3(file.FileDescriptorProto)
goTyp, _ := p.GoType(message, field)
fieldname := p.GetFieldName(message, field)
goTypName := generator.GoTypeToName(goTyp)
if generator.IsMap(file.FileDescriptorProto, field) {
mapmsg := generator.GetMap(file.FileDescriptorProto, field)
mapkey, mapvalue := mapmsg.GetMapFields()
keygoTyp, _ := p.GoType(nil, mapkey)
valuegoTyp, _ := p.GoType(nil, mapvalue)
keytypName := generator.GoTypeToName(keygoTyp)
valuetypName := generator.GoTypeToName(valuegoTyp)
mapvaluegoType := valuegoTyp
if !mapvalue.IsMessage() {
mapvaluegoType = strings.Replace(mapvaluegoType, "*", "", 1)
}
p.P(p.varGen.Next(), ` := r.Intn(10)`)
p.P(`this.`, fieldname, ` = make(map[`, strings.Replace(keygoTyp, "*", "", 1), `]`, mapvaluegoType, `)`)
p.P(`for i := 0; i < `, p.varGen.Current(), `; i++ {`)
p.In()
keyval := ""
if mapkey.IsString() {
keyval = fmt.Sprintf("randString%v(r)", p.localName)
} else {
keyval = value(keytypName, mapkey.GetType())
}
if mapvalue.IsMessage() || p.IsGroup(field) {
s := `this.` + fieldname + `[` + keyval + `]` + ` = `
goTypName := generator.GoTypeToName(valuegoTyp)
funcCall := getFuncCall(goTypName)
s += funcCall
p.P(s)
} else if mapvalue.IsEnum() {
s := `this.` + fieldname + `[` + keyval + `]` + ` = ` + p.getEnumVal(mapvalue, valuegoTyp)
p.P(s)
} else if mapvalue.IsBytes() {
count := p.varGen.Next()
p.P(count, ` := r.Intn(100)`)
p.P(p.varGen.Next(), ` := `, keyval)
p.P(`this.`, fieldname, `[`, p.varGen.Current(), `] = make(`, valuegoTyp, `, `, count, `)`)
p.P(`for i := 0; i < `, count, `; i++ {`)
p.In()
p.P(`this.`, fieldname, `[`, p.varGen.Current(), `][i] = byte(r.Intn(256))`)
p.Out()
p.P(`}`)
} else if mapvalue.IsString() {
s := `this.` + fieldname + `[` + keyval + `]` + ` = ` + fmt.Sprintf("randString%v(r)", p.localName)
p.P(s)
} else {
p.P(p.varGen.Next(), ` := `, keyval)
p.P(`this.`, fieldname, `[`, p.varGen.Current(), `] = `, value(valuetypName, mapvalue.GetType()))
if negative(mapvalue.GetType()) {
p.P(`if r.Intn(2) == 0 {`)
p.In()
p.P(`this.`, fieldname, `[`, p.varGen.Current(), `] *= -1`)
p.Out()
p.P(`}`)
}
}
p.Out()
p.P(`}`)
} else if field.IsMessage() || p.IsGroup(field) {
funcCall := getFuncCall(goTypName)
if field.IsRepeated() {
p.P(p.varGen.Next(), ` := r.Intn(10)`)
p.P(`this.`, fieldname, ` = make(`, goTyp, `, `, p.varGen.Current(), `)`)
p.P(`for i := 0; i < `, p.varGen.Current(), `; i++ {`)
p.In()
if gogoproto.IsNullable(field) {
p.P(`this.`, fieldname, `[i] = `, funcCall)
} else {
p.P(p.varGen.Next(), `:= `, funcCall)
p.P(`this.`, fieldname, `[i] = *`, p.varGen.Current())
}
p.Out()
p.P(`}`)
} else {
if gogoproto.IsNullable(field) {
p.P(`this.`, fieldname, ` = `, funcCall)
} else {
p.P(p.varGen.Next(), `:= `, funcCall)
p.P(`this.`, fieldname, ` = *`, p.varGen.Current())
}
}
} else {
if field.IsEnum() {
val := p.getEnumVal(field, goTyp)
if field.IsRepeated() {
p.P(p.varGen.Next(), ` := r.Intn(10)`)
p.P(`this.`, fieldname, ` = make(`, goTyp, `, `, p.varGen.Current(), `)`)
p.P(`for i := 0; i < `, p.varGen.Current(), `; i++ {`)
p.In()
p.P(`this.`, fieldname, `[i] = `, val)
p.Out()
p.P(`}`)
} else if !gogoproto.IsNullable(field) || proto3 {
p.P(`this.`, fieldname, ` = `, val)
} else {
p.P(p.varGen.Next(), ` := `, val)
p.P(`this.`, fieldname, ` = &`, p.varGen.Current())
//.........这里部分代码省略.........
示例5: TurnOffNullableForNativeTypesOnly
func TurnOffNullableForNativeTypesOnly(field *descriptor.FieldDescriptorProto) {
if field.IsRepeated() || field.IsMessage() {
return
}
SetBoolFieldOption(gogoproto.E_Nullable, false)(field)
}
示例6: TurnOffNullable
func TurnOffNullable(field *descriptor.FieldDescriptorProto) {
if field.IsRepeated() && !field.IsMessage() {
return
}
SetBoolFieldOption(gogoproto.E_Nullable, false)(field)
}