structpb

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2021 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NullValue_name = map[int32]string{
		0: "NULL_VALUE",
	}
	NullValue_value = map[string]int32{
		"NULL_VALUE": 0,
	}
)

Enum value maps for NullValue.

View Source
var File_struct_proto protoreflect.FileDescriptor

Functions

This section is empty.

Types

type Dict added in v0.2.0

type Dict struct {

	// Unordered map of dynamically typed values.
	Fields map[string]*Value `` /* 153-byte string literal not displayed */
	// contains filtered or unexported fields
}

`Dict` represents a structured data value, consisting of fields which map to dynamically typed values.

The JSON representation for `Struct` is JSON object.

func NewDict added in v0.2.0

func NewDict(v map[string]interface{}) (*Dict, error)

NewDict constructs a Struct from a general-purpose Go map. The map keys must be valid UTF-8. The map values are converted using NewValue.

func NewEmptyDict added in v0.2.0

func NewEmptyDict() *Dict

func (*Dict) AsMap added in v0.2.0

func (x *Dict) AsMap() map[string]interface{}

AsMap converts x to a general-purpose Go map. The map values are converted by calling Value.AsInterface.

func (*Dict) Clone added in v0.2.0

func (x *Dict) Clone() *Dict

func (*Dict) Descriptor deprecated added in v0.2.0

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

Deprecated: Use Dict.ProtoReflect.Descriptor instead.

func (*Dict) Get added in v0.2.0

func (x *Dict) Get(key string) *Value

Get equals x.Fields[key] but can be called from nil safely

func (*Dict) GetFields added in v0.2.0

func (x *Dict) GetFields() map[string]*Value

func (*Dict) MarshalJSON added in v0.2.0

func (x *Dict) MarshalJSON() ([]byte, error)

func (*Dict) MarshalJSONPB added in v0.2.0

func (x *Dict) MarshalJSONPB(m *jsonpb.Marshaler) ([]byte, error)

func (*Dict) ProtoMessage added in v0.2.0

func (*Dict) ProtoMessage()

func (*Dict) ProtoReflect added in v0.2.0

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

func (*Dict) Reset added in v0.2.0

func (x *Dict) Reset()

func (*Dict) Set added in v0.2.0

func (x *Dict) Set(key string, value *Value) bool

Set equals x.Fields[key] = value but is more safe return value is false only if struct == nil

func (*Dict) String added in v0.2.0

func (x *Dict) String() string

func (*Dict) ToStarlark added in v0.2.0

func (x *Dict) ToStarlark() *starlark.Dict

func (*Dict) UnmarshalJSON added in v0.2.0

func (x *Dict) UnmarshalJSON(p []byte) error

func (*Dict) UnmarshalJSONPB added in v0.2.0

func (x *Dict) UnmarshalJSONPB(_ *jsonpb.Unmarshaler, p []byte) error

type List added in v0.2.0

type List struct {

	// Repeated field of dynamically typed values.
	Values []*Value `protobuf:"bytes,1,rep,name=values,proto3" json:"values,omitempty"`
	// contains filtered or unexported fields
}

`List` is a wrapper around a repeated field of values.

The JSON representation for `List` is JSON array.

func New2DList

func New2DList(v [][]interface{}) (*List, error)

func NewEmptyList added in v0.1.4

func NewEmptyList() *List

func NewList

func NewList(v []interface{}) (*List, error)

NewList constructs a ListValue from a general-purpose Go slice. The slice elements are converted using NewValue.

func NewStringList

func NewStringList(v []string) (*List, error)

NewStringList constructs a ListValue from a gstring Go slice. The slice elements are converted using NewValue.

func (*List) AsSlice added in v0.2.0

func (x *List) AsSlice() []interface{}

AsSlice converts x to a general-purpose Go slice. The slice elements are converted by calling Value.AsInterface.

func (*List) Clone added in v0.2.0

func (x *List) Clone() *List

func (*List) Descriptor deprecated added in v0.2.0

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

Deprecated: Use List.ProtoReflect.Descriptor instead.

func (*List) GetValues added in v0.2.0

