Documentation ¶
Overview ¶
Package buffer implement methods for efficiently writing and reading values to and from io.Writer and io.Reader that also expose their internal buffers.
Index ¶
- func EqualAsUint16Slice[T any](a, b []T) bool
- func EqualAsUint32Slice[T any](a, b []T) bool
- func EqualAsUint64[T any](a, b T) bool
- func EqualAsUint64Slice[T any](a, b []T) bool
- func EqualAsUint8Slice[T any](a, b []T) bool
- func Read(r Reader, c []byte) (n int64, err error)
- func ReadAsUint16[T any](r Reader, c *T) (n int64, err error)
- func ReadAsUint16Slice[T any](r Reader, c []T) (n int64, err error)
- func ReadAsUint32[T any](r Reader, c *T) (n int64, err error)
- func ReadAsUint32Slice[T any](r Reader, c []T) (n int64, err error)
- func ReadAsUint64[T any](r Reader, c *T) (n int64, err error)
- func ReadAsUint64Slice[T any](r Reader, c []T) (n int64, err error)
- func ReadAsUint8[T any](r Reader, c *T) (n int64, err error)
- func ReadAsUint8Slice[T any](r Reader, c []T) (n int64, err error)
- func ReadUint16(r Reader, c *uint16) (n int64, err error)
- func ReadUint16Slice(r Reader, c []uint16) (n int64, err error)
- func ReadUint32(r Reader, c *uint32) (n int64, err error)
- func ReadUint32Slice(r Reader, c []uint32) (n int64, err error)
- func ReadUint64(r Reader, c *uint64) (n int64, err error)
- func ReadUint64Slice(r Reader, c []uint64) (n int64, err error)
- func ReadUint8(r Reader, c *uint8) (n int64, err error)
- func ReadUint8Slice(r Reader, c []uint8) (n int64, err error)
- func RequireSerializerCorrect(t *testing.T, input binarySerializer)
- func Write(w Writer, c []byte) (n int64, err error)
- func WriteAsUint16[T any](w Writer, c T) (n int64, err error)
- func WriteAsUint16Slice[T any](w Writer, c []T) (n int64, err error)
- func WriteAsUint32[T any](w Writer, c T) (n int64, err error)
- func WriteAsUint32Slice[T any](w Writer, c []T) (n int64, err error)
- func WriteAsUint64[T any](w Writer, c T) (n int64, err error)
- func WriteAsUint64Slice[T any](w Writer, c []T) (n int64, err error)
- func WriteAsUint8[T any](w Writer, c T) (n int64, err error)
- func WriteAsUint8Slice[T any](w Writer, c []T) (n int64, err error)
- func WriteUint16(w Writer, c uint16) (n int64, err error)
- func WriteUint16Slice(w Writer, c []uint16) (n int64, err error)
- func WriteUint32(w Writer, c uint32) (n int64, err error)
- func WriteUint32Slice(w Writer, c []uint32) (n int64, err error)
- func WriteUint64(w Writer, c uint64) (n int64, err error)
- func WriteUint64Slice(w Writer, c []uint64) (n int64, err error)
- func WriteUint8(w Writer, c uint8) (n int64, err error)
- func WriteUint8Slice(w Writer, c []uint8) (n int64, err error)
- type Buffer
- func (b *Buffer) Available() int
- func (b *Buffer) AvailableBuffer() []byte
- func (b *Buffer) Bytes() []byte
- func (b *Buffer) Discard(n int) (discarded int, err error)
- func (b *Buffer) Flush() (err error)
- func (b *Buffer) Peek(n int) ([]byte, error)
- func (b *Buffer) Read(p []byte) (n int, err error)
- func (b *Buffer) Reset()
- func (b *Buffer) Size() int
- func (b *Buffer) Write(p []byte) (n int, err error)
- type Reader
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EqualAsUint16Slice ¶
EqualAsUint16Slice casts &[]T into *[]uint16 and performs a comparison. User must ensure that T can be stored in an uint16.
func EqualAsUint32Slice ¶
EqualAsUint32Slice casts &[]T into *[]uint32 and performs a comparison. User must ensure that T can be stored in an uint32.
func EqualAsUint64 ¶
EqualAsUint64 casts &T to an *uint64 and performs a comparison. User must ensure that T can be stored in an uint64.
func EqualAsUint64Slice ¶
EqualAsUint64Slice casts &[]T into *[]uint64 and performs a comparison. User must ensure that T can be stored in an uint64.
func EqualAsUint8Slice ¶
EqualAsUint8Slice casts &[]T into *[]uint8 and performs a comparison. User must ensure that T can be stored in an uint8.
func ReadAsUint16 ¶
ReadAsUint16 reads an uint16 from r and stores the result into c with pointer type casting into type T.
func ReadAsUint16Slice ¶
ReadAsUint16Slice reads a slice of uint16 from r and stores the result into c with pointer type casting into type T.
func ReadAsUint32 ¶
ReadAsUint32 reads an uint32 from r and stores the result into c with pointer type casting into type T.
func ReadAsUint32Slice ¶
ReadAsUint32Slice reads a slice of uint32 from r and stores the result into c with pointer type casting into type T.
func ReadAsUint64 ¶
ReadAsUint64 reads an uint64 from r and stores the result into c with pointer type casting into type T.
func ReadAsUint64Slice ¶
ReadAsUint64Slice reads a slice of uint64 from r and stores the result into c with pointer type casting into type T.
func ReadAsUint8 ¶
ReadAsUint8 reads an uint8 from r and stores the result into c with pointer type casting into type T.
func ReadAsUint8Slice ¶
ReadAsUint8Slice reads a slice of uint8 from r and stores the result into c with pointer type casting into type T.
func ReadUint16 ¶
ReadUint16 reads a uint16 from r and stores the result into *c.
func ReadUint16Slice ¶
ReadUint16Slice reads a slice of uint16 from r and stores the result into c.
func ReadUint32 ¶
ReadUint32 reads a uint32 from r and stores the result into *c.
func ReadUint32Slice ¶
ReadUint32Slice reads a slice of uint32 from r and stores the result into c.
func ReadUint64 ¶
ReadUint64 reads a uint64 from r and stores the result into c.
func ReadUint64Slice ¶
ReadUint64Slice reads a slice of uint64 from r and stores the result into c.
func ReadUint8Slice ¶
ReadUint8Slice reads a slice of byte from r and stores the result into c.
func RequireSerializerCorrect ¶
RequireSerializerCorrect tests that:
- input and output implement TestInterface
- input.WriteTo(io.Writer) writes a number of bytes on the writer equal to the number of bytes generated by input.MarshalBinary()
- input.WriteTo buffered bytes are equal to the bytes generated by input.MarshalBinary()
- output.ReadFrom(io.Reader) reads a number of bytes on the reader equal to the number of bytes written using input.WriteTo(io.Writer)
- applies require.Equalf between the original and reconstructed object for
- all the above WriteTo, ReadFrom, MarhsalBinary and UnmarshalBinary do not return an error
func WriteAsUint16 ¶
WriteAsUint16 casts &T to an *uint16 and writes it to w. User must ensure that T can be stored in an uint16.
func WriteAsUint16Slice ¶
WriteAsUint16Slice casts &[]T into *[]uint16 and writes it to w. User must ensure that T can be stored in an uint16.
func WriteAsUint32 ¶
WriteAsUint32 casts &T to an *uint32 and writes it to w. User must ensure that T can be stored in an uint32.
func WriteAsUint32Slice ¶
WriteAsUint32Slice casts &[]T into *[]uint32 and writes it to w. User must ensure that T can be stored in an uint32.
func WriteAsUint64 ¶
WriteAsUint64 casts &T to an *uint64 and writes it to w. User must ensure that T can be stored in an uint64.
func WriteAsUint64Slice ¶
WriteAsUint64Slice casts &[]T into *[]uint64 and writes it to w. User must ensure that T can be stored in an uint64.
func WriteAsUint8 ¶
WriteAsUint8 casts &T to an *uint8 and writes it to w. User must ensure that T can be stored in an uint8.
func WriteAsUint8Slice ¶
WriteAsUint8Slice casts &[]T into *[]uint8 and writes it to w. User must ensure that T can be stored in an uint8.
func WriteUint16 ¶
WriteUint16 writes a uint16 c to w.
func WriteUint16Slice ¶
WriteUint16Slice writes a slice of uint16 c to w.
func WriteUint32 ¶
WriteUint32 writes a uint32 c into w.
func WriteUint32Slice ¶
WriteUint32Slice writes a slice of uint32 c into w.
func WriteUint64 ¶
WriteUint64 writes a uint64 c into w.
func WriteUint64Slice ¶
WriteUint64Slice writes a slice of uint64 into w.
func WriteUint8 ¶
WriteUint8 writes a byte c to w.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is a simple []byte-based buffer that complies to the Writer and Reader interfaces. This type assumes that its backing slice has a fixed size and won't attempt to extend it. Instead, writes beyond capacity will result in an error.
func NewBuffer ¶
NewBuffer creates a new Buffer struct with buff as a backing []byte. The read and write offset are initialized at buff[0]. Hence, writing new data will overwrite the content of buff.
func NewBufferSize ¶
NewBufferSize creates a new Buffer with size capacity.
func (*Buffer) Available ¶
Available returns the number of bytes available for writes on the buffer.
func (*Buffer) AvailableBuffer ¶
AvailableBuffer returns an empty buffer with b.Available() capacity, to be directly appended to and passed to a Write call. The buffer is only valid until the next write operation on b.
func (*Buffer) Discard ¶
Discard skips the next n bytes, returning the number of bytes discarded. If Discard skips fewer than n bytes, it also returns an error.
func (*Buffer) Peek ¶
Peek returns the next n bytes without advancing the read offset, directly as a reslice of the internal buffer. It returns an error if the number of returned bytes is smaller than n.
func (*Buffer) Read ¶
Read reads len(p) bytes from the read offset of b into p. It returns the number n of bytes read and an error if n < len(p).
func (*Buffer) Reset ¶
func (b *Buffer) Reset()
Reset re-initializes the read and write offsets of b.
type Reader ¶
type Reader interface { io.Reader Size() int Peek(n int) ([]byte, error) Discard(n int) (discarded int, err error) }
Reader is an interface for readers that expose their internal buffers. This interface is notably implemented by the bufio.Reader type (see https://pkg.go.dev/bufio#Reader) and by the Buffer type.
type Writer ¶
Writer is an interface for writers that expose their internal buffers. This interface is notably implemented by the bufio.Writer type (see https://pkg.go.dev/bufio#Writer) and by the Buffer type.