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

Method write

compress.go:217–234  ·  view source on GitHub ↗
(p []byte)

Source from the content-addressed store, hash-verified

215}
216
217func (sw *slidingWindow) write(p []byte) {
218 if len(p) >= cap(sw.buf) {
219 sw.buf = sw.buf[:cap(sw.buf)]
220 p = p[len(p)-cap(sw.buf):]
221 copy(sw.buf, p)
222 return
223 }
224
225 left := cap(sw.buf) - len(sw.buf)
226 if left < len(p) {
227 // We need to shift spaceNeeded bytes from the end to make room for p at the end.
228 spaceNeeded := len(p) - left
229 copy(sw.buf, sw.buf[spaceNeeded:])
230 sw.buf = sw.buf[:len(sw.buf)-spaceNeeded]
231 }
232
233 sw.buf = append(sw.buf, p...)
234}

Callers 1

Test_slidingWindowFunction · 0.95

Calls

no outgoing calls

Tested by 1

Test_slidingWindowFunction · 0.76