stream

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var WriteBufferSize = 128 * 1024

WriteBufferSize is the largest []byte that Write() will pass to its underlying send function.

Functions

func NewReader

func NewReader(receiver func() ([]byte, error)) io.Reader

NewReader turns receiver into an io.Reader. Errors from the receiver function are passed on unmodified. This means receiver should emit io.EOF when done.

func NewSyncWriter

func NewSyncWriter(m *sync.Mutex, sender func(p []byte) error) io.Writer

NewSyncWriter turns sender into an io.Writer. The sender callback will receive []byte arguments of length at most WriteBufferSize. All calls to the sender will be synchronized via the mutex.

func NewWriter

func NewWriter(sender func(p []byte) error) io.Writer

NewWriter turns sender into an io.Writer. The sender callback will receive []byte arguments of length at most WriteBufferSize.

func Proxy

func Proxy(revSend func() error) (err error)

Proxy calls recvSend until it receives an error. The error is returned to the caller unless it is io.EOF.

func ProxyFast

func ProxyFast(requestFunc func() error, requestStream CloseSender, responseFunc func() error) error

ProxyFast works like Proxy but runs multiple callbacks simultaneously. It returns immediately if proxying one of the callbacks fails. If the response stream is done, ProxyBidi returns immediately without waiting for the client stream to finish proxying.

func ProxyLoop

func ProxyLoop(requestFunc func() error, requestStream CloseSender, responseFunc func() error) error

Types

type ChunkData

type ChunkData interface {
	Size() int
}

type Chunker

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

Chunker lets you spread items you want to send over multiple chunks. This type is not thread-safe.

func NewChunker

func NewChunker(s Sender) *Chunker

New returns a new Chunker.

func (*Chunker) Flush

func (c *Chunker) Flush() error

Flush sends remaining items in the current chunk, if any.

func (*Chunker) Send

func (c *Chunker) Send(it ChunkData) error

Send will append an item to the current chunk and send the chunk if it is full.

type CloseSender

type CloseSender interface {
	CloseSend() error
}

CloseSender captures the CloseSend method from gRPC streams.

type Sender

type Sender interface {
	// Reset should create a fresh response message.
	Reset()
	// Append should append the given item to the slice in the current response message
	Append(ChunkData)
	// Send should send the current response message
	Send() error
}

Sender encapsulates a gRPC response stream and the current chunk that's being built.

Reset, Append, [Append...], Send, Reset, Append, [Append...], Send, ...

Jump to

Keyboard shortcuts

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