Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( NoUnkeyedLiteralFieldName = "XXX_NoUnkeyedLiteral" NoUnkeyedLiteralFieldNameOnce sync.Once )
Functions ¶
func SetPBNoUnkeyedLiteralFieldName ¶
func SetPBNoUnkeyedLiteralFieldName(name string)
SetPBNoUnkeyedLiteralFieldName sets the name of the field used to store unknown fields as raw values in protobuf structs
func SetPBUnknownFieldName ¶
func SetPBUnknownFieldName(name string)
SetPBUnknownFieldName sets the name of the field used to store unknown fields in protobuf structs
func SetThriftUnknownFieldName ¶
func SetThriftUnknownFieldName(name string)
Types ¶
type AssignOptions ¶
type AssignOptions struct {
// DisallowNotDefined if true, returns ErrNotFound when a field/index/key is not found
DisallowNotDefined bool
}
AssignOptions contains options for AssignAny
type Assigner ¶
type Assigner struct {
AssignOptions
}
func (Assigner) AssignAny ¶
func (a Assigner) AssignAny(desc *Descriptor, src interface{}, dest interface{}) error
AssignAny assigns values from src (map[string]interface{}) to dest (protobuf struct) according to desc. For fields that exist in src but not in dest's struct definition (unknown fields):
- If the field exists in descriptor: it will be encoded to XXX_unrecognized field using protobuf binary encoding
- All unknown fields (with or without descriptor) will be stored in XXX_NoUnkeyedLiteral field (if present) as map[string]interface{} with field names as keys
Warning: desc must be normalized before calling this method. This method uses try-best mode: it will continue processing even if some fields fail, collecting all errors and returning them at the end.
func (Assigner) AssignValue ¶
AssignValue assigns values from src to dest by matching reflect-type or map-key or json-tag This method uses try-best mode: it will continue processing even if some fields fail, collecting all errors and returning them at the end.
type Descriptor ¶
type Descriptor struct {
// the kind of corresponding type
// Based on this, we can decide how to manipulate the data (e.g. mapKey or strucField)
Kind TypeKind
// Type of the type
Type string
// children for TypeKind_Struct|TypeKind_StrMap|TypeKind_List
// - For TypeKind_StrMap, either each Field is a key-value pair or one field with Name "*"
// - For TypeKind_Struct, each Field is a field with both Name and ID
// - For TypeKind_List, either each Field.ID is the element index or one field with Name "*" (means all elements)
Children []Field
// contains filtered or unexported fields
}
Descriptor describes the entire a DSL-pruning scheme for a type. base on this, we can fetch the type's object data on demands
WARNING: user must call Normalize() before using this
func (*Descriptor) MarshalJSON ¶
func (d *Descriptor) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler interface for Descriptor It handles circular references by using $ref to reference already visited descriptors
func (*Descriptor) Normalize ¶
func (d *Descriptor) Normalize()
Normalize cache all the fields in the descriptor for speeding up search. It handles circular references by using an atomic flag to detect re-entry.
func (*Descriptor) String ¶
func (d *Descriptor) String() string
String returns the string representation of the descriptor in JSON-like format. It handles circular references by tracking visited descriptors. Format: <TypeName>{...} for struct/map, "-" for scalar types.
func (*Descriptor) UnmarshalJSON ¶
func (d *Descriptor) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler interface for Descriptor It handles circular references by resolving $ref references after initial parsing
type ErrNotFound ¶
type ErrNotFound struct {
Parent *Descriptor
Field Field // the field that is not found
Msg string // additional message
}
ErrNotFound is returned when a field/index/key is not found and disallowNotFound is enabled
func (ErrNotFound) Error ¶
func (e ErrNotFound) Error() string
type FetchOptions ¶
type FetchOptions struct {
// DisallowNotFound if true, returns ErrNotFound when a field/index/key is not found
DisallowNotFound bool
}
FetchOptions contains options for FetchAny
type Fetcher ¶
type Fetcher struct {
FetchOptions
}
func (Fetcher) FetchAny ¶
func (f Fetcher) FetchAny(desc *Descriptor, any interface{}) (interface{}, error)
FetchAny fetches the value of the field described by desc from any based on go reflect.
Warning: desc must be normalized before calling this method.
type Field ¶
type Field struct {
// Name of the field path for TypeKind_Struct
// Or the selection key for TypeKind_StrMap
Name string
// Field ID in Struct
// or List Index in List
ID int
// the child of the field
Desc *Descriptor
}
Field represents a mapping selection
type MultiErrors ¶
type MultiErrors struct {
Errors []error
}
MultiErrors contains multiple errors encountered during fetching
func (MultiErrors) Error ¶
func (e MultiErrors) Error() string
type TypeKind ¶
type TypeKind int
TypeKind is the kind of type.
const ( // TypeKind_Leaf indicates Descriptor is a leaf node, its underlying type can be anything (event go struct/map/list) TypeKind_Leaf TypeKind = iota // TypeKind_Struct indicates Descriptor.Field is struct field TypeKind_Struct // TypeKind_StrMap indicates Descriptor.Field is map key TypeKind_StrMap // TypeKind_List indicates Descriptor.Field is list index TypeKind_List )