Documentation
¶
Index ¶
- type DoneReadingSignal
- type Reader
- func (r *Reader) Discard(n int)
- func (r *Reader) DiscardMessage()
- func (r *Reader) Next(doneReadingSignal chan struct{}) bool
- func (r *Reader) PopBytes() []byte
- func (r *Reader) PopSlice(n uint32) *Reader
- func (r *Reader) PopString() string
- func (r *Reader) PopUUID() types.UUID
- func (r *Reader) PopUint16() uint16
- func (r *Reader) PopUint32() uint32
- func (r *Reader) PopUint64() uint64
- func (r *Reader) PopUint8() uint8
- type Writer
- func (w *Writer) BeginBytes()
- func (w *Writer) BeginMessage(mType uint8)
- func (w *Writer) EndBytes()
- func (w *Writer) EndMessage()
- func (w *Writer) PushBytes(val []byte)
- func (w *Writer) PushString(val string)
- func (w *Writer) PushUUID(val types.UUID)
- func (w *Writer) PushUint16(val uint16)
- func (w *Writer) PushUint32(val uint32)
- func (w *Writer) PushUint64(val uint64)
- func (w *Writer) PushUint8(val uint8)
- func (w *Writer) Unwrap() []byte
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 ¶
Reader is a buffer reader.
func SimpleReader ¶
SimpleReader creates a new reader that operates on a single []byte.
func (*Reader) DiscardMessage ¶
func (r *Reader) DiscardMessage()
DiscardMessage discards all remaining bytes in the current message.
func (*Reader) Next ¶
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.
If the previous message was not fully read Next() panics.
Next() panics if called on a reader created with SimpleReader().
func (*Reader) PopBytes ¶
PopBytes reads a []byte and advances the buffer. The returned slice is owned by the buffer.
func (*Reader) PopSlice ¶
PopSlice returns a SimpleReader populated with the first n bytes from the buffer and discards those bytes.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer is a write buffer.
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 ¶
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) PushString ¶
PushString writes a string to the buffer.
func (*Writer) PushUint16 ¶
PushUint16 writes a uint16 to the buffer.
func (*Writer) PushUint32 ¶
PushUint32 writes a uint32 to the buffer.
func (*Writer) PushUint64 ¶
PushUint64 writes a uint64 to the buffer.