Documentation ¶
Index ¶
- Constants
- Variables
- func NewCtxReader(x context.Context, r io.Reader) io.ReadCloser
- func ReadFully(r io.Reader, b []byte) (int, error)
- func ReadStringList(r Reader, s *[]string) error
- func WriteStringList(w Writer, s []string) error
- type Chunk
- func (c Chunk) Avaliable(n int) bool
- func (c *Chunk) Bool() (bool, error)
- func (c *Chunk) Bytes() ([]byte, error)
- func (c *Chunk) Clear()
- func (Chunk) Close() error
- func (c Chunk) Empty() bool
- func (c *Chunk) Float32() (float32, error)
- func (c *Chunk) Float64() (float64, error)
- func (Chunk) Flush() error
- func (c *Chunk) Grow(n int) error
- func (c *Chunk) Int() (int, error)
- func (c *Chunk) Int16() (int16, error)
- func (c *Chunk) Int32() (int32, error)
- func (c *Chunk) Int64() (int64, error)
- func (c *Chunk) Int8() (int8, error)
- func (c Chunk) Left() int
- func (c Chunk) Len() int
- func (c Chunk) MarshalStream(w Writer) error
- func (c Chunk) Payload() []byte
- func (c *Chunk) Read(b []byte) (int, error)
- func (c *Chunk) ReadBool(p *bool) error
- func (c *Chunk) ReadFloat32(p *float32) error
- func (c *Chunk) ReadFloat64(p *float64) error
- func (c *Chunk) ReadFrom(r io.Reader) (int64, error)
- func (c *Chunk) ReadInt(p *int) error
- func (c *Chunk) ReadInt16(p *int16) error
- func (c *Chunk) ReadInt32(p *int32) error
- func (c *Chunk) ReadInt64(p *int64) error
- func (c *Chunk) ReadInt8(p *int8) error
- func (c *Chunk) ReadString(p *string) error
- func (c *Chunk) ReadUint(p *uint) error
- func (c *Chunk) ReadUint16(p *uint16) error
- func (c *Chunk) ReadUint32(p *uint32) error
- func (c *Chunk) ReadUint64(p *uint64) error
- func (c *Chunk) ReadUint8(p *uint8) error
- func (c *Chunk) Reset()
- func (c *Chunk) Rewind()
- func (c *Chunk) Seek(o int64, w int) (int64, error)
- func (c Chunk) Size() int
- func (c Chunk) String() string
- func (c *Chunk) StringVal() (string, error)
- func (c *Chunk) Truncate(n int) error
- func (c *Chunk) Uint() (uint, error)
- func (c *Chunk) Uint16() (uint16, error)
- func (c *Chunk) Uint32() (uint32, error)
- func (c *Chunk) Uint64() (uint64, error)
- func (c *Chunk) Uint8() (uint8, error)
- func (c *Chunk) UnmarshalStream(r Reader) error
- func (c *Chunk) Write(b []byte) (int, error)
- func (c *Chunk) WriteBool(b bool) error
- func (c *Chunk) WriteBytes(b []byte) error
- func (c *Chunk) WriteFloat32(f float32) error
- func (c *Chunk) WriteFloat64(f float64) error
- func (c *Chunk) WriteInt(n int) error
- func (c *Chunk) WriteInt16(n int16) error
- func (c *Chunk) WriteInt32(n int32) error
- func (c *Chunk) WriteInt64(n int64) error
- func (c *Chunk) WriteInt8(n int8) error
- func (c *Chunk) WriteString(s string) error
- func (c *Chunk) WriteTo(w io.Writer) (int64, error)
- func (c *Chunk) WriteUint(n uint) error
- func (c *Chunk) WriteUint16(n uint16) error
- func (c *Chunk) WriteUint32(n uint32) error
- func (c *Chunk) WriteUint64(n uint64) error
- func (c *Chunk) WriteUint8(n uint8) error
- type Flusher
- type Readable
- type Reader
- type Writeable
- type Writer
Constants ¶
const ( // ErrTooLarge is raised if memory cannot be allocated to store data in a Chunk. ErrTooLarge = dataError(3) // ErrInvalidIndex is raised if a specified Grow or index function is supplied with an negative or out of // bounds number or when a Seek index is not valid. ErrInvalidIndex = dataError(2) // ErrInvalidType is an error that occurs when the Bytes, ReadBytes, StringVal or ReadString functions could not // propertly determine the underlying type of array from the Reader. ErrInvalidType = dataError(1) )
const ( // DataLimitSmall is the size value allowed for small strings using the WriteString and WriteBytes functions. DataLimitSmall uint64 = 2 << 7 // DataLimitLarge is the size value allowed for large strings using the WriteString and WriteBytes functions. DataLimitLarge uint64 = 2 << 31 // DataLimitMedium is the size value allowed for medium strings using the WriteString and WriteBytes functions. DataLimitMedium uint64 = 2 << 15 )
Variables ¶
var ( // ErrLimit is an error that is returned when a Limit is set on a Chunk and the size limit was hit when // attempting to write to the Chunk. This error wraps the io.EOF error, which allows this error to match // io.EOF for sanity checking. ErrLimit = new(limitError) )
Functions ¶
func NewCtxReader ¶
NewCtxReader creates a reader backed by the supplied Reader and Context. This reader will automatically close when the parent context is canceled. This is useful in situations when direct copies using 'io.Copy' on threads or timed operations are required.
func ReadFully ¶
ReadFully attempts to Read all the bytes from the specified reader until the length of the array or EOF.
func ReadStringList ¶
ReadStringList attempts to read a string list written using the 'WriteStringList' function from the supplied string into the string list pointer. If the provided array is nil or not large enough, it will be resized.
func WriteStringList ¶
WriteStringList will attempt to write the supplied string list to the writer. If the string list is nil or empty, it will write a zero byte to the Writer. The resulting data can be read using the 'ReadStringList' function.
Types ¶
type Chunk ¶
type Chunk struct { Limit int // contains filtered or unexported fields }
Chunk is a low level data container. Chunks allow for simple read/write operations on static containers. Chunk fulfils the Reader, Seeker, Writer, Flusher and Closer interfaces.
func NewChunk ¶
NewChunk creates a new Chunk struct and will use the provided byte array as the underlying structure.
func (Chunk) Avaliable ¶
Avaliable returns if a limit will block the writing of n bytes. This function can be used to check if there is space to write before commiting a write.
func (*Chunk) Clear ¶
func (c *Chunk) Clear()
Clear is similar to Reset, but discards the buffer, which must be allocated again. If using the buffer the Reset function is preferable.
func (*Chunk) Grow ¶
Grow grows the Chunk's buffer capacity, if necessary, to guarantee space for another n bytes.
func (Chunk) Left ¶
Left returns the amount of bytes avaliable in this Chunk when a Limit is set. This function will return -1 if there us no limit set.
func (Chunk) Len ¶
Len returns the same result as Size. This function returns the amount of bytes written or contained in this Chunk.
func (Chunk) MarshalStream ¶
MarshalStream writes the unread Chunk data into a binary data representation. This function will return an error if any part of the writes fail.
func (*Chunk) Read ¶
Read reads the next len(p) bytes from the Chunk or until the Chunk is drained. The return value n is the number of bytes read.
func (*Chunk) ReadBool ¶
ReadBool reads the value from the Chunk payload buffer into the provided pointer.
func (*Chunk) ReadFloat32 ¶
ReadFloat32 reads the value from the Chunk payload buffer into the provided pointer.
func (*Chunk) ReadFloat64 ¶
ReadFloat64 reads the value from the Chunk payload buffer into the provided pointer.
func (*Chunk) ReadFrom ¶
ReadFrom reads data from the supplied Reader until EOF or error. The return value is the number of bytes read. Any error except io.EOF encountered during the read is also returned.
func (*Chunk) ReadInt ¶
ReadInt reads the value from the Chunk payload buffer into the provided pointer.
func (*Chunk) ReadInt16 ¶
ReadInt16 reads the value from the Chunk payload buffer into the provided pointer.
func (*Chunk) ReadInt32 ¶
ReadInt32 reads the value from the Chunk payload buffer into the provided pointer.
func (*Chunk) ReadInt64 ¶
ReadInt64 reads the value from the Chunk payload buffer into the provided pointer.
func (*Chunk) ReadInt8 ¶
ReadInt8 reads the value from the Chunk payload buffer into the provided pointer.
func (*Chunk) ReadString ¶
ReadString reads the value from the Chunk payload buffer into the provided pointer.
func (*Chunk) ReadUint ¶
ReadUint reads the value from the Chunk payload buffer into the provided pointer.
func (*Chunk) ReadUint16 ¶
ReadUint16 reads the value from the Chunk payload buffer into the provided pointer.
func (*Chunk) ReadUint32 ¶
ReadUint32 reads the value from the Chunk payload buffer into the provided pointer.
func (*Chunk) ReadUint64 ¶
ReadUint64 reads the value from the Chunk payload buffer into the provided pointer.
func (*Chunk) ReadUint8 ¶
ReadUint8 reads the value from the Chunk payload buffer into the provided pointer.
func (*Chunk) Reset ¶
func (c *Chunk) Reset()
Reset resets the Chunk buffer to be empty but retains the underlying storage for use by future writes.
func (*Chunk) Rewind ¶
func (c *Chunk) Rewind()
Rewind will seek the writing and reading positions back to zero. This function can be used to 'reset' the Chunk without deleting any data.
func (*Chunk) Seek ¶
Seek will attempt to seek to the provided offset index and whence. This function will return the new offset if successful and will return an error if the offset and/or whence are invalid.
func (*Chunk) Truncate ¶
Truncate discards all but the first n unread bytes from the Chunk but continues to use the same allocated storage. This will return an error if n is negative or greater than the length of the buffer.
func (*Chunk) UnmarshalStream ¶
UnmarshalStream reads the Chunk data from a binary data representation. This function will return an error if any part of the writes fail.
func (*Chunk) Write ¶
Write appends the contents of p to the buffer, growing the buffer as needed. If the buffer becomes too large, Write will return ErrTooLarge. If there is a limit set, this function will return ErrLimit if the Limit is being hit. If an ErrLimit is returned, check the returned bytes as ErrLimit is returned as a warning that not all bytes have been written before refusing writes.
func (*Chunk) WriteBytes ¶
WriteBytes writes the supplied value to the Chunk payload buffer.
func (*Chunk) WriteFloat32 ¶
WriteFloat32 writes the supplied value to the Chunk payload buffer.
func (*Chunk) WriteFloat64 ¶
WriteFloat64 writes the supplied value to the Chunk payload buffer.
func (*Chunk) WriteInt16 ¶
WriteInt16 writes the supplied value to the Chunk payload buffer.
func (*Chunk) WriteInt32 ¶
WriteInt32 writes the supplied value to the Chunk payload buffer.
func (*Chunk) WriteInt64 ¶
WriteInt64 writes the supplied value to the Chunk payload buffer.
func (*Chunk) WriteString ¶
WriteString writes the supplied value to the Chunk payload buffer.
func (*Chunk) WriteTo ¶
WriteTo writes data to the supplied Writer until there's no more data to write or when an error occurs. The return value is the number of bytes written. Any error encountered during the write is also returned.
func (*Chunk) WriteUint16 ¶
WriteUint16 writes the supplied value to the Chunk payload buffer.
func (*Chunk) WriteUint32 ¶
WriteUint32 writes the supplied value to the Chunk payload buffer.
func (*Chunk) WriteUint64 ¶
WriteUint64 writes the supplied value to the Chunk payload buffer.
func (*Chunk) WriteUint8 ¶
WriteUint8 writes the supplied value to the Chunk payload buffer.
type Flusher ¶
type Flusher interface {
Flush() error
}
Flusher is an interface that supports Flushing the stream output to the underlying Writer.
type Readable ¶
Readable is an interface that supports reading the target struct data from a Reader.
type Reader ¶
type Reader interface { Int() (int, error) Bool() (bool, error) Int8() (int8, error) Uint() (uint, error) Int16() (int16, error) Int32() (int32, error) Int64() (int64, error) Uint8() (uint8, error) Bytes() ([]byte, error) Uint16() (uint16, error) Uint32() (uint32, error) Uint64() (uint64, error) Float32() (float32, error) Float64() (float64, error) StringVal() (string, error) ReadInt(*int) error ReadBool(*bool) error ReadInt8(*int8) error ReadUint(*uint) error ReadInt16(*int16) error ReadInt32(*int32) error ReadInt64(*int64) error ReadUint8(*uint8) error ReadUint16(*uint16) error ReadUint32(*uint32) error ReadUint64(*uint64) error ReadString(*string) error ReadFloat32(*float32) error ReadFloat64(*float64) error io.ReadCloser }
Reader is a basic interface that supports all types of read functions of the core Golang builtin types. Pointer functions are avaliable to allow for easier usage and fluid operation.
type Writeable ¶
Writeable is an interface that supports writing the target struct data to a Writer.
type Writer ¶
type Writer interface { WriteInt(int) error WriteBool(bool) error WriteInt8(int8) error WriteUint(uint) error WriteInt16(int16) error WriteInt32(int32) error WriteInt64(int64) error WriteUint8(uint8) error WriteBytes([]byte) error WriteUint16(uint16) error WriteUint32(uint32) error WriteUint64(uint64) error WriteString(string) error WriteFloat32(float32) error WriteFloat64(float64) error io.WriteCloser Flusher }
Writer is a basic interface that supports writing of all core Golang builtin types.