protoreflect

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

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 protogh.Message) ([]*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方法

Jump to

Keyboard shortcuts

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