rwutil

package
v0.7.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalBinary

func MarshalBinary(object interface{ Write(w io.Writer) error }) ([]byte, error)

MarshalBinary is an adapter function that uses an object's Write() function to marshal the object to data bytes. It is typically used to implement a one-line MarshalBinary() member function for the object.

func MustSize32FromBytes

func MustSize32FromBytes(b []byte) uint32

func ReadBool

func ReadBool(r io.Reader) (bool, error)

func ReadByte

func ReadByte(r io.Reader) (byte, error)

func ReadBytes

func ReadBytes(r io.Reader) ([]byte, error)

func ReadFromBytes

func ReadFromBytes[T any](rr *Reader, fromBytes func([]byte) (T, error)) (ret T)

ReadFromBytes allows a reader to use any <Type>FromBytes() function as a source. It will read the next group of bytes and pass it to the specified function and returns the correct type of object

func ReadInt16

func ReadInt16(r io.Reader) (int16, error)

func ReadInt32

func ReadInt32(r io.Reader) (int32, error)

func ReadInt64

func ReadInt64(r io.Reader) (int64, error)

func ReadInt8

func ReadInt8(r io.Reader) (int8, error)

func ReadMarshaled

func ReadMarshaled(r io.Reader, val encoding.BinaryUnmarshaler) error

func ReadN

func ReadN(r io.Reader, data []byte) error

func ReadSize32

func ReadSize32(r io.Reader) (uint32, error)

func ReadString

func ReadString(r io.Reader) (string, error)

func ReadUint16

func ReadUint16(r io.Reader) (uint16, error)

func ReadUint32

func ReadUint32(r io.Reader) (uint32, error)

func ReadUint64

func ReadUint64(r io.Reader) (uint64, error)

func ReadUint8

func ReadUint8(r io.Reader) (uint8, error)

func ReaderFromBytes

func ReaderFromBytes[T interface{ Read(r io.Reader) error }](data []byte, object T) (T, error)

ReaderFromBytes is a wrapper that uses an object's Read() function to marshal the object from data bytes. It's typically used to implement a one-line <Type>FromBytes() function and returns the expected type and error.

func Size32FromBytes

func Size32FromBytes(buf []byte) (uint32, error)

func Size32ToBytes

func Size32ToBytes(s uint32) []byte

func UnmarshalBinary

func UnmarshalBinary[T interface{ Read(r io.Reader) error }](data []byte, object T) error

UnmarshalBinary is an adapter function that uses an object's Read() function to marshal the object from data bytes. It is typically used to implement a one-line UnmarshalBinary member function for the object.

func WriteBool

func WriteBool(w io.Writer, cond bool) error

func WriteByte

func WriteByte(w io.Writer, val byte) error

func WriteBytes

func WriteBytes(w io.Writer, data []byte) error

func WriteInt16

func WriteInt16(w io.Writer, val int16) error

func WriteInt32

func WriteInt32(w io.Writer, val int32) error

func WriteInt64

func WriteInt64(w io.Writer, val int64) error

func WriteInt8

func WriteInt8(w io.Writer, val int8) error

func WriteMarshaled

func WriteMarshaled(w io.Writer, val encoding.BinaryMarshaler) error

func WriteN

func WriteN(w io.Writer, data []byte) error

func WriteSize32

func WriteSize32(w io.Writer, value uint32) error

func WriteString

func WriteString(w io.Writer, str string) error

func WriteUint16

func WriteUint16(w io.Writer, val uint16) error

func WriteUint32

func WriteUint32(w io.Writer, val uint32) error

func WriteUint64

func WriteUint64(w io.Writer, val uint64) error

func WriteUint8

func WriteUint8(w io.Writer, val uint8) error

func WriterToBytes

func WriterToBytes(object interface{ Write(w io.Writer) error }) []byte

WriterToBytes is a wrapper that uses an object's Write() function to marshal the object to data bytes. It's typically used to implement a one-line Bytes() function for the object.

Types

type Counter

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

func NewReadCounter

func NewReadCounter(rr *Reader) (ret *Counter)

func NewWriteCounter

func NewWriteCounter(ww *Writer) (ret *Counter)

func (*Counter) Close

func (c *Counter) Close()

func (*Counter) Count

func (c *Counter) Count() uint32

func (*Counter) Read

func (c *Counter) Read(buf []byte) (int, error)

func (*Counter) Write

func (c *Counter) Write(buf []byte) (int, error)

type Kind

type Kind byte

type PushBack

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

func (*PushBack) Read

func (push *PushBack) Read(data []byte) (int, error)

func (*PushBack) Write

func (push *PushBack) Write(data []byte) (n int, err error)

type Reader

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

func NewBytesReader

func NewBytesReader(data []byte) *Reader

func NewReader

func NewReader(r io.Reader) *Reader

func (*Reader) PushBack

func (rr *Reader) PushBack() *Writer

PushBack returns a pushback writer that allows you to insert data before the stream. The Reader will read this data first, and then resume reading from the stream. The pushback Writer is only valid for this Reader until it resumes the stream.

func (*Reader) Read

