MCPcopy
hub / github.com/nats-io/nats.go / drainPending

Method drainPending

ws.go:379–404  ·  view source on GitHub ↗
(p []byte)

Source from the content-addressed store, hash-verified

377}
378
379func (r *websocketReader) drainPending(p []byte) int {
380 var n int
381 var max = len(p)
382
383 for i, buf := range r.pending {
384 if n+len(buf) <= max {
385 copy(p[n:], buf)
386 n += len(buf)
387 } else {
388 // Is there room left?
389 if n < max {
390 // Write the partial and update this slice.
391 rem := max - n
392 copy(p[n:], buf[:rem])
393 n += rem
394 r.pending[i] = buf[rem:]
395 }
396 // These are the remaining slices that will need to be used at
397 // the next Read() call.
398 r.pending = r.pending[i:]
399 return n
400 }
401 }
402 r.pending = r.pending[:0]
403 return n
404}
405
406func wsGet(r io.Reader, buf []byte, pos, needed int) ([]byte, int, error) {
407 avail := len(buf) - pos

Callers 1

ReadMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected