container

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2019 License: GPL-3.0 Imports: 2 Imported by: 8

Documentation

Overview

Package container gives you a []byte slice on steroids, allowing for quick data appending, prepending and fetching as well as transparent error transportation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Container

type Container struct {
	// contains filtered or unexported fields
}

Container is []byte sclie on steroids, allowing for quick data appending, prepending and fetching as well as transparent error transportation. (Error transportation requires use of varints for data)

func New

func New(data ...[]byte) *Container

New creates a new container with an optional initial []byte slice. Data will NOT be copied.

func NewContainer

func NewContainer(data ...[]byte) *Container

NewContainer is DEPRECATED, please use New(), it's the same thing.

func (*Container) Append

func (c *Container) Append(data []byte)

Append appends the given data. Data will NOT be copied.

func (*Container) AppendAsBlock

func (c *Container) AppendAsBlock(data []byte)

AppendAsBlock appends the length of the data and the data itself. Data will NOT be copied.

func (*Container) AppendNumber

func (c *Container) AppendNumber(n uint64)

AppendNumber appends a number (varint encoded).

func (*Container) CheckError

func (c *Container) CheckError()

CheckError checks if there is an error in the data. If so, it will parse the error and delete the data.

func (*Container) CompileData

func (c *Container) CompileData() []byte

CompileData concatenates all bytes held by the container and returns it as one single []byte slice. Data will NOT be copied and is NOT consumed.

func (*Container) ErrString

func (c *Container) ErrString() string

ErrString returns the error as a string.

func (*Container) Error

func (c *Container) Error() error

Error returns the error.

func (*Container) Get

func (c *Container) Get(n int) ([]byte, error)

Get returns the given amount of bytes. Data MAY be copied and IS consumed.

func (*Container) GetMax

func (c *Container) GetMax(n int) []byte

GetMax returns as much as possible, but the given amount of bytes at maximum. Data MAY be copied and IS consumed.

func (*Container) GetNextBlock

func (c *Container) GetNextBlock() ([]byte, error)

GetNextBlock returns the next block of data defined by a varint (note: data will MAY be copied and IS consumed).

func (*Container) GetNextN16

func (c *Container) GetNextN16() (uint16, error)

GetNextN16 parses and returns a varint of type uint16.

func (*Container) GetNextN32

func (c *Container) GetNextN32() (uint32, error)

GetNextN32 parses and returns a varint of type uint32.

func (*Container) GetNextN64

func (c *Container) GetNextN64() (uint64, error)

GetNextN64 parses and returns a varint of type uint64.

func (*Container) GetNextN8

func (c *Container) GetNextN8() (uint8, error)

GetNextN8 parses and returns a varint of type uint8.

func (*Container) HasError

func (c *Container) HasError() bool

HasError returns wether or not the container is holding an error.

func (*Container) Length

func (c *Container) Length() (length int)

Length returns the full length of all bytes held by the container.

func (*Container) Prepend

func (c *Container) Prepend(data []byte)

Prepend prepends data. Data will NOT be copied.

func (*Container) PrependLength

func (c *Container) PrependLength()

PrependLength prepends the current full length of all bytes in the container.

func (*Container) Replace

func (c *Container) Replace(data []byte)

Replace replaces all held data with a new data slice. Data will NOT be copied.

func (*Container) SetError

func (c *Container) SetError(err error)

SetError sets an error.

func (*Container) WriteToSlice

func (c *Container) WriteToSlice(slice []byte) (n int, containerEmptied bool)

WriteToSlice copies data to the give slice until it is full, or the container is empty. It returns the bytes written and if the container is now empty. Data IS copied and IS consumed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL