fieldmask

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

README

ThriftPath RFC

What is thrift path?

A path string represents a arbitrary endpoint of thrift object. It is used for locating data from thrift root message, and defined from-top-to-bottom. For exapmle, a thrift message defined as below:

struct Example {
    1: string Foo,
    2: i64 Bar
    3: Example Self
}

A thrift path $.Foo represents the string value of Example.Foo, and $.Self.Bar represents the secondary layer i64 value of Example.Self.Bar Since thrift has four nesting types (LIST/SET/MAP/STRUCT), thrift path should also support locating elements in all these types' object, not only STRUCT.

Syntax

Here are basic hypothesis:

  • fieldname is the field name of a field in a struct, it MUST ONLY contain '[a-zA-Z]' alphabet letters, integer numbers and char '_'.
  • index is the index of a element in a list or set, it MUST ONLY contain integer numbers.
  • key is the string-typed key of a element in a map, it can contain any letters, but it MUST be a quoted string.
  • id is the integer-typed key of a element in a map, it MUST ONLY contain integer numbers.

Here is detailed syntax:

ThriftPath Description
$ the root object,every path must start with it.
.fieldname get the child field of a struct corepsonding to fieldname. For example, $.FieldA.ChildrenB
[index,index...] get any number of elements in an List/Set corepsonding to indices. Indices must be integer.For example: $.FieldList[1,3,4] .Notice: a index beyond actual list size can written but is useless.
{"key","key"...} get any number of values corepsonding to key in a string-typed-key map. For example: $.StrMap{"abcd","1234"}
{id,id...} get the child field with specific id in a integer-typed-key map. For example, $.IntMap{1,2}
* get ALL fields/elements, that is: $.StrMap{*}.FieldX menas gets all the elements' FieldX in a map Root.StrMap; $.List[*].FieldX means get all the elements' FieldX in a list Root.List

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FieldMask

type FieldMask struct {
	// contains filtered or unexported fields
}

FieldMask represents a collection of thrift pathes See

func GetFieldMask

func GetFieldMask(desc *thrift_reflection.TypeDescriptor, paths ...string) (*FieldMask, error)

GetFieldMask reuse fieldmask from pool

func NewFieldMask

func NewFieldMask(desc *thrift_reflection.TypeDescriptor, pathes ...string) (*FieldMask, error)

NewFieldMask create a new fieldmask

func (*FieldMask) All

func (self *FieldMask) All() bool

All tells if the mask allows all elements pass (*)

func (*FieldMask) Exist

func (self *FieldMask) Exist() bool

Exist tells if the fieldmask is setted

func (*FieldMask) Field

func (self *FieldMask) Field(id int16) (*FieldMask, bool)

Field returns the specific sub mask for a given id, and tells if the id in the mask

func (*FieldMask) Int

func (self *FieldMask) Int(id int) (*FieldMask, bool)

Int returns the specific sub mask for a given index, and tells if the index in the mask

func (*FieldMask) PathInMask

func (cur *FieldMask) PathInMask(curDesc *thrift_reflection.TypeDescriptor, path string) bool

PathInMask tells if a given path is already in current fieldmask

func (*FieldMask) Recycle

func (self *FieldMask) Recycle()

Recycle puts fieldmask into pool

func (*FieldMask) Str

func (self *FieldMask) Str(id string) (*FieldMask, bool)

Field returns the specific sub mask for a given string, and tells if the string in the mask

func (FieldMask) String

func (self FieldMask) String(desc *thrift_reflection.TypeDescriptor) string

String pretty prints the structure a FieldMask represents

For example: pathes `[]string{"$.Extra[0].List", "$.Extra[*].Set", "$.Meta.F2{0}", "$.Meta.F2{*}.Addr"}` will print:

  (Base)
	.Extra (list<ExtraInfo>)
	[
	  *
	]
	.Meta (MetaInfo)
	  .F2 (map<i8,Base>)
	  {
	    *
	  }

WARING: This is unstable API, the printer format is not guaranteed

Jump to

Keyboard shortcuts

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