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


Golang FieldDescriptorProto.GetTypeName方法代码示例

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


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

示例1: 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

示例2: 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


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