rqre

package module
v0.0.0-...-157f577 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2025 License: AGPL-3.0 Imports: 13 Imported by: 0

README

rqre

rqre is a Go library designed to handle message boundaries on streaming connections, providing efficient and reliable communication for request/response patterns. The library offers multiple key features:

  • Message Boundary Management: Handles message framing with support for both fixed and variable-length message sizes

  • Buffer Pool Management: Provides flexible buffer management strategies through both simple allocation (NewBuffers) and efficient reuse (PoolBuffers)

  • High-Level Messaging: Offers a Messenger type that combines boundary handling with efficient buffer management

  • Secure Communication: Includes ALECMessenger for Application-Layer Encryption, adding transparent message encryption/decryption

The library is particularly suitable for applications requiring structured message exchange over streaming connections, with options for both basic and secure communication patterns.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseMsg32

func CloseMsg32(f []byte, max uint) error

CloseMsg32 finalizes a message to be sent. If max > 0 if is checked if the message payload exceeds a size of max byte and, in case, returns an error. In any case a message payload must no be greater than math.MaxUint32.

func CloseMsgVI

func CloseMsgVI(f []byte, max uint) ([]byte, error)

func NewMsg32

func NewMsg32(buf []byte) []byte

NewMsg32 prepares buf to be a new message or allocates a new message if buf is nil. After appending the payload to message one must call CloseMsg32 to be ready to send it.

func NewMsgVI

func NewMsgVI(buf []byte) []byte

NewMsgVI prepares buffer buf to be used as a message with Uvait encoded size.

func ReadMsg32

func ReadMsg32(r io.Reader, buf []byte, max uint) ([]byte, error)

ReadMsg32 reads a message from r an place the payload into buf adjusting buf's size as necessary. If max > 0, it is checked that the payload size does not exceed max before reading the payload from r.

func ReadMsgVI

func ReadMsgVI(r io.Reader, buf []byte, max uint) ([]byte, error)

func Recv

func Recv(r io.Reader, p encoding.BinaryUnmarshaler, m Message, buf []byte) (_ []byte, err error)

func Send

func Send(w io.Writer, p encoding.BinaryAppender, m Message, buf []byte) (_ []byte, err error)

Types

type AESGCM

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

func NewAESGCM

func NewAESGCM(key []byte) (AESGCM, error)

The key argument must be the AES key, either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256 as in aes.NewCipher.

func (AESGCM) Decrypt

func (sb AESGCM) Decrypt(crypt []byte) ([]byte, error)

func (AESGCM) Ecrypt

func (sb AESGCM) Ecrypt(msg []byte) ([]byte, error)

type ALECMessenger

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

ALECMessenger (Application-Layer EnCryption Messenger) provides secure message exchange by adding encryption at the application layer. It wraps a Messenger and adds transparent encryption/decryption of messages using a provided Cryptographer implementation. This ensures message confidentiality while maintaining the underlying message boundary handling and buffer management of the base Messenger.

func (ALECMessenger) Recv

func (alec ALECMessenger) Recv(r io.Reader, p encoding.BinaryUnmarshaler) (err error)

func (ALECMessenger) Send

func (alec ALECMessenger) Send(w io.Writer, p encoding.BinaryAppender) (err error)

type Cryptographer

type Cryptographer interface {
	Ecrypt(msg []byte) ([]byte, error)
	Decrypt(crypt []byte) ([]byte, error)
}

type Message

type Message interface {
	// New prepares buf to hold a message to be sent. Actual data has to be
	// appended to message. A message must be closed before sending.
	New(buf []byte) (message []byte)

	// Close closes the message and returns the send buffer as a subslice of
	// message.
	Close(message []byte) (send []byte, err error)

	Read(r io.Reader, buf []byte) (data []byte, err error)
}

Message defines the interface for handling message boundaries on streaming connections in the rqre library.

type Messenger

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

Messenger combines a Message implementation for handling message boundaries with a BufferPool for efficient buffer management to exchange messages on streaming connections.

func NewMessenger

func NewMessenger(m Message, b httputil.BufferPool) Messenger

func (Messenger) Recv

func (m Messenger) Recv(r io.Reader, p encoding.BinaryUnmarshaler) (err error)

func (Messenger) Send

func (m Messenger) Send(w io.Writer, p encoding.BinaryAppender) (err error)

type Msg32

type Msg32 uint32

Msg32 handles messages with a 32-bit size field. If Msg32 > 0 message payload must not exceed that value.

func (Msg32) Close

func (f Msg32) Close(message []byte) (_ []byte, err error)

func (Msg32) New

func (Msg32) New(buf []byte) []byte

func (Msg32) Read

func (f Msg32) Read(r io.Reader, buf []byte) ([]byte, error)

type MsgVI

type MsgVI uint

MsgVI implements Message with variable integer encoded message sizes. If MsgVI > 0, message payload must not exceed that value.

func (MsgVI) Close

func (f MsgVI) Close(message []byte) (_ []byte, err error)

func (MsgVI) New

func (f MsgVI) New(buf []byte) []byte

func (MsgVI) Read

func (f MsgVI) Read(r io.Reader, buf []byte) ([]byte, error)

type NewBuffers

type NewBuffers int

NewBuffers implements httputil.BufferPool by creating new byte slices for each Get() call. The integer value defines the capacity of created buffers. This implementation does not reuse buffers, making it suitable for cases where buffer reuse is not beneficial or when memory pressure is not a concern.

func (NewBuffers) Get

func (b NewBuffers) Get() []byte

func (NewBuffers) Put

func (b NewBuffers) Put([]byte)

type PoolBuffers

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

PoolBuffers implements httputil.BufferPool using a sync.Pool for efficient buffer reuse. This implementation reduces memory allocation overhead by recycling buffers, making it suitable for high-throughput scenarios or when memory pressure is a concern.

func NewPoolBuffers

func NewPoolBuffers(init int) PoolBuffers

func (PoolBuffers) Get

func (b PoolBuffers) Get() []byte

func (PoolBuffers) Put

func (b PoolBuffers) Put(buf []byte)

Jump to

Keyboard shortcuts

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