buff

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DoneReadingSignal

type DoneReadingSignal struct {
	Chan chan struct{}
	// contains filtered or unexported fields
}

DoneReadingSignal is a convenient type to use with buff.Reader.Next()

func NewSignal

func NewSignal() *DoneReadingSignal

NewSignal returns a new DoneReadingSignal. Only use the returned object once per Reader.Next() for loop.

func (*DoneReadingSignal) Signal

func (d *DoneReadingSignal) Signal()

Signal sends on Chan the first time Signal is called. Subsequent calls are no-op.

type Reader

type Reader struct {
	Err     error
	Buf     []byte
	MsgType uint8
	// contains filtered or unexported fields
}

Reader is a buffer reader.

func NewReader

func NewReader(toBeDeserialized chan *soc.Data) *Reader

NewReader returns a new Reader.

func SimpleReader

func SimpleReader(buf []byte) *Reader

SimpleReader creates a new reader that operates on a single []byte.

func (*Reader) Discard

func (r *Reader) Discard(n int)

Discard skips n bytes.

func (*Reader) DiscardMessage

func (r *Reader) DiscardMessage()

DiscardMessage discards all remaining bytes in the current message.

func (*Reader) Next

func (r *Reader) Next(doneReadingSignal chan struct{}) bool

Next advances the reader to the next message. Next returns false when the reader doesn't own any socket data and a signal is received on doneReadingSignal, or an error is encountered while reading.

Callers must continue to call Next until it returns false.

Next() panics if called on a reader created with SimpleReader().

func (*Reader) PopBytes

func (r *Reader) PopBytes() []byte

PopBytes reads a []byte and advances the buffer. The returned slice is owned by the buffer.

func (*Reader) PopSlice

func (r *Reader) PopSlice(n uint32) *Reader

PopSlice returns a SimpleReader populated with the first n bytes from the buffer and discards those bytes.

func (*Reader) PopString

func (r *Reader) PopString() string

PopString reads a string and advances the buffer.

func (*Reader) PopUUID

func (r *Reader) PopUUID() types.UUID

PopUUID reads a types.UUID and advances the buffer.

func (*Reader) PopUint16

func (r *Reader) PopUint16() uint16

PopUint16 reads a uint16 and advances the buffer.

func (*Reader) PopUint32

func (r *Reader) PopUint32() uint32

PopUint32 reads a uint32 and advances the buffer.

func (*Reader) PopUint64

func (r *Reader) PopUint64() uint64

PopUint64 reads a uint64 and advances the buffer.

func (*Reader) PopUint8

func (r *Reader) PopUint8() uint8

PopUint8 returns the next byte and advances the buffer.

type Writer

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

Writer is a write buffer.

func NewWriter

func NewWriter(alocatedMemory []byte) *Writer

NewWriter returns a new Writer.

func (*Writer) BeginBytes

func (w *Writer) BeginBytes()

BeginBytes allocates space for `data_length` in the buffer. May be called multiple times to create nested bytes blocks. Calling EndBytes once for each BeginBytes call is required before ending a message. BeginBytes panics if BeginMessage was not called first.

func (*Writer) BeginMessage

func (w *Writer) BeginMessage(mType uint8)

BeginMessage writes mType to the buffer and allocates space for message length. BeginMessage panics if the EndMessage was not called for the previous message.

func (*Writer) EndBytes

func (w *Writer) EndBytes()

EndBytes sets the `data_length` allocated by BeginBytes to the number of bytes that were written since the last BeginBytes call. EndBytes panics if BeginBytes was not called first.

func (*Writer) EndMessage

func (w *Writer) EndMessage()

EndMessage sets the `message_length` allocated by BeginMessage. EndMessage panics if BeginMessage was not called first or if BeginBytes was not followed by EndBytes.

func (*Writer) PushBytes

func (w *Writer) PushBytes(val []byte)

PushBytes writes []byte to the buffer.

func (*Writer) PushString

func (w *Writer) PushString(val string)

PushString writes a string to the buffer.

func (*Writer) PushUUID

func (w *Writer) PushUUID(val types.UUID)

PushUUID writes a types.UUID to the buffer.

func (*Writer) PushUint16

func (w *Writer) PushUint16(val uint16)

PushUint16 writes a uint16 to the buffer.

func (*Writer) PushUint32

func (w *Writer) PushUint32(val uint32)

PushUint32 writes a uint32 to the buffer.

func (*Writer) PushUint64

func (w *Writer) PushUint64(val uint64)

PushUint64 writes a uint64 to the buffer.

func (*Writer) PushUint8

func (w *Writer) PushUint8(val uint8)

PushUint8 writes a uint8 to the buffer.

func (*Writer) Unwrap added in v0.9.0

func (w *Writer) Unwrap() []byte

Unwrap returns the underlying []byte.

Jump to

Keyboard shortcuts

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