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

Golang descriptor.FieldDescriptorProto类代码示例

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

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



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

示例1: fieldDefaultValue

func fieldDefaultValue(inField *descriptor.FieldDescriptorProto) string {
	switch inField.GetType() {
	case descriptor.FieldDescriptorProto_TYPE_INT32,
		descriptor.FieldDescriptorProto_TYPE_INT64,
		descriptor.FieldDescriptorProto_TYPE_UINT32,
		descriptor.FieldDescriptorProto_TYPE_UINT64,
		descriptor.FieldDescriptorProto_TYPE_SINT32,
		descriptor.FieldDescriptorProto_TYPE_SINT64,
		descriptor.FieldDescriptorProto_TYPE_FIXED32,
		descriptor.FieldDescriptorProto_TYPE_FIXED64,
		descriptor.FieldDescriptorProto_TYPE_SFIXED32,
		descriptor.FieldDescriptorProto_TYPE_SFIXED64:
		return "0"
	case descriptor.FieldDescriptorProto_TYPE_FLOAT,
		descriptor.FieldDescriptorProto_TYPE_DOUBLE:
		return "0.0"
	case descriptor.FieldDescriptorProto_TYPE_BOOL:
		return "False"
	case descriptor.FieldDescriptorProto_TYPE_STRING:
		return "\"\""
	case descriptor.FieldDescriptorProto_TYPE_ENUM:
		// TODO: Default enum value.
		return defaultEnumValue(elmFieldType(inField))
	case descriptor.FieldDescriptorProto_TYPE_MESSAGE:
		return "xxx"
	case descriptor.FieldDescriptorProto_TYPE_BYTES:
		return "xxx"
	default:
		return fmt.Sprintf("Error generating decoder for field %s", inField.GetType())
	}
}
开发者ID:tiziano88,项目名称:elm-protobuf,代码行数:31,代码来源:message.go


示例2: fieldDecoderName

func fieldDecoderName(inField *descriptor.FieldDescriptorProto) string {
	switch inField.GetType() {
	case descriptor.FieldDescriptorProto_TYPE_INT32,
		descriptor.FieldDescriptorProto_TYPE_INT64,
		descriptor.FieldDescriptorProto_TYPE_UINT32,
		descriptor.FieldDescriptorProto_TYPE_UINT64,
		descriptor.FieldDescriptorProto_TYPE_SINT32,
		descriptor.FieldDescriptorProto_TYPE_SINT64,
		descriptor.FieldDescriptorProto_TYPE_FIXED32,
		descriptor.FieldDescriptorProto_TYPE_FIXED64,
		descriptor.FieldDescriptorProto_TYPE_SFIXED32,
		descriptor.FieldDescriptorProto_TYPE_SFIXED64:
		// TODO: Handle parsing from string (for 64 bit types).
		return "JD.int"
	case descriptor.FieldDescriptorProto_TYPE_FLOAT,
		descriptor.FieldDescriptorProto_TYPE_DOUBLE:
		return "JD.float"
	case descriptor.FieldDescriptorProto_TYPE_BOOL:
		return "JD.bool"
	case descriptor.FieldDescriptorProto_TYPE_STRING:
		return "JD.string"
	case descriptor.FieldDescriptorProto_TYPE_ENUM:
		// TODO: Default enum value.
		// Remove leading ".".
		return decoderName(elmFieldType(inField))
	case descriptor.FieldDescriptorProto_TYPE_MESSAGE:
		// Remove leading ".".
		return decoderName(elmFieldType(inField))
	case descriptor.FieldDescriptorProto_TYPE_BYTES:
		return "bytesFieldDecoder"
	default:
		return fmt.Sprintf("Error generating decoder for field %s", inField.GetType())
	}
}
开发者ID:tiziano88,项目名称:elm-protobuf,代码行数:34,代码来源:message.go


示例3: elmFieldType

func elmFieldType(field *descriptor.FieldDescriptorProto) string {
	inFieldName := field.GetTypeName()
	packageName, messageName := convert(inFieldName)

	if packageName == "" {
		return messageName
	} else {
		return packageName + "." + messageName
	}
}
开发者ID:tiziano88,项目名称:elm-protobuf,代码行数:10,代码来源:main.go


示例4: int64AsNumber

func int64AsNumber(field *descriptor.FieldDescriptorProto) bool {
	var int64Encoding int64_encoding.Int64Encoding
	if field.Options != nil {
		extMap := field.GetOptions().ExtensionMap()
		if _, ok := extMap[50001]; ok {
			itf, err := proto.GetExtension(field.GetOptions(), int64_encoding.E_Jstype)
			if err == nil {
				int64Encoding = *itf.(*int64_encoding.Int64Encoding)
			}
		}
	}
	return int64Encoding == int64_encoding.Int64Encoding_JS_NUMBER
}
开发者ID:samegoal,项目名称:protoclosure,代码行数:13,代码来源:helper.go


示例5: lintProtoField

func (p *protoBufErrors) lintProtoField(
	pathIndex int32,
	parentPath []int32,
	messageField *descriptor.FieldDescriptorProto,
) {
	path := append(
		parentPath,
		pathMessageField,
		pathIndex,
	)
	if !isLowerUnderscore(messageField.GetName()) {
		p.addError(&protoBufError{
			path:        path,
			errorCode:   errorFieldCase,
			errorString: messageField.GetName(),
		})
	}
}
开发者ID:ckaznocha,项目名称:protoc-gen-lint,代码行数:18,代码来源:protoBuffErrors.go


示例6: fieldElmType