func (x *List) GetValues() []*Value

func (*List) MarshalJSON added in v0.2.0

func (x *List) MarshalJSON() ([]byte, error)

func (*List) MarshalJSONPB added in v0.2.0

func (x *List) MarshalJSONPB(m *jsonpb.Marshaler) ([]byte, error)

func (*List) ProtoMessage added in v0.2.0

func (*List) ProtoMessage()

func (*List) ProtoReflect added in v0.2.0

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

func (*List) Reset added in v0.2.0

func (x *List) Reset()

func (*List) String added in v0.2.0

func (x *List) String() string

func (*List) ToStarlark added in v0.2.0

func (x *List) ToStarlark() *starlark.List

func (*List) UnmarshalJSON added in v0.2.0

func (x *List) UnmarshalJSON(p []byte) error

func (*List) UnmarshalJSONPB added in v0.2.0

func (x *List) UnmarshalJSONPB(_ *jsonpb.Unmarshaler, p []byte) error

type NullValue

type NullValue int32

`NullValue` is a singleton enumeration to represent the null value for the `Value` type union.

The JSON representation for `NullValue` is JSON `null`.
const (
	// Null value.
	NullValue_NULL_VALUE NullValue = 0
)

func (NullValue) Descriptor

func (NullValue) Descriptor() protoreflect.EnumDescriptor

func (NullValue) Enum

func (x NullValue) Enum() *NullValue

func (NullValue) EnumDescriptor deprecated

func (NullValue) EnumDescriptor() ([]byte, []int)

Deprecated: Use NullValue.Descriptor instead.

func (NullValue) Number

func (x NullValue) Number() protoreflect.EnumNumber

func (NullValue) String

func (x NullValue) String() string

func (*NullValue) ToStarlark

func (x *NullValue) ToStarlark() starlark.NoneType

func (NullValue) Type

type Value

type Value struct {

	// The kind of value.
	//
	// Types that are assignable to Kind:
	//	*Value_NullValue
	//	*Value_IntValue
	//	*Value_FloatValue
	//	*Value_StringValue
	//	*Value_BoolValue
	//	*Value_DictValue
	//	*Value_ListValue
	Kind isValue_Kind `protobuf_oneof:"kind"`
	// contains filtered or unexported fields
}

`Value` represents a dynamically typed value which can be either null, a number, a string, a boolean, a recursive struct value, or a list of values. A producer of value is expected to set one of that variants, absence of any variant indicates an error.

The JSON representation for `Value` is JSON value.

func NewBoolValue

func NewBoolValue(v bool) *Value

NewBoolValue constructs a new boolean Value.

func NewFloatValue

func NewFloatValue(v float64) *Value

NewFloatValue constructs a new float number Value.

func NewIntValue

func NewIntValue(v int64) *Value

NewIntValue constructs a new integer number Value.

func NewListValue

func NewListValue(v *List) *Value

NewListValue constructs a new list Value.

func NewNullValue

func NewNullValue() *Value

NewNullValue constructs a new null Value.

func NewStringValue

func NewStringValue(v string) *Value

NewStringValue constructs a new string Value.

func NewStructValue

func NewStructValue(v *Dict) *Value

NewStructValue constructs a new struct Value.

func NewValue

func NewValue(v interface{}) (*Value, error)

NewValue constructs a Value from a general-purpose Go interface.

╔════════════════════════╤════════════════════════════════════════════╗
║ Go type                │ Conversion                                 ║
╠════════════════════════╪════════════════════════════════════════════╣
║ nil                    │ stored as NullValue                        ║
║ bool                   │ stored as BoolValue                        ║
║ int, int*              │ stored as IntValue                         ║
║ uint*                  │ stored as IntValue                         ║
║ uint, uint64           │ stored as IntValue / FloatValue            ║
║ float32, float64       │ stored as FloatValue                       ║
║ string                 │ stored as StringValue; must be valid UTF-8 ║
║ []byte                 │ stored as StringValue; base64-encoded      ║
║ map[string]interface{} │ stored as StructValue                      ║
║ []interface{}          │ stored as ListValue                        ║
╚════════════════════════╧════════════════════════════════════════════╝

