Search in sources :

Example 6 with DecodingException

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);
    }
}
Also used : Message(com.google.protobuf.Message) DecodingException(cn.taketoday.core.codec.DecodingException) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) IOException(java.io.IOException) DataBufferLimitException(cn.taketoday.core.io.buffer.DataBufferLimitException) DecodingException(cn.taketoday.core.codec.DecodingException)

Aggregations

DecodingException (cn.taketoday.core.codec.DecodingException)6 Message (com.google.protobuf.Message)4 DataBufferLimitException (cn.taketoday.core.io.buffer.DataBufferLimitException)2 HttpHeaders (cn.taketoday.http.HttpHeaders)2 MediaType (cn.taketoday.http.MediaType)2 ReactiveHttpOutputMessage (cn.taketoday.http.ReactiveHttpOutputMessage)2 HttpMessageEncoder (cn.taketoday.http.codec.HttpMessageEncoder)2 ConcurrentReferenceHashMap (cn.taketoday.util.ConcurrentReferenceHashMap)2 Descriptors (com.google.protobuf.Descriptors)2 IOException (java.io.IOException)2 ByteBuffer (java.nio.ByteBuffer)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Flux (reactor.core.publisher.Flux)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1