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


Golang FileDescriptorProto.GetMessageType方法代码示例

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


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

示例1: fillTreeWithFile

func fillTreeWithFile(tree *tree, file *descriptor.FileDescriptorProto) {
	key := fmt.Sprintf(".%s", file.GetPackage())
	locs := make(map[string]*descriptor.SourceCodeInfo_Location)
	for _, loc := range file.GetSourceCodeInfo().GetLocation() {
		if loc.LeadingComments == nil {
			continue
		}
		var p []string
		for _, n := range loc.Path {
			p = append(p, strconv.Itoa(int(n)))
		}
		locs[strings.Join(p, ",")] = loc
	}

	// Messages
	for idx, proto := range file.GetMessageType() {
		fillTreeWithMessage(tree, key, proto, fmt.Sprintf("4,%d", idx), locs)
	}

	// Enums
	for idx, proto := range file.GetEnumType() {
		fillTreeWithEnum(tree, key, proto, fmt.Sprintf("5,%d", idx), locs)
	}

	// Services
	for idx, proto := range file.GetService() {
		fillTreeWithService(tree, key, proto, fmt.Sprintf("6,%d", idx), locs)
	}
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:29,代码来源:build_tree.go

示例2: convertFile

func convertFile(file *descriptor.FileDescriptorProto) ([]*plugin.CodeGeneratorResponse_File, error) {
	name := path.Base(file.GetName())
	pkg, ok := globalPkg.relativelyLookupPackage(file.GetPackage())
	if !ok {
		return nil, fmt.Errorf("no such package found: %s", file.GetPackage())
	}

	response := []*plugin.CodeGeneratorResponse_File{}
	for _, msg := range file.GetMessageType() {
		options := msg.GetOptions()
		if options == nil {
			continue
		}
		if !proto.HasExtension(options, E_TableName) {
			continue
		}
		optionValue, err := proto.GetExtension(options, E_TableName)
		if err != nil {
			return nil, err
		}
		tableName := *optionValue.(*string)
		if len(tableName) == 0 {
			return nil, fmt.Errorf("table name of %s cannot be empty", msg.GetName())
		}

		glog.V(2).Info("Generating schema for a message type ", msg.GetName())
		schema, err := convertMessageType(pkg, msg)
		if err != nil {
			glog.Errorf("Failed to convert %s: %v", name, err)
			return nil, err
		}

		jsonSchema, err := json.Marshal(schema)
		if err != nil {
			glog.Error("Failed to encode schema", err)
			return nil, err
		}

		resFile := &plugin.CodeGeneratorResponse_File{
			Name:    proto.String(fmt.Sprintf("%s/%s.schema", strings.Replace(file.GetPackage(), ".", "/", -1), tableName)),
			Content: proto.String(string(jsonSchema)),
		}
		response = append(response, resFile)
	}

	return response, nil
}
开发者ID:GoogleCloudPlatform,项目名称:protoc-gen-bq-schema,代码行数:47,代码来源:main.go

示例3: loadFile

// loadFile loads messages and fiels from "file".
// It does not loads services and methods in "file".  You need to call
// loadServices after loadFiles is called for all files to load services and methods.
func (r *Registry) loadFile(file *descriptor.FileDescriptorProto) {
	pkg := GoPackage{
		Path: r.goPackagePath(file),
		Name: defaultGoPackageName(file),
	}
	if err := r.ReserveGoPackageAlias(pkg.Name, pkg.Path); err != nil {
		for i := 0; ; i++ {
			alias := fmt.Sprintf("%s_%d", pkg.Name, i)
			if err := r.ReserveGoPackageAlias(alias, pkg.Path); err == nil {
				pkg.Alias = alias
				break
			}
		}
	}
	f := &File{
		FileDescriptorProto: file,
		GoPkg:               pkg,
	}

	r.files[file.GetName()] = f
	r.registerMsg(f, nil, file.GetMessageType())
}
开发者ID:vvakame,项目名称:grpc-gateway,代码行数:25,代码来源:registry.go

示例4: loadFile

// loadFile loads messages and fiels from "file".
// It does not loads services and methods in "file".  You need to call
// loadServices after loadFiles is called for all files to load services and methods.
func (r *Registry) loadFile(file *descriptor.FileDescriptorProto) {
	pkg := GoPackage{
		Path: r.goPackagePath(file),
		Name: defaultGoPackageName(file),
	}
	if err := r.ReserveGoPackageAlias(pkg.Name, pkg.Path); err != nil {
		for i := 0; ; i++ {
			alias := fmt.Sprintf("%s_%d", pkg.Name, i)
			if err := r.ReserveGoPackageAlias(alias, pkg.Path); err == nil {
				pkg.Alias = alias
				break
			}
		}
	}

	comments := make(map[string]*descriptor.SourceCodeInfo_Location)
	for _, loc := range file.GetSourceCodeInfo().GetLocation() {
		if loc.LeadingComments == nil && loc.TrailingComments == nil {
			continue
		}

		var p []string
		for _, n := range loc.Path {
			p = append(p, strconv.Itoa(int(n)))
		}

		comments[strings.Join(p, ",")] = loc
	}

	f := &File{
		FileDescriptorProto: file,
		GoPkg:               pkg,
		Comments:            comments,
	}

	r.files[file.GetName()] = f
	r.registerMsg(f, nil, nil, file.GetMessageType())
}
开发者ID:ceram1,项目名称:grpc-gateway,代码行数:41,代码来源:registry.go

示例5: LintProtoFile

// LintProtoFile takes a file name, proto file description, and a file.
// It checks the file for errors and writes them to the output file
func LintProtoFile(
	protoFile *descriptor.FileDescriptorProto,
	outFile io.WriteCloser,
) (int, error) {
	var (
		errors      = protoBufErrors{}
		protoSource = protoFile.GetSourceCodeInfo()
	)

	for i, v := range protoFile.GetMessageType() {
		errors.lintProtoMessage(int32(i), pathMessage, []int32{}, v)
	}

	for i, v := range protoFile.GetEnumType() {
		errors.lintProtoEnumType(int32(i), pathEnumType, []int32{}, v)
	}

	for i, v := range protoFile.GetService() {
		errors.lintProtoService(int32(i), v)
	}
	for _, v := range errors {
		line, col := v.getSourceLineNumber(protoSource)
		fmt.Fprintf(
			outFile,
			"%s:%d:%d: '%s' - %s\n",
			*protoFile.Name,
			line,
			col,
			v.errorString,
			linterErrors[v.errorCode],
		)
	}

	return len(errors), nil

}
开发者ID:ckaznocha,项目名称:protoc-gen-lint,代码行数:38,代码来源:linter.go

示例6: processFile

func processFile(inFile *descriptor.FileDescriptorProto) (*plugin.CodeGeneratorResponse_File, error) {
	if inFile.GetSyntax() != "proto3" {
		return nil, fmt.Errorf("Only proto3 syntax is supported")
	}

	outFile := &plugin.CodeGeneratorResponse_File{}

	inFilePath := inFile.GetName()
	inFileDir, inFileName := filepath.Split(inFilePath)

	shortModuleName := firstUpper(strings.TrimSuffix(inFileName, ".proto"))

	fullModuleName := ""
	outFileName := ""
	for _, segment := range strings.Split(inFileDir, "/") {
		if segment == "" {
			continue
		}
		fullModuleName += firstUpper(segment) + "."
		outFileName += firstUpper(segment) + "/"
	}
	fullModuleName += shortModuleName
	outFileName += shortModuleName + ".elm"

	outFile.Name = proto.String(outFileName)

	b := &bytes.Buffer{}
	fg := NewFileGenerator(b)

	fg.GenerateModule(fullModuleName)
	fg.GenerateImports()
	fg.GenerateRuntime()

	var err error

	// Top-level enums.
	for _, inEnum := range inFile.GetEnumType() {
		err = fg.GenerateEnumDefinition("", inEnum)
		if err != nil {
			return nil, err
		}

		err = fg.GenerateEnumDecoder("", inEnum)
		if err != nil {
			return nil, err
		}

		err = fg.GenerateEnumEncoder("", inEnum)
		if err != nil {
			return nil, err
		}
	}

	// Top-level messages.
	for _, inMessage := range inFile.GetMessageType() {
		err = fg.GenerateEverything("", inMessage)
		if err != nil {
			return nil, err
		}
	}

	outFile.Content = proto.String(b.String())

	return outFile, nil
}
开发者ID:tiziano88,项目名称:elm-protobuf,代码行数:65,代码来源:main.go


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