protoreflect

package
v0.0.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WireVarint     = 0
	WireFixed32    = 5
	WireFixed64    = 1
	WireBytes      = 2
	WireStartGroup = 3
	WireEndGroup   = 4
)
View Source
const (
	GONAME_XXX_PREFIX         = "XXX_"
	GONAME_X_NOUNKEYEDLITERAL = "XXX_NoUnkeyedLiteral"
	GONAME_X_UNRECOGNIZED     = "XXX_unrecognized"
	GONAME_X_SIZECACHE        = "XXX_sizecache"

	GONAME_N_STATE           = "state"
	GONAME_N_SIZECACHE       = "sizeCache"
	GONAME_N_UNKNOWNFIELDS   = "unknownFields"
	GONAME_N_EXTENSIONFIELDS = "extensionFields"
	GONAME_N_WEAKFIELDS      = "weakFields"
)

自动生成字段名常量定义

Variables

This section is empty.

Functions

func IsGeneratedAutoFields

func IsGeneratedAutoFields(fieldName string) (bool, error)

IsGeneratedAutoFields 判断字段是否是proto-gen-go自动生成的特殊字段

@param fieldName 字段名
@return bool 是否是proto-gen-go自动生成的特殊字段
@return error

Types

type FieldInfo

type FieldInfo struct {
	// FieldName 字段名(go结构体中的字段名)
	FieldName string

	// ProtoName proto字段名(protobuf消息中定义的原始字段名)
	ProtoName string

	// jsonName json字段名(protobuf消息中定义的json字段名)
	JsonName string

	// FieldType 字段类型(go结构体中的字段类型)
	FieldType reflect.Type

	// FiledValue 字段类型(go结构体中的字段值)
	FiledValue reflect.Value

	// ExplicitDef 是否显式定义字段
	//  proto3会自动给消息添加state,sizeCache,unknownFields三个通用字段,它们就不是显式定义字段。
	ExplicitDef bool
}

FieldInfo 字段情报

func GetFields

func GetFields(msg proto.Message) ([]*FieldInfo, error)

GetFields 获取目标proto消息的字段信息

@param msg protobuf消息
@return []*FieldInfo 字段信息列表
@return error

func GetFieldsByProperties

func GetFieldsByProperties(msg protoadapt.MessageV1) ([]*FieldInfo, error)

GetFieldsByProperties 根据StructProperties获取proto消息字段信息

注意,该函数使用了`github.com/golang/protobuf/proto`的弃用函数`GetProperties`
@param msg protobuf消息
@return []*FieldInfo 字段信息列表
@return error

func (*FieldInfo) String

func (fd *FieldInfo) String() string

String 重写String方法

type OneofProperties added in v0.0.12

type OneofProperties struct {
	// Type is a pointer to the generated wrapper type for the field value.
	// This is nil for messages that are not in the open-struct API.
	Type reflect.Type
	// Field is the index into StructProperties.Prop for the containing oneof.
	Field int
	// Prop is the properties for the field.
	Prop *Properties
}

type Properties added in v0.0.12

type Properties struct {
	// Name is a placeholder name with little meaningful semantic value.
	// If the name has an "XXX_" prefix, the entire Properties must be ignored.
	Name string
	// OrigName is the protobuf field name or oneof name.
	OrigName string
	// JSONName is the JSON name for the protobuf field.
	JSONName string
	// Enum is a placeholder name for enums.
	// For historical reasons, this is neither the Go name for the enum,
	// nor the protobuf name for the enum.
	Enum string // Deprecated: Do not use.
	// Weak contains the full name of the weakly referenced message.
	Weak string
	// Wire is a string representation of the wire type.
	Wire string
	// WireType is the protobuf wire type for the field.
	WireType int
	// Tag is the protobuf field number.
	Tag int
	// Required reports whether this is a required field.
	Required bool
	// Optional reports whether this is a optional field.
	Optional bool
	// Repeated reports whether this is a repeated field.
	Repeated bool
	// Packed reports whether this is a packed repeated field of scalars.
	Packed bool
	// Proto3 reports whether this field operates under the proto3 syntax.
	Proto3 bool
	// Oneof reports whether this field belongs within a oneof.
	Oneof bool

	// Default is the default value in string form.
	Default string
	// HasDefault reports whether the field has a default value.
	HasDefault bool

	// MapKeyProp is the properties for the key field for a map field.
	MapKeyProp *Properties
	// MapValProp is the properties for the value field for a map field.
	MapValProp *Properties
}

func (*Properties) Init added in v0.0.12

func (p *Properties) Init(typ reflect.Type, name, tag string, f *reflect.StructField)

func (*Properties) Parse added in v0.0.12

func (p *Properties) Parse(tag string)

type StructProperties added in v0.0.12

type StructProperties struct {
	// Prop are the properties for each field.
	//
	// Fields belonging to a oneof are stored in OneofTypes instead, with a
	// single Properties representing the parent oneof held here.
	//
	// The order of Prop matches the order of fields in the Go struct.
	// Struct fields that are not related to protobufs have a "XXX_" prefix
	// in the Properties.Name and must be ignored by the user.
	Prop []*Properties

	// OneofTypes contains information about the oneof fields in this message.
	// It is keyed by the protobuf field name.
	OneofTypes map[string]*OneofProperties
}

func GetProperties added in v0.0.12

func GetProperties(t reflect.Type) *StructProperties

GetProperties returns the list of properties for the type represented by t, which must be a generated protocol buffer message in the open-struct API, where protobuf message fields are represented by exported Go struct fields.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL