thrift

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: Apache-2.0 Imports: 9 Imported by: 241

Documentation

Index

Constants

View Source
const (
	UNKNOWN_APPLICATION_EXCEPTION  = 0
	UNKNOWN_METHOD                 = 1
	INVALID_MESSAGE_TYPE_EXCEPTION = 2
	WRONG_METHOD_NAME              = 3
	BAD_SEQUENCE_ID                = 4
	MISSING_RESULT                 = 5
	INTERNAL_ERROR                 = 6
	PROTOCOL_ERROR                 = 7
	INVALID_TRANSFORM              = 8
	INVALID_PROTOCOL               = 9
	UNSUPPORTED_CLIENT_TYPE        = 10
)
View Source
const (
	UNKNOWN_PROTOCOL_EXCEPTION = 0
	INVALID_DATA               = 1
	NEGATIVE_SIZE              = 2
	SIZE_LIMIT                 = 3
	BAD_VERSION                = 4
	NOT_IMPLEMENTED            = 5
	DEPTH_LIMIT                = 6
)

Variables

View Source
var NocopyWriteThreshold = 4096

NocopyWriteThreshold represents the threshold of using `NocopyWriter` for binary or string

It's used by `WriteBinaryNocopy` and `WriteStringNocopy` of `BinaryProtocol` which are relied by kitex tool or thriftgo

Functions

func FastMarshal

func FastMarshal(msg FastCodec) []byte

FastMarshal marshals the msg to buf. The msg should implement FastCodec.

func FastUnmarshal

func FastUnmarshal(buf []byte, msg FastCodec) error

FastUnmarshal unmarshal the buf into msg. The msg should implement FastCodec.

func MarshalFastMsg

func MarshalFastMsg(method string, msgType TMessageType, seq int32, msg FastCodec) ([]byte, error)

MarshalFastMsg encodes the given msg to buf for generic thrift RPC.

func PrependError

func PrependError(prepend string, err error) error

Prepends additional information to an error without losing the Thrift exception interface

func UnmarshalFastMsg

func UnmarshalFastMsg(b []byte, msg FastCodec) (method string, seq int32, err error)

UnmarshalFastMsg parses the given buf and stores the result to msg for generic thrift RPC. for EXCEPTION msgType, it will returns `err` with *ApplicationException type without storing the result to msg.

Types

type ApplicationException

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

ApplicationException is for replacing apache.TApplicationException it implements ThriftFastCodec interface.

func NewApplicationException

func NewApplicationException(t int32, msg string) *ApplicationException

NewApplicationException creates an ApplicationException instance

func (*ApplicationException) BLength

func (e *ApplicationException) BLength() int

BLength returns the len of encoded buffer.

func (*ApplicationException) Error

func (e *ApplicationException) Error() string

Error ...

func (*ApplicationException) FastRead

func (e *ApplicationException) FastRead(b []byte) (off int, err error)

FastRead ...

func (*ApplicationException) FastWrite

func (e *ApplicationException) FastWrite(b []byte) (off int)

FastWrite ...

func (*ApplicationException) FastWriteNocopy

func (e *ApplicationException) FastWriteNocopy(b []byte, _ NocopyWriter) int

FastWriteNocopy ...

func (*ApplicationException) Msg

func (e *ApplicationException) Msg() string

Msg ...

func (*ApplicationException) String

func (e *ApplicationException) String() string

String ...

func (*ApplicationException) TypeID

func (e *ApplicationException) TypeID() int32

TypeID ... for kitex

func (*ApplicationException) TypeId

func (e *ApplicationException) TypeId() int32

TypeId ... for apache ApplicationException compatibility

type BinaryProtocol

type BinaryProtocol struct{}
var Binary BinaryProtocol

func (BinaryProtocol) AppendBinary

func (p BinaryProtocol) AppendBinary(buf, v []byte) []byte

func (BinaryProtocol) AppendBool

func (BinaryProtocol) AppendBool(buf []byte, v bool) []byte

func (BinaryProtocol) AppendByte

func (BinaryProtocol) AppendByte(buf []byte, v int8) []byte

func (BinaryProtocol) AppendDouble

func (BinaryProtocol) AppendDouble(buf []byte, v float64) []byte

func (BinaryProtocol) AppendFieldBegin

func (BinaryProtocol) AppendFieldBegin(buf []byte, typeID TType, id int16) []byte

func (BinaryProtocol) AppendFieldStop

func (BinaryProtocol) AppendFieldStop(buf []byte) []byte

func (BinaryProtocol) AppendI16

func (BinaryProtocol) AppendI16(buf []byte, v int16) []byte

func (BinaryProtocol) AppendI32

func (BinaryProtocol) AppendI32(buf []byte, v int32) []byte

func (BinaryProtocol) AppendI64

