MCPcopy Index your code
hub / github.com/coder/coder / NewEncoder

Function NewEncoder

codersdk/wsjson/encoder.go:39–44  ·  view source on GitHub ↗

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.

(conn *websocket.Conn, typ websocket.MessageType)

Source from the content-addressed store, hash-verified

37// You may then call Encode() to send objects over the websocket. Creating an Encoder closes the
38// websocket for reading, turning it into a unidirectional write stream of JSON-encoded objects.
39func NewEncoder[T any](conn *websocket.Conn, typ websocket.MessageType) *Encoder[T] {
40 // Here we close the websocket for reading, so that the websocket library will handle pings and
41 // close frames.
42 _ = conn.CloseRead(context.Background())
43 return &Encoder[T]{conn: conn, typ: typ}
44}

Callers 5

followMethod · 0.92
workspaceAgentLogsMethod · 0.92
derpMapUpdatesMethod · 0.92
runMethod · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected