thrift

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package thrift contains an implementation of Apache Thrift.

Index

Constants

View Source
const (
	DefaultMaxBufferSize  = 1024
	DefaultMaxMessageSize = 8192
)

Variables

View Source
var DefaultTConfiguration = &TConfiguration{
	StrictWrite:    true,
	MaxBufferSize:  DefaultMaxBufferSize,
	MaxMessageSize: DefaultMaxMessageSize,
}

DefaultTConfiguration default TConfiguration.

Functions

func NewTProtocolExceptionFromError

func NewTProtocolExceptionFromError(err error) error

NewTProtocolExceptionFromError returns new TProtocolException. it will returns nil if given err is nil.

func NewTTransportExceptionFromError

func NewTTransportExceptionFromError(err error) error

NewTTransportExceptionFromError returns new TTransportException. it will returns nil if given err is nil.

func Skip

func Skip(v TType, p TProtocol) (err error)

Skip skips over next v from p.

Types

type TApplicationError

type TApplicationError = int32

TApplicationError kind of TApplicationException.

const (
	TApplicationErrorUnknown TApplicationError = iota
	TApplicationErrorUnknownMethod
	TApplicationErrorInvalidMessageType
	TApplicationErrorWrongMethodName
	TApplicationErrorBadSequenceID
	TApplicationErrorMissingResult
	TApplicationErrorInternalError
	TApplicationErrorProtocolError
	TApplicationErrorInvalidTransform
	TApplicationErrorInvalidProtocol
	TApplicationErrorUnsupportedClientType
)

type TApplicationException

type TApplicationException struct {
	Message string            `thrift:"1"`
	Type    TApplicationError `thrift:"2"`
}

TApplicationException an application-level exception.

func (*TApplicationException) Error

func (e *TApplicationException) Error() string

Error returns a error message.

func (*TApplicationException) Read

func (e *TApplicationException) Read(p TProtocol) (err error)

Read reads values from p.

func (*TApplicationException) Write

func (e *TApplicationException) Write(p TProtocol) (err error)

Write writes values to p.

type TClient

type TClient interface {
	// Call writes a message.
	Call(ctx context.Context, method string, args, result TStruct) (err error)
}

TClient is interface that wraps Call method.

type TConfiguration

type TConfiguration struct {
	StrictRead, StrictWrite bool
	MaxMessageSize          int
	MaxBufferSize           int
}

TConfiguration a shared configuration between an implementations.

func (*TConfiguration) CheckSizeForProtocol

func (cfg *TConfiguration) CheckSizeForProtocol(size int) error

CheckSizeForProtocol returns TProtocolException if size is not valid.

func (*TConfiguration) GetMaxBufferSize

func (cfg *TConfiguration) GetMaxBufferSize() int

GetMaxBufferSize returns max buffer size. will returns DefaultMaxBufferSize if cfg.MaxBufferSize < 1.

func (*TConfiguration) GetMaxMessageSize

func (cfg *TConfiguration) GetMaxMessageSize() int

GetMaxMessageSize returns max message size. will returns DefaultMaxMessageSize if cfg.MaxMessageSize < 1.

func (*TConfiguration) IsStrictRead

func (cfg *TConfiguration) IsStrictRead() bool

IsStrictRead returns protocol strict read configuration.

func (*TConfiguration) IsStrictWrite

func (cfg *TConfiguration) IsStrictWrite() bool

IsStrictWrite returns protocol strict write configuration.

func (*TConfiguration) NonNil

func (cfg *TConfiguration) NonNil() *TConfiguration

NonNil returns DefaultTConfiguration if cfg is nil.

func (*TConfiguration) Propagate

func (cfg *TConfiguration) Propagate(impls ...interface{})

Propagate propagates cfg to impls. if cfg is nil. DefaultTConfiguration will used instead.

type TConfigurationSetter

type TConfigurationSetter interface {
	SetTConfiguration(cfg *TConfiguration)
}

TConfigurationSetter is interface that wraps SetTConfiguration method.

type TExtraTransport

type TExtraTransport interface {
	TTransport
	io.ByteReader
	io.ByteWriter
}

TExtraTransport enhanced version of TTransport

func NewTExtraTransport

func NewTExtraTransport(t TTransport, cfg *TConfiguration) TExtraTransport

NewTExtraTransport wraps t to TExtraTransport.

type TFieldHeader

type TFieldHeader struct {
	Name     string
	Type     TType
	Identity int16
}

TFieldHeader field header.

type TFlusher

type TFlusher interface {
	Flush(ctx context.Context) (err error)
}

TFlusher interface that wraps Flush method which allows to flush underlying buffer. it implemented by TTransport and TProtocol.

type THttpClient

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

THttpClient a http client implementation for TTransport.

func NewTHttpClient

func NewTHttpClient(urlstr string) (*THttpClient, error)

NewTHttpClient returns new THttpClient.

func NewTHttpClientWithOptions

