[#1338] Respect default ByteOrder of ChannelBufferFactory when using ProtoBufEncoder

This commit is contained in:
Norman Maurer 2013-05-12 13:10:49 +02:00
parent 23a919cdcd
commit 56c34214f8

View File

@ -15,8 +15,6 @@
*/
package org.jboss.netty.handler.codec.protobuf;
import static org.jboss.netty.buffer.ChannelBuffers.*;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandler.Sharable;
@ -67,10 +65,12 @@ public class ProtobufEncoder extends OneToOneEncoder {
protected Object encode(
ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
if (msg instanceof MessageLite) {
return wrappedBuffer(((MessageLite) msg).toByteArray());
byte[] array = ((MessageLite) msg).toByteArray();
return ctx.getChannel().getConfig().getBufferFactory().getBuffer(array, 0, array.length);
}
if (msg instanceof MessageLite.Builder) {
return wrappedBuffer(((MessageLite.Builder) msg).build().toByteArray());
byte[] array = ((MessageLite.Builder) msg).build().toByteArray();
return ctx.getChannel().getConfig().getBufferFactory().getBuffer(array, 0, array.length);
}
return msg;
}