thrift

package
Version: v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2022 License: MIT Imports: 15 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(p Protocol, v interface{}) ([]byte, error)

Marshal serializes v into a thrift representation according to the the protocol p.

The function panics if v cannot be converted to a thrift representation.

func Unmarshal

func Unmarshal(p Protocol, b []byte, v interface{}) error

Unmarshal deserializes the thrift data from b to v using to the protocol p.

The function errors if the data in b does not match the type of v.

The function panics if v cannot be converted to a thrift representation.

As an optimization, the value passed in v may be reused across multiple calls to Unmarshal, allowing the function to reuse objects referenced by pointer fields of struct values. When reusing objects, the application is responsible for resetting the state of v before calling Unmarshal again.

Types

type BinaryProtocol

type BinaryProtocol struct {
	NonStrict bool
}

BinaryProtocol is a Protocol implementation for the binary thrift protocol.

https://github.com/apache/thrift/blob/master/doc/specs/thrift-binary-protocol.md

func (*BinaryProtocol) Features

func (p *BinaryProtocol) Features() Features

func (*BinaryProtocol) NewReader

func (p *BinaryProtocol) NewReader(r io.Reader) Reader

func (*BinaryProtocol) NewWriter

func (p *BinaryProtocol) NewWriter(w io.Writer) Writer

type CompactProtocol

type CompactProtocol struct{}

CompactProtocol is a Protocol implementation for the compact thrift protocol.

https://github.com/apache/thrift/blob/master/doc/specs/thrift-compact-protocol.md#integer-encoding

func (*CompactProtocol) Features

func (p *CompactProtocol) Features() Features

func (*CompactProtocol) NewReader

func (p *CompactProtocol) NewReader(r io.Reader) Reader

func (*CompactProtocol) NewWriter

func (p *CompactProtocol) NewWriter(w io.Writer) Writer

type Decoder

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

func NewDecoder

func NewDecoder(r Reader) *Decoder

func (*Decoder) Decode

func (d *Decoder) Decode(v interface{}) error

func (*Decoder) Reset

func (d *Decoder) Reset(r Reader)

func (*Decoder) SetStrict

func (d *Decoder) SetStrict(enabled bool)

type Encoder

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

func NewEncoder

func NewEncoder(w Writer) *Encoder

func (*Encoder) Encode

func (e *Encoder) Encode(v interface{}) error

func (*Encoder) Reset

func (e *Encoder) Reset(w Writer)

type Features

type Features uint

Features is a bitset describing the thrift encoding features supported by protocol implementations.

const (
	// DeltaEncoding is advertised by protocols that allow encoders to apply
	// delta encoding on struct fields.
	UseDeltaEncoding Features = 1 << iota

	// CoalesceBoolFields is advertised by protocols that allow encoders to
	// coalesce boolean values into field types.
	CoalesceBoolFields
)

type Field

type Field struct {
	ID    int16
	Type  Type
	Delta bool // whether the field id is a delta
}

func (Field) String

func (f Field) String() string

type List

type List struct {
	Size int32
	Type Type
}

func (List) String

func (l List) String() string

type Map

type Map struct {
	Size  int32
	Key   Type
	Value Type
}

func (Map) String

func (m Map) String() string

type Message

type Message struct {
	Type  MessageType
	Name  string
	SeqID int32
}

type MessageType

type MessageType int8
const (
	Call MessageType = iota
	Reply
	Exception
	Oneway
)

func (MessageType) String

func (m MessageType) String() string

type MissingField

type MissingField struct {
	Field Field
}

func (*MissingField) Error

func (e *MissingField) Error() string

type Protocol

type Protocol interface {
	NewReader(r io.Reader) Reader
	NewWriter(w io.Writer) Writer
	Features() Features
}

The Protocol interface abstracts the creation of low-level thrift readers and writers implementing the various protocols that the encoding supports.

Protocol instances must be safe to use concurrently from multiple gourintes. However, the readers and writer that they instantiates are intended to be used by a single goroutine.

type Reader

type Reader interface {
	Protocol() Protocol
	Reader() io.Reader
	ReadBool() (bool, error)
	ReadInt8() (int8, error)
	ReadInt16() (int16, error)
	ReadInt32() (int32, error)
	ReadInt64() (int64, error)
	ReadFloat64() (float64, error)
	ReadBytes() ([]byte, error)
	ReadString() (string, error)
	ReadLength() (int, error)
	ReadMessage() (Message, error)
	ReadField() (Field, error)
	ReadList() (List, error)
	ReadSet() (Set, error)
	ReadMap() (Map, error)
}

Reader represents a low-level reader of values encoded according to one of the thrift protocols.

func NewDebugReader

func NewDebugReader(r Reader, l *log.Logger) Reader

type Set

type Set List

func (Set) String

func (s Set) String() string

type Type

type Type int8
const (
	STOP Type = iota
	TRUE
	FALSE
	I8
	I16
	I32
	I64
	DOUBLE
	BINARY
	LIST
	SET
	MAP
	STRUCT
	BOOL = FALSE
)

func TypeOf

func TypeOf(t reflect.Type) Type

func (Type) GoString

func (t Type) GoString() string

func (Type) String

func (t Type) String() string

type TypeMismatch

type TypeMismatch struct {
	Expect Type
	Found  Type
	// contains filtered or unexported fields
}

func (*TypeMismatch) Error

func (e *TypeMismatch) Error() string

type Writer

type Writer interface {
	Protocol() Protocol
	Writer() io.Writer
	WriteBool(bool) error
	WriteInt8(int8) error
	WriteInt16(int16) error
	WriteInt32(int32) error
	WriteInt64(int64) error
	WriteFloat64(float64) error
	WriteBytes([]byte) error
	WriteString(string) error
	WriteLength(int) error
	WriteMessage(Message) error
	WriteField(Field) error
	WriteList(List) error
	WriteSet(Set) error
	WriteMap(Map) error
}

Writer represents a low-level writer of values encoded according to one of the thrift protocols.

func NewDebugWriter

func NewDebugWriter(w Writer, l *log.Logger) Writer

Jump to

Keyboard shortcuts

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