Documentation
¶
Overview ¶
Package transport abstracts the WebSocket layer so the dispatcher never touches a concrete websocket library.
Index ¶
- Variables
- type CompressionMode
- type FakeWS
- func (f *FakeWS) Close(StatusCode, string) error
- func (f *FakeWS) Inject(msg []byte)
- func (f *FakeWS) Ping(ctx context.Context) error
- func (f *FakeWS) PingCount() int64
- func (f *FakeWS) Read(ctx context.Context) ([]byte, error)
- func (f *FakeWS) Sent() <-chan []byte
- func (f *FakeWS) SetPingFunc(fn func(context.Context) error)
- func (f *FakeWS) Subprotocol() string
- func (f *FakeWS) Write(ctx context.Context, data []byte) error
- type StatusCode
- type WS
Constants ¶
This section is empty.
Variables ¶
var ErrFakeClosed = errors.New("transport: fake ws closed")
ErrFakeClosed is returned by a closed FakeWS.
Functions ¶
This section is empty.
Types ¶
type CompressionMode ¶ added in v0.1.7
type CompressionMode int
CompressionMode selects RFC 7692 permessage-deflate behavior for a WebSocket connection. It mirrors coder/websocket's modes so callers do not import that package directly.
const ( // CompressionDisabled turns permessage-deflate off (no negotiation). CompressionDisabled CompressionMode = iota // CompressionContextTakeover keeps the flate sliding window across messages // (best ratio, more memory per connection). CompressionContextTakeover // CompressionNoContextTakeover resets the flate window per message (less // memory, slightly worse ratio). Default for OCPP connections. CompressionNoContextTakeover )
func (CompressionMode) Coder ¶ added in v0.1.7
func (m CompressionMode) Coder() websocket.CompressionMode
Coder maps to the coder/websocket CompressionMode.
type FakeWS ¶
type FakeWS struct {
// contains filtered or unexported fields
}
FakeWS is an in-memory WS for tests. Inbound messages are injected via Inject; outbound writes are observable via Sent.
func (*FakeWS) SetPingFunc ¶ added in v0.1.2
SetPingFunc configures Ping behavior for tests. nil restores the default.
func (*FakeWS) Subprotocol ¶
type StatusCode ¶
type StatusCode int
StatusCode mirrors RFC 6455 close codes (subset used by OCPP).
const ( StatusNormalClosure StatusCode = 1000 StatusGoingAway StatusCode = 1001 StatusProtocolError StatusCode = 1002 StatusInternalError StatusCode = 1011 )
type WS ¶
type WS interface {
// Read blocks until one full text message arrives or ctx is cancelled.
Read(ctx context.Context) ([]byte, error)
// Write sends one text message, respecting ctx for cancellation.
Write(ctx context.Context, data []byte) error
// Ping sends a WebSocket ping and waits for the matching pong.
Ping(ctx context.Context) error
// Close sends a close frame with the given status code and reason.
Close(code StatusCode, reason string) error
// Subprotocol returns the negotiated subprotocol (e.g. "ocpp1.6").
Subprotocol() string
}
WS is a context-native WebSocket connection. All blocking operations accept a context so the dispatcher can cancel reads/writes during connection teardown.
func NewCoderWS ¶
NewCoderWS wraps a coder/websocket connection as a WS.