func NewTHttpClientWithOptions(urlstr string, options THttpClientOptions) (*THttpClient, error)

NewTHttpClientWithOptions returns new THttpClient with options.

func (*THttpClient) DelHeader

func (c *THttpClient) DelHeader(k string)

DelHeader delete a http header.

func (*THttpClient) Flush

func (c *THttpClient) Flush(ctx context.Context) (err error)

Flush sends request to server.

func (*THttpClient) Read

func (c *THttpClient) Read(v []byte) (int, error)

Read reads v from response body.

func (*THttpClient) ReadByte

func (c *THttpClient) ReadByte() (byte, error)

ReadByte reads next one byte from response body.

func (*THttpClient) SetHeader

func (c *THttpClient) SetHeader(k, v string)

SetHeader set a http header.

func (*THttpClient) Write

func (c *THttpClient) Write(v []byte) (int, error)

Write writes v to request buffer.

func (*THttpClient) WriteByte

func (c *THttpClient) WriteByte(v byte) error

WriteByte writes v to request buffer.

type THttpClientFactory

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

THttpClientFactory a factory of THttpClient.

func NewTHttpClientFactory

func NewTHttpClientFactory(urlstr string) *THttpClientFactory

NewTHttpClientFactory returns new THttpClientFactory.

func NewTHttpClientFactoryWithOptions

func NewTHttpClientFactoryWithOptions(urlstr string, options THttpClientOptions) *THttpClientFactory

NewTHttpClientFactoryWithOptions returns new THttpClientFactory with options.

func (*THttpClientFactory) GetTransport

func (f *THttpClientFactory) GetTransport(t TTransport) (TTransport, error)

GetTransport returns new THttpClient.

type THttpClientOptions

type THttpClientOptions struct {
	Client *http.Client
	Header http.Header
}

THttpClientOptions an optional configurations for THttpClient.

func NewDefaultTHttpClientOptions added in v0.0.3

func NewDefaultTHttpClientOptions() THttpClientOptions

NewDefaultTHttpClientOptions returns new default THttpClientOptions.

type TListHeader

type TListHeader struct {
	Element TType
	Size    int
}

TListHeader list header.

type TMapHeader

type TMapHeader struct {
	Key, Value TType
	Size       int
}

TMapHeader map header.

type TMemoryBuffer

type TMemoryBuffer struct {
	*bytes.Buffer
}

TMemoryBuffer memory buffer-based implementation for TTransport.

func NewTMemoryBuffer

func NewTMemoryBuffer() *TMemoryBuffer

NewTMemoryBuffer returns new empty TMemoryBuffer.

func (*TMemoryBuffer) Flush

func (*TMemoryBuffer) Flush(ctx context.Context) error

Flush flushing is no-op; always returns nil.

type TMessageHeader

type TMessageHeader struct {
	Name     string
	Type     TMessageType
	Identity int32
}

TMessageHeader message header.

type TMessageType

type TMessageType = byte

TMessageType type of message used in TMessageHeader.

const (
	CALL TMessageType = iota + 1
	REPLY
	EXCEPTION
	ONEWAY
)

type TPoolClient

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

TPoolClient concurrency implementation of TStandardClient.

func NewTPoolClient

func NewTPoolClient(itrans, otrans TTransportFactory, iprot, oprot TProtocolFactory) *TPoolClient

NewTPoolClient returns new TPoolClient.

func (*TPoolClient) Call

func (cp *TPoolClient) Call(ctx context.Context, method string, args, result TStruct) error

Call calls the acquired TStandardClient.

type TProtocol

type TProtocol interface {
	TFlusher

	WriteMessageBegin(h TMessageHeader) (err error)

	WriteMessageEnd() (err error)

	WriteStructBegin(h TStructHeader) (err error)

	WriteStructEnd() (err error)

	WriteFieldBegin(h TFieldHeader) (err error)

	WriteFieldEnd() (err error)

	WriteFieldStop() (err error)

	WriteMapBegin(h TMapHeader) (err error)

	WriteMapEnd() (err error)

	WriteSetBegin(h TSetHeader) (err error)

	WriteSetEnd() (err error)

	WriteListBegin(h TListHeader) (err error)

	WriteListEnd() (err error)

	WriteBool(v bool) (err error)

	WriteByte(v byte) (err error)

	WriteDouble(v float64) (err error)

	WriteU16(v uint16) (err error)

	WriteI16(v int16) (err error)

	WriteU32(v uint32) (err error)

	WriteI32(v int32) (err error)

	WriteU64(v uint64) (err error)

	WriteI64(v int64) (err error)

	WriteString(v string) (err error)

	WriteBinary(v []byte) (err error)

	ReadMessageBegin() (h TMessageHeader, err error)

	ReadMessageEnd() (err error)

	ReadStructBegin() (h TStructHeader, err error)

	ReadStructEnd() (err error)

	ReadFieldBegin() (h TFieldHeader, err error)

	ReadFieldEnd() (err error)

	ReadMapBegin() (h TMapHeader, err error)

	ReadMapEnd() (err error)

	ReadSetBegin() (h TSetHeader, err error)

	ReadSetEnd() (err error)

	ReadListBegin() (h TListHeader, err error)

	ReadListEnd() (err error)

	ReadBool() (v bool, err error)

	ReadByte() (v byte, err error)

	ReadDouble() (v float64, err error)

	ReadU16() (v uint16, err error)

	ReadI16() (v int16, err error)

	ReadU32() (v uint32, err error)

	ReadI32() (v int32, err error)

	ReadU64() (v uint64, err error)

	ReadI64() (v int64, err error)

	ReadString() (v string, err error)

	ReadBinary() (v []byte, err error)

	Skip(v TType) (err error)
}

TProtocol an interface that contains read/write value methods. it also implement TFlusher which allow to flush buffered buffer.

func NewTBinaryProtocol

func NewTBinaryProtocol(t TTransport, cfg *TConfiguration) TProtocol

NewTBinaryProtocol returns new binary protocol.

func NewTCompactProtocol added in v0.0.2

func NewTCompactProtocol(t TTransport, cfg *TConfiguration) TProtocol

NewTCompactProtocol returns new compact protocol.

type TProtocolError

type TProtocolError byte

TProtocolError kind of TProtocolException.

const (
	TProtocolErrorUnknown TProtocolError = iota
	TProtocolErrorInvalidData
	TProtocolErrorNegativeSize
	TProtocolErrorSizeLimit
	TProtocolErrorBadVersion
)

type TProtocolException

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

TProtocolException a protocol-level exception.

func NewTProtocolException

func NewTProtocolException(k TProtocolError, text string) *TProtocolException

NewTProtocolException returns new TProtocolException.

func (*TProtocolException) Error

func (e *TProtocolException) Error() string

Error returns error message.

func (*TProtocolException) Kind

Kind returns kind of TProtocolException.

func (*TProtocolException) Unwrap

func (e *TProtocolException) Unwrap() error

Unwrap returns holding error.

type TProtocolFactory

type TProtocolFactory interface {
	// GetProtocol retursn new TTransport.
	GetProtocol(t TTransport) (p TProtocol)
}

TProtocolFactory a factory of TProtocol.

func NewTBinaryProtocolFactory

func NewTBinaryProtocolFactory(cfg *TConfiguration) TProtocolFactory

NewTBinaryProtocolFactory returns new TProtocolFactory of NewTBinaryProtocol.

func NewTCompactProtocolFactory added in v0.0.2

func NewTCompactProtocolFactory(cfg *TConfiguration) TProtocolFactory

NewTCompactProtocolFactory returns new TProtocolFactory of NewtCompactProtocol.

type TSetHeader

type TSetHeader struct {
	Element TType
	Size    int
}

TSetHeader set header.

type TStandardClient

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

TStandardClient an implementation of TClient.

func NewTStandardClient

func NewTStandardClient(iprot, oprot TProtocol) *TStandardClient

NewTStandardClient returns new TStandardClient.

func (*TStandardClient) Call

func (p *TStandardClient) Call(ctx context.Context, method string, args, result TStruct) (err error)

Call writes message to oprot and reads from iprot.

type TStruct

type TStruct interface {
	// Read reads value from p.
	Read(p TProtocol) (err error)

	// Write writes value to p.
	Write(p TProtocol) (err error)
}

TStruct is interface that wraps Read and Write methods.

type TStructHeader

type TStructHeader struct {
	Name string
}

TStructHeader struct header.

type TTransport

type TTransport interface {
	io.ReadWriter
	TFlusher
}

TTransport interface that groups io.ReadWriter and Flusher. it should be used by TProtocol

type TTransportError

type TTransportError byte

TTransportError kind of TTransportException.

const (
	TTransportErrorUnknown TTransportError = iota
	TTransportErrorEOF
	TTransportErrorTimeout
)

type TTransportException

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

TTransportException a transport-level exception.

func NewTTransportException

func NewTTransportException(k TTransportError, text string) *TTransportException

NewTTransportException returns new TTransportException.

func (*TTransportException) Error

func (e *TTransportException) Error() string

Error returns error message.

func (*TTransportException) Kind

Kind returns kind of TTransportException.

func (*TTransportException) Timeout

func (e *TTransportException) Timeout() bool

Timeout returns true if is timeout error.

func (*TTransportException) Unwrap

func (e *TTransportException) Unwrap() error

Unwrap returns holding error.

type TTransportFactory

type TTransportFactory interface {
	// GetTransport returns new TTransport.
	GetTransport(t TTransport) (TTransport, error)
}

TTransportFactory a factory of TTransport.

type TType

type TType = byte

TType type of value.

const (
	STOP TType = iota
	VOID
	BOOL
	BYTE
	DOUBLE
	U16
	I16
	U32
	I32
	U64
	I64
	STRING
	STRUCT
	MAP
	SET
	LIST
)

Jump to

Keyboard shortcuts

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