attribute

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxAttributesSize is the maximum total size in bytes, for the event+asset attributes.
	//
	// Currently the limiting factor is the eventsourcepoller topic with a max bytes of a message at
	//   262144 bytes. (256kb due to the pricing tier we have for azure service bus)
	//
	// The message being added to the topic is the evidence format for the entire event
	//   (including asset creation events). So it is not the same size of the requested asset/event
	//   via the api.
	//
	// We need some wiggle room for possible size increase due to conversion from api -> evidence format.
	// We need to take into account sizes principal_declared, principal_accepted, and timestamps as well.
	//
	// For now make the max 51,200 bytes. This allows for 10 attributes
	//   with key size 1024 and value size 4096 to be created.
	//
	// Note. the input validation for attribute key/validation is measured in golang rune count,
	//   not number of bytes.
	//
	// Note. it is easy to increase the limit, but harder to decrease.
	// Also Note. assets requests of size 100,000 bytes have been added successfully onto the block chain.
	MaxAttributesSize = 51200
)

Variables

View Source
var File_datatrails_common_api_attribute_v2_attribute_attribute_proto protoreflect.FileDescriptor

Functions

func AttributeSize

func AttributeSize(attr *Attribute) int64

AttributeSize gets the size of the given attribute in bytes.

func AttributesSize

func AttributesSize(attrs map[string]*Attribute) int64

AttributesSize gets the size of the given attributes in bytes.

including the key values in the map.

func MakeAttributes

func MakeAttributes(namedAttributes ...any) (map[string]*Attribute, error)

MakeAttributes accepts pairs of name, value and returns a map[string]*Attribute. value must be a string, a map[string]string or a []map[string]string

func MakeUnion

func MakeUnion(attributesMaps ...map[string]*Attribute) map[string]*Attribute

MakeUnion makes a union of map attributes from a list of attribute maps.

the value priority for same keys goes for maps later in the argument list. e.g:

if `map1["foo"] = "1"`` and `map2["foo"] = "2"`,
then the resulting map would be `mapResult["foo"] = "2"``

Types

type Attribute

type Attribute struct {

	// Types that are assignable to Value:
	//
	//	*Attribute_StrVal
	//	*Attribute_DictVal
	//	*Attribute_ListVal
	Value isAttribute_Value `protobuf_oneof:"value"`
	// contains filtered or unexported fields
}

func NewAttribute

func NewAttribute(value any) (*Attribute, error)

NewAttribute creates an attribute whose type is infered from a native go-lang type. string -> StrVal, map[string]string -> DictVal, []map[string]string -> ListVal

func NewDictAttribute

func NewDictAttribute(v map[string]string) *Attribute

func NewListAttribute

func NewListAttribute(v []map[string]string) *Attribute

func NewStringAttribute

func NewStringAttribute(v string) *Attribute

func (*Attribute) Descriptor deprecated

func (*Attribute) Descriptor() ([]byte, []int)

Deprecated: Use Attribute.ProtoReflect.Descriptor instead.

func (*Attribute) GetDict

func (m *Attribute) GetDict() (map[string]string, bool)

GetDict returns the map if the value is the correct type. Otherwise the bool return value will be false.

func (*Attribute) GetDictVal

func (x *Attribute) GetDictVal() *DictAttr

func (*Attribute) GetList

func (m *Attribute) GetList() ([]map[string]string, bool)

GetList returns the list of maps if the value is the correct type. Otherwise the bool return value will be false.

func (*Attribute) GetListVal

func (x *Attribute) GetListVal() *ListAttr

func (*Attribute) GetStrVal

func (x *Attribute) GetStrVal() string

func (*Attribute) GetString

func (m *Attribute) GetString() (string, bool)

GetString returns the string if the value is the correct type. Otherwise the bool return value will be false.

func (*Attribute) GetValue

func (m *Attribute) GetValue() isAttribute_Value

func (*Attribute) IsEqual

func (m *Attribute) IsEqual(other *Attribute) bool

IsEqual returns true if both values are equal. For dicts and lists we do a deep compare. For lists, the the order of items in both list must be the same.

func (*Attribute) ProtoMessage

