sds

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2022 License: MIT Imports: 4 Imported by: 7

README

sds

GoDoc

This package provides a fast and simple way for reading and writing custom data streams in Go.

Supports reading and writing most basic types including: int8, int16, int32, int64, uint8, uint16, uint32, uint64, byte, bool, float32, float64, []byte, string. Also uvarint and varint.

Usage

Installing

To start using sds, install Go and run go get:

$ go get -u github.com/tidwall/sds
Basic operations
// create a writer
var bb bytes.Buffer
w := sds.NewWriter(&bb) 

// write some stuff
err = w.WriteString("Hello Jello")
err = w.WriteBytes(someBinary)
err = w.WriteUvarint(8589869056)
err = w.WriteVarint(-119290019)
err = w.WriteUint16(-119290019)

// close the reader when done
w.Flush()

// create a reader
r := sds.NewReader(&bb)

// read some stuff
s, err = w.ReadString()
b, err = w.ReadBytes()
x, err = w.ReadUvarint()
x, err = w.ReadVarint()
x, err = w.ReadUint16()

Now isn't that nice.

License

sds source code is available under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

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

Reader for reading snapbits

func NewReader

func NewReader(r io.Reader) *Reader

NewReader returns a new Reader

func (*Reader) Error added in v0.2.0

func (r *Reader) Error() error

Error returns any previous error.

func (*Reader) ReadBool

func (r *Reader) ReadBool() (bool, error)

ReadBool reads a bool

func (*Reader) ReadByte

func (r *Reader) ReadByte() (byte, error)

ReadByte reads a byte

func (*Reader) ReadBytes

func (r *Reader) ReadBytes() ([]byte, error)

ReadBytes reads bytes

func (*Reader) ReadFloat32

func (r *Reader) ReadFloat32() (float32, error)

ReadFloat32 reads a float32

func (*Reader) ReadFloat64

func (r *Reader) ReadFloat64() (float64, error)

ReadFloat64 reads a float64

func (*Reader) ReadInt8

func (r *Reader) ReadInt8() (int8, error)

ReadInt8 reads an int8

func (*Reader) ReadInt16

func (r *Reader) ReadInt16() (int16, error)

ReadInt16 reads an int16

func (*Reader) ReadInt32

func (r *Reader) ReadInt32() (int32, error)

ReadInt32 reads an int32

func (*Reader) ReadInt64

func (r *Reader) ReadInt64() (int64, error)

ReadInt64 reads an int64

func (*Reader) ReadString

func (r *Reader) ReadString() (string, error)

ReadString reads a string

func (*Reader) ReadUint8

func (r *Reader) ReadUint8() (uint8, error)

ReadUint8 reads a uint8

func (*Reader) ReadUint16

func (r *Reader) ReadUint16() (uint16, error)

ReadUint16 reads a uint16

func (*Reader) ReadUint32

func (r *Reader) ReadUint32() (uint32, error)

ReadUint32 reads a uint32

func (*Reader) ReadUint64

func (r *Reader) ReadUint64() (uint64, error)

ReadUint64 reads a uint64

func (*Reader) ReadUvarint

func (r *Reader) ReadUvarint() (uint64, error)

ReadUvarint reads a uvarint

func (*Reader) ReadVarint

func (r *Reader) ReadVarint() (int64, error)

ReadVarint reads a varint

func (*Reader) SetError added in v0.3.0

func (r *Reader) SetError(err error)

SetError allows for setting a custom user error, which will then be returned from all further Reader.Set*() calls. This operation is ignored if an error has already been assigned to Reader.

type Writer

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

Writer for write stuff

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter returns a new Writer

func (*Writer) Error added in v0.2.0

func (w *Writer) Error() error

Error returns any previous error.

func (*Writer) Flush

func (w *Writer) Flush() error

Flush the buffered bytes to the underlying writer.

func (*Writer) SetError added in v0.3.0

func (w *Writer) SetError(err error)

SetError allows for setting a custom user error, which will then be returned from all further Writer.Set*() calls. This operation is ignored if an error has already been assigned to Writer.

func (*Writer) WriteBool

func (w *Writer) WriteBool(t bool) error

WriteBool writes a bool

func (*Writer) WriteByte

func (w *Writer) WriteByte(x byte) error

WriteByte writes a byte

func (*Writer) WriteBytes

func (w *Writer) WriteBytes(b []byte) error

WriteBytes writes bytes

func (*Writer) WriteFloat32

func (w *Writer) WriteFloat32(f float32) error

WriteFloat32 writes a float32

func (*Writer) WriteFloat64

func (w *Writer) WriteFloat64(f float64) error

WriteFloat64 writes a float64

func (*Writer) WriteInt8

func (w *Writer) WriteInt8(x int8) error

WriteInt8 writes an int8

func (*Writer) WriteInt16

func (w *Writer) WriteInt16(x int16) error

WriteInt16 writes an int16

func (*Writer) WriteInt32

func (w *Writer) WriteInt32(x int32) error

WriteInt32 writes an int32

func (*Writer) WriteInt64

func (w *Writer) WriteInt64(x int64) error

WriteInt64 writes an int64

func (*Writer) WriteString

func (w *Writer) WriteString(s string) error

WriteString writes a string

func (*Writer) WriteUint8

func (w *Writer) WriteUint8(x uint8) error

WriteUint8 writes a uint8

func (*Writer) WriteUint16

func (w *Writer) WriteUint16(x uint16) error

WriteUint16 writes a uint16

func (*Writer) WriteUint32

func (w *Writer) WriteUint32(x uint32) error

WriteUint32 writes a uint32

func (*Writer) WriteUint64

func (w *Writer) WriteUint64(x uint64) error

WriteUint64 writes a uint64

func (*Writer) WriteUvarint

func (w *Writer) WriteUvarint(x uint64) error

WriteUvarint writes a uvarint

func (*Writer) WriteVarint

func (w *Writer) WriteVarint(x int64) error

WriteVarint writes a varint

Jump to

Keyboard shortcuts

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