ttstream

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: Apache-2.0 Imports: 29 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidStreamKind = errors.New("invalid stream kind")
	ErrClosedStream      = errors.New("stream is closed")
	ErrCanceledStream    = errors.New("stream is canceled")
)
View Source
var DefaultLongConnConfig = LongConnConfig{
	MaxIdleTimeout: time.Minute,
}
View Source
var DefaultMuxConnConfig = MuxConnConfig{
	PoolSize:       runtime.GOMAXPROCS(0),
	MaxIdleTimeout: time.Minute,
}

Functions

func DecodePayload

func DecodePayload(ctx context.Context, payload []byte, msg any) error

func EncodeException

func EncodeException(ctx context.Context, method string, seq int32, ex error) ([]byte, error)

func EncodeFrame

func EncodeFrame(ctx context.Context, writer bufiox.Writer, fr *Frame) (err error)

EncodeFrame will not call Flush!

func EncodeGenericPayload

func EncodeGenericPayload(ctx context.Context, msg any) ([]byte, error)

func EncodePayload

func EncodePayload(ctx context.Context, msg any) ([]byte, error)

func NewClientProvider

func NewClientProvider(opts ...ClientProviderOption) streamx.ClientProvider

NewClientProvider return a client provider

func NewServerProvider

func NewServerProvider(opts ...ServerProviderOption) streamx.ServerProvider

NewServerProvider return a server provider

Types

type ClientProviderOption

type ClientProviderOption func(cp *clientProvider)

ClientProviderOption define client provider options

func WithClientDisableCancelingTransmit

func WithClientDisableCancelingTransmit() ClientProviderOption

WithClientDisableCancelingTransmit disable canceling transmit from upstream

func WithClientHeaderFrameHandler

func WithClientHeaderFrameHandler(handler HeaderFrameWriteHandler) ClientProviderOption

WithClientHeaderFrameHandler register TTHeader Streaming header frame handler

func WithClientLongConnPool

func WithClientLongConnPool(config LongConnConfig) ClientProviderOption

WithClientLongConnPool using long connection pool for client

func WithClientMetaFrameHandler

func WithClientMetaFrameHandler(handler MetaFrameHandler) ClientProviderOption

WithClientMetaFrameHandler register TTHeader Streaming meta frame handler

func WithClientMuxConnPool

func WithClientMuxConnPool(config MuxConnConfig) ClientProviderOption

WithClientMuxConnPool using mux connection pool for client

func WithClientShortConnPool

func WithClientShortConnPool() ClientProviderOption

WithClientShortConnPool using short connection pool for client

type ClientStreamMeta

type ClientStreamMeta interface {
	streamx.ClientStream
	Header() (streamx.Header, error)
	Trailer() (streamx.Trailer, error)
}

ClientStreamMeta cannot send header directly, should send from ctx

type Frame

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

Frame define a TTHeader Streaming Frame

func DecodeFrame

func DecodeFrame(ctx context.Context, reader bufiox.Reader) (fr *Frame, err error)

func (*Frame) String

func (f *Frame) String() string

type HeaderFrameHandler

type HeaderFrameHandler interface {
	HeaderFrameReadHandler
	HeaderFrameWriteHandler
}

type HeaderFrameReadHandler

type HeaderFrameReadHandler interface {
	OnReadStream(ctx context.Context, ihd IntHeader, shd StrHeader) (context.Context, error)
}

type HeaderFrameWriteHandler

type HeaderFrameWriteHandler interface {
	OnWriteStream(ctx context.Context) (ihd IntHeader, shd StrHeader, err error)
}

type IntHeader

type IntHeader map[uint16]string

only for meta frame handler

type LongConnConfig

type LongConnConfig struct {
	MaxIdleTimeout time.Duration
}

type MetaFrameHandler

type MetaFrameHandler interface {
	OnMetaFrame(smeta StreamMeta, intHeader IntHeader, header streamx.Header, payload []byte) error
}

type MuxConnConfig

type MuxConnConfig struct {
	PoolSize       int
	MaxIdleTimeout time.Duration
}

type ServerProviderOption

type ServerProviderOption func(pc *serverProvider)

ServerProviderOption define server provider options

func WithServerHeaderFrameHandler

func WithServerHeaderFrameHandler(handler HeaderFrameReadHandler) ServerProviderOption

WithServerHeaderFrameHandler register TTHeader Streaming header frame handler

func WithServerMetaFrameHandler

func WithServerMetaFrameHandler(handler MetaFrameHandler) ServerProviderOption

WithServerMetaFrameHandler register TTHeader Streaming meta frame handler

type ServerStreamMeta

type ServerStreamMeta interface {
	streamx.ServerStream
	SetHeader(hd streamx.Header) error
	SendHeader(hd streamx.Header) error
	SetTrailer(hd streamx.Trailer) error
}

ServerStreamMeta cannot read header directly, should read from ctx

type StrHeader

type StrHeader = streamx.Header

only for meta frame handler

type StreamMeta

type StreamMeta interface {
	Meta() map[string]string
	GetMeta(k string) (string, bool)
	SetMeta(k, v string, kvs ...string)
}

StreamMeta is a kv storage for meta frame handler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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