starlight
starlight copied to clipboard
Fail-fast in unpack will be better?
BaiduRpcProtocol now is below
int bodySize = fixHeaderBuf.readInt();
if (in.readableBytes() < FIXED_LEN + bodySize) {
throw notEnoughDataException;
}
// 512M
if (bodySize > 512 * 1024 * 1024) {
throw new TooBigDataException("to big body size:" + bodySize);
}
change sequence like this will be better?
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;
}
why? Since notEnoughDataException is more likely to happen than TooBigDataException.