Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Decoder ¶
type Decoder[T any] struct { // contains filtered or unexported fields }
func NewDecoder ¶
func NewDecoder[T any](conn *websocket.Conn, typ websocket.MessageType, logger slog.Logger) *Decoder[T]
NewDecoder creates a JSON-over-websocket decoder for type T, which must be deserializable from JSON.
func (*Decoder[T]) Chan ¶
func (d *Decoder[T]) Chan() <-chan T
Chan starts the decoder reading from the websocket and returns a channel for reading the resulting values. The chan T is closed if the underlying websocket is closed, or we encounter an error. We also close the underlying websocket if we encounter an error reading or decoding.
type Encoder ¶
type Encoder[T any] struct { // contains filtered or unexported fields }
func NewEncoder ¶
NewEncoder creates a JSON-over websocket encoder for the type T, which must be JSON-serializable. You may then call Encode() to send objects over the websocket. Creating an Encoder closes the websocket for reading, turning it into a unidirectional write stream of JSON-encoded objects.