func (*Attribute) ProtoMessage()

func (*Attribute) ProtoReflect

func (x *Attribute) ProtoReflect() protoreflect.Message

func (*Attribute) Reset

func (x *Attribute) Reset()

func (*Attribute) SetString

func (m *Attribute) SetString(value string) bool

Sets an attribute to a string value and returns true IF its a string type Otherwise returns false

func (*Attribute) String

func (x *Attribute) String() string

func (*Attribute) Validate

func (m *Attribute) Validate() error

Validate checks the field values on Attribute with the rules defined in the proto definition for this message. If any rules are violated, the first error encountered is returned, or nil if there are no violations.

func (*Attribute) ValidateAll

func (m *Attribute) ValidateAll() error

ValidateAll checks the field values on Attribute with the rules defined in the proto definition for this message. If any rules are violated, the result is a list of violation errors wrapped in AttributeMultiError, or nil if none found.

type AttributeMultiError

type AttributeMultiError []error

AttributeMultiError is an error wrapping multiple validation errors returned by Attribute.ValidateAll() if the designated constraints aren't met.

func (AttributeMultiError) AllErrors

func (m AttributeMultiError) AllErrors() []error

AllErrors returns a list of validation violation errors.

func (AttributeMultiError) Error

func (m AttributeMultiError) Error() string

Error returns a concatenation of all the error messages it wraps.

type AttributeValidationError

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

AttributeValidationError is the validation error returned by Attribute.Validate if the designated constraints aren't met.

func (AttributeValidationError) Cause

func (e AttributeValidationError) Cause() error

Cause function returns cause value.

func (AttributeValidationError) Error

func (e AttributeValidationError) Error() string

Error satisfies the builtin error interface

func (AttributeValidationError) ErrorName

func (e AttributeValidationError) ErrorName() string

ErrorName returns error name.

func (AttributeValidationError) Field

func (e AttributeValidationError) Field() string

Field function returns field value.

func (AttributeValidationError) Key

Key function returns key value.

func (AttributeValidationError) Reason

func (e AttributeValidationError) Reason() string

Reason function returns reason value.

type Attribute_DictVal

type Attribute_DictVal struct {
	DictVal *DictAttr `protobuf:"bytes,2,opt,name=dict_val,json=dictVal,proto3,oneof"`
}

func (*Attribute_DictVal) Get

func (dv *Attribute_DictVal) Get() map[string]string

GetDict returns the map if the value is the correct type. Otherwise the bool return value will be false.

type Attribute_ListVal

type Attribute_ListVal struct {
	ListVal *ListAttr `protobuf:"bytes,3,opt,name=list_val,json=listVal,proto3,oneof"`
}

func (*Attribute_ListVal) Get

func (lv *Attribute_ListVal) Get() []map[string]string

GetList returns the list of maps if the value is the correct type. Otherwise the bool return value will be false.

type Attribute_StrVal

type Attribute_StrVal struct {
	StrVal string `protobuf:"bytes,1,opt,name=str_val,json=strVal,proto3,oneof"`
}

func (*Attribute_StrVal) Get

func (sv *Attribute_StrVal) Get() string

type DictAttr

type DictAttr struct {
	Value map[string]string `` /* 151-byte string literal not displayed */
	// contains filtered or unexported fields
}

func (*DictAttr) Descriptor deprecated

func (*DictAttr) Descriptor() ([]byte, []int)

Deprecated: Use DictAttr.ProtoReflect.Descriptor instead.

func (*DictAttr) GetValue

func (x *DictAttr) GetValue() map[string]string

func (*DictAttr) ProtoMessage

func (*DictAttr) ProtoMessage()

func (*DictAttr) ProtoReflect

func (x *DictAttr) ProtoReflect() protoreflect.Message

func (*DictAttr) Reset

func (x *DictAttr) Reset()

func (*DictAttr) String

func (x *DictAttr) String() string

func (*DictAttr) Validate

func (m *DictAttr) Validate() error

Validate checks the field values on DictAttr with the rules defined in the proto definition for this message. If any rules are violated, the first error encountered is returned, or nil if there are no violations.

func (*DictAttr) ValidateAll

func (m *DictAttr) ValidateAll() error