func (BinaryProtocol) AppendI64(buf []byte, v int64) []byte

func (BinaryProtocol) AppendListBegin

func (p BinaryProtocol) AppendListBegin(buf []byte, et TType, size int) []byte

func (BinaryProtocol) AppendMapBegin

func (p BinaryProtocol) AppendMapBegin(buf []byte, kt, vt TType, size int) []byte

func (BinaryProtocol) AppendMessageBegin

func (p BinaryProtocol) AppendMessageBegin(buf []byte, name string, typeID TMessageType, seq int32) []byte

func (BinaryProtocol) AppendSetBegin

func (p BinaryProtocol) AppendSetBegin(buf []byte, et TType, size int) []byte

func (BinaryProtocol) AppendString

func (p BinaryProtocol) AppendString(buf []byte, v string) []byte

func (BinaryProtocol) BinaryLength

func (BinaryProtocol) BinaryLength(v []byte) int

func (BinaryProtocol) BinaryLengthNocopy

func (BinaryProtocol) BinaryLengthNocopy(v []byte) int

func (BinaryProtocol) BoolLength

func (BinaryProtocol) BoolLength() int

func (BinaryProtocol) ByteLength

func (BinaryProtocol) ByteLength() int

func (BinaryProtocol) DoubleLength

func (BinaryProtocol) DoubleLength() int

func (BinaryProtocol) FieldBeginLength

func (BinaryProtocol) FieldBeginLength() int

func (BinaryProtocol) FieldStopLength

func (BinaryProtocol) FieldStopLength() int

func (BinaryProtocol) I16Length

func (BinaryProtocol) I16Length() int

func (BinaryProtocol) I32Length

func (BinaryProtocol) I32Length() int

func (BinaryProtocol) I64Length

func (BinaryProtocol) I64Length() int

func (BinaryProtocol) ListBeginLength

func (BinaryProtocol) ListBeginLength() int

func (BinaryProtocol) MapBeginLength

func (BinaryProtocol) MapBeginLength() int

func (BinaryProtocol) MessageBeginLength

func (BinaryProtocol) MessageBeginLength(method string) int

func (BinaryProtocol) ReadBinary

func (p BinaryProtocol) ReadBinary(buf []byte) (b []byte, l int, err error)

func (BinaryProtocol) ReadBool

func (BinaryProtocol) ReadBool(buf []byte) (v bool, l int, err error)

func (BinaryProtocol) ReadByte

func (BinaryProtocol) ReadByte(buf []byte) (v int8, l int, err error)

func (BinaryProtocol) ReadDouble

func (BinaryProtocol) ReadDouble(buf []byte) (v float64, l int, err error)

func (BinaryProtocol) ReadFieldBegin

func (BinaryProtocol) ReadFieldBegin(buf []byte) (typeID TType, id int16, l int, err error)

func (BinaryProtocol) ReadI16

func (BinaryProtocol) ReadI16(buf []byte) (v int16, l int, err error)

func (BinaryProtocol) ReadI32

func (BinaryProtocol) ReadI32(buf []byte) (v int32, l int, err error)

func (BinaryProtocol) ReadI64

func (BinaryProtocol) ReadI64(buf []byte) (v int64, l int, err error)

func (BinaryProtocol) ReadListBegin

func (BinaryProtocol) ReadListBegin(buf []byte) (et TType, size, l int, err error)

func (BinaryProtocol) ReadMapBegin

func (BinaryProtocol) ReadMapBegin(buf []byte) (kt, vt TType, size, l int, err error)

func (BinaryProtocol) ReadMessageBegin

func (p BinaryProtocol) ReadMessageBegin(buf []byte) (name string, typeID TMessageType, seq int32, l int, err error)

func (BinaryProtocol) ReadSetBegin

func (BinaryProtocol) ReadSetBegin(buf []byte) (et TType, size, l int, err error)

func (BinaryProtocol) ReadString

func (p BinaryProtocol) ReadString(buf []byte) (s string, l int, err error)

func (BinaryProtocol) SetBeginLength

func (BinaryProtocol) SetBeginLength() int

func (BinaryProtocol) Skip

func (BinaryProtocol) Skip(b []byte, t TType) (int, error)

Skip skips over the value for the given type using Go implementation.

func (BinaryProtocol) StringLength

func (BinaryProtocol) StringLength(v string) int

func (BinaryProtocol) StringLengthNocopy

func (BinaryProtocol) StringLengthNocopy(v string) int

func (BinaryProtocol) WriteBinary

func (BinaryProtocol) WriteBinary(buf, v []byte) int

func (BinaryProtocol) WriteBinaryNocopy

func (p BinaryProtocol) WriteBinaryNocopy(buf []byte, w NocopyWriter, v []byte) int

func (BinaryProtocol) WriteBool

func (BinaryProtocol) WriteBool(buf []byte, v bool) int

func (BinaryProtocol) WriteByte

func (BinaryProtocol) WriteByte(buf []byte, v int8) int

func (BinaryProtocol) WriteDouble

func (BinaryProtocol) WriteDouble(buf []byte, v float64) int

func (BinaryProtocol) WriteFieldBegin

func (BinaryProtocol) WriteFieldBegin(buf []byte, typeID TType, id int16) int

func (BinaryProtocol) WriteFieldStop

func (BinaryProtocol) WriteFieldStop(buf []byte) int

func (BinaryProtocol) WriteI16

func (BinaryProtocol) WriteI16(buf []byte, v int16) int

func (BinaryProtocol) WriteI32

func (BinaryProtocol) WriteI32(buf []byte, v int32) int

func (BinaryProtocol) WriteI64

func (BinaryProtocol) WriteI64(buf []byte, v int64) int

func (BinaryProtocol) WriteListBegin

func (BinaryProtocol) WriteListBegin(buf []byte, et TType, size int) int

func (BinaryProtocol) WriteMapBegin

func (BinaryProtocol) WriteMapBegin(buf []byte, kt, vt TType, size int) int

func (BinaryProtocol) WriteMessageBegin

func (BinaryProtocol) WriteMessageBegin(buf []byte, name string, typeID TMessageType, seq int32) int

func (BinaryProtocol) WriteSetBegin

func (BinaryProtocol) WriteSetBegin(buf []byte, et TType, size int) int

func (BinaryProtocol) WriteString

func (BinaryProtocol) WriteString(buf []byte, v string) int

func (BinaryProtocol) WriteStringNocopy

func (p BinaryProtocol) WriteStringNocopy(buf []byte, w NocopyWriter, v string) int

type BinaryReader

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

BinaryReader represents a reader for binary protocol

func NewBinaryReader

func NewBinaryReader(r io.Reader) *BinaryReader

NewBinaryReader ... call Release if no longer use for reusing

func (*BinaryReader) ReadBinary

func (r *BinaryReader) ReadBinary() (b []byte, err error)

ReadBinary ...

func (*BinaryReader) ReadBool

func (r *BinaryReader) ReadBool() (v bool, err error)

ReadBool ...

func (*BinaryReader) ReadByte

func (r *BinaryReader) ReadByte() (v int8, err error)

ReadByte ...

func (*BinaryReader) ReadDouble

func (r *BinaryReader) ReadDouble() (v float64, err error)

ReadDouble ...

func (*BinaryReader) ReadFieldBegin

func (r *BinaryReader) ReadFieldBegin() (typeID TType, id int16, err error)

ReadFieldBegin ...

func (*BinaryReader) ReadI16

func (r *BinaryReader) ReadI16() (v int16, err error)

ReadI16 ...

func (*BinaryReader) ReadI32

func (r *BinaryReader) ReadI32() (v int32, err error)

ReadI32 ...

func (*BinaryReader) ReadI64

func (r *BinaryReader) ReadI64() (v int64, err error)

ReadI64 ...

func (*BinaryReader) ReadListBegin

func (r *BinaryReader) ReadListBegin() (et TType, size int, err error)

ReadListBegin ...

func (*BinaryReader) ReadMapBegin

func (r *BinaryReader) ReadMapBegin() (kt, vt TType, size int, err error)

ReadMapBegin ...

func (*BinaryReader) ReadMessageBegin

func (r *BinaryReader) ReadMessageBegin() (name string, typeID TMessageType, seq int32, err error)

ReadMessageBegin ...

func (*BinaryReader) ReadSetBegin

func (r *BinaryReader) ReadSetBegin() (et TType, size int, err error)

ReadSetBegin ...

func (*BinaryReader) ReadString

func (r *BinaryReader) ReadString() (s string, err error)

ReadString ...

func (*BinaryReader) Readn

func (r *BinaryReader) Readn() int64

Readn returns total bytes read from underlying reader

func (*BinaryReader) Release

func (r *BinaryReader) Release()

Release ...

func (*BinaryReader) Skip

func (r *BinaryReader) Skip(t TType) error

Skip ...

type BinaryWriter

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

func NewBinaryWriter

func NewBinaryWriter() *BinaryWriter

func NewBinaryWriterSize

func NewBinaryWriterSize(sz int) *BinaryWriter

func (*BinaryWriter) Bytes

func (w *BinaryWriter) Bytes() []byte

func (*BinaryWriter) Release

func (w *BinaryWriter) Release()

func (*BinaryWriter) Reset

func (w *BinaryWriter) Reset()

func (*BinaryWriter) WriteBinary

func (w *BinaryWriter) WriteBinary(v []byte)

func (*BinaryWriter) WriteBool

func (w *BinaryWriter) WriteBool(v bool)

