ProtoDecoder implements Decoder { @Override @SuppressWarnings("unchecked") public <T> T decode(ByteBuf body, CharSequence contentType, Class<T> clazz) throws IOException { if (!MessageLite.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException( String.format("%s does not extend from MessageLite", clazz.getName())); } MessageLite message = protoDefaultInstances.get(clazz); Parser<?> parser = message.getParserForType(); try (ByteBufInputStream stream = new ByteBufInputStream(body)) { return (T) parser.parseFrom(stream); } }  @Override CharSequence mediaType(); @Override @SuppressWarnings("unchecked") T decode(ByteBuf body, CharSequence contentType, Class<T> clazz);  }
@Test void testDecode() throws IOException { Dino result = decoder.decode(Unpooled.wrappedBuffer(dino.toByteArray()), "", Dino.class); assertEquals(dino, result); }