MCPcopy
hub / github.com/grpc/grpc-go / Peek

Method Peek

mem/buffer_slice.go:327–345  ·  view source on GitHub ↗

Peek returns the next n bytes without advancing the reader. Peek appends results to the provided res slice and returns the updated slice. This pattern allows re-using the storage of res if it has sufficient capacity. The returned subslices are views into the underlying buffers and are only valid u

(n int, res [][]byte)

Source from the content-addressed store, hash-verified

325//
326// If Peek returns fewer than n bytes, it also returns an error.
327func (r *Reader) Peek(n int, res [][]byte) ([][]byte, error) {
328 for i := 0; n > 0 && i < len(r.data); i++ {
329 curData := r.data[i].ReadOnlyData()
330 start := 0
331 if i == 0 {
332 start = r.bufferIdx
333 }
334 curSize := min(n, len(curData)-start)
335 if curSize == 0 {
336 continue
337 }
338 res = append(res, curData[start:start+curSize])
339 n -= curSize
340 }
341 if n > 0 {
342 return nil, fmt.Errorf("insufficient bytes in reader")
343 }
344 return res, nil
345}

Callers 2

processDataMethod · 0.80

Implementers 3

conncredentials/alts/internal/conn/record.
nonBlockingReaderinternal/transport/readyreader/ready_r
blockingReaderinternal/transport/readyreader/ready_r

Calls 2

ReadOnlyDataMethod · 0.65
ErrorfMethod · 0.65

Tested by 1