Fixed issue: NETTY-314 ProtobufEncoder and ProtobufDecoder should accept MessageLite as well as Message.

This commit is contained in:
Trustin Lee 2010-05-06 04:11:11 +00:00
parent 1793c659ca
commit 56cdf73cb9
2 changed files with 13 additions and 11 deletions

View File

@ -29,14 +29,15 @@ import org.jboss.netty.handler.codec.oneone.OneToOneDecoder;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.Message;
import com.google.protobuf.MessageLite;
/**
* Decodes a received {@link ChannelBuffer} into a
* <a href="http://code.google.com/p/protobuf/">Google Protocol Buffers</a>
* {@link Message}. Please note that this decoder must be used with a proper
* {@link FrameDecoder} such as {@link LengthFieldBasedFrameDecoder} if you are
* using a stream-based transport such as TCP/IP. A typical setup for TCP/IP
* would be:
* {@link Message} and {@link MessageLite}. Please note that this decoder must
* be used with a proper {@link FrameDecoder} such as {@link ProtobufVarint32FrameDecoder}
* or {@link LengthFieldBasedFrameDecoder} if you are using a stream-based
* transport such as TCP/IP. A typical setup for TCP/IP would be:
* <pre>
* {@link ChannelPipeline} pipeline = ...;
*
@ -71,17 +72,17 @@ import com.google.protobuf.Message;
@Sharable
public class ProtobufDecoder extends OneToOneDecoder {
private final Message prototype;
private final MessageLite prototype;
private final ExtensionRegistry extensionRegistry;
/**
* Creates a new instance.
*/
public ProtobufDecoder(Message prototype) {
public ProtobufDecoder(MessageLite prototype) {
this(prototype, null);
}
public ProtobufDecoder(Message prototype, ExtensionRegistry extensionRegistry) {
public ProtobufDecoder(MessageLite prototype, ExtensionRegistry extensionRegistry) {
if (prototype == null) {
throw new NullPointerException("prototype");
}

View File

@ -28,11 +28,12 @@ import org.jboss.netty.handler.codec.frame.LengthFieldPrepender;
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
import com.google.protobuf.Message;
import com.google.protobuf.MessageLite;
/**
* Encodes the requested <a href="http://code.google.com/p/protobuf/">Google
* Protocol Buffers</a> {@link Message} into a {@link ChannelBuffer}.
* A typical setup for TCP/IP would be:
* Protocol Buffers</a> {@link Message} and {@link MessageLite} into a
* {@link ChannelBuffer}. A typical setup for TCP/IP would be:
* <pre>
* {@link ChannelPipeline} pipeline = ...;
*
@ -77,9 +78,9 @@ public class ProtobufEncoder extends OneToOneEncoder {
@Override
protected Object encode(
ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
if (!(msg instanceof Message)) {
if (!(msg instanceof MessageLite)) {
return msg;
}
return wrappedBuffer(((Message) msg).toByteArray());
return wrappedBuffer(((MessageLite) msg).toByteArray());
}
}