* Correct byte order
* All encoders should ignore the message whose type is unknown to the encoder
This commit is contained in:
parent
b859f120d8
commit
2b2d53ff62
@ -167,6 +167,7 @@ public class Base64 {
|
|||||||
|
|
||||||
int len43 = len * 4 / 3;
|
int len43 = len * 4 / 3;
|
||||||
ChannelBuffer dest = bufferFactory.getBuffer(
|
ChannelBuffer dest = bufferFactory.getBuffer(
|
||||||
|
src.order(),
|
||||||
len43 +
|
len43 +
|
||||||
(len % 3 > 0? 4 : 0) + // Account for padding
|
(len % 3 > 0? 4 : 0) + // Account for padding
|
||||||
(breakLines? len43 / MAX_LINE_LENGTH : 0)); // New lines
|
(breakLines? len43 / MAX_LINE_LENGTH : 0)); // New lines
|
||||||
@ -292,7 +293,7 @@ public class Base64 {
|
|||||||
byte[] DECODABET = decodabet(dialect);
|
byte[] DECODABET = decodabet(dialect);
|
||||||
|
|
||||||
int len34 = len * 3 / 4;
|
int len34 = len * 3 / 4;
|
||||||
ChannelBuffer dest = bufferFactory.getBuffer(len34); // Upper limit on size of output
|
ChannelBuffer dest = bufferFactory.getBuffer(src.order(), len34); // Upper limit on size of output
|
||||||
int outBuffPosn = 0;
|
int outBuffPosn = 0;
|
||||||
|
|
||||||
byte[] b4 = new byte[4];
|
byte[] b4 = new byte[4];
|
||||||
|
@ -107,8 +107,12 @@ public class LengthFieldPrepender 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 {
|
||||||
ChannelBuffer header = channel.getConfig().getBufferFactory().getBuffer(lengthFieldLength);
|
if (!(msg instanceof ChannelBuffer)) {
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
ChannelBuffer body = (ChannelBuffer) msg;
|
ChannelBuffer body = (ChannelBuffer) msg;
|
||||||
|
ChannelBuffer header = channel.getConfig().getBufferFactory().getBuffer(body.order(), lengthFieldLength);
|
||||||
|
|
||||||
int length = lengthIncludesLengthFieldLength?
|
int length = lengthIncludesLengthFieldLength?
|
||||||
body.readableBytes() + lengthFieldLength : body.readableBytes();
|
body.readableBytes() + lengthFieldLength : body.readableBytes();
|
||||||
|
@ -44,10 +44,15 @@ public class ProtobufVarint32LengthFieldPrepender extends OneToOneEncoder {
|
|||||||
@Override
|
@Override
|
||||||
protected Object encode(ChannelHandlerContext ctx, Channel channel,
|
protected Object encode(ChannelHandlerContext ctx, Channel channel,
|
||||||
Object msg) throws Exception {
|
Object msg) throws Exception {
|
||||||
|
if (!(msg instanceof ChannelBuffer)) {
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
ChannelBuffer body = (ChannelBuffer) msg;
|
ChannelBuffer body = (ChannelBuffer) msg;
|
||||||
int length = body.readableBytes();
|
int length = body.readableBytes();
|
||||||
ChannelBuffer header =
|
ChannelBuffer header =
|
||||||
channel.getConfig().getBufferFactory().getBuffer(
|
channel.getConfig().getBufferFactory().getBuffer(
|
||||||
|
body.order(),
|
||||||
CodedOutputStream.computeRawVarint32Size(length));
|
CodedOutputStream.computeRawVarint32Size(length));
|
||||||
CodedOutputStream codedOutputStream = CodedOutputStream
|
CodedOutputStream codedOutputStream = CodedOutputStream
|
||||||
.newInstance(new ChannelBufferOutputStream(header));
|
.newInstance(new ChannelBufferOutputStream(header));
|
||||||
|
Loading…
Reference in New Issue
Block a user