Version: v2.1.4+incompatible Latest Latest

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

Go to latest
Published: Apr 11, 2021 License: Apache-2.0 Imports: 9 Imported by: 119



Package frame provides functionality for manipulating STOMP frames.



View Source
const (
	AckAuto             = "auto"              // Client does not send ACK
	AckClient           = "client"            // Client sends ACK/NACK
	AckClientIndividual = "client-individual" // Client sends ACK/NACK for individual messages

Valid values for the "ack" header entry.

View Source
const (
	// Connect commands.
	STOMP     = "STOMP"

	// Client commands.
	SEND        = "SEND"
	ACK         = "ACK"
	NACK        = "NACK"
	BEGIN       = "BEGIN"
	ABORT       = "ABORT"

	// Server commands.

STOMP frame commands. Used upper case naming convention to avoid clashing with STOMP header names.

View Source
const (
	ContentLength = "content-length"
	ContentType   = "content-type"
	Receipt       = "receipt"
	AcceptVersion = "accept-version"
	Host          = "host"
	Version       = "version"
	Login         = "login"
	Passcode      = "passcode"
	HeartBeat     = "heart-beat"
	Session       = "session"
	Server        = "server"
	Destination   = "destination"
	Id            = "id"
	Ack           = "ack"
	Transaction   = "transaction"
	ReceiptId     = "receipt-id"
	Subscription  = "subscription"
	MessageId     = "message-id"
	Message       = "message"

STOMP header names. Some of the header names have commands with the same name (eg Ack, Message, Receipt). Commands use an upper-case naming convention, header names use pascal-case naming convention.


View Source
var (
	ErrInvalidCommand     = errors.New("invalid command")
	ErrInvalidFrameFormat = errors.New("invalid frame format")
View Source
var (
	ErrInvalidHeartBeat = errors.New("invalid heart-beat")


func ParseHeartBeat

func ParseHeartBeat(heartBeat string) (time.Duration, time.Duration, error)

ParseHeartBeat parses the value of a STOMP heart-beat entry and returns two time durations. Returns an error if the heart-beat value is not in the correct format, or if the time durations are too big to be represented by the time.Duration type.


type Frame

type Frame struct {
	Command string
	Header  *Header
	Body    []byte

A Frame represents a STOMP frame. A frame consists of a command followed by a collection of header entries, and then an optional body.

func New

func New(command string, headers ...string) *Frame

New creates a new STOMP frame with the specified command and headers. The headers should contain an even number of entries. Each even index is the header name, and the odd indexes are the assocated header values.

func (*Frame) Clone

func (f *Frame) Clone() *Frame

Clone creates a deep copy of the frame and its header. The cloned frame shares the body with the original frame.

type Header struct {
	// contains filtered or unexported fields

A Header represents the header part of a STOMP frame. The header in a STOMP frame consists of a list of header entries. Each header entry is a key/value pair of strings.

Normally a STOMP header only has one header entry for a given key, but the STOMP standard does allow for multiple header entries with the same key. In this case, the first header entry contains the value, and any subsequent header entries with the same key are ignored.

Example header containing 6 header entries. Note that the second header entry with the key "comment" would be ignored.

comment:some comment
comment:another comment

func NewHeader

func NewHeader(headerEntries ...string) *Header

NewHeader creates a new Header and populates it with header entries. This function expects an even number of strings as parameters. The even numbered indices are keys and the odd indices are values. See the example for more information.

func (*Header) Add

func (h *Header) Add(key, value string)

Add adds the key, value pair to the header.

func (*Header) AddHeader

func (h *Header) AddHeader(header *Header)

AddHeader adds all of the key value pairs in header to h.

func (*Header) Clone

func (h *Header) Clone() *Header

Clone returns a deep copy of a Header.

func (*Header) Contains

func (h *Header) Contains(key string) (value string, ok bool)

Contains gets the first value associated with the given key, and also returns a bool indicating whether the header entry exists.

If there are no values associated with the key, Get returns "" for the value, and ok is false.

func (*Header) ContentLength

func (h *Header) ContentLength() (value int, ok bool, err error)

ContentLength returns the value of the "content-length" header entry. If the "content-length" header is missing, then ok is false. If the "content-length" entry is present but is not a valid non-negative integer then err is non-nil.

func (*Header) Del

func (h *Header) Del(key string)

Del deletes all header entries with the specified key.

func (*Header) Get

func (h *Header) Get(key string) string

Get gets the first value associated with the given key. If there are no values associated with the key, Get returns "".

func (*Header) GetAll

func (h *Header) GetAll(key string) []string

GetAll returns all of the values associated with a given key. Normally there is only one header entry per key, but it is permitted to have multiple entries according to the STOMP standard.

func (*Header) GetAt

func (h *Header) GetAt(index int) (key, value string)

Returns the header name and value at the specified index in the collection. The index should be in the range 0 <= index < Len(), a panic will occur if it is outside this range.

func (*Header) Len

func (h *Header) Len() int

Len returns the number of header entries in the header.

func (*Header) Set

func (h *Header) Set(key, value string)

Set replaces the value of any existing header entry with the specified key. If there is no existing header entry with the specified key, a new header entry is added.

type Reader

type Reader struct {
	// contains filtered or unexported fields

The Reader type reads STOMP frames from an underlying io.Reader. The reader is buffered, and the size of the buffer is the maximum size permitted for the STOMP frame command and header section. A STOMP frame is rejected if its command and header section exceed the buffer size.

func NewReader

func NewReader(reader io.Reader) *Reader

NewReader creates a Reader with the default underlying buffer size.

func NewReaderSize

func NewReaderSize(reader io.Reader, bufferSize int) *Reader

NewReaderSize creates a Reader with an underlying bufferSize of the specified size.

func (*Reader) Read

func (r *Reader) Read() (*Frame, error)

Read a STOMP frame from the input. If the input contains one or more heart-beat characters and no frame, then nil will be returned for the frame. Calling programs should always check for a nil frame.

type Writer

type Writer struct {
	// contains filtered or unexported fields

Writes STOMP frames to an underlying io.Writer.

func NewWriter

func NewWriter(writer io.Writer) *Writer

Creates a new Writer object, which writes to an underlying io.Writer.

func NewWriterSize

func NewWriterSize(writer io.Writer, bufferSize int) *Writer

func (*Writer) Write

func (w *Writer) Write(f *Frame) error

Write the contents of a frame to the underlying io.Writer.

Jump to

Keyboard shortcuts

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