eventstream

package
v1.27.2 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChunkSignatureHeader = `:chunk-signature` // chunk signature for message
	DateHeader           = `:date`            // Date header for signature
	ContentTypeHeader    = ":content-type"    // message payload content-type

	// Message header and values
	MessageTypeHeader    = `:message-type` // Identifies type of message.
	EventMessageType     = `event`
	ErrorMessageType     = `error`
	ExceptionMessageType = `exception`

	// Message Events
	EventTypeHeader = `:event-type` // Identifies message event type e.g. "Stats".

	// Message Error
	ErrorCodeHeader    = `:error-code`
	ErrorMessageHeader = `:error-message`

	// Message Exception
	ExceptionTypeHeader = `:exception-type`
)

EventStream headers with specific meaning to async API functionality.

Variables

This section is empty.

Functions

func EncodeHeaders

func EncodeHeaders(w io.Writer, headers Headers) error

EncodeHeaders writes the header values to the writer encoded in the event stream format. Returns an error if a header fails to encode.

Types

type BoolValue

type BoolValue bool

An BoolValue provides eventstream encoding, and representation of a Go bool value.

func (BoolValue) Get

func (v BoolValue) Get() any

Get returns the underlying type

func (BoolValue) String

func (v BoolValue) String() string

type BytesValue

type BytesValue []byte

An BytesValue provides eventstream encoding, and representation of a Go byte slice.

func (BytesValue) Get

func (v BytesValue) Get() any

Get returns the underlying value.

func (BytesValue) String

func (v BytesValue) String() string

type ChecksumError

type ChecksumError struct{}

ChecksumError provides the error for message checksum invalidation errors.

func (ChecksumError) Error

func (e ChecksumError) Error() string

type Decoder

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

Decoder provides decoding of an Event Stream messages.

func NewDecoder

func NewDecoder(optFns ...func(*DecoderOptions)) *Decoder

NewDecoder initializes and returns a Decoder for decoding event stream messages from the reader provided.

func (*Decoder) Decode

func (d *Decoder) Decode(reader io.Reader, payloadBuf []byte) (m Message, err error)

Decode attempts to decode a single message from the event stream reader. Will return the event stream message, or error if decodeMessage fails to read the message from the stream.

payloadBuf is a byte slice that will be used in the returned Message.Payload. Callers must ensure that the Message.Payload from a previous decode has been consumed before passing in the same underlying payloadBuf byte slice.

type DecoderOptions

type DecoderOptions struct {
	Logger      logging.Logger
	LogMessages bool
}

DecoderOptions is the Decoder configuration options.

type Encoder

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

Encoder provides EventStream message encoding.

func NewEncoder

func NewEncoder(optFns ...func(*EncoderOptions)) *Encoder

NewEncoder initializes and returns an Encoder to encode Event Stream messages.

func (*Encoder) Encode

func (e *Encoder) Encode(w io.Writer, msg Message) (err error)

Encode encodes a single EventStream message to the io.Writer the Encoder was created with. An error is returned if writing the message fails.

type EncoderOptions

type EncoderOptions struct {
	Logger      logging.Logger
	LogMessages bool
}

EncoderOptions is the configuration options for Encoder.

type Header struct {
	Name  string
	Value Value
}

Header is a single EventStream Key Value header pair.

type Headers

type Headers []Header

Headers are a collection of EventStream header values.

func (Headers) Clone

func (hs Headers) Clone() Headers

Clone returns a deep copy of the headers

func (*Headers) Del

func (hs *Headers) Del(name string)

Del deletes the value in the Headers if it exists.

func (Headers) Get

func (hs Headers) Get(name string) Value

Get returns the Value associated with the header. Nil is returned if the value does not exist.

func (*Headers) Set

func (hs *Headers) Set(name string, value Value)

Set associates the name with a value. If the header name already exists in the Headers the value will be replaced with the new one.

type Int8Value

type Int8Value int8

An Int8Value provides eventstream encoding, and representation of a Go int8 value.

func (Int8Value) Get

func (v Int8Value) Get() any

Get returns the underlying value.

func (Int8Value) String

func (v Int8Value) String() string

type Int16Value

type Int16Value int16

