eventstream

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package eventstream decodes the AWS application/vnd.amazon.eventstream framing used by Bedrock streaming responses.

Wire format (big-endian, network order):

+--------------------+ 4 bytes total length (incl. trailer CRC)
+--------------------+ 4 bytes headers length
+--------------------+ 4 bytes prelude CRC32 over the previous 8 bytes
+--------------------+ headers (typed key/value pairs)
+--------------------+ payload (totalLen - headersLen - 16)
+--------------------+ 4 bytes message CRC32 over the entire message except the trailer

Header value types — only the ones Bedrock uses are decoded fully:

  • 7 (string)

Other types are recognised so the framer doesn't crash, but their values are returned as raw bytes.

Index

Constants

This section is empty.

Variables

View Source
var ErrTruncated = errors.New("eventstream: truncated frame")

ErrTruncated is returned when EOF arrives mid-frame.

Functions

func Encode

func Encode(headers map[string]string, payload []byte) []byte

Encode produces a single event-stream frame with the given string headers and payload. Used by tests; exported so external callers can build fixtures.

Types

type Decoder

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

Decoder reads frames sequentially from an underlying reader.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder constructs a Decoder.

func (*Decoder) Next

func (d *Decoder) Next() (Frame, error)

Next decodes the next frame. Returns io.EOF cleanly only at frame boundary.

type Frame

type Frame struct {
	Headers map[string]string
	Payload []byte
}

Frame is a decoded event-stream message.

func (Frame) Get

func (f Frame) Get(k string) string

Get returns the value of header key, or "".

Jump to

Keyboard shortcuts

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