wire

package
v1.20.2 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package wire provides types and constants that map directly to the wire representation of Thrift values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EvaluateValue

func EvaluateValue(v Value) error

EvaluateValue ensures that the given Value is fully evaluated. Lazy lists are spinned and any errors raised by them are returned.

func ListsAreEqual

func ListsAreEqual(left, right ValueList) bool

ListsAreEqual checks if two lists are equal.

func MapsAreEqual

func MapsAreEqual(left, right MapItemList) bool

MapsAreEqual checks if two maps are equal.

func SetsAreEqual

func SetsAreEqual(left, right ValueList) bool

SetsAreEqual checks if two sets are equal.

func StructsAreEqual

func StructsAreEqual(left, right Struct) bool

StructsAreEqual checks if two structs are equal.

func ValuesAreEqual

func ValuesAreEqual(left, right Value) bool

ValuesAreEqual checks if two values are equal.

Types

type Envelope

type Envelope struct {
	Name  string
	Type  EnvelopeType
	SeqID int32
	Value Value
}

Envelope represents an enveloped value which includes metadata about the method, the type of data in the envelope, and the value.

type EnvelopeType

type EnvelopeType int8

EnvelopeType is the type of data inside of the envelope.

const (
	Call      EnvelopeType = 1
	Reply     EnvelopeType = 2
	Exception EnvelopeType = 3
	OneWay    EnvelopeType = 4
)

List of envelope types, same as TMessageType in Apache Thrift.

func (EnvelopeType) String

func (et EnvelopeType) String() string

type Field

type Field struct {
	ID    int16
	Value Value
}

Field is a single field inside a Struct.

func (Field) String

func (f Field) String() string

type MapItem

type MapItem struct {
	Key   Value
	Value Value
}

MapItem is a single item in a Map.

func MapItemListToSlice

func MapItemListToSlice(l MapItemList) []MapItem

MapItemListToSlice builds a slice of values from the given MapItemList.

func (MapItem) String

func (mi MapItem) String() string

type MapItemList

type MapItemList interface {
	// Size returns the size of this lazy list.
	Size() int

	// KeyType and ValueType specify the kind of values held in this
	// MapItemList.
	KeyType() Type
	ValueType() Type

	// ForEach calls the given function on each element of the list.
	//
	// If any call fails with an error, that error is returned and the
	// iteration is stopped.
	ForEach(f func(MapItem) error) error

	// Close indicates that the caller is finished reading from the lazy list.
	Close()
}

MapItemList represents a collection of MapItem objects as an iteration through it. This helps us avoid the cost of allocating memory for all collections passing through the system.

func MapItemListFromSlice

func MapItemListFromSlice(k, v Type, items []MapItem) MapItemList

MapItemListFromSlice builds a MapItemList from the given slice of Values.

type Struct

type Struct struct {
	Fields []Field
}

Struct provides a wire-level representation of a struct.

At this level, structs don't have names or named fields.

func (Struct) String

func (s Struct) String() string

type Type

type Type byte

Type identifies the different types supported by Thrift over the wire.

const (
	TBool   Type = 2
	TI8     Type = 3
	TDouble Type = 4
	TI16    Type = 6
	TI32    Type = 8
	TI64    Type = 10
	TBinary Type = 11
	TStruct Type = 12
	TMap    Type = 13
	TSet    Type = 14
	TList   Type = 15
)

Type codes of the different types supported by Thrift.

func (Type) String

func (i Type) String() string

type Value

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

Value holds the over-the-wire representation of a Thrift value.

The Type of the value determines which field in the Value is valid.

func NewValueBinary

func NewValueBinary(v []byte) Value

NewValueBinary constructs a new Value that contains a binary string.

func NewValueBool

func NewValueBool(v bool) Value

NewValueBool constructs a new Value that contains a boolean.

func NewValueDouble

func NewValueDouble(v float64) Value

NewValueDouble constructs a new Value that contains a double.

func NewValueI16

func NewValueI16(v int16) Value

NewValueI16 constructs a new Value that contains a 16-bit integer.

func NewValueI32

func NewValueI32(v int32) Value

NewValueI32 constructs a new Value that contains a 32-bit integer.

func NewValueI64

func NewValueI64(v int64) Value

NewValueI64 constructs a new Value that contains a 64-bit integer.

func NewValueI8

func NewValueI8(v int8) Value

NewValueI8 constructs a new Value that contains a byte

func NewValueList

func NewValueList(v ValueList) Value

NewValueList constructs a new Value that contains a list.

func NewValueMap

func NewValueMap(v MapItemList) Value

NewValueMap constructs a new Value that contains a map.

func NewValueSet

func NewValueSet(v ValueList) Value

NewValueSet constructs a new Value that contains a set.

func NewValueString

func NewValueString(v string) Value

NewValueString constructs a new Value that contains a string.

func NewValueStruct

func NewValueStruct(v Struct) Value

NewValueStruct constructs a new Value that contains a struct.

func ValueListToSlice

func ValueListToSlice(l ValueList) []Value

ValueListToSlice builds a slice of values from the given ValueList.

func (*Value) Get

func (v *Value) Get() interface{}

Get retrieves whatever value the given Value contains.

func (*Value) GetBinary

func (v *Value) GetBinary() []byte

GetBinary gets the Binary value from a Value.

func (*Value) GetBool

func (v *Value) GetBool() bool

GetBool gets the Bool value from a Value.

func (*Value) GetDouble

func (v *Value) GetDouble() float64

GetDouble gets the Double value from a Value.

func (*Value) GetI16

func (v *Value) GetI16() int16

GetI16 gets the I16 value from a Value.

func (*Value) GetI32

func (v *Value) GetI32() int32

GetI32 gets the I32 value from a Value.

func (*Value) GetI64

func (v *Value) GetI64() int64

GetI64 gets the I64 value from a Value.

func (*Value) GetI8

func (v *Value) GetI8() int8

GetI8 gets the I8 value from a Value.

func (*Value) GetList

func (v *Value) GetList() ValueList

GetList gets the List value from a Value.

func (*Value) GetMap

func (v *Value) GetMap() MapItemList

GetMap gets the Map value from a Value.

func (*Value) GetSet

func (v *Value) GetSet() ValueList

GetSet gets the Set value from a Value.

func (*Value) GetString

func (v *Value) GetString() string

GetString gets a string value from a Value.

func (*Value) GetStruct

func (v *Value) GetStruct() Struct

GetStruct gets the Struct value from a Value.

func (Value) String

func (v Value) String() string

func (*Value) Type

func (v *Value) Type() Type

Type retrieves the type of value inside a Value.

type ValueList

type ValueList interface {
	// Size returns the size of this lazy list.
	Size() int

	// ValueType specifies the type of values contained in this list.
	ValueType() Type

	// ForEach calls the given function on each element of the list.
	//
	// If any call fails with an error, that error is returned and the
	// iteration is stopped.
	ForEach(f func(Value) error) error

	// Close indicates that the caller is finished reading from the lazy list.
	Close()
}

ValueList represents a collection of Value objects as an iteration through it. This helps us avoid the cost of allocating memory for all collections passing through the system.

func ValueListFromSlice

func ValueListFromSlice(t Type, values []Value) ValueList

ValueListFromSlice builds a ValueList from the given slice of Values.

Jump to

Keyboard shortcuts

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