Fixed issue: NETTY-314 ProtobufEncoder and ProtobufDecoder should accept MessageLite as well as Message.
This commit is contained in:
parent
1793c659ca
commit
56cdf73cb9
@ -29,14 +29,15 @@ import org.jboss.netty.handler.codec.oneone.OneToOneDecoder;
|
|||||||
|
|
||||||
import com.google.protobuf.ExtensionRegistry;
|
import com.google.protobuf.ExtensionRegistry;
|
||||||
import com.google.protobuf.Message;
|
import com.google.protobuf.Message;
|
||||||
|
import com.google.protobuf.MessageLite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decodes a received {@link ChannelBuffer} into a
|
* Decodes a received {@link ChannelBuffer} into a
|
||||||
* <a href="http://code.google.com/p/protobuf/">Google Protocol Buffers</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 Message} and {@link MessageLite}. Please note that this decoder must
|
||||||
* {@link FrameDecoder} such as {@link LengthFieldBasedFrameDecoder} if you are
|
* be used with a proper {@link FrameDecoder} such as {@link ProtobufVarint32FrameDecoder}
|
||||||
* using a stream-based transport such as TCP/IP. A typical setup for TCP/IP
|
* or {@link LengthFieldBasedFrameDecoder} if you are using a stream-based
|
||||||
* would be:
|
* transport such as TCP/IP. A typical setup for TCP/IP would be:
|
||||||
* <pre>
|
* <pre>
|
||||||
* {@link ChannelPipeline} pipeline = ...;
|
* {@link ChannelPipeline} pipeline = ...;
|
||||||
*
|
*
|
||||||
@ -71,17 +72,17 @@ import com.google.protobuf.Message;
|
|||||||
@Sharable
|
@Sharable
|
||||||
public class ProtobufDecoder extends OneToOneDecoder {
|
public class ProtobufDecoder extends OneToOneDecoder {
|
||||||
|
|
||||||
private final Message prototype;
|
private final MessageLite prototype;
|
||||||
private final ExtensionRegistry extensionRegistry;
|
private final ExtensionRegistry extensionRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance.
|
* Creates a new instance.
|
||||||
*/
|
*/
|
||||||
public ProtobufDecoder(Message prototype) {
|
public ProtobufDecoder(MessageLite prototype) {
|
||||||
this(prototype, null);
|
this(prototype, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProtobufDecoder(Message prototype, ExtensionRegistry extensionRegistry) {
|
public ProtobufDecoder(MessageLite prototype, ExtensionRegistry extensionRegistry) {
|
||||||
if (prototype == null) {
|
if (prototype == null) {
|
||||||
throw new NullPointerException("prototype");
|
throw new NullPointerException("prototype");
|
||||||
}
|
}
|
||||||
|
@ -28,11 +28,12 @@ import org.jboss.netty.handler.codec.frame.LengthFieldPrepender;
|
|||||||
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
|
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
|
||||||
|
|
||||||
import com.google.protobuf.Message;
|
import com.google.protobuf.Message;
|
||||||
|
import com.google.protobuf.MessageLite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encodes the requested <a href="http://code.google.com/p/protobuf/">Google
|
* Encodes the requested <a href="http://code.google.com/p/protobuf/">Google
|
||||||
* Protocol Buffers</a> {@link Message} into a {@link ChannelBuffer}.
|
* Protocol Buffers</a> {@link Message} and {@link MessageLite} into a
|
||||||
* A typical setup for TCP/IP would be:
|
* {@link ChannelBuffer}. A typical setup for TCP/IP would be:
|
||||||
* <pre>
|
* <pre>
|
||||||
* {@link ChannelPipeline} pipeline = ...;
|
* {@link ChannelPipeline} pipeline = ...;
|
||||||
*
|
*
|
||||||
@ -77,9 +78,9 @@ public class ProtobufEncoder extends OneToOneEncoder {
|
|||||||
@Override
|
@Override
|
||||||
protected Object encode(
|
protected Object encode(
|
||||||
ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
|
ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
|
||||||
if (!(msg instanceof Message)) {
|
if (!(msg instanceof MessageLite)) {
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
return wrappedBuffer(((Message) msg).toByteArray());
|
return wrappedBuffer(((MessageLite) msg).toByteArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user