When converting an int64 or uint64 to a NumberValue, numeric precision loss is possible since they are stored as a float64.

func (*Value) AsInterface

func (x *Value) AsInterface() interface{}

AsInterface converts x to a general-purpose Go interface.

Unlike Unwrap, this function will always return Go's basic types.

For Null, Int, String, Bool, the return value is same as Unwrap (will return nil, int64, string, bool) For Float, this may return a float64 or "NaN" "Infinity" "-Infinity" string For Dict, this will return a map[string]interface{}, which is returned from (*Dict).AsMap() For List, this will return a []interface{}, which is returned from (*List).AsSlice()

Call from nil is safe

func (*Value) Clone added in v0.1.6

func (x *Value) Clone() *Value

func (*Value) Descriptor deprecated

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

Deprecated: Use Value.ProtoReflect.Descriptor instead.

func (*Value) GetBoolValue

func (x *Value) GetBoolValue() bool

func (*Value) GetDictValue added in v0.2.0

func (x *Value) GetDictValue() *Dict

func (*Value) GetFloatValue

func (x *Value) GetFloatValue() float64

func (*Value) GetIntValue

func (x *Value) GetIntValue() int64

func (*Value) GetKind

func (x *Value) GetKind() isValue_Kind

func (*Value) GetListValue

func (x *Value) GetListValue() *List

func (*Value) GetNullValue

func (x *Value) GetNullValue() NullValue

func (*Value) GetStringValue

func (x *Value) GetStringValue() string

func (*Value) MarshalJSON

func (x *Value) MarshalJSON() ([]byte, error)

func (*Value) MarshalJSONPB

func (x *Value) MarshalJSONPB(m *jsonpb.Marshaler) ([]byte, error)

func (*Value) ProtoMessage

func (*Value) ProtoMessage()

func (*Value) ProtoReflect

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

func (*Value) Reset

func (x *Value) Reset()

func (*Value) String

func (x *Value) String() string

func (*Value) ToStarlark

func (x *Value) ToStarlark() starlark.Value

func (*Value) UnmarshalJSON added in v0.1.4

func (x *Value) UnmarshalJSON(p []byte) error

func (*Value) UnmarshalJSONPB added in v0.1.4

func (x *Value) UnmarshalJSONPB(_ *jsonpb.Unmarshaler, p []byte) error

func (*Value) Unwrap added in v0.1.4

func (x *Value) Unwrap() interface{}

Unwrap returns the underlying value it's type may be nil, int64, float64, string, bool, *Dict, *List

Call from a nil is safe

type Value_BoolValue

type Value_BoolValue struct {
	// Represents a boolean value.
	BoolValue bool `protobuf:"varint,4,opt,name=bool_value,json=boolValue,proto3,oneof"`
}

type Value_DictValue added in v0.2.0

type Value_DictValue struct {
	// Represents a structured value.
	DictValue *Dict `protobuf:"bytes,5,opt,name=dict_value,json=dictValue,proto3,oneof"`
}

type Value_FloatValue

type Value_FloatValue struct {
	// Represents a float value.
	FloatValue float64 `protobuf:"fixed64,2,opt,name=float_value,json=floatValue,proto3,oneof"`
}

type Value_IntValue

type Value_IntValue struct {
	// Represents a number value
	IntValue int64 `protobuf:"varint,7,opt,name=int_value,json=intValue,proto3,oneof"`
}

type Value_ListValue

type Value_ListValue struct {
	// Represents a repeated `Value`.
	ListValue *List `protobuf:"bytes,6,opt,name=list_value,json=listValue,proto3,oneof"`
}

type Value_NullValue

type Value_NullValue struct {
	// Represents a null value.
	NullValue NullValue `protobuf:"varint,1,opt,name=null_value,json=nullValue,proto3,enum=struct.NullValue,oneof"`
}

type Value_StringValue

type Value_StringValue struct {
	// Represents a string value.
	StringValue string `protobuf:"bytes,3,opt,name=string_value,json=stringValue,proto3,oneof"`
}

Jump to

Keyboard shortcuts

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