Class MessageDecoder


  • public final class MessageDecoder
    extends Object
    A simple decoder that accumulates chunks of bytes and emits eventstream messages. Instances of this class are not thread-safe.
    • Constructor Detail

      • MessageDecoder

        public MessageDecoder()
        Creates a MessageDecoder instance that will buffer messages internally as they are decoded. Decoded messages can be obtained by calling getDecodedMessages().
      • MessageDecoder

        public MessageDecoder​(Consumer<Message> messageConsumer)
        Creates a MessageDecoder instance that will publish messages incrementally to the supplied messageConsumer as they are decoded. The resulting instance does not support the getDecodedMessages() operation, and will throw an exception if it is invoked.
        Parameters:
        messageConsumer - a function that consumes Message instances
    • Method Detail

      • getDecodedMessages

        public List<Message> getDecodedMessages()
        Returns Message instances that have been decoded since this method was last invoked. Note that this method is only supported if this decoder was not configured to use a custom message consumer.
        Returns:
        all messages decoded since the last invocation of this method
      • feed

        public void feed​(byte[] bytes)
      • feed

        public void feed​(byte[] bytes,
                         int offset,
                         int length)
      • feed

        public MessageDecoder feed​(ByteBuffer byteBuffer)
        Feed the contents of the given ByteBuffer into this decoder. Messages will be incrementally decoded and buffered or published to the message consumer (depending on configuration).
        Parameters:
        byteBuffer - a ByteBuffer whose entire contents will be read into the decoder's internal buffer
        Returns:
        this MessageDecoder instance