use of com.baidu.brpc.exceptions.TooBigDataException in project brpc-java by baidu.
the class DubboRpcProtocol method decode.
@Override
public Object decode(ChannelHandlerContext ctx, DynamicCompositeByteBuf in, boolean isDecodingRequest) throws TooBigDataException, NotEnoughDataException, BadSchemaException {
if (in.readableBytes() < DubboConstants.FIXED_HEAD_LEN) {
throw notEnoughDataException;
}
ByteBuf headerBuf = in.retainedSlice(DubboConstants.FIXED_HEAD_LEN);
try {
DubboHeader dubboHeader = DubboHeader.decode(headerBuf);
if (dubboHeader.getMagic() != DubboConstants.MAGIC) {
throw new BadSchemaException("not valid magic head for dubbo");
}
// 512M
if (dubboHeader.getBodyLength() > 512 * 1024 * 1024) {
throw new TooBigDataException("dubbo too big body size:" + dubboHeader.getBodyLength());
}
if (in.readableBytes() < dubboHeader.getBodyLength() + DubboConstants.FIXED_HEAD_LEN) {
throw notEnoughDataException;
}
in.skipBytes(DubboConstants.FIXED_HEAD_LEN);
ByteBuf bodyBuf = in.readRetainedSlice(dubboHeader.getBodyLength());
DubboPacket dubboPacket = new DubboPacket();
dubboPacket.setHeader(dubboHeader);
dubboPacket.setBodyBuf(bodyBuf);
return dubboPacket;
} finally {
headerBuf.release();
}
}
use of com.baidu.brpc.exceptions.TooBigDataException in project brpc-java by baidu.
the class HuluRpcProtocol method decode.
@Override
public HuluRpcDecodePacket decode(ChannelHandlerContext ctx, DynamicCompositeByteBuf in, boolean isDecodingRequest) throws BadSchemaException, TooBigDataException, NotEnoughDataException {
if (in.readableBytes() < FIXED_LEN) {
throw notEnoughDataException;
}
ByteBuf fixHeaderBuf = in.retainedSlice(FIXED_LEN);
try {
byte[] magic = new byte[4];
fixHeaderBuf.readBytes(magic);
if (!Arrays.equals(magic, MAGIC_HEAD)) {
throw new BadSchemaException("not valid magic head for hulu");
}
int bodySize = fixHeaderBuf.readIntLE();
int metaSize = fixHeaderBuf.readIntLE();
// 512M
if (bodySize > 512 * 1024 * 1024) {
throw new TooBigDataException("to big body size:" + bodySize);
}
if (in.readableBytes() < FIXED_LEN + bodySize) {
throw notEnoughDataException;
}
in.skipBytes(FIXED_LEN);
HuluRpcDecodePacket packet = new HuluRpcDecodePacket();
try {
// meta
ByteBuf metaBuf = in.readRetainedSlice(metaSize);
packet.setMetaBuf(metaBuf);
// body
ByteBuf protoAndAttachmentBuf = in.readRetainedSlice(bodySize - metaSize);
packet.setProtoAndAttachmentBuf(protoAndAttachmentBuf);
return packet;
} catch (Exception ex) {
LOG.warn("decode failed, ex={}", ex.getMessage());
throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, ex);
}
} finally {
fixHeaderBuf.release();
}
}
use of com.baidu.brpc.exceptions.TooBigDataException in project brpc-java by baidu.
the class PublicPbrpcProtocol method decode.
@Override
public PublicPbRpcPacket decode(ChannelHandlerContext ctx, DynamicCompositeByteBuf in, boolean isDecodingRequest) throws BadSchemaException, TooBigDataException, NotEnoughDataException {
if (in.readableBytes() < NSHead.NSHEAD_LENGTH) {
throw notEnoughDataException;
}
PublicPbRpcPacket packet = new PublicPbRpcPacket();
ByteBuf fixHeaderBuf = in.retainedSlice(NSHead.NSHEAD_LENGTH);
try {
NSHead nsHead = NSHead.fromByteBuf(fixHeaderBuf);
packet.setNsHead(nsHead);
int bodyLength = nsHead.bodyLength;
// 512M
if (bodyLength > 512 * 1024 * 1024) {
throw new TooBigDataException("to big body size:" + bodyLength);
}
if (in.readableBytes() < NSHead.NSHEAD_LENGTH + bodyLength) {
throw notEnoughDataException;
}
in.skipBytes(NSHead.NSHEAD_LENGTH);
ByteBuf bodyBuf = in.readRetainedSlice(bodyLength);
packet.setBody(bodyBuf);
return packet;
} finally {
fixHeaderBuf.release();
}
}
use of com.baidu.brpc.exceptions.TooBigDataException in project brpc-java by baidu.
the class SofaRpcProtocol method decode.
@Override
public SofaRpcDecodePacket decode(ChannelHandlerContext ctx, DynamicCompositeByteBuf in, boolean isDecodingRequest) throws BadSchemaException, TooBigDataException, NotEnoughDataException {
if (in.readableBytes() < FIXED_LEN) {
throw notEnoughDataException;
}
ByteBuf fixHeaderBuf = in.retainedSlice(FIXED_LEN);
try {
byte[] magic = new byte[4];
fixHeaderBuf.readBytes(magic);
if (!Arrays.equals(magic, MAGIC_HEAD)) {
throw new BadSchemaException("not valid magic head for sofa");
}
int metaSize = fixHeaderBuf.readIntLE();
int bodySize = (int) fixHeaderBuf.readLongLE();
int msgSize = (int) fixHeaderBuf.readLongLE();
if (msgSize != metaSize + bodySize) {
throw new BadSchemaException("msgSize != metaSize + bodySize");
}
// 512M
if (bodySize > 512 * 1024 * 1024) {
throw new TooBigDataException("to big body size:" + bodySize);
}
if (in.readableBytes() < FIXED_LEN + msgSize) {
throw notEnoughDataException;
}
in.skipBytes(FIXED_LEN);
SofaRpcDecodePacket packet = new SofaRpcDecodePacket();
try {
// meta
ByteBuf metaBuf = in.readRetainedSlice(metaSize);
packet.setMetaBuf(metaBuf);
// body
ByteBuf protoBuf = in.readRetainedSlice(bodySize);
packet.setProtoBuf(protoBuf);
return packet;
} catch (Exception ex) {
LOG.debug("decode failed, ex={}", ex.getMessage());
throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, ex);
}
} finally {
fixHeaderBuf.release();
}
}
use of com.baidu.brpc.exceptions.TooBigDataException in project brpc-java by baidu.
the class BaiduRpcProtocol method decode.
@Override
public BaiduRpcDecodePacket decode(ChannelHandlerContext ctx, DynamicCompositeByteBuf in, boolean isDecodingRequest) throws BadSchemaException, TooBigDataException, NotEnoughDataException {
if (in.readableBytes() < FIXED_LEN) {
throw notEnoughDataException;
}
ByteBuf fixHeaderBuf = in.retainedSlice(FIXED_LEN);
try {
byte[] magic = new byte[4];
fixHeaderBuf.readBytes(magic);
if (!Arrays.equals(magic, MAGIC_HEAD)) {
throw new BadSchemaException("not valid magic head for brpc");
}
int bodySize = fixHeaderBuf.readInt();
// 512M
if (bodySize > 512 * 1024 * 1024) {
throw new TooBigDataException("to big body size:" + bodySize);
}
if (in.readableBytes() < FIXED_LEN + bodySize) {
throw notEnoughDataException;
}
int metaSize = fixHeaderBuf.readInt();
in.skipBytes(FIXED_LEN);
BaiduRpcDecodePacket packet = new BaiduRpcDecodePacket();
try {
// meta
ByteBuf metaBuf = in.readRetainedSlice(metaSize);
packet.setMetaBuf(metaBuf);
// proto and attachment
ByteBuf protoAndAttachmentBuf = in.readRetainedSlice(bodySize - metaSize);
packet.setProtoAndAttachmentBuf(protoAndAttachmentBuf);
return packet;
} catch (Exception ex) {
LOG.warn("decode failed:", ex);
throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, ex);
}
} finally {
fixHeaderBuf.release();
}
}
Aggregations