• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang descriptor.DescriptorProto类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: lintProtoMessage

func (p *protoBufErrors) lintProtoMessage(
	pathIndex int32,
	pathType int32,
	parentPath []int32,
	protoMessage *descriptor.DescriptorProto,
) {

	path := append(
		parentPath,
		pathType,
		pathIndex,
	)

	if !isCamelCase(protoMessage.GetName()) {
		p.addError(&protoBufError{
			path:        path,
			errorCode:   errorMessageCase,
			errorString: protoMessage.GetName(),
		})
	}

	for i, v := range protoMessage.GetField() {
		p.lintProtoField(int32(i), path, v)
	}

	for i, v := range protoMessage.GetEnumType() {
		p.lintProtoEnumType(int32(i), pathMessageEnum, path, v)
	}

	for i, v := range protoMessage.GetNestedType() {
		p.lintProtoMessage(int32(i), pathMessageMessage, path, v)
	}
}
开发者ID:ckaznocha,项目名称:protoc-gen-lint,代码行数:33,代码来源:protoBuffErrors.go


示例2: getTmplMessageDatas

func getTmplMessageDatas(pkg string, parents []string, messageType *descriptor.DescriptorProto, messageDatas []*tmplMessageData) []*tmplMessageData {
	protoName := pkg
	for _, parent := range parents {
		protoName = protoName + "." + parent
	}
	name := messageType.GetName()
	protoName = protoName + "." + name
	goName := name
	for i := len(parents) - 1; i >= 0; i-- {
		goName = parents[i] + "_" + goName
	}
	messageDatas = append(
		messageDatas,
		&tmplMessageData{
			ProtoName: protoName,
			GoName:    goName,
		},
	)
	for _, child := range messageType.NestedType {
		if child.Options == nil || !child.Options.GetMapEntry() {
			messageDatas = getTmplMessageDatas(
				pkg,
				append(parents, name),
				child,
				messageDatas,
			)
		}
	}
	return messageDatas
}
开发者ID:kunthar,项目名称:pachyderm,代码行数:30,代码来源:main.go


示例3: fillTreeWithMessage

func fillTreeWithMessage(tree *tree, key string, proto *descriptor.DescriptorProto, loc string, locs map[string]*descriptor.SourceCodeInfo_Location) *message {
	key = fmt.Sprintf("%s.%s", key, proto.GetName())
	tree.messages[key] = &message{key: key, comment: getComment(loc, locs), DescriptorProto: proto}

	// Oneofs
	for idx, proto := range proto.GetOneofDecl() {
		tree.messages[key].oneofs = append(tree.messages[key].oneofs, &oneof{
			index:                int32(idx),
			OneofDescriptorProto: proto,
		})
	}

	// Fields
	for idx, proto := range proto.GetField() {
		field := fillTreeWithField(tree, key, proto, fmt.Sprintf("%s,2,%d", loc, idx), locs)
		tree.messages[key].fields = append(tree.messages[key].fields, field)
	}

	// Nested
	for idx, proto := range proto.GetNestedType() {
		message := fillTreeWithMessage(tree, key, proto, fmt.Sprintf("%s,3,%d", loc, idx), locs)
		tree.messages[key].nested = append(tree.messages[key].nested, message)
	}

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

	return tree.messages[key]
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:31,代码来源:build_tree.go


示例4: GenerateOneofDefinition

func (fg *FileGenerator) GenerateOneofDefinition(prefix string, inMessage *descriptor.DescriptorProto, oneofIndex int) error {
	inOneof := inMessage.GetOneofDecl()[oneofIndex]

	// TODO: Prefix with message name to avoid collisions.
	oneofType := oneofType(inOneof)

	fg.P("")
	fg.P("")
	fg.P("type %s", oneofType)
	{
		fg.In()

		leading := "="
		{
			oneofVariantName := oneofUnspecifiedValue(inOneof)
			fg.P("%s %s", leading, oneofVariantName)
			leading = "|"
		}
		for _, inField := range inMessage.GetField() {
			if inField.OneofIndex != nil && inField.GetOneofIndex() == int32(oneofIndex) {

				oneofVariantName := elmTypeName(inField.GetName())
				oneofArgumentType := fieldElmType(inField)
				fg.P("%s %s %s", leading, oneofVariantName, oneofArgumentType)

				leading = "|"
			}
		}
		fg.Out()
	}

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


示例5: GenerateOneofDecoder

func (fg *FileGenerator) GenerateOneofDecoder(prefix string, inMessage *descriptor.DescriptorProto, oneofIndex int) error {
	inOneof := inMessage.GetOneofDecl()[oneofIndex]

	// TODO: Prefix with message name to avoid collisions.
	oneofType := oneofType(inOneof)
	decoderName := oneofDecoderName(inOneof)

	fg.P("")
	fg.P("")
	fg.P("%s : JD.Decoder %s", decoderName, oneofType)
	fg.P("%s =", decoderName)
	{
		fg.In()
		fg.P("JD.lazy <| \\_ -> JD.oneOf")
		{
			fg.In()

			leading := "["
			for _, inField := range inMessage.GetField() {
				if inField.OneofIndex != nil && inField.GetOneofIndex() == int32(oneofIndex) {
					oneofVariantName := elmTypeName(inField.GetName())
					decoderName := fieldDecoderName(inField)
					fg.P("%s JD.map %s (JD.field %q %s)", leading, oneofVariantName, inField.GetJsonName(), decoderName)
					leading = ","
				}
			}
			fg.P("%s JD.succeed %s", leading, oneofUnspecifiedValue(inOneof))
			fg.P("]")
			fg.Out()
		}
		fg.Out()
	}

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


示例6: convertMessageType

func convertMessageType(curPkg *ProtoPackage, msg *descriptor.DescriptorProto) (schema []*Field, err error) {
	if glog.V(4) {
		glog.Info("Converting message: ", proto.MarshalTextString(msg))
	}
	for _, fieldDesc := range msg.GetField() {
		field, err := convertField(curPkg, fieldDesc, msg)
		if err != nil {
			glog.Errorf("Failed to convert field %s in %s: %v", fieldDesc.GetName(), msg.GetName(), err)
			return nil, err
		}
		schema = append(schema, field)
	}
	return
}
开发者ID:GoogleCloudPlatform,项目名称:protoc-gen-bq-schema,代码行数:14,代码来源:main.go


示例7: GenerateMessageDefinition

func (fg *FileGenerator) GenerateMessageDefinition(prefix string, inMessage *descriptor.DescriptorProto) error {
	typeName := prefix + inMessage.GetName()

	fg.P("")
	fg.P("")
	fg.P("type alias %s =", typeName)
	{
		fg.In()

		leading := "{"
		for _, inField := range inMessage.GetField() {
			if inField.OneofIndex != nil {
				// Handled in the oneof only.
				continue
			}

			optional := (inField.GetLabel() == descriptor.FieldDescriptorProto_LABEL_OPTIONAL) &&
				(inField.GetType() == descriptor.FieldDescriptorProto_TYPE_MESSAGE)
			repeated := inField.GetLabel() == descriptor.FieldDescriptorProto_LABEL_REPEATED

			fType := fieldElmType(inField)

			fName := elmFieldName(inField.GetName())
			fNumber := inField.GetNumber()

			if repeated {
				fg.P("%s %s : List %s -- %d", leading, fName, fType, fNumber)
			} else {
				if optional {
					fg.P("%s %s : Maybe %s -- %d", leading, fName, fType, fNumber)
				} else {
					fg.P("%s %s : %s -- %d", leading, fName, fType, fNumber)
				}
			}

			leading = ","
		}

		for _, inOneof := range inMessage.GetOneofDecl() {
			oneofName := elmFieldName(inOneof.GetName())
			// TODO: Prefix with message name to avoid collisions.
			oneofTypeName := elmTypeName(inOneof.GetName())
			fg.P("%s %s : %s", leading, oneofName, oneofTypeName)

			leading = ","
		}

		fg.P("}")
		fg.Out()
	}

	for i, _ := range inMessage.GetOneofDecl() {
		fg.GenerateOneofDefinition(prefix, inMessage, i)
		fg.GenerateOneofDecoder(prefix, inMessage, i)
		fg.GenerateOneofEncoder(prefix, inMessage, i)
	}

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


示例8: relativelyLookupNestedType

func relativelyLookupNestedType(desc *descriptor.DescriptorProto, name string) (*descriptor.DescriptorProto, bool) {
	components := strings.Split(name, ".")
componentLoop:
	for _, component := range components {
		for _, nested := range desc.GetNestedType() {
			if nested.GetName() == component {
				desc = nested
				continue componentLoop
			}
		}
		glog.Infof("no such nested message %s in %s", component, desc.GetName())
		return nil, false
	}
	return desc, true
}
开发者ID:GoogleCloudPlatform,项目名称:protoc-gen-bq-schema,代码行数:15,代码来源:main.go


示例9: GenerateEverything

func (fg *FileGenerator) GenerateEverything(prefix string, inMessage *descriptor.DescriptorProto) error {
	newPrefix := prefix + inMessage.GetName() + "_"
	var err error

	err = fg.GenerateMessageDefinition(prefix, inMessage)
	if err != nil {
		return err
	}

	for _, inEnum := range inMessage.GetEnumType() {
		err = fg.GenerateEnumDefinition(newPrefix, inEnum)
		if err != nil {
			return err
		}
	}

	err = fg.GenerateMessageDecoder(prefix, inMessage)
	if err != nil {
		return err
	}

	for _, inEnum := range inMessage.GetEnumType() {
		err = fg.GenerateEnumDecoder(newPrefix, inEnum)
		if err != nil {
			return err
		}
	}

	err = fg.GenerateMessageEncoder(prefix, inMessage)
	if err != nil {
		return err
	}

	for _, inEnum := range inMessage.GetEnumType() {
		err = fg.GenerateEnumEncoder(newPrefix, inEnum)
		if err != nil {
			return err
		}
	}

	// Nested messages.
	for _, nested := range inMessage.GetNestedType() {
		fg.GenerateEverything(newPrefix, nested)
	}

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


示例10: GenerateOneofEncoder

func (fg *FileGenerator) GenerateOneofEncoder(prefix string, inMessage *descriptor.DescriptorProto, oneofIndex int) error {
	inOneof := inMessage.GetOneofDecl()[oneofIndex]

	// TODO: Prefix with message name to avoid collisions.
	oneofType := oneofType(inOneof)
	encoderName := oneofEncoderName(inOneof)
	argName := "v"

	fg.P("")
	fg.P("")
	fg.P("%s : %s -> Maybe ( String, JE.Value )", encoderName, oneofType)
	fg.P("%s %s =", encoderName, argName)
	{
		fg.In()
		fg.P("case %s of", argName)
		{
			fg.In()

			valueName := "x"
			{
				oneofVariantName := oneofUnspecifiedValue(inOneof)
				fg.P("%s -> Nothing", oneofVariantName)
			}
			// TODO: Evaluate them in reverse order, as per
			// https://developers.google.com/protocol-buffers/docs/proto3#oneof
			for _, inField := range inMessage.GetField() {
				if inField.OneofIndex != nil && inField.GetOneofIndex() == int32(oneofIndex) {
					oneofVariantName := elmTypeName(inField.GetName())
					e := fieldEncoderName(inField)
					fg.P("%s %s ->", oneofVariantName, valueName)
					fg.In()
					fg.P("Just ( %q, %s %s )", inField.GetJsonName(), e, valueName)
					fg.Out()
				}
			}
			fg.Out()
		}
		fg.Out()
	}

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


示例11: registerType

func registerType(pkgName *string, msg *descriptor.DescriptorProto) {
	pkg := globalPkg
	if pkgName != nil {
		for _, node := range strings.Split(*pkgName, ".") {
			if pkg == globalPkg && node == "" {
				// Skips leading "."
				continue
			}
			child, ok := pkg.children[node]
			if !ok {
				child = &ProtoPackage{
					name:     pkg.name + "." + node,
					parent:   pkg,
					children: make(map[string]*ProtoPackage),
					types:    make(map[string]*descriptor.DescriptorProto),
				}
				pkg.children[node] = child
			}
			pkg = child
		}
	}
	pkg.types[msg.GetName()] = msg
}
开发者ID:GoogleCloudPlatform,项目名称:protoc-gen-bq-schema,代码行数:23,代码来源:main.go


示例12: GenerateMessageEncoder

func (fg *FileGenerator) GenerateMessageEncoder(prefix string, inMessage *descriptor.DescriptorProto) error {
	typeName := prefix + inMessage.GetName()
	argName := "v"

	fg.P("")
	fg.P("")
	fg.P("%s : %s -> JE.Value", encoderName(typeName), typeName)
	fg.P("%s %s =", encoderName(typeName), argName)
	{
		fg.In()
		fg.P("JE.object <| List.filterMap identity <|")
		{
			fg.In()

			leading := "["
			for _, inField := range inMessage.GetField() {
				if inField.OneofIndex != nil {
					// Handled in the oneof only.
					continue
				}

				optional := (inField.GetLabel() == descriptor.FieldDescriptorProto_LABEL_OPTIONAL) &&
					(inField.GetType() == descriptor.FieldDescriptorProto_TYPE_MESSAGE)
				repeated := inField.GetLabel() == descriptor.FieldDescriptorProto_LABEL_REPEATED
				d := fieldEncoderName(inField)
				val := argName + "." + elmFieldName(inField.GetName())
				def := fieldDefaultValue(inField)
				if repeated {
					fg.P("%s (repeatedFieldEncoder %q %s %s)", leading, jsonFieldName(inField), d, val)
				} else {
					if optional {
						fg.P("%s (optionalEncoder %q %s %s)", leading, jsonFieldName(inField), d, val)
					} else {
						fg.P("%s (requiredFieldEncoder %q %s %s %s)", leading, jsonFieldName(inField), d, def, val)
					}
				}

				leading = ","
			}

			for _, inOneof := range inMessage.GetOneofDecl() {
				val := argName + "." + elmFieldName(inOneof.GetName())
				oneofEncoderName := oneofEncoderName(inOneof)
				fg.P("%s (%s %s)", leading, oneofEncoderName, val)
				leading = ","
			}

			fg.P("]")

			fg.Out()
		}
		fg.Out()
	}
	return nil
}
开发者ID:tiziano88,项目名称:elm-protobuf,代码行数:55,代码来源:message.go


示例13: GenerateMessageDecoder

func (fg *FileGenerator) GenerateMessageDecoder(prefix string, inMessage *descriptor.DescriptorProto) error {
	typeName := prefix + inMessage.GetName()

	fg.P("")
	fg.P("")
	fg.P("%s : JD.Decoder %s", decoderName(typeName), typeName)
	fg.P("%s =", decoderName(typeName))
	{
		fg.In()
		fg.P("JD.lazy <| \\_ -> %s", typeName)
		{
			fg.In()

			leading := "<$>"
			for _, inField := range inMessage.GetField() {
				if inField.OneofIndex != nil {
					// Handled in the oneof only.
					continue
				}

				optional := (inField.GetLabel() == descriptor.FieldDescriptorProto_LABEL_OPTIONAL) &&
					(inField.GetType() == descriptor.FieldDescriptorProto_TYPE_MESSAGE)
				repeated := inField.GetLabel() == descriptor.FieldDescriptorProto_LABEL_REPEATED
				d := fieldDecoderName(inField)
				def := fieldDefaultValue(inField)

				if repeated {
					fg.P("%s (repeatedFieldDecoder %q %s)", leading, jsonFieldName(inField), d)
				} else {
					if optional {
						fg.P("%s (optionalFieldDecoder %q %s)", leading, jsonFieldName(inField), d)
					} else {
						fg.P("%s (requiredFieldDecoder %q %s %s)", leading, jsonFieldName(inField), def, d)
					}
				}

				leading = "<*>"
			}

			for _, inOneof := range inMessage.GetOneofDecl() {
				oneofDecoderName := oneofDecoderName(inOneof)
				fg.P("%s %s", leading, oneofDecoderName)

				leading = "<*>"
			}

			fg.Out()
		}
		fg.Out()
	}
	return nil
}
开发者ID:tiziano88,项目名称:elm-protobuf,代码行数:52,代码来源:message.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang descriptor.FieldDescriptorProto类代码示例发布时间:2022-05-23
下一篇:
Golang proto.Properties类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap