本文整理汇总了Java中io.netty.buffer.ByteBuf.readShort方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuf.readShort方法的具体用法?Java ByteBuf.readShort怎么用?Java ByteBuf.readShort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.buffer.ByteBuf
的用法示例。
在下文中一共展示了ByteBuf.readShort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: channelRead0
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
while (true) {
if (byteBuf.readableBytes() < FrameSetting.FRAME_HEAD_LENGTH) {
return;
}
if (byteBuf.readByte() != FrameSetting.MAJOR_FRAME_HEAD_1
|| byteBuf.readByte() != FrameSetting.MAJOR_FRAME_HEAD_2) {
return;
}
int groupId = byteBuf.readByte() & 0xFF;
int msgId = byteBuf.readByte() & 0xFF;
int deviceId = byteBuf.readByte() & 0xFF;
int backupMsg = byteBuf.readByte() & 0xFF;
int dataLength = byteBuf.readShort() & 0xFF;
FrameMajorHeader headMsg = new FrameMajorHeader(msgId, groupId, deviceId, dataLength, backupMsg);
ByteBuf subBuf = ctx.alloc().buffer(dataLength);
byteBuf.readBytes(subBuf, dataLength);
ctx.fireChannelRead(new FrameMajor(headMsg, subBuf));
}
}
示例2: fromBytes
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void fromBytes(ByteBuf buf) {
short len = buf.readShort();
byte[] compressedBody = new byte[len];
for (short i = 0; i < len; i++) {
compressedBody[i] = buf.readByte();
}
try {
ObjectInputStream obj = new ObjectInputStream(new GZIPInputStream(new ByteArrayInputStream(compressedBody)));
values = (Map<String, Object>) obj.readObject();
obj.close();
}
catch (Exception e) {
Throwables.propagate(e);
}
}
示例3: decode
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
if (!hasHeader) {
if (in.readableBytes() >= 7) {
short id = in.readShort();
int payloadLength = in.readMedium();
short version = in.readShort();
hasHeader = true;
header.id = id;
header.payload = new byte[payloadLength];
}
} else {
if (in.readableBytes() >= header.payload.length) {
in.readBytes(header.payload);
hasHeader = false;
crypto.decryptPacket(header);
ClientMessage message = processPacket();
if (message != null) {
out.add(message);
}
}
}
}
示例4: decode
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
try {
//LibraLog.info("decode is bytebuf in is :" + JsonUtil.ObjectToJsonString(in.array()));
// 空的buf
if (in instanceof EmptyByteBuf || in.readableBytes() < 0) {
return;
}
short length = in.readShort();
if (length != in.readableBytes()) {
return;
}
// 反序列化
LibraMessage message = LibraMessage.decode(in);
if (message == null) {
return;
}
out.add(message);
} catch (Exception e) {
e.printStackTrace();
return;
}
}
示例5: channelRead
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
ByteBuf buf = (ByteBuf) msg;
int curCount = buf.readShort();
if (curCount == -1) {
scheduleSrv.schedule(new Runnable() {
@Override
public void run() {
ctx.close();
}
}, 3, TimeUnit.SECONDS);
} else {
int idx = curCount - 1;
long time = buf.readInt();
if (rtts[idx] != -1) {
log.error("???");
}
//log.info("rcv count {} {}", curCount, System.currentTimeMillis());
rtts[idx] = (int) (System.currentTimeMillis() - startTime - time);
log.info("rtt {}: {}", curCount, rtts[idx]);
}
buf.release();
}
示例6: fromBytes
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void fromBytes(ByteBuf buf) {
short len = buf.readShort();
byte[] compressedBody = new byte[len];
for (short i = 0; i < len; i++) {
compressedBody[i] = buf.readByte();
}
try {
ObjectInputStream obj = new ObjectInputStream(new GZIPInputStream(new ByteArrayInputStream(compressedBody)));
registry = (Map<Integer, UUID>) obj.readObject();
obj.close();
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
示例7: decode
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
/**
* Decodes the machine information of the user during the {@link WorldLoginDecoder}.
*
* @param buffer The {@link ByteBuf}.
* @return The created machine information.
*/
public static MachineInformation decode(ByteBuf buffer) {
buffer.readByte();
int osArch = buffer.readByte();
boolean is64Bit = buffer.readByte() == 1;
int osBuild = buffer.readByte();
int vendor = buffer.readByte();
buffer.readByte();
buffer.readByte();
buffer.readByte();
buffer.readByte();
buffer.readShort();
buffer.readByte();
buffer.readMedium();
buffer.readShort();
ByteBufUtils.readJagString(buffer);
ByteBufUtils.readJagString(buffer);
ByteBufUtils.readJagString(buffer);
ByteBufUtils.readJagString(buffer);
buffer.readByte();
buffer.readShort();
ByteBufUtils.readJagString(buffer);
ByteBufUtils.readJagString(buffer);
buffer.readByte();
buffer.readByte();
return new MachineInformation(osArch, is64Bit, osBuild, vendor);
}
示例8: read
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public void read( ByteBuf buf ) throws IOException {
entityId = readVarInt( buf );
deltaX = buf.readShort();
deltaY = buf.readShort();
deltaZ = buf.readShort();
yaw = buf.readFloat();
pitch = buf.readFloat();
onGround = buf.readBoolean();
}
示例9: parseFrame
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private void parseFrame(ByteBuf buffer, List<Object> out) throws Exception {
buffer.markReaderIndex();
if (buffer.readableBytes() > FRAME_SIZE_WITHOUT_PAYLOAD) {
byte type = buffer.readByte();
int channel = buffer.readShort();
long payloadSize = buffer.readInt();
long estimatedRemainingSize = payloadSize + 1;
if (buffer.readableBytes() < estimatedRemainingSize) {
buffer.resetReaderIndex();
return;
}
GeneralFrame frame = null;
switch (type) {
case 1: // Method
short amqpClass = buffer.readShort();
short amqpMethod = buffer.readShort();
AmqMethodBodyFactory factory = methodRegistry.getFactory(amqpClass, amqpMethod);
frame = factory.newInstance(buffer, channel, payloadSize);
break;
case 2: // Header
frame = HeaderFrame.parse(buffer, channel);
break;
case 3: // Body
frame = ContentFrame.parse(buffer, channel, payloadSize);
break;
case 4: // Heartbeat
throw new Exception("Method Not implemented");
}
byte frameEnd = buffer.readByte();
if (frameEnd != (byte) GeneralFrame.FRAME_END) {
throw new Exception("Invalid AMQP frame");
}
out.add(frame);
}
}
示例10: fromBytes
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public void fromBytes(ByteBuf buf) {
type = EnumParticleTypes.values()[buf.readShort()];
x = buf.readDouble();
y = buf.readDouble();
z = buf.readDouble();
loopSize = buf.readInt();
}
示例11: fromBytes
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
void fromBytes(ByteBuf bytes)
{
dimensionId = bytes.readInt();
byte[] data = new byte[bytes.readShort()];
bytes.readBytes(data);
providerId = new String(data, Charsets.UTF_8);
}
示例12: channelRead0
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, FrameMajor msg) throws Exception {
FrameMajorHeader head = msg.getHead();
ByteBuf byteBuf = msg.getData();
while (byteBuf.readableBytes() >= FrameSetting.SUB_FRAME_HEAD_LENGTH) {
int subMsgId = byteBuf.readByte() & 0xFF;
byte[] data = new byte[byteBuf.readShort()];
byteBuf.readBytes(data);
server.decodeAndHuntMessage(head, subMsgId, data, ctx.channel());
}
}
示例13: read
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public void read( ByteBuf buf ) throws IOException {
protocolVersion = readVarInt( buf );
serverAddress = readString( buf );
port = buf.readShort();
nextState = readVarInt( buf );
}
示例14: decodeError
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private Tpdu decodeError(ByteBuf userData, List<Parameter> parameters) {
Tpdu tpdu;
short destinationReference = userData.readShort();
RejectCause rejectCause = RejectCause.valueOf(userData.readByte());
tpdu = new ErrorTpdu(destinationReference, rejectCause, parameters, userData);
return tpdu;
}
示例15: read
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public void read( ByteBuf buf ) throws IOException {
entityId = readVarInt( buf );
deltaX = buf.readShort();
deltaY = buf.readShort();
deltaZ = buf.readShort();
onGround = buf.readBoolean();
}