stomp: github.com/go-stomp/stomp/frame Index | Files

package frame

import "github.com/go-stomp/stomp/frame"

Package frame provides functionality for manipulating STOMP frames.

Index

Package Files

ack.go command.go encode.go errors.go frame.go header.go heartbeat.go reader.go writer.go

Constants

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.

const (
    // Connect commands.
    CONNECT   = "CONNECT"
    STOMP     = "STOMP"
    CONNECTED = "CONNECTED"

    // Client commands.
    SEND        = "SEND"
    SUBSCRIBE   = "SUBSCRIBE"
    UNSUBSCRIBE = "UNSUBSCRIBE"
    ACK         = "ACK"
    NACK        = "NACK"
    BEGIN       = "BEGIN"
    COMMIT      = "COMMIT"
    ABORT       = "ABORT"
    DISCONNECT  = "DISCONNECT"

    // Server commands.
    MESSAGE = "MESSAGE"
    RECEIPT = "RECEIPT"
    ERROR   = "ERROR"
)

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

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.

Variables

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

func ParseHeartBeat Uses

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 Uses

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 Uses

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 Uses

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.

login:scott
passcode:tiger
host:stompserver
accept-version:1.0,1.1,1.2
comment:some comment
comment:another comment

func NewHeader Uses

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 Uses

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

Add adds the key, value pair to the header.

func (*Header) AddHeader Uses

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

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

func (*Header) Clone Uses

func (h *Header) Clone() *Header

Clone returns a deep copy of a Header.

func (*Header) Contains Uses

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 Uses

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 Uses

func (h *Header) Del(key string)

Del deletes all header entries with the specified key.

func (*Header) Get Uses

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 Uses

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 Uses

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 Uses

func (h *Header) Len() int

Len returns the number of header entries in the header.

func (*Header) Set Uses

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 Uses

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 Uses

func NewReader(reader io.Reader) *Reader

NewReader creates a Reader with the default underlying buffer size.

func NewReaderSize Uses

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

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

func (*Reader) Read Uses

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 Uses

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

Writes STOMP frames to an underlying io.Writer.

func NewWriter Uses

func NewWriter(writer io.Writer) *Writer

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

func NewWriterSize Uses

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

func (*Writer) Write Uses

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

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

Package frame imports 9 packages (graph) and is imported by 41 packages. Updated 2019-02-13. Refresh now. Tools for package owners.