An Int16Value provides eventstream encoding, and representation of a Go int16 value.

func (Int16Value) Get

func (v Int16Value) Get() any

Get returns the underlying value.

func (Int16Value) String

func (v Int16Value) String() string

type Int32Value

type Int32Value int32

An Int32Value provides eventstream encoding, and representation of a Go int32 value.

func (Int32Value) Get

func (v Int32Value) Get() any

Get returns the underlying value.

func (Int32Value) String

func (v Int32Value) String() string

type Int64Value

type Int64Value int64

An Int64Value provides eventstream encoding, and representation of a Go int64 value.

func (Int64Value) Get

func (v Int64Value) Get() any

Get returns the underlying value.

func (Int64Value) String

func (v Int64Value) String() string

type LengthError

type LengthError struct {
	Part  string
	Want  int
	Have  int
	Value any
}

LengthError provides the error for items being larger than a maximum length.

func (LengthError) Error

func (e LengthError) Error() string

type Message

type Message struct {
	Headers Headers
	Payload []byte
}

A Message provides the eventstream message representation.

func (Message) Clone

func (m Message) Clone() Message

Clone returns a deep copy of the message.

type MessageSigner

type MessageSigner interface {
	SignMessage(headers, payload []byte, signingTime time.Time) ([]byte, error)
}

MessageSigner signs event stream message header and payload byte pairs. Each invocation chains off the previous signature.

type ShapeDeserializer

type ShapeDeserializer struct {
	Message *Message
	// contains filtered or unexported fields
}

ShapeDeserializer wraps a smithy.ShapeDeserializer to handle event stream message binding traits.

func NewShapeDeserializer

func NewShapeDeserializer(msg *Message, inner smithy.ShapeDeserializer) *ShapeDeserializer

NewShapeDeserializer returns a deserializer for a Message.

func (*ShapeDeserializer) ReadBigFloat

func (d *ShapeDeserializer) ReadBigFloat(_ *smithy.Schema, _ *big.Float) error

ReadBigFloat is unimplemented and will return an error.

func (*ShapeDeserializer) ReadBigInt

func (d *ShapeDeserializer) ReadBigInt(_ *smithy.Schema, _ *big.Int) error

ReadBigInt is unimplemented and will return an error.

func (*ShapeDeserializer) ReadBlob

func (d *ShapeDeserializer) ReadBlob(s *smithy.Schema, v *[]byte) error

func (*ShapeDeserializer) ReadBool

func (d *ShapeDeserializer) ReadBool(s *smithy.Schema, v *bool) error

func (*ShapeDeserializer) ReadDocument

func (d *ShapeDeserializer) ReadDocument(s *smithy.Schema, v *document.Value) error

func (*ShapeDeserializer) ReadFloat32

func (d *ShapeDeserializer) ReadFloat32(s *smithy.Schema, v *float32) error

func (*ShapeDeserializer) ReadFloat64

func (d *ShapeDeserializer) ReadFloat64(s *smithy.Schema, v *float64) error

func (*ShapeDeserializer) ReadInt8

func (d *ShapeDeserializer) ReadInt8(s *smithy.Schema, v *int8) error

func (*ShapeDeserializer) ReadInt16

func (d *ShapeDeserializer) ReadInt16(s *smithy.Schema, v *int16) error

func (*ShapeDeserializer) ReadInt32

func (d *ShapeDeserializer) ReadInt32(s *smithy.Schema, v *int32) error

func (*ShapeDeserializer) ReadInt64

func (d *ShapeDeserializer) ReadInt64(s *smithy.Schema, v *int64) error

func (*ShapeDeserializer) ReadList

func (d *ShapeDeserializer) ReadList(s *smithy.Schema) error

func (*ShapeDeserializer) ReadListItem

func (d *ShapeDeserializer) ReadListItem(s *smithy.Schema) (bool, error)

func (*ShapeDeserializer) ReadMap

func (d *ShapeDeserializer) ReadMap(s *smithy.Schema) error

func (*ShapeDeserializer) ReadMapKey

func (d *ShapeDeserializer) ReadMapKey(s *smithy.Schema) (string, bool, error)

func (*ShapeDeserializer) ReadNil

