Documentation ¶
Index ¶
- Constants
- Variables
- func CheckMapDuplicateKey(dst, src proto.Message) error
- func EqualMessage(v1, v2 pref.Value) bool
- func EqualValue(fd pref.FieldDescriptor, v1, v2 pref.Value) bool
- 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 PatchMerge(dst, src proto.Message) error
- type EnumCache
- type TypeInfo
- type TypeInfos
- type UnionDescriptor
Constants ¶
const (
TableauProtoPackage = "tableau"
)
Variables ¶
var DefaultBoolValue pref.Value
var DefaultBytesValue pref.Value
var DefaultDurationValue pref.Value
var DefaultEnumValue pref.Value
var DefaultFloat32Value pref.Value
var DefaultFloat64Value 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 ¶ added in v0.10.7
CheckMapDuplicateKey checks the map field's duplicate key in message with the same descriptor.
func EqualMessage ¶ added in v0.9.17
EqualMessage reports whether two messages are equal.
func EqualValue ¶ added in v0.9.17
func EqualValue(fd pref.FieldDescriptor, v1, v2 pref.Value) bool
EqualValue compares two singular values. NOTE(wenchy): borrowed from https://github.com/protocolbuffers/protobuf-go/blob/v1.27.1/proto/equal.go#L113
func GetFieldDefaultValue ¶ added in v0.11.0
func GetFieldDefaultValue(fd pref.FieldDescriptor) string
func GetFieldTypeName ¶ added in v0.11.0
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 ¶ added in v0.11.0
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 ¶ added in v0.11.0
func IsUnion(md protoreflect.MessageDescriptor) bool
func IsUnionField ¶ added in v0.11.0
func IsUnionField(fd protoreflect.FieldDescriptor) bool
func Merge ¶ added in v0.10.7
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 ¶ added in v0.9.14
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 ¶ added in v0.9.17
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 PatchMerge ¶ added in v0.11.0
PatchMerge merges src into dst, which must be a message with the same descriptor.
Default PatchMerge mechanism ¶
- scalar: Populated scalar fields in src are copied to dst.
- message: Populated singular messages in src are merged into dst by recursively calling proto.Merge.
- list: The elements of every list field in src are appended to the corresponded list fields in dst.
- map: The entries of every map field in src are copied into the corresponding map field in dst, possibly replacing existing entries.
- unknown: The unknown fields of src are appended to the unknown fields of dst.
Top-field patch option "PATCH_REPLACE" ¶
- list: Clear field firstly, and then all elements of this list field in src are appended to the corresponded list fields in dst.
- map: Clear field firstly, and then all entries of this map field in src are copied into the corresponding map field in dst.
Types ¶
type EnumCache ¶ added in v0.10.7
func (*EnumCache) GetValueByAlias ¶ added in v0.10.7
type TypeInfos ¶ added in v0.10.7
type TypeInfos struct {
// contains filtered or unexported fields
}
func GetAllTypeInfo ¶ added in v0.9.17
func GetAllTypeInfo(files *protoregistry.Files, protoPackage string) *TypeInfos
func NewTypeInfos ¶ added in v0.10.7
func (*TypeInfos) Get ¶ added in v0.10.7
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 ¶ added in v0.10.7
func (x *TypeInfos) GetByFullName(fullName protoreflect.FullName) *TypeInfo
GetByFullName retrieves type info by type's full name.
type UnionDescriptor ¶ added in v0.11.0
type UnionDescriptor struct { Type protoreflect.FieldDescriptor Value protoreflect.OneofDescriptor }
func ExtractUnionDescriptor ¶ added in v0.11.0
func ExtractUnionDescriptor(md protoreflect.MessageDescriptor) *UnionDescriptor
func (UnionDescriptor) GetValueByNumber ¶ added in v0.11.0
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 ¶ added in v0.11.0
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 ¶ added in v0.11.0
func (u UnionDescriptor) ValueFieldName() string
ValueFieldName returns the value field name. It returns "Field" if not set explicitly in oneof extension.