当前位置: 首页>>代码示例>>Golang>>正文


Golang Descriptor.TypeName方法代码示例

本文整理汇总了Golang中limbo/services/protobuf/protoc-gen-gogo/generator.Descriptor.TypeName方法的典型用法代码示例。如果您正苦于以下问题:Golang Descriptor.TypeName方法的具体用法?Golang Descriptor.TypeName怎么用?Golang Descriptor.TypeName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在limbo/services/protobuf/protoc-gen-gogo/generator.Descriptor的用法示例。


在下文中一共展示了Descriptor.TypeName方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: hasLoop

func (p *plugin) hasLoop(field *descriptor.FieldDescriptorProto, visited []*generator.Descriptor, excludes []*generator.Descriptor) *generator.Descriptor {
	if field.IsMessage() || p.IsGroup(field) || p.IsMap(field) {
		var fieldMessage *generator.Descriptor
		if p.IsMap(field) {
			m := p.GoMapType(nil, field)
			if !m.ValueField.IsMessage() {
				return nil
			}
			fieldMessage = p.ObjectNamed(m.ValueField.GetTypeName()).(*generator.Descriptor)
		} else {
			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
}
开发者ID:limbo-services,项目名称:protobuf,代码行数:34,代码来源:populate.go

示例2: checkNameSpace

func (p *plugin) checkNameSpace(message *generator.Descriptor) map[string]bool {
	ccTypeName := generator.CamelCaseSlice(message.TypeName())
	names := make(map[string]bool)
	for _, field := range message.Field {
		fieldname := generator.CamelCase(*field.Name)
		if field.IsMessage() && gogoproto.IsEmbed(field) {
			desc := p.ObjectNamed(field.GetTypeName())
			moreNames := p.checkNameSpace(desc.(*generator.Descriptor))
			for another := range moreNames {
				if names[another] {
					fmt.Fprintf(os.Stderr, "ERROR: duplicate embedded fieldname %v in type %v\n", fieldname, ccTypeName)
					os.Exit(1)
				}
				names[another] = true
			}
		} else {
			if names[fieldname] {
				fmt.Fprintf(os.Stderr, "ERROR: duplicate embedded fieldname %v in type %v\n", fieldname, ccTypeName)
				os.Exit(1)
			}
			names[fieldname] = true
		}
	}
	return names
}
开发者ID:limbo-services,项目名称:protobuf,代码行数:25,代码来源:embedcheck.go

示例3: generateMessageSchema

func (g *jsonschema) generateMessageSchema(file *generator.FileDescriptor, msg *generator.Descriptor, index int) {
	typeName := file.GetPackage() + "." + strings.Join(msg.TypeName(), ".")
	typeName = strings.TrimPrefix(typeName, ".")

	if g.definitions[typeName] == nil {
		def, deps := g.messageToSchema(file, msg)
		g.definitions[typeName] = def
		g.dependencies[typeName] = deps
	}
}
开发者ID:limbo-services,项目名称:core,代码行数:10,代码来源:jsonschema.go

示例4: checkRepeated

func (p *plugin) checkRepeated(message *generator.Descriptor) {
	ccTypeName := generator.CamelCaseSlice(message.TypeName())
	for _, field := range message.Field {
		if !gogoproto.IsEmbed(field) {
			continue
		}
		if field.IsBytes() {
			fieldname := generator.CamelCase(*field.Name)
			fmt.Fprintf(os.Stderr, "ERROR: found embedded bytes field %s in message %s\n", fieldname, ccTypeName)
			os.Exit(1)
		}
		if !field.IsRepeated() {
			continue
		}
		fieldname := generator.CamelCase(*field.Name)
		fmt.Fprintf(os.Stderr, "ERROR: found repeated embedded field %s in message %s\n", fieldname, ccTypeName)
		os.Exit(1)
	}
}
开发者ID:limbo-services,项目名称:protobuf,代码行数:19,代码来源:embedcheck.go

示例5: checkOverwrite

func (p *plugin) checkOverwrite(message *generator.Descriptor, enablers map[string]gogoproto.EnableFunc) {
	ccTypeName := generator.CamelCaseSlice(message.TypeName())
	names := []string{}
	for name := range enablers {
		names = append(names, name)
	}
	for _, field := range message.Field {
		if field.IsMessage() && gogoproto.IsEmbed(field) {
			fieldname := generator.CamelCase(*field.Name)
			desc := p.ObjectNamed(field.GetTypeName())
			msg := desc.(*generator.Descriptor)
			for errStr, enabled := range enablers {
				if enabled(msg.File(), msg.DescriptorProto) {
					fmt.Fprintf(os.Stderr, "WARNING: found non-%v %v with embedded %v %v\n", names, ccTypeName, errStr, fieldname)
				}
			}
			p.checkOverwrite(msg, enablers)
		}
	}
}
开发者ID:limbo-services,项目名称:protobuf,代码行数:20,代码来源:embedcheck.go

示例6: messageToSchema

func (g *jsonschema) messageToSchema(file *generator.FileDescriptor, desc *generator.Descriptor) (interface{}, []string) {
	typeName := file.GetPackage() + "." + strings.Join(desc.TypeName(), ".")
	typeName = strings.TrimPrefix(typeName, ".")

	title := desc.TypeName()[len(desc.TypeName())-1]

	var (
		dependencies       []string
		properties         = make(map[string]interface{})
		requiredProperties []string
	)

	for i, field := range desc.GetField() {
		if field.OneofIndex != nil {
			continue
		}

		f, dep := g.fieldToSchema(field)
		if f == nil {
			continue
		}

		if limbo.IsRequiredProperty(field) {
			requiredProperties = append(requiredProperties, getJSONName(field))
		}

		{
			comment := g.gen.Comments(fmt.Sprintf("%s,%d,%d", desc.Path(), 2, i))
			comment = strings.TrimSpace(comment)
			if comment != "" {
				f["description"] = comment
			}
		}

		properties[getJSONName(field)] = f
		if dep != "" {
			dependencies = append(dependencies, dep)
		}
	}

	schema := map[string]interface{}{
		"type":       "object",
		"properties": properties,
	}
	if len(requiredProperties) > 0 {
		schema["required"] = requiredProperties
	}

	if len(desc.OneofDecl) > 0 {
		allOffDefs := make([]interface{}, 0, 1+len(desc.OneofDecl))
		oneOfDefs := make([][]interface{}, len(desc.OneofDecl))
		for i, field := range desc.GetField() {
			if field.OneofIndex == nil {
				continue
			}
			oneofIndex := *field.OneofIndex

			f, dep := g.fieldToSchema(field)
			if f == nil {
				continue
			}

			if field.IsRepeated() {
				f = map[string]interface{}{
					"type":  "array",
					"items": f,
				}
			}

			{
				comment := g.gen.Comments(fmt.Sprintf("%s,%d,%d", desc.Path(), 2, i))
				comment = strings.TrimSpace(comment)
				if comment != "" {
					f["description"] = comment
				}
			}

			def := map[string]interface{}{
				"type": "object",
				"properties": map[string]interface{}{
					getJSONName(field): f,
				},
				"required": []string{getJSONName(field)},
			}

			oneOfDefs[oneofIndex] = append(oneOfDefs[oneofIndex], def)
			if dep != "" {
				dependencies = append(dependencies, dep)
			}
		}

		allOffDefs = append(allOffDefs, schema)
		for i, defs := range oneOfDefs {
			def := map[string]interface{}{
				"oneOf": defs,
			}

			{
				comment := g.gen.Comments(fmt.Sprintf("%s,%d,%d", desc.Path(), 8, i))
				comment = strings.TrimSpace(comment)
//.........这里部分代码省略.........
开发者ID:limbo-services,项目名称:core,代码行数:101,代码来源:jsonschema.go

示例7: generateMessage

func (p *plugin) generateMessage(file *generator.FileDescriptor, message *generator.Descriptor) {
	ccTypeName := generator.CamelCaseSlice(message.TypeName())
	p.P(`func (this *`, ccTypeName, `) Compare(that interface{}) int {`)
	p.In()
	p.generateMsgNullAndTypeCheck(ccTypeName)
	oneofs := make(map[string]struct{})

	for _, field := range message.Field {
		oneof := field.OneofIndex != nil
		if oneof {
			fieldname := p.GetFieldName(message, field)
			if _, ok := oneofs[fieldname]; ok {
				continue
			} else {
				oneofs[fieldname] = struct{}{}
			}
			p.P(`if that1.`, fieldname, ` == nil {`)
			p.In()
			p.P(`if this.`, fieldname, ` != nil {`)
			p.In()
			p.P(`return 1`)
			p.Out()
			p.P(`}`)
			p.Out()
			p.P(`} else if this.`, fieldname, ` == nil {`)
			p.In()
			p.P(`return -1`)
			p.Out()
			p.P(`} else if c := this.`, fieldname, `.Compare(that1.`, fieldname, `); c != 0 {`)
			p.In()
			p.P(`return c`)
			p.Out()
			p.P(`}`)
		} else {
			p.generateField(file, message, field)
		}
	}
	if message.DescriptorProto.HasExtension() {
		fieldname := "XXX_extensions"
		if gogoproto.HasExtensionsMap(file.FileDescriptorProto, message.DescriptorProto) {
			p.P(`extkeys := make([]int32, 0, len(this.`, fieldname, `)+len(that1.`, fieldname, `))`)
			p.P(`for k, _ := range this.`, fieldname, ` {`)
			p.In()
			p.P(`extkeys = append(extkeys, k)`)
			p.Out()
			p.P(`}`)
			p.P(`for k, _ := range that1.`, fieldname, ` {`)
			p.In()
			p.P(`if _, ok := this.`, fieldname, `[k]; !ok {`)
			p.In()
			p.P(`extkeys = append(extkeys, k)`)
			p.Out()
			p.P(`}`)
			p.Out()
			p.P(`}`)
			p.P(p.sortkeysPkg.Use(), `.Int32s(extkeys)`)
			p.P(`for _, k := range extkeys {`)
			p.In()
			p.P(`if v, ok := this.`, fieldname, `[k]; ok {`)
			p.In()
			p.P(`if v2, ok := that1.`, fieldname, `[k]; ok {`)
			p.In()
			p.P(`if c := v.Compare(&v2); c != 0 {`)
			p.In()
			p.P(`return c`)
			p.Out()
			p.P(`}`)
			p.Out()
			p.P(`} else  {`)
			p.In()
			p.P(`return 1`)
			p.Out()
			p.P(`}`)
			p.Out()
			p.P(`} else {`)
			p.In()
			p.P(`return -1`)
			p.Out()
			p.P(`}`)
			p.Out()
			p.P(`}`)
		} else {
			p.P(`if c := `, p.bytesPkg.Use(), `.Compare(this.`, fieldname, `, that1.`, fieldname, `); c != 0 {`)
			p.In()
			p.P(`return c`)
			p.Out()
			p.P(`}`)
		}
	}
	if gogoproto.HasUnrecognized(file.FileDescriptorProto, message.DescriptorProto) {
		fieldname := "XXX_unrecognized"
		p.P(`if c := `, p.bytesPkg.Use(), `.Compare(this.`, fieldname, `, that1.`, fieldname, `); c != 0 {`)
		p.In()
		p.P(`return c`)
		p.Out()
		p.P(`}`)
	}
	p.P(`return 0`)
	p.Out()
	p.P(`}`)
//.........这里部分代码省略.........
开发者ID:limbo-services,项目名称:protobuf,代码行数:101,代码来源:compare.go

示例8: generateMessage

func (p *plugin) generateMessage(file *generator.FileDescriptor, message *generator.Descriptor, verbose bool) {
	ccTypeName := generator.CamelCaseSlice(message.TypeName())
	if verbose {
		p.P(`func (this *`, ccTypeName, `) VerboseEqual(that interface{}) error {`)
	} else {
		p.P(`func (this *`, ccTypeName, `) Equal(that interface{}) bool {`)
	}
	p.In()
	p.generateMsgNullAndTypeCheck(ccTypeName, verbose)
	oneofs := make(map[string]struct{})

	for _, field := range message.Field {
		oneof := field.OneofIndex != nil
		if oneof {
			fieldname := p.GetFieldName(message, field)
			if _, ok := oneofs[fieldname]; ok {
				continue
			} else {
				oneofs[fieldname] = struct{}{}
			}
			p.P(`if that1.`, fieldname, ` == nil {`)
			p.In()
			p.P(`if this.`, fieldname, ` != nil {`)
			p.In()
			if verbose {
				p.P(`return `, p.fmtPkg.Use(), `.Errorf("this.`, fieldname, ` != nil && that1.`, fieldname, ` == nil")`)
			} else {
				p.P(`return false`)
			}
			p.Out()
			p.P(`}`)
			p.Out()
			p.P(`} else if this.`, fieldname, ` == nil {`)
			p.In()
			if verbose {
				p.P(`return `, p.fmtPkg.Use(), `.Errorf("this.`, fieldname, ` == nil && that1.`, fieldname, ` != nil")`)
			} else {
				p.P(`return false`)
			}
			p.Out()
			if verbose {
				p.P(`} else if err := this.`, fieldname, `.VerboseEqual(that1.`, fieldname, `); err != nil {`)
			} else {
				p.P(`} else if !this.`, fieldname, `.Equal(that1.`, fieldname, `) {`)
			}
			p.In()
			if verbose {
				p.P(`return err`)
			} else {
				p.P(`return false`)
			}
			p.Out()
			p.P(`}`)
		} else {
			p.generateField(file, message, field, verbose)
		}
	}
	if message.DescriptorProto.HasExtension() {
		fieldname := "XXX_extensions"
		if gogoproto.HasExtensionsMap(file.FileDescriptorProto, message.DescriptorProto) {
			p.P(`for k, v := range this.`, fieldname, ` {`)
			p.In()
			p.P(`if v2, ok := that1.`, fieldname, `[k]; ok {`)
			p.In()
			p.P(`if !v.Equal(&v2) {`)
			p.In()
			if verbose {
				p.P(`return `, p.fmtPkg.Use(), `.Errorf("`, fieldname, ` this[%v](%v) Not Equal that[%v](%v)", k, this.`, fieldname, `[k], k, that1.`, fieldname, `[k])`)
			} else {
				p.P(`return false`)
			}
			p.Out()
			p.P(`}`)
			p.Out()
			p.P(`} else  {`)
			p.In()
			if verbose {
				p.P(`return `, p.fmtPkg.Use(), `.Errorf("`, fieldname, `[%v] Not In that", k)`)
			} else {
				p.P(`return false`)
			}
			p.Out()
			p.P(`}`)
			p.Out()
			p.P(`}`)

			p.P(`for k, _ := range that1.`, fieldname, ` {`)
			p.In()
			p.P(`if _, ok := this.`, fieldname, `[k]; !ok {`)
			p.In()
			if verbose {
				p.P(`return `, p.fmtPkg.Use(), `.Errorf("`, fieldname, `[%v] Not In this", k)`)
			} else {
				p.P(`return false`)
			}
			p.Out()
			p.P(`}`)
			p.Out()
			p.P(`}`)
		} else {
//.........这里部分代码省略.........
开发者ID:limbo-services,项目名称:protobuf,代码行数:101,代码来源:equal.go


注:本文中的limbo/services/protobuf/protoc-gen-gogo/generator.Descriptor.TypeName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。