func (d *ShapeDeserializer) ReadNil(s *smithy.Schema) (bool, error)

func (*ShapeDeserializer) ReadString

func (d *ShapeDeserializer) ReadString(s *smithy.Schema, v *string) error

func (*ShapeDeserializer) ReadStruct

func (d *ShapeDeserializer) ReadStruct(s *smithy.Schema) error

func (*ShapeDeserializer) ReadStructMember

func (d *ShapeDeserializer) ReadStructMember() (*smithy.Schema, error)

func (*ShapeDeserializer) ReadTime

func (d *ShapeDeserializer) ReadTime(s *smithy.Schema, v *time.Time) error

func (*ShapeDeserializer) ReadUnion

func (d *ShapeDeserializer) ReadUnion(s *smithy.Schema) (*smithy.Schema, error)

type ShapeSerializer

type ShapeSerializer struct {
	Message *Message
	// contains filtered or unexported fields
}

ShapeSerializer wraps a smithy.ShapeSerializer, much like the internal httpbinding serializer, to handle event stream message binding traits.

func NewShapeSerializer

func NewShapeSerializer(msg *Message, inner smithy.ShapeSerializer) *ShapeSerializer

NewShapeSerializer returns a serializer for a single Message.

func (*ShapeSerializer) Bytes

func (s *ShapeSerializer) Bytes() []byte

Bytes returns the serialized body bytes.

func (*ShapeSerializer) CloseList

func (s *ShapeSerializer) CloseList()

CloseList implements smithy.ShapeSerializer.

func (*ShapeSerializer) CloseMap

func (s *ShapeSerializer) CloseMap()

CloseMap implements smithy.ShapeSerializer.

func (*ShapeSerializer) CloseStruct

func (s *ShapeSerializer) CloseStruct()

CloseStruct implements smithy.ShapeSerializer.

func (*ShapeSerializer) CloseUnion

func (s *ShapeSerializer) CloseUnion()

CloseUnion implements smithy.ShapeSerializer.

func (*ShapeSerializer) ContentType

func (s *ShapeSerializer) ContentType() string

ContentType returns the resolved content type for the event message payload after serialization, which may be affected by bindings.

func (*ShapeSerializer) WriteBigFloat

func (s *ShapeSerializer) WriteBigFloat(schema *smithy.Schema, v *big.Float)

WriteBigFloat implements smithy.ShapeSerializer.

func (*ShapeSerializer) WriteBigInt

func (s *ShapeSerializer) WriteBigInt(schema *smithy.Schema, v *big.Int)

WriteBigInt implements smithy.ShapeSerializer.

func (*ShapeSerializer) WriteBlob

func (s *ShapeSerializer) WriteBlob(schema *smithy.Schema, v []byte)

WriteBlob implements smithy.ShapeSerializer.

func (*ShapeSerializer) WriteBool

func (s *ShapeSerializer) WriteBool(schema *smithy.Schema, v bool)

WriteBool implements smithy.ShapeSerializer.

func (*ShapeSerializer) WriteDocument

func (s *ShapeSerializer) WriteDocument(schema *smithy.Schema, v document.Value)

WriteDocument implements smithy.ShapeSerializer.

func (*ShapeSerializer) WriteFloat32

func (s *ShapeSerializer) WriteFloat32(schema *smithy.Schema, v float32)

WriteFloat32 implements smithy.ShapeSerializer.

func (*ShapeSerializer) WriteFloat64

func (s *ShapeSerializer) WriteFloat64(schema *smithy.Schema, v float64)

WriteFloat64 implements smithy.ShapeSerializer.

func (*ShapeSerializer) WriteInt8

func (s *ShapeSerializer) WriteInt8(schema *smithy.Schema, v int8)

WriteInt8 implements smithy.ShapeSerializer.

func (*ShapeSerializer) WriteInt16

func (s *ShapeSerializer) WriteInt16(schema *smithy.Schema, v int16)

WriteInt16 implements smithy.ShapeSerializer.

func (*ShapeSerializer) WriteInt32

func (s *ShapeSerializer) WriteInt32(schema *smithy.Schema, v int32)

WriteInt32 implements smithy.ShapeSerializer.

