/** * Take raw data and convert it to messages. Each raw message may produce multiple messages and therefore * multiple errors. A {@link MessageParserResult} is returned, which will have both the messages produced * and the errors. * @param parseMessage the raw bytes of the message * @return Optional of {@link MessageParserResult} */ default Optional<MessageParserResult<T>> parseOptionalResult(byte[] parseMessage) { Optional<MessageParserResult<T>> result = Optional.empty(); try { Optional<List<T>> optionalMessages = parseOptional(parseMessage); if (optionalMessages.isPresent()) { result = Optional.of(new DefaultMessageParserResult<>(optionalMessages.get())); } } catch (Throwable t) { return Optional.of(new DefaultMessageParserResult<>(t)); } return result; }