{"modulePath":"github.com/andrewbytecoder/nmq","version":"v0.0.0-20261028105650-d8b0a59c570e","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package buffer\n\n## Constants\n\n```go\nconst MinRead = 512\n```\nMinRead is the minimum slice size passed to a Read call by Buffer.ReadFrom.  As long as the Buffer has at least MinRead bytes beyond what is required to hold the contents of r, ReadFrom will not grow the underlying buffer.\n\n## Types\n\n```go\ntype Buffer struct {\n\t// contains filtered or unexported fields\n}\n```\nA Buffer is a variable-sized buffer of bytes with Read and Write methods. The zero value for Buffer is an empty buffer ready to use.\n\n```go\nfunc NewBuffer(buf []byte) *Buffer\n```\nNewBuffer creates and initializes a new Buffer using buf as its initial contents.  It is intended to prepare a Buffer to read existing data.  It can also be used to size the internal buffer for writing. To do that, buf should have the desired capacity but a length of zero.\n\nIn most cases, new(Buffer) (or just declaring a Buffer variable) is sufficient to initialize a Buffer.\n\n```go\nfunc (b *Buffer) Alloc(n int) []byte\n```\nAlloc allocs n bytes of slice from the buffer, growing the buffer as needed. If n is negative, Alloc will panic. If the buffer can't grow it will panic with bytes.ErrTooLarge.\n\n```go\nfunc (b *Buffer) Bytes() []byte\n```\nBytes returns a slice of the contents of the unread portion of the buffer; len(b.Bytes()) == b.Len().  If the caller changes the contents of the returned slice, the contents of the buffer will change provided there are no intervening method calls on the Buffer.\n\n```go\nfunc (b *Buffer) Grow(n int)\n```\nGrow grows the buffer's capacity, if necessary, to guarantee space for another n bytes. After Grow(n), at least n bytes can be written to the buffer without another allocation. If n is negative, Grow will panic. If the buffer can't grow it will panic with bytes.ErrTooLarge.\n\n```go\nfunc (b *Buffer) Len() int\n```\nLen returns the number of bytes of the unread portion of the buffer; b.Len() == len(b.Bytes()).\n\n```go\nfunc (b *Buffer) Next(n int) []byte\n```\nNext returns a slice containing the next n bytes from the buffer, advancing the buffer as if the bytes had been returned by Read. If there are fewer than n bytes in the buffer, Next returns the entire buffer. The slice is only valid until the next call to a read or write method.\n\n```go\nfunc (b *Buffer) Read(p []byte) (n int, err error)\n```\nRead reads the next len(p) bytes from the buffer or until the buffer is drained.  The return value n is the number of bytes read.  If the buffer has no data to return, err is io.EOF (unless len(p) is zero); otherwise it is nil.\n\n```go\nfunc (b *Buffer) ReadByte() (c byte, err error)\n```\nReadByte reads and returns the next byte from the buffer. If no byte is available, it returns error io.EOF.\n\n```go\nfunc (b *Buffer) ReadBytes(delim byte) (line []byte, err error)\n```\nReadBytes reads until the first occurrence of delim in the input, returning a slice containing the data up to and including the delimiter. If ReadBytes encounters an error before finding a delimiter, it returns the data read before the error and the error itself (often io.EOF). ReadBytes returns err != nil if and only if the returned data does not end in delim.\n\n```go\nfunc (b *Buffer) ReadFrom(r io.Reader) (n int64, err error)\n```\nReadFrom reads data from r until EOF and appends it to the buffer, growing the buffer as needed. The return value n is the number of bytes read. Any error except io.EOF encountered during the read is also returned. If the buffer becomes too large, ReadFrom will panic with bytes.ErrTooLarge.\n\n```go\nfunc (b *Buffer) Reset()\n```\nReset resets the buffer so it has no content. b.Reset() is the same as b.Truncate(0).\n\n```go\nfunc (b *Buffer) String() string\n```\nString returns the contents of the unread portion of the buffer as a string.  If the Buffer is a nil pointer, it returns \"\\\u003cnil\u003e\".\n\n```go\nfunc (b *Buffer) Truncate(n int)\n```\nTruncate discards all but the first n unread bytes from the buffer. It panics if n is negative or greater than the length of the buffer.\n\n```go\nfunc (b *Buffer) Write(p []byte) (n int, err error)\n```\nWrite appends the contents of p to the buffer, growing the buffer as needed. The return value n is the length of p; err is always nil. If the buffer becomes too large, Write will panic with bytes.ErrTooLarge.\n\n```go\nfunc (b *Buffer) WriteByte(c byte) error\n```\nWriteByte appends the byte c to the buffer, growing the buffer as needed. The returned error is always nil, but is included to match bufio.Writer's WriteByte. If the buffer becomes too large, WriteByte will panic with bytes.ErrTooLarge.\n\n```go\nfunc (b *Buffer) WriteTo(w io.Writer) (n int64, err error)\n```\nWriteTo writes data to w until the buffer is drained or an error occurs. The return value n is the number of bytes written; it always fits into an int, but it is int64 to match the io.WriterTo interface. Any error encountered during the write is also returned.\n\n","path":"github.com/andrewbytecoder/nmq/pkg/utils/buffer","name":"buffer","synopsis":"","isRedistributable":true}