func (rr *Reader) Read(reader interface{ Read(r io.Reader) error })

func (*Reader) ReadBool

func (rr *Reader) ReadBool() (ret bool)

func (*Reader) ReadByte

func (rr *Reader) ReadByte() (ret byte)

func (*Reader) ReadBytes

func (rr *Reader) ReadBytes() (ret []byte)

func (*Reader) ReadDuration

func (rr *Reader) ReadDuration() (ret time.Duration)

func (*Reader) ReadInt16

func (rr *Reader) ReadInt16() (ret int16)

func (*Reader) ReadInt32

func (rr *Reader) ReadInt32() (ret int32)

func (*Reader) ReadInt64

func (rr *Reader) ReadInt64() (ret int64)

func (*Reader) ReadInt8

func (rr *Reader) ReadInt8() (ret int8)

func (*Reader) ReadKind

func (rr *Reader) ReadKind() Kind

func (*Reader) ReadKindAndVerify

func (rr *Reader) ReadKindAndVerify(expectedKind Kind)

func (*Reader) ReadMarshaled

func (rr *Reader) ReadMarshaled(m encoding.BinaryUnmarshaler)

func (*Reader) ReadN

func (rr *Reader) ReadN(ret []byte)

func (*Reader) ReadSerialized

func (rr *Reader) ReadSerialized(s deserializable)

func (*Reader) ReadSize16

func (rr *Reader) ReadSize16() (ret int)

func (*Reader) ReadSize32

func (rr *Reader) ReadSize32() (ret int)

func (*Reader) ReadSizeWithLimit

func (rr *Reader) ReadSizeWithLimit(limit uint32) int

func (*Reader) ReadString

func (rr *Reader) ReadString() (ret string)

func (*Reader) ReadUint16

func (rr *Reader) ReadUint16() (ret uint16)

func (*Reader) ReadUint256

func (rr *Reader) ReadUint256() (ret *big.Int)

func (*Reader) ReadUint32

func (rr *Reader) ReadUint32() (ret uint32)

func (*Reader) ReadUint64

func (rr *Reader) ReadUint64() (ret uint64)

func (*Reader) ReadUint8

func (rr *Reader) ReadUint8() (ret uint8)

type Skipper

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

func (*Skipper) Read

func (skip *Skipper) Read(data []byte) (n int, err error)

func (*Skipper) Write

func (skip *Skipper) Write(data []byte) (n int, err error)

type Writer

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

func NewBytesWriter

func NewBytesWriter() *Writer

func NewWriter

func NewWriter(w io.Writer) *Writer

func (*Writer) Bytes

func (ww *Writer) Bytes() []byte

func (*Writer) Skip

func (ww *Writer) Skip() *Reader

func (*Writer) Write

func (ww *Writer) Write(writer interface{ Write(w io.Writer) error }) *Writer

func (*Writer) WriteBool

func (ww *Writer) WriteBool(val bool) *Writer

func (*Writer) WriteByte

func (ww *Writer) WriteByte(val byte) *Writer

func (*Writer) WriteBytes

func (ww *Writer) WriteBytes(val []byte) *Writer

func (*Writer) WriteDuration

func (ww *Writer) WriteDuration(val time.Duration) *Writer

func (*Writer) WriteFromBytes

func (ww *Writer) WriteFromBytes(bytes interface{ Bytes() []byte }) *Writer

func (*Writer) WriteInt16

func (ww *Writer) WriteInt16(val int16) *Writer

func (*Writer) WriteInt32

func (ww *Writer) WriteInt32(val int32) *Writer

func (*Writer) WriteInt64

func (ww *Writer) WriteInt64(val int64) *Writer

func (*Writer) WriteInt8

func (ww *Writer) WriteInt8(val int8) *Writer

func (*Writer) WriteKind

func (ww *Writer) WriteKind(msgType Kind) *Writer

func (*Writer) WriteMarshaled

func (ww *Writer) WriteMarshaled(m encoding.BinaryMarshaler) *Writer

func (*Writer) WriteN

func (ww *Writer) WriteN(val []byte) *Writer

func (*Writer) WriteSerialized

func (ww *Writer) WriteSerialized(s serializable) *Writer

func (*Writer) WriteSize16

func (ww *Writer) WriteSize16(val int) *Writer

func (*Writer) WriteSize32

func (ww *Writer) WriteSize32(val int) *Writer

func (*Writer) WriteSizeWithLimit

func (ww *Writer) WriteSizeWithLimit(val int, limit uint32) *Writer

func (*Writer) WriteString

func (ww *Writer) WriteString(val string) *Writer

func (*Writer) WriteUint16

func (ww *Writer) WriteUint16(val uint16) *Writer

func (*Writer) WriteUint256

func (ww *Writer) WriteUint256(val *big.Int) *Writer

func (*Writer) WriteUint32

func (ww *Writer) WriteUint32(val uint32) *Writer

func (*Writer) WriteUint64

func (ww *Writer) WriteUint64(val uint64) *Writer

func (*Writer) WriteUint8

func (ww *Writer) WriteUint8(val uint8) *Writer

Jump to

Keyboard shortcuts

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