func (*ShapeSerializer) WriteInt64

func (s *ShapeSerializer) WriteInt64(schema *smithy.Schema, v int64)

WriteInt64 implements smithy.ShapeSerializer.

func (*ShapeSerializer) WriteKey

func (s *ShapeSerializer) WriteKey(schema *smithy.Schema, key string)

WriteKey implements smithy.ShapeSerializer.

func (*ShapeSerializer) WriteList

func (s *ShapeSerializer) WriteList(schema *smithy.Schema)

WriteList implements smithy.ShapeSerializer.

func (*ShapeSerializer) WriteMap

func (s *ShapeSerializer) WriteMap(schema *smithy.Schema)

WriteMap implements smithy.ShapeSerializer.

func (*ShapeSerializer) WriteNil

func (s *ShapeSerializer) WriteNil(schema *smithy.Schema)

WriteNil implements smithy.ShapeSerializer.

func (*ShapeSerializer) WriteString

func (s *ShapeSerializer) WriteString(schema *smithy.Schema, v string)

WriteString implements smithy.ShapeSerializer.

func (*ShapeSerializer) WriteStruct

func (s *ShapeSerializer) WriteStruct(schema *smithy.Schema)

WriteStruct implements smithy.ShapeSerializer.

func (*ShapeSerializer) WriteTime

func (s *ShapeSerializer) WriteTime(schema *smithy.Schema, v time.Time)

WriteTime implements smithy.ShapeSerializer.

func (*ShapeSerializer) WriteUnion

func (s *ShapeSerializer) WriteUnion(schema, variant *smithy.Schema)

WriteUnion implements smithy.ShapeSerializer.

type SigningWriter

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

SigningWriter wraps an io.WriteCloser and signs each event stream message frame written to it. Each Write call MUST contain exactly one complete encoded event stream message frame.

The signing writer wraps each incoming frame in an outer event stream message with :date and :chunk-signature headers, then encodes the outer message to the underlying writer.

Close sends a signed empty message to signal end-of-stream, then closes the underlying writer.

func NewSigningWriter

func NewSigningWriter(w io.WriteCloser, signer MessageSigner) *SigningWriter

NewSigningWriter returns a SigningWriter that signs frames and writes them to w.

func (*SigningWriter) Close

func (s *SigningWriter) Close() error

Close sends a signed empty message to signal end-of-stream, then closes the underlying writer.

func (*SigningWriter) Write

func (s *SigningWriter) Write(frame []byte) (int, error)

Write signs a complete event stream message frame and writes the signed outer envelope to the underlying writer.

type StringValue

type StringValue string

An StringValue provides eventstream encoding, and representation of a Go string.

func (StringValue) Get

func (v StringValue) Get() any

Get returns the underlying value.

func (StringValue) String

func (v StringValue) String() string

type TimestampValue

type TimestampValue time.Time

An TimestampValue provides eventstream encoding, and representation of a Go timestamp.

func (TimestampValue) Get

func (v TimestampValue) Get() any

Get returns the underlying value.

func (TimestampValue) MarshalJSON

func (v TimestampValue) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface

func (TimestampValue) String

func (v TimestampValue) String() string

type UUIDValue

type UUIDValue [16]byte

An UUIDValue provides eventstream encoding, and representation of a UUID value.

func (UUIDValue) Get

func (v UUIDValue) Get() any

Get returns the underlying value.

func (UUIDValue) String

func (v UUIDValue) String() string

type UnknownMessageError

type UnknownMessageError struct {
	Type    string
	Message *Message
}

UnknownMessageError provides an error when a message is received from the stream, but the reader is unable to determine what kind of message it is.

func (*UnknownMessageError) Error

func (e *UnknownMessageError) Error() string

type UnknownUnionMember

type UnknownUnionMember struct {
	Tag   string
	Value []byte
}

UnknownUnionMember is returned when a union member is returned over the wire, but has an unknown tag.

func (*UnknownUnionMember) Deserialize

Deserialize is a no-op. The raw bytes are already captured in Value.

type Value

type Value interface {
	Get() any
	String() string
	// contains filtered or unexported methods
}

Value represents the abstract header value.

Jump to

Keyboard shortcuts

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