MCPcopy
hub / github.com/coder/websocket / read

Function read

wsjson/wsjson.go:21–44  ·  view source on GitHub ↗
(ctx context.Context, c *websocket.Conn, v any)

Source from the content-addressed store, hash-verified

19}
20
21func read(ctx context.Context, c *websocket.Conn, v any) (err error) {
22 defer errd.Wrap(&err, "failed to read JSON message")
23
24 _, r, err := c.Reader(ctx)
25 if err != nil {
26 return err
27 }
28
29 b := bpool.Get()
30 defer bpool.Put(b)
31
32 _, err = b.ReadFrom(r)
33 if err != nil {
34 return err
35 }
36
37 err = json.Unmarshal(b.Bytes(), v)
38 if err != nil {
39 c.Close(websocket.StatusInvalidFramePayloadData, "failed to unmarshal JSON")
40 return fmt.Errorf("failed to unmarshal JSON: %w", err)
41 }
42
43 return nil
44}
45
46// Write writes the JSON message v to c.
47// It will reuse buffers in between calls to avoid allocations.

Callers 1

ReadFunction · 0.85

Calls 5

WrapFunction · 0.92
GetFunction · 0.92
PutFunction · 0.92
ReaderMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…