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.
type Splitter ¶
type Splitter struct {
// contains filtered or unexported fields
}
Splitter splits one stream into events.
func New ¶
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 ¶
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).