/** * Decodes one or more STOMP frames from the given {@code ByteBuffer} into a * list of {@link Message Messages}. * <p>If there was enough data to parse a "content-length" header, then the * value is used to determine how much more data is needed before a new * attempt to decode is made. * <p>If there was not enough data to parse the "content-length", or if there * is "content-length" header, every subsequent call to decode attempts to * parse again with all available data. Therefore the presence of a "content-length" * header helps to optimize the decoding of large messages. * @param newBuffer a buffer containing new data to decode * @return decoded messages or an empty list * @throws StompConversionException raised in case of decoding issues */ public List<Message<byte[]>> decode(ByteBuffer newBuffer) { this.chunks.add(newBuffer); checkBufferLimits(); Integer contentLength = this.expectedContentLength; if (contentLength != null && getBufferSize() < contentLength) { return Collections.emptyList(); } ByteBuffer bufferToDecode = assembleChunksAndReset(); MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); List<Message<byte[]>> messages = this.stompDecoder.decode(bufferToDecode, headers); if (bufferToDecode.hasRemaining()) { this.chunks.add(bufferToDecode); this.expectedContentLength = StompHeaderAccessor.getContentLength(headers); } return messages; }
/** * Decodes one or more STOMP frames from the given {@code ByteBuffer} into a * list of {@link Message Messages}. * <p>If there was enough data to parse a "content-length" header, then the * value is used to determine how much more data is needed before a new * attempt to decode is made. * <p>If there was not enough data to parse the "content-length", or if there * is "content-length" header, every subsequent call to decode attempts to * parse again with all available data. Therefore the presence of a "content-length" * header helps to optimize the decoding of large messages. * @param newBuffer a buffer containing new data to decode * @return decoded messages or an empty list * @throws StompConversionException raised in case of decoding issues */ public List<Message<byte[]>> decode(ByteBuffer newBuffer) { this.chunks.add(newBuffer); checkBufferLimits(); Integer contentLength = this.expectedContentLength; if (contentLength != null && getBufferSize() < contentLength) { return Collections.emptyList(); } ByteBuffer bufferToDecode = assembleChunksAndReset(); MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); List<Message<byte[]>> messages = this.stompDecoder.decode(bufferToDecode, headers); if (bufferToDecode.hasRemaining()) { this.chunks.add(bufferToDecode); this.expectedContentLength = StompHeaderAccessor.getContentLength(headers); } return messages; }
/** * Decodes one or more STOMP frames from the given {@code ByteBuffer} into a * list of {@link Message Messages}. * <p>If there was enough data to parse a "content-length" header, then the * value is used to determine how much more data is needed before a new * attempt to decode is made. * <p>If there was not enough data to parse the "content-length", or if there * is "content-length" header, every subsequent call to decode attempts to * parse again with all available data. Therefore the presence of a "content-length" * header helps to optimize the decoding of large messages. * @param newBuffer a buffer containing new data to decode * @return decoded messages or an empty list * @throws StompConversionException raised in case of decoding issues */ public List<Message<byte[]>> decode(ByteBuffer newBuffer) { this.chunks.add(newBuffer); checkBufferLimits(); Integer contentLength = this.expectedContentLength; if (contentLength != null && getBufferSize() < contentLength) { return Collections.emptyList(); } ByteBuffer bufferToDecode = assembleChunksAndReset(); MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); List<Message<byte[]>> messages = this.stompDecoder.decode(bufferToDecode, headers); if (bufferToDecode.hasRemaining()) { this.chunks.add(bufferToDecode); this.expectedContentLength = StompHeaderAccessor.getContentLength(headers); } return messages; }
/** * Decodes one or more STOMP frames from the given {@code ByteBuffer} into a * list of {@link Message Messages}. * <p>If there was enough data to parse a "content-length" header, then the * value is used to determine how much more data is needed before a new * attempt to decode is made. * <p>If there was not enough data to parse the "content-length", or if there * is "content-length" header, every subsequent call to decode attempts to * parse again with all available data. Therefore the presence of a "content-length" * header helps to optimize the decoding of large messages. * @param newBuffer a buffer containing new data to decode * @return decoded messages or an empty list * @throws StompConversionException raised in case of decoding issues */ public List<Message<byte[]>> decode(ByteBuffer newBuffer) { this.chunks.add(newBuffer); checkBufferLimits(); Integer contentLength = this.expectedContentLength; if (contentLength != null && getBufferSize() < contentLength) { return Collections.emptyList(); } ByteBuffer bufferToDecode = assembleChunksAndReset(); MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); List<Message<byte[]>> messages = this.stompDecoder.decode(bufferToDecode, headers); if (bufferToDecode.hasRemaining()) { this.chunks.add(bufferToDecode); this.expectedContentLength = StompHeaderAccessor.getContentLength(headers); } return messages; }