streams

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 5 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package streams splits streamed responses into the events that are inspected one by one (#323, docs/design/0006 §2): a Server-Sent Events stream into its events, a gRPC server stream into its messages. A Splitter is fed the stream as it comes, in any chunks, and says how many of the bytes written belong to an event not complete yet, which an adapter in block mode holds until it is inspected. Those are bounded: an event longer than the limit is returned cut once the limit is reached, and the rest of it isn't held.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	// Data is the event's text: an SSE event's data lines, joined by
	// newlines; a gRPC message's text fields, joined by newlines.
	Data []byte
	// Truncated: the event was longer than the limit, or couldn't be read
	// whole (a message compressed in an encoding the engine can't read, a
	// stream that isn't framed as gRPC): Data is what was read, and the
	// rest went uninspected.
	Truncated bool
	// End is the offset in the stream (the bytes written to the Splitter)
	// where the event ends: the bytes before it can go out once the event
	// and those before it are allowed.
	End int64
	// Fields are a gRPC message's text fields, named by their field
	// numbers as grpcMessages names a request's ("2.1": field 1 of the
	// message in field 2): what a request message's rules see (#315).
	// Nil for SSE.
	Fields []grpcwire.Field
	// Unframed: the stream isn't gRPC framing (a flag other than 0 or 1),
	// with Truncated; nothing more of it is inspected. Unlike a message
	// cut at the limit, it says the body isn't gRPC at all.
	Unframed bool
}

Event is one event of a stream, as it is inspected.

type Kind

type Kind int

Kind is a kind of streamed response.

const (
	// None is a response that isn't a stream this package splits.
	None Kind = iota
	// SSE is Server-Sent Events (text/event-stream).
	SSE
	// GRPC is a gRPC response (application/grpc, application/grpc+proto):
	// length-prefixed messages.
	GRPC
)

func KindOf

func KindOf(contentType string) Kind

KindOf returns the kind of a response with this Content-Type. gRPC-Web isn't split: its text form is base64, and its trailers are framed in the body.

func (Kind) String

func (k Kind) String() string

type Splitter

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

Splitter splits one stream into events.

func New

func New(kind Kind, max int64, encoding string) *Splitter

New returns a Splitter for a stream of kind, whose events are inspected up to max bytes each; encoding is a gRPC stream's grpc-encoding.

func (*Splitter) Close

func (s *Splitter) Close() []Event

Close ends the stream, and returns the event it ended inside, if any: inspected as it is (an SSE client drops it; it still went out).

func (*Splitter) Pending

func (s *Splitter) Pending() int64

Pending returns how many bytes at the end of what was written belong to an event not returned yet.

func (*Splitter) Write

func (s *Splitter) Write(p []byte) []Event

Write adds the next part of the stream and returns the events it completes.

Jump to

Keyboard shortcuts

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