func (*BinaryWriter) WriteByte

func (w *BinaryWriter) WriteByte(v int8)

func (*BinaryWriter) WriteDouble

func (w *BinaryWriter) WriteDouble(v float64)

func (*BinaryWriter) WriteFieldBegin

func (w *BinaryWriter) WriteFieldBegin(typeID TType, id int16)

func (*BinaryWriter) WriteFieldStop

func (w *BinaryWriter) WriteFieldStop()

func (*BinaryWriter) WriteI16

func (w *BinaryWriter) WriteI16(v int16)

func (*BinaryWriter) WriteI32

func (w *BinaryWriter) WriteI32(v int32)

func (*BinaryWriter) WriteI64

func (w *BinaryWriter) WriteI64(v int64)

func (*BinaryWriter) WriteListBegin

func (w *BinaryWriter) WriteListBegin(et TType, size int)

func (*BinaryWriter) WriteMapBegin

func (w *BinaryWriter) WriteMapBegin(kt, vt TType, size int)

func (*BinaryWriter) WriteMessageBegin

func (w *BinaryWriter) WriteMessageBegin(name string, typeID TMessageType, seq int32)

func (*BinaryWriter) WriteSetBegin

func (w *BinaryWriter) WriteSetBegin(et TType, size int)

func (*BinaryWriter) WriteString

func (w *BinaryWriter) WriteString(v string)

type FastCodec

type FastCodec interface {
	BLength() int
	FastWriteNocopy(buf []byte, bw NocopyWriter) int
	FastRead(buf []byte) (int, error)
}

FastCodec represents the interface of thrift fastcodec generated structs

type NocopyWriter

type NocopyWriter interface {
	WriteDirect(b []byte, remainCap int) error
}

BinaryWriter represents the method used in thrift encoding for nocopy writes It supports netpoll nocopy feature, see: https://github.com/cloudwego/netpoll/blob/develop/nocopy.go

type ProtocolException

type ProtocolException struct {
	ApplicationException // same implementation ...
	// contains filtered or unexported fields
}

ProtocolException is for replacing apache.ProtocolException it implements ThriftFastCodec interface.

func NewProtocolException

func NewProtocolException(t int32, m string) *ProtocolException

NewTransportExceptionWithType

func NewProtocolExceptionWithErr

func NewProtocolExceptionWithErr(err error) *ProtocolException

NewProtocolException ...

func (*ProtocolException) Is

func (e *ProtocolException) Is(err error) bool

Is ... for errors pkg

func (*ProtocolException) Unwrap

func (e *ProtocolException) Unwrap() error

Unwrap ... for errors pkg

type SkipDecoder

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

SkipDecoder scans the underlying io.Reader and returns the bytes of a type

func NewSkipDecoder

func NewSkipDecoder(r io.Reader) *SkipDecoder

NewSkipDecoder ... call Release if no longer use

func (*SkipDecoder) Next

func (p *SkipDecoder) Next(t TType) (buf []byte, err error)

Next skips a specific type and returns its bytes

func (*SkipDecoder) Release

func (p *SkipDecoder) Release()

Release ...

func (*SkipDecoder) Reset

func (p *SkipDecoder) Reset(r io.Reader)

Reset ...

type TMessageType

type TMessageType = int32 // use alias for better flexibility of interfaces

TMessageType represents message type constants in the Thrift protocol. originally from github.com/apache/thrift

const (
	INVALID_TMESSAGE_TYPE TMessageType = 0
	CALL                  TMessageType = 1
	REPLY                 TMessageType = 2
	EXCEPTION             TMessageType = 3
	ONEWAY                TMessageType = 4
)

type TType

type TType = int8 // use alias for better flexibility of interfaces

TType represents field type constants in the Thrift protocol originally from github.com/apache/thrift

const (
	STOP   TType = 0
	VOID   TType = 1
	BOOL   TType = 2
	BYTE   TType = 3
	I08    TType = 3
	DOUBLE TType = 4
	I16    TType = 6
	I32    TType = 8
	I64    TType = 10
	STRING TType = 11
	UTF7   TType = 11
	STRUCT TType = 12
	MAP    TType = 13
	SET    TType = 14
	LIST   TType = 15
	UTF8   TType = 16
	UTF16  TType = 17
)

type TransportException

type TransportException struct {
	ApplicationException // same implementation ...
}

TransportException is for replacing apache.TransportException it implements ThriftFastCodec interface.

func NewTransportException

func NewTransportException(t int32, m string) *TransportException

NewTransportException ...

Directories

Path Synopsis
Package apache contains code for working with apache thrift indirectly
Package apache contains code for working with apache thrift indirectly
Code generated by thriftgo (0.3.15) (fastgo).
Code generated by thriftgo (0.3.15) (fastgo).

Jump to

Keyboard shortcuts

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