xproto

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TableauProtoPackage = "tableau"
)

Variables

View Source
var DefaultBoolValue pref.Value
View Source
var DefaultBytesValue pref.Value
View Source
var DefaultDurationValue pref.Value
View Source
var DefaultEnumValue pref.Value
View Source
var DefaultFloat32Value pref.Value
View Source
var DefaultFloat64Value pref.Value
View Source
var DefaultInt32Value pref.Value
View Source
var DefaultInt64Value pref.Value
View Source
var DefaultStringValue pref.Value
View Source
var DefaultTimestampValue pref.Value
View Source
var DefaultUint32Value pref.Value
View Source
var DefaultUint64Value pref.Value
View Source
var ErrDuplicateKey = fmt.Errorf("duplicate key")

Functions

func CheckMapDuplicateKey added in v0.10.7

func CheckMapDuplicateKey(dst, src proto.Message) error

CheckMapDuplicateKey checks the map field's duplicate key in message with the same descriptor.

func EqualMessage added in v0.9.17

func EqualMessage(v1, v2 pref.Value) bool

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 IsUnionField added in v0.11.0

func IsUnionField(fd protoreflect.FieldDescriptor) bool

func Merge added in v0.10.7

func Merge(dst, src proto.Message) error

Merge merges src into dst, which must be a message with the same descriptor.

NOTE: message should only has two kinds of field:

  1. list
  2. 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

func PatchMerge(dst, src proto.Message) error

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

type EnumCache struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*EnumCache) GetValueByAlias added in v0.10.7

func (ec *EnumCache) GetValueByAlias(ed pref.EnumDescriptor, valueAlias string) (pref.Value, bool)

type TypeInfo added in v0.9.17

type TypeInfo struct {
	FullName       protoreflect.FullName
	ParentFilename string
	Kind           types.Kind

	FirstFieldOptionName string // only for MessageKind
}

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 NewTypeInfos(protoPackage string) *TypeInfos

func (*TypeInfos) Get added in v0.10.7

func (x *TypeInfos) Get(name string) *TypeInfo

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.

func (*TypeInfos) Put added in v0.10.7

func (x *TypeInfos) Put(info *TypeInfo)

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.

Jump to

Keyboard shortcuts

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