ValidateAll checks the field values on DictAttr with the rules defined in the proto definition for this message. If any rules are violated, the result is a list of violation errors wrapped in DictAttrMultiError, or nil if none found.

type DictAttrMultiError

type DictAttrMultiError []error

DictAttrMultiError is an error wrapping multiple validation errors returned by DictAttr.ValidateAll() if the designated constraints aren't met.

func (DictAttrMultiError) AllErrors

func (m DictAttrMultiError) AllErrors() []error

AllErrors returns a list of validation violation errors.

func (DictAttrMultiError) Error

func (m DictAttrMultiError) Error() string

Error returns a concatenation of all the error messages it wraps.

type DictAttrValidationError

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

DictAttrValidationError is the validation error returned by DictAttr.Validate if the designated constraints aren't met.

func (DictAttrValidationError) Cause

func (e DictAttrValidationError) Cause() error

Cause function returns cause value.

func (DictAttrValidationError) Error

func (e DictAttrValidationError) Error() string

Error satisfies the builtin error interface

func (DictAttrValidationError) ErrorName

func (e DictAttrValidationError) ErrorName() string

ErrorName returns error name.

func (DictAttrValidationError) Field

func (e DictAttrValidationError) Field() string

Field function returns field value.

func (DictAttrValidationError) Key

func (e DictAttrValidationError) Key() bool

Key function returns key value.

func (DictAttrValidationError) Reason

func (e DictAttrValidationError) Reason() string

Reason function returns reason value.

type ListAttr

type ListAttr struct {
	Value []*DictAttr `protobuf:"bytes,1,rep,name=value,proto3" json:"value,omitempty"`
	// contains filtered or unexported fields
}

func (*ListAttr) Descriptor deprecated

func (*ListAttr) Descriptor() ([]byte, []int)

Deprecated: Use ListAttr.ProtoReflect.Descriptor instead.

func (*ListAttr) GetValue

func (x *ListAttr) GetValue() []*DictAttr

func (*ListAttr) ProtoMessage

func (*ListAttr) ProtoMessage()

func (*ListAttr) ProtoReflect

func (x *ListAttr) ProtoReflect() protoreflect.Message

func (*ListAttr) Reset

func (x *ListAttr) Reset()

func (*ListAttr) String

func (x *ListAttr) String() string

func (*ListAttr) Validate

func (m *ListAttr) Validate() error

Validate checks the field values on ListAttr with the rules defined in the proto definition for this message. If any rules are violated, the first error encountered is returned, or nil if there are no violations.

func (*ListAttr) ValidateAll

func (m *ListAttr) ValidateAll() error

ValidateAll checks the field values on ListAttr with the rules defined in the proto definition for this message. If any rules are violated, the result is a list of violation errors wrapped in ListAttrMultiError, or nil if none found.

type ListAttrMultiError

type ListAttrMultiError []error

ListAttrMultiError is an error wrapping multiple validation errors returned by ListAttr.ValidateAll() if the designated constraints aren't met.

func (ListAttrMultiError) AllErrors

func (m ListAttrMultiError) AllErrors() []error

AllErrors returns a list of validation violation errors.

func (ListAttrMultiError) Error

func (m ListAttrMultiError) Error() string

Error returns a concatenation of all the error messages it wraps.

type ListAttrValidationError

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

ListAttrValidationError is the validation error returned by ListAttr.Validate if the designated constraints aren't met.

func (ListAttrValidationError) Cause

func (e ListAttrValidationError) Cause() error

Cause function returns cause value.

func (ListAttrValidationError) Error

func (e ListAttrValidationError) Error() string

Error satisfies the builtin error interface

func (ListAttrValidationError) ErrorName

func (e ListAttrValidationError) ErrorName() string

ErrorName returns error name.

func (ListAttrValidationError) Field

func (e ListAttrValidationError) Field() string

Field function returns field value.

func (ListAttrValidationError) Key

func (e ListAttrValidationError) Key() bool

Key function returns key value.

func (ListAttrValidationError) Reason

func (e ListAttrValidationError) Reason() string

Reason function returns reason value.

Jump to

Keyboard shortcuts

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