MCPcopy Index your code
hub / github.com/gobwas/ws / WriteHeader

Function WriteHeader

write.go:49–87  ·  view source on GitHub ↗

WriteHeader writes header binary representation into w.

(w io.Writer, h Header)

Source from the content-addressed store, hash-verified

47
48// WriteHeader writes header binary representation into w.
49func WriteHeader(w io.Writer, h Header) error {
50 // Make slice of bytes with capacity 14 that could hold any header.
51 bts := make([]byte, MaxHeaderSize)
52
53 if h.Fin {
54 bts[0] |= bit0
55 }
56 bts[0] |= h.Rsv << 4
57 bts[0] |= byte(h.OpCode)
58
59 var n int
60 switch {
61 case h.Length <= len7:
62 bts[1] = byte(h.Length)
63 n = 2
64
65 case h.Length <= len16:
66 bts[1] = 126
67 binary.BigEndian.PutUint16(bts[2:4], uint16(h.Length))
68 n = 4
69
70 case h.Length <= len64:
71 bts[1] = 127
72 binary.BigEndian.PutUint64(bts[2:10], uint64(h.Length))
73 n = 10
74
75 default:
76 return ErrHeaderLengthUnexpected
77 }
78
79 if h.Masked {
80 bts[1] |= bit0
81 n += copy(bts[n:], h.Mask[:])
82 }
83
84 _, err := w.Write(bts[:n])
85
86 return err
87}
88
89// WriteFrame writes frame binary representation into w.
90func WriteFrame(w io.Writer, f Frame) error {

Callers 9

wsHandlerFunction · 0.92
HandlePingMethod · 0.92
HandleCloseMethod · 0.92
TestReadMessageEOFFunction · 0.92
flushFragmentMethod · 0.92
TestWriteHeaderFunction · 0.85
BenchmarkWriteHeaderFunction · 0.85
WriteFrameFunction · 0.85

Calls 1

WriteMethod · 0.45

Tested by 4

TestReadMessageEOFFunction · 0.74
TestWriteHeaderFunction · 0.68
BenchmarkWriteHeaderFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…