func fieldElmType(inField *descriptor.FieldDescriptorProto) string {
	switch inField.GetType() {
	case descriptor.FieldDescriptorProto_TYPE_INT32,
		descriptor.FieldDescriptorProto_TYPE_INT64,
		descriptor.FieldDescriptorProto_TYPE_UINT32,
		descriptor.FieldDescriptorProto_TYPE_UINT64,
		descriptor.FieldDescriptorProto_TYPE_SINT32,
		descriptor.FieldDescriptorProto_TYPE_SINT64,
		descriptor.FieldDescriptorProto_TYPE_FIXED32,
		descriptor.FieldDescriptorProto_TYPE_FIXED64,
		descriptor.FieldDescriptorProto_TYPE_SFIXED32,
		descriptor.FieldDescriptorProto_TYPE_SFIXED64:
		return "Int"
	case descriptor.FieldDescriptorProto_TYPE_FLOAT,
		descriptor.FieldDescriptorProto_TYPE_DOUBLE:
		return "Float"
	case descriptor.FieldDescriptorProto_TYPE_BOOL:
		return "Bool"
	case descriptor.FieldDescriptorProto_TYPE_STRING:
		return "String"
	case descriptor.FieldDescriptorProto_TYPE_ENUM:
		// XXX
		return elmFieldType(inField)
	case descriptor.FieldDescriptorProto_TYPE_MESSAGE:
		// XXX
		return elmFieldType(inField)
	case descriptor.FieldDescriptorProto_TYPE_BYTES:
		// XXX
		return "Bytes"
	default:
		// TODO: Return error.
		return fmt.Sprintf("Error generating type for field %q %s", inField.GetName(), inField.GetType())
	}
}
开发者ID:tiziano88,项目名称:elm-protobuf,代码行数:34,代码来源:message.go


示例7: fillTreeWithField

func fillTreeWithField(tree *tree, parent string, proto *descriptor.FieldDescriptorProto, loc string, locs map[string]*descriptor.SourceCodeInfo_Location) *field {
	key := fmt.Sprintf("%s.%s", parent, proto.GetName())
	tree.fields[key] = &field{key: key, comment: getComment(loc, locs), FieldDescriptorProto: proto}
	if proto.GetLabel() == descriptor.FieldDescriptorProto_LABEL_REPEATED {
		tree.fields[key].repeated = true
	}
	if proto.OneofIndex != nil {
		if parent, ok := tree.messages[parent]; ok {
			for _, oneof := range parent.oneofs {
				if oneof.index == proto.GetOneofIndex() {
					oneof.fields = append(oneof.fields, tree.fields[key])
					tree.fields[key].isOneOf = true
				}
			}
		}
	}
	return tree.fields[key]
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:18,代码来源:build_tree.go


示例8: convertField

func convertField(curPkg *ProtoPackage, desc *descriptor.FieldDescriptorProto, msg *descriptor.DescriptorProto) (*Field, error) {
	field := &Field{
		Name: desc.GetName(),
	}

	switch desc.GetType() {
	case descriptor.FieldDescriptorProto_TYPE_DOUBLE,
		descriptor.FieldDescriptorProto_TYPE_FLOAT:
		field.Type = "FLOAT"

	case descriptor.FieldDescriptorProto_TYPE_INT64,
		descriptor.FieldDescriptorProto_TYPE_UINT64,
		descriptor.FieldDescriptorProto_TYPE_INT32,
		descriptor.FieldDescriptorProto_TYPE_UINT32,
		descriptor.FieldDescriptorProto_TYPE_FIXED64,
		descriptor.FieldDescriptorProto_TYPE_FIXED32,
		descriptor.FieldDescriptorProto_TYPE_SFIXED32,
		descriptor.FieldDescriptorProto_TYPE_SFIXED64,
		descriptor.FieldDescriptorProto_TYPE_SINT32,
		descriptor.FieldDescriptorProto_TYPE_SINT64:
		field.Type = "INTEGER"

	case descriptor.FieldDescriptorProto_TYPE_STRING,
		descriptor.FieldDescriptorProto_TYPE_BYTES,
		descriptor.FieldDescriptorProto_TYPE_ENUM:
		field.Type = "STRING"

	case descriptor.FieldDescriptorProto_TYPE_BOOL:
		field.Type = "BOOLEAN"

	case descriptor.FieldDescriptorProto_TYPE_GROUP,
		descriptor.FieldDescriptorProto_TYPE_MESSAGE:
		field.Type = "RECORD"

	default:
		return nil, fmt.Errorf("unrecognized field type: %s", desc.GetType().String())
	}

	switch desc.GetLabel() {
	case descriptor.FieldDescriptorProto_LABEL_OPTIONAL:
		field.Mode = "NULLABLE"

	case descriptor.FieldDescriptorProto_LABEL_REQUIRED:
		field.Mode = "REQUIRED"

	case descriptor.FieldDescriptorProto_LABEL_REPEATED:
		field.Mode = "REPEATED"

	default:
		return nil, fmt.Errorf("unrecognized field label: %s", desc.GetLabel().String())
	}

	if field.Type != "RECORD" {
		return field, nil
	}

	recordType, ok := curPkg.lookupType(desc.GetTypeName())
	if !ok {
		return nil, fmt.Errorf("no such message type named %s", desc.GetTypeName())
	}
	var err error
	field.Fields, err = convertMessageType(curPkg, recordType)
	if err != nil {
		return nil, err
	}

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


示例9: jsonFieldName

func jsonFieldName(field *descriptor.FieldDescriptorProto) string {
	return field.GetJsonName()
}
开发者ID:tiziano88,项目名称:elm-protobuf,代码行数:3,代码来源:main.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang descriptor.FileDescriptorProto类代码示例发布时间:2022-05-23
下一篇:
Golang descriptor.DescriptorProto类代码示例发布时间: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