Documentation
¶
Index ¶
- Constants
- Variables
- func CheckMapDuplicateKey(dst, src proto.Message) error
- func GetFieldDefaultValue(fd pref.FieldDescriptor) string
- func GetFieldTypeName(fd protoreflect.FieldDescriptor) string
- func GetOneofFieldByNumber(od protoreflect.OneofDescriptor, n int32) protoreflect.FieldDescriptor
- func IsUnion(md protoreflect.MessageDescriptor) bool
- func IsUnionField(fd protoreflect.FieldDescriptor) bool
- func Merge(dst, src proto.Message) error
- func NewFiles(protoPaths []string, protoFiles []string, excludeProtoFiles ...string) (*protoregistry.Files, error)
- func ParseFieldValue(fd pref.FieldDescriptor, rawValue string, locationName string) (v pref.Value, present bool, err error)
- func ParseProtos(protoPaths []string, protoFiles ...string) (*protoregistry.Files, error)
- func PatchMessage(dst, src proto.Message) error
- type EnumCache
- type TypeInfo
- type TypeInfos
- type UnionDescriptor
Constants ¶
const ( InternalProtoPackage = "internal" MetabookFullName = "internal.Metabook" )
Variables ¶
var DefaultBoolValue pref.Value
var DefaultBytesValue pref.Value
var DefaultComparatorValue pref.Value
var DefaultDurationValue pref.Value
var DefaultEnumValue pref.Value
var DefaultFloat32Value pref.Value
var DefaultFloat64Value pref.Value
var DefaultFractionValue pref.Value
var DefaultInt32Value pref.Value
var DefaultInt64Value pref.Value
var DefaultStringValue pref.Value
var DefaultTimestampValue pref.Value
var DefaultUint32Value pref.Value
var DefaultUint64Value pref.Value
var ErrDuplicateKey = fmt.Errorf("duplicate key")
Functions ¶
func CheckMapDuplicateKey ¶
CheckMapDuplicateKey checks the map field's duplicate key in message with the same descriptor.
func GetFieldDefaultValue ¶
func GetFieldDefaultValue(fd pref.FieldDescriptor) string
func GetFieldTypeName ¶
func GetFieldTypeName(fd protoreflect.FieldDescriptor) string
GetFieldTypeName parses and returns correct field type name in desired format from field descriptor.
The desired formats are:
- map<KeyType, ValueType>
- repeated ElemType
- MessageType
- EnumType
- ScalarType
func GetOneofFieldByNumber ¶
func GetOneofFieldByNumber(od protoreflect.OneofDescriptor, n int32) protoreflect.FieldDescriptor
GetOneofFieldByNumber returns the FieldDescriptor for a field numbered n. It returns nil if not found.
func IsUnion ¶
func IsUnion(md protoreflect.MessageDescriptor) bool
func IsUnionField ¶
func IsUnionField(fd protoreflect.FieldDescriptor) bool
func Merge ¶
Merge merges src into dst, which must be a message with the same descriptor.
NOTE: message should only has two kinds of field:
- list
- map: src should not has duplicate key in dst
func NewFiles ¶
func NewFiles(protoPaths []string, protoFiles []string, excludeProtoFiles ...string) (*protoregistry.Files, error)
NewFiles creates a new protoregistry.Files from the proto paths and proto Gob filenames.
func ParseFieldValue ¶
func ParseFieldValue(fd pref.FieldDescriptor, rawValue string, locationName string) (v pref.Value, present bool, err error)
ParseFieldValue parses field value by FieldDescriptor. It can parse following basic types:
Scalar types ¶
- Numbers: int32, uint32, int64, uint64, float, double
- Booleans: bool
- Strings: string
- Bytes: bytes
Enum type ¶
Well-known types ¶
- "google.protobuf.Timestamp": datetime, date, time
- "google.protobuf.Duration": duration
func ParseProtos ¶
func ParseProtos(protoPaths []string, protoFiles ...string) (*protoregistry.Files, error)
ParseProtos parses the proto paths and proto files to desc.FileDescriptor slices.
func PatchMessage ¶
PatchMessage patches src into dst, which must be a message with the same descriptor.
Default PatchMessage mechanism ¶
- scalar: Populated scalar fields in src are copied to dst.
- message: Populated singular messages in src are merged into dst by recursively calling xproto.PatchMessage, or replace dst message if "PATCH_REPLACE" is specified for this field.
- list: The elements of every list field in src are appended to the corresponded list fields in dst, or replace dst list if "PATCH_REPLACE" is specified for this field.
- map: The entries of every map field in src are MERGED (different from the behavior of proto.Merge) into the corresponding map field in dst, or replace dst map if "PATCH_REPLACE" is specified for this field.
- unknown: The unknown fields of src are appended to the unknown fields of dst (TODO: untested).
Types ¶
type EnumCache ¶
func (*EnumCache) GetValueByAlias ¶
type TypeInfos ¶
type TypeInfos struct {
// contains filtered or unexported fields
}
func GetAllTypeInfo ¶
func GetAllTypeInfo(files *protoregistry.Files, protoPackage string) *TypeInfos
func NewTypeInfos ¶
func (*TypeInfos) Get ¶
Get retrieves type info by name in proto package.
NOTE: if name is prefixed with ".", then default proto package name will be prepended to generate full name. For example: ".ItemType" will be conveted to "<ProtoPackage>.ItemType"
func (*TypeInfos) GetByFullName ¶
func (x *TypeInfos) GetByFullName(fullName protoreflect.FullName) *TypeInfo
GetByFullName retrieves type info by type's full name.
type UnionDescriptor ¶
type UnionDescriptor struct { Type protoreflect.FieldDescriptor Value protoreflect.OneofDescriptor }
func ExtractUnionDescriptor ¶
func ExtractUnionDescriptor(md protoreflect.MessageDescriptor) *UnionDescriptor
func (UnionDescriptor) GetValueByNumber ¶
func (u UnionDescriptor) GetValueByNumber(n int32) protoreflect.FieldDescriptor
GetValueByNumber returns the FieldDescriptor for a field numbered n. It returns nil if not found.
func (UnionDescriptor) TypeName ¶
func (u UnionDescriptor) TypeName() string
TypeName returns the type field name. It returns CameCase style of proto field name if not set explicitly in field extension.
func (UnionDescriptor) ValueFieldName ¶
func (u UnionDescriptor) ValueFieldName() string
ValueFieldName returns the value field name. It returns "Field" if not set explicitly in oneof extension.