atomic_rbuf.go
func (b *AtomicFixedSizeRingBuf) Bytes(makeCopy bool) []byte {
	b.tex.Lock()
	defer b.tex.Unlock()

	extent := b.Beg + b.readable
	if extent <= b.N {
		// we fit contiguously in this buffer without wrapping to the other
		return b.A[b.Use][b.Beg:(b.Beg + b.readable)]
	}

	// wrap into the other buffer
	src := b.Use
	dest := 1 - b.Use

	n := copy(b.A[dest], b.A[src][b.Beg:])
	n += copy(b.A[dest][n:], b.A[src][0:(extent%b.N)])

	b.Use = dest
	b.Beg = 0

	if makeCopy {
		ret := make([]byte, n)
		copy(ret, b.A[b.Use][:n])
		return ret
	}
	return b.A[b.Use][:n]
}
func (b *AtomicFixedSizeRingBuf) Bytes(makeCopy bool) []byte {
	b.tex.Lock()
	defer b.tex.Unlock()

	extent := b.Beg + b.readable
	if extent <= b.N {
		// we fit contiguously in this buffer without wrapping to the other
		return b.A[b.Use][b.Beg:(b.Beg + b.readable)]
	}

	// wrap into the other buffer
	src := b.Use
	dest := 1 - b.Use

	n := copy(b.A[dest], b.A[src][b.Beg:])
	n += copy(b.A[dest][n:], b.A[src][0:(extent%b.N)])

	b.Use = dest
	b.Beg = 0

	if makeCopy {
		ret := make([]byte, n)
		copy(ret, b.A[b.Use][:n])
		return ret
	}
	return b.A[b.Use][:n]
}
// Bytes() returns a slice of the contents of the unread portion of the buffer.
//
// To avoid copying, see the companion BytesTwo() call.
//
// Unlike the standard library Bytes() method (on bytes.Buffer for example),
// the result of the AtomicFixedSizeRingBuf::Bytes(true) is a completely new
// returned slice, so modifying that slice will have no impact on the contents
// of the internal ring.
//
// Bytes(false) acts like the standard library bytes.Buffer::Bytes() call,
// in that it returns a slice which is backed by the buffer itself (so
// no copy is involved).
//
// The largest slice Bytes ever returns is bounded above by the maxViewInBytes
// value used when calling NewAtomicFixedSizeRingBuf().
//
// Possible side-effect: may modify b.Use, the buffer in use.
//