本文整理汇总了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;
}