org.springframework.messaging.simp.stomp

## Class StompDecoder

- java.lang.Object
- - org.springframework.messaging.simp.stomp.StompDecoder

- Direct Known Subclasses:
    BufferingStompDecoder

      public class StompDecoder
      extends Object

  Decodes one or more STOMP frames contained in a `ByteBuffer`.

  An attempt is made to read all complete STOMP frames from the buffer, which could be zero, one, or more. If there is any left-over content, i.e. an incomplete STOMP frame, at the end the buffer is reset to point to the beginning of the partial content. The caller is then responsible for dealing with that incomplete content by buffering until there is more input available.

  Since:
    4.0
  Author:
    Andy Wilkinson, Rossen Stoyanchev

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `StompDecoder()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `List<Message<byte[]>>` | `decode(ByteBuffer buffer)` Decodes one or more STOMP frames from the given `ByteBuffer` into a list of `Message`s.
    `List<Message<byte[]>>` | `decode(ByteBuffer buffer, MultiValueMap<String,String> headers)` Decodes one or more STOMP frames from the given `buffer` and returns a list of `Message`s.
    `protected Integer` | `getContentLength(MultiValueMap<String,String> headers)`
    `protected void` | `skipLeadingEol(ByteBuffer buffer)` Skip one ore more EOL characters at the start of the given ByteBuffer.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### StompDecoder

          public StompDecoder()

  - ### Method Detail

    - #### decode

          public List<Message<byte[]>> decode(ByteBuffer buffer)

      Decodes one or more STOMP frames from the given `ByteBuffer` into a list of `Message`s. If the input buffer contains any incplcontains partial STOMP frame content, or additional content with a partial STOMP frame, the buffer is reset and `null` is returned.
      Parameters:
        `buffer` - The buffer to decode the STOMP frame from
      Returns:
        the decoded messages or an empty list

    - #### decode

          public List<Message<byte[]>> decode(ByteBuffer buffer,
                                              MultiValueMap<String,String> headers)

      Decodes one or more STOMP frames from the given `buffer` and returns a list of `Message`s.

      If the given ByteBuffer contains only partial STOMP frame content and no complete STOMP frames, an empty list is returned, and the buffer is reset to to where it was.

      If the buffer contains one ore more STOMP frames, those are returned and the buffer reset to point to the beginning of the unused partial content.

      The input headers map is used to store successfully parsed headers and is cleared after ever successfully read message. So when partial content is read the caller can check if a "content-length" header was read, which helps to determine how much more content is needed before the next STOMP frame can be decoded.

      Parameters:
        `buffer` - The buffer to decode the STOMP frame from
        `headers` - an empty map that will contain successfully parsed headers in cases where the partial buffer ended with a partial STOMP frame
      Returns:
        decoded messages or an empty list
      Throws:
        `StompConversionException` - raised in case of decoding issues

    - #### skipLeadingEol

          protected void skipLeadingEol(ByteBuffer buffer)

      Skip one ore more EOL characters at the start of the given ByteBuffer. Those are STOMP heartbeat frames.

    - #### getContentLength

          protected Integer getContentLength(MultiValueMap<String,String> headers)