use of cn.taketoday.core.codec.DecodingException in project today-framework by TAKETODAY.
the class ProtobufDecoder method decode.
@Override
public Message decode(DataBuffer dataBuffer, ResolvableType targetType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) throws DecodingException {
try {
Message.Builder builder = getMessageBuilder(targetType.toClass());
ByteBuffer buffer = dataBuffer.asByteBuffer();
builder.mergeFrom(CodedInputStream.newInstance(buffer), this.extensionRegistry);
return builder.build();
} catch (IOException ex) {
throw new DecodingException("I/O error while parsing input stream", ex);
} catch (Exception ex) {
throw new DecodingException("Could not read Protobuf message: " + ex.getMessage(), ex);
} finally {
DataBufferUtils.release(dataBuffer);
}
}
Aggregations