本文整理匯總了Java中io.netty.buffer.ByteBufUtil.swapMedium方法的典型用法代碼示例。如果您正苦於以下問題:Java ByteBufUtil.swapMedium方法的具體用法?Java ByteBufUtil.swapMedium怎麽用?Java ByteBufUtil.swapMedium使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.netty.buffer.ByteBufUtil
的用法示例。
在下文中一共展示了ByteBufUtil.swapMedium方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: readIndex
import io.netty.buffer.ByteBufUtil; //導入方法依賴的package包/類
Integer readIndex(ByteBuf in) {
if (in.readableBytes() < 1) return null;
int[] prev = prev_positive;
int b = in.readUnsignedByte();
if (b == 0xff) {
prev = prev_negative;
if (in.readableBytes() < 1) return null;
b = in.readUnsignedByte();
} else if (b == 0) {
return NDX_DONE;
}
int num;
if (b == 0xfe) {
if (in.readableBytes() < 2) return null;
b = in.readUnsignedByte();
if ((b & 0x80) == 0x80) {
if (in.readableBytes() < 3) return null;
num = ByteBufUtil.swapMedium(in.readMedium()) + ((b & ~0x80) << 24);
} else {
num = (b << 8) + in.readByte() + prev[0];
}
} else {
num = b + prev[0];
}
prev[0] = num;
if (prev == prev_negative)
num = -num;
return num;
}
示例2: decode
import io.netty.buffer.ByteBufUtil; //導入方法依賴的package包/類
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
if (in.readableBytes() < 4) return;
int dataSize = ByteBufUtil.swapMedium(in.readUnsignedMedium());
int tagByte = in.readUnsignedByte();
MessageType tag = MessageType.typeForTag(tagByte - MPLEX_BASE);
// todo: be better about this.
if (tag == null) throw new Exception("Invalid tag: " + (tagByte - MPLEX_BASE));
switch (tag) {
case MSG_DATA:
if (in.readableBytes() < dataSize) {
in.resetReaderIndex();
return;
}
if (dataSize > 0x10000)
LOGGER.debug("Very large data packet received, {} bytes", dataSize);
ByteBuf content = ctx.alloc().heapBuffer(dataSize);
content.writeBytes(in.readBytes(dataSize));
out.add(content);
break;
default:
throw new Exception("Unhandled tag: " + tag);
}
}
示例3: decodeLiteral
import io.netty.buffer.ByteBufUtil; //導入方法依賴的package包/類
/**
* Reads a literal from the input buffer directly to the output buffer.
* A "literal" is an uncompressed segment of data stored directly in the
* byte stream.
*
* @param tag The tag that identified this segment as a literal is also
* used to encode part of the length of the data
* @param in The input buffer to read the literal from
* @param out The output buffer to write the literal to
* @return The number of bytes appended to the output buffer, or -1 to indicate "try again later"
*/
private static int decodeLiteral(byte tag, ByteBuf in, ByteBuf out) {
in.markReaderIndex();
int length;
switch(tag >> 2 & 0x3F) {
case 60:
if (!in.isReadable()) {
return NOT_ENOUGH_INPUT;
}
length = in.readUnsignedByte();
break;
case 61:
if (in.readableBytes() < 2) {
return NOT_ENOUGH_INPUT;
}
length = ByteBufUtil.swapShort(in.readShort());
break;
case 62:
if (in.readableBytes() < 3) {
return NOT_ENOUGH_INPUT;
}
length = ByteBufUtil.swapMedium(in.readUnsignedMedium());
break;
case 64:
if (in.readableBytes() < 4) {
return NOT_ENOUGH_INPUT;
}
length = ByteBufUtil.swapInt(in.readInt());
break;
default:
length = tag >> 2 & 0x3F;
}
length += 1;
if (in.readableBytes() < length) {
in.resetReaderIndex();
return NOT_ENOUGH_INPUT;
}
out.writeBytes(in, length);
return length;
}
示例4: decodeLiteral
import io.netty.buffer.ByteBufUtil; //導入方法依賴的package包/類
/**
* Reads a literal from the input buffer directly to the output buffer.
* A "literal" is an uncompressed segment of data stored directly in the
* byte stream.
*
* @param tag The tag that identified this segment as a literal is also
* used to encode part of the length of the data
* @param in The input buffer to read the literal from
* @param out The output buffer to write the literal to
* @return The number of bytes appended to the output buffer, or -1 to indicate "try again later"
*/
static int decodeLiteral(byte tag, ByteBuf in, ByteBuf out) {
in.markReaderIndex();
int length;
switch(tag >> 2 & 0x3F) {
case 60:
if (!in.isReadable()) {
return NOT_ENOUGH_INPUT;
}
length = in.readUnsignedByte();
break;
case 61:
if (in.readableBytes() < 2) {
return NOT_ENOUGH_INPUT;
}
length = ByteBufUtil.swapShort(in.readShort());
break;
case 62:
if (in.readableBytes() < 3) {
return NOT_ENOUGH_INPUT;
}
length = ByteBufUtil.swapMedium(in.readUnsignedMedium());
break;
case 63:
if (in.readableBytes() < 4) {
return NOT_ENOUGH_INPUT;
}
length = ByteBufUtil.swapInt(in.readInt());
break;
default:
length = tag >> 2 & 0x3F;
}
length += 1;
if (in.readableBytes() < length) {
in.resetReaderIndex();
return NOT_ENOUGH_INPUT;
}
out.writeBytes(in, length);
return length;
}