本文整理了Java中io.netty.buffer.ByteBuf.readShort()
方法的一些代码示例,展示了ByteBuf.readShort()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteBuf.readShort()
方法的具体详情如下:
包路径:io.netty.buffer.ByteBuf
类名称:ByteBuf
方法名:readShort
[英]Gets a 16-bit short integer at the current readerIndexand increases the readerIndex by 2 in this buffer.
[中]获取当前readerIndex处的16位短整数,并在此缓冲区中将readerIndex增加2。
代码示例来源:origin: alibaba/fescar
@Override
public boolean decode(ByteBuf in) {
int i = in.readableBytes();
if (i < 3) {
return false;
}
i -= 3;
this.identified = (in.readByte() == 1);
short len = in.readShort();
if (len > 0) {
if (i < len) {
return false;
}
byte[] bs = new byte[len];
in.readBytes(bs);
this.setVersion(new String(bs, UTF8));
}
return true;
}
}
代码示例来源:origin: weibocom/motan
private void decodeV1(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
long startTime = System.currentTimeMillis();
in.resetReaderIndex();
in.skipBytes(2);// skip magic num
byte messageType = (byte) in.readShort();
long requestId = in.readLong();
int dataLength = in.readInt();
// FIXME 如果dataLength过大,可能导致问题
if (in.readableBytes() < dataLength) {
in.resetReaderIndex();
return;
}
checkMaxContext(dataLength, ctx, messageType == MotanConstants.FLAG_REQUEST, requestId);
byte[] data = new byte[dataLength];
in.readBytes(data);
decode(data, out, messageType == MotanConstants.FLAG_REQUEST, requestId).setStartTime(startTime);
}
代码示例来源:origin: alibaba/fescar
@Override
public boolean decode(ByteBuf in) {
int i = in.readableBytes();
try {
short len = in.readShort();
if (len > 0) {
byte[] bs = new byte[len];
this.setVersion(new String(bs, UTF8));
len = in.readShort();
if (len > 0) {
byte[] bs = new byte[len];
this.setApplicationId(new String(bs, UTF8));
len = in.readShort();
if (len > 0) {
byte[] bs = new byte[len];
this.setTransactionServiceGroup(new String(bs, UTF8));
len = in.readShort();
if (len > 0) {
byte[] bs = new byte[len];
LOGGER.debug(in.writerIndex() == in.readerIndex() ? "true" : "false" + this);
代码示例来源:origin: org.apache.plc4x/plc4j-protocol-s7
protected void decode(ChannelHandlerContext ctx, IsoTPMessage in, List<Object> out) {
if (logger.isTraceEnabled()) {
logger.trace("Got Data: {}", ByteBufUtil.hexDump(in.getUserData()));
if (userData.readableBytes() == 0) {
return;
userData.readShort(); // Reserved (is always constant 0x0000)
short tpduReference = userData.readShort();
short headerParametersLength = userData.readShort();
short userDataLength = userData.readShort();
byte errorClass = 0;
byte errorCode = 0;
代码示例来源:origin: org.opendaylight.bgpcep/bgp-linkstate
final List<PeerSetSids> peerSetSids = new ArrayList<>();
for (final Entry<Integer, ByteBuf> entry : attributes.entries()) {
LOG.trace("Link attribute TLV {}", entry.getKey());
final int key = entry.getKey();
final ByteBuf value = entry.getValue();
break;
case LINK_PROTECTION_TYPE:
builder.setLinkProtection(LinkProtectionType.forValue(value.readShort()));
LOG.debug("Parsed Link Protection Type {}", builder.getLinkProtection());
break;
builder.setPeerSetSids(peerSetSids);
LOG.trace("Finished parsing Link Attributes.");
return new LinkAttributesCaseBuilder().setLinkAttributes(builder.build()).build();
代码示例来源:origin: qunarcorp/qmq
@Override
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf in, List<Object> list) throws Exception {
if (in.readableBytes() < RemotingHeader.MIN_HEADER_SIZE + RemotingHeader.LENGTH_FIELD) return;
int magicCode = in.getInt(in.readerIndex() + RemotingHeader.LENGTH_FIELD);
if (DEFAULT_MAGIC_CODE != magicCode) {
throw new IOException("Illegal Data, MagicCode=" + Integer.toHexString(magicCode));
int total = in.readInt();
if (in.readableBytes() < total) {
in.resetReaderIndex();
return;
short headerSize = in.readShort();
RemotingHeader remotingHeader = decodeHeader(in);
代码示例来源:origin: traccar/traccar
int idLength = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x00) - buf.readerIndex();
String id = buf.readBytes(idLength).toString(StandardCharsets.US_ASCII);
buf.readByte();
int blockEnd = buf.readInt() + buf.readerIndex();
position.setLatitude(buf.readDoubleLE());
position.setAltitude(buf.readDoubleLE());
position.setSpeed(buf.readShort());
position.setCourse(buf.readShort());
position.set(Position.KEY_SATELLITES, buf.readByte());
} else {
break;
case 3:
position.set(name, buf.readInt());
break;
case 4:
代码示例来源:origin: wildfly/wildfly
/**
* Returns the closing status code as per <a href="http://tools.ietf.org/html/rfc6455#section-7.4">RFC 6455</a>. If
* a getStatus code is set, -1 is returned.
*/
public int statusCode() {
ByteBuf binaryData = content();
if (binaryData == null || binaryData.capacity() == 0) {
return -1;
}
binaryData.readerIndex(0);
int statusCode = binaryData.readShort();
binaryData.readerIndex(0);
return statusCode;
}
代码示例来源:origin: alibaba/fescar
@Override
public boolean decode(ByteBuf in) {
int leftLen = in.readableBytes();
int read = 0;
int xidLen = in.readShort();
if (xidLen > 0) {
if (leftLen < xidLen) {
leftLen --;
int resourceIdLen = in.readShort();
if (resourceIdLen > 0) {
if (leftLen < resourceIdLen) {
int applicationDataLen = in.readInt();
if (applicationDataLen > 0) {
if (leftLen < applicationDataLen) {
代码示例来源:origin: alipay/sofa-bolt
public void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
if (in.readableBytes() >= lessLen) {
in.markReaderIndex();
byte protocol = in.readByte();
if (type == RpcCommandType.REQUEST || type == RpcCommandType.REQUEST_ONEWAY) {
if (in.readableBytes() >= RpcProtocolV2.getRequestHeaderLength() - 3) {
short cmdCode = in.readShort();
byte ver2 = in.readByte();
int requestId = in.readInt();
byte serializer = in.readByte();
byte protocolSwitchValue = in.readByte();
int timeout = in.readInt();
short classLen = in.readShort();
short headerLen = in.readShort();
int contentLen = in.readInt();
byte[] clazz = null;
byte[] header = null;
short cmdCode = in.readShort();
byte protocolSwitchValue = in.readByte();
short status = in.readShort();
short classLen = in.readShort();
short headerLen = in.readShort();
代码示例来源:origin: alibaba/fescar
@Override
public boolean decode(ByteBuf in) {
int i = in.readableBytes();
if (i < 1) {
return false;
}
setResultCode(ResultCode.get(in.readByte()));
i--;
if (resultCode == ResultCode.Failed) {
if (i < 2) {
return false;
}
short len = in.readShort();
i -= 2;
if (i < len) {
return false;
}
if (len > 0) {
byte[] msg = new byte[len];
in.readBytes(msg);
this.setMsg(new String(msg, UTF8));
}
}
return true;
}
}
代码示例来源:origin: wildfly/wildfly
return;
if (buffer.readableBytes() == 1) {
protocolViolation(ctx, "Invalid close frame body");
int idx = buffer.readerIndex();
buffer.readerIndex(0);
int statusCode = buffer.readShort();
if (statusCode >= 0 && statusCode <= 999 || statusCode >= 1004 && statusCode <= 1006
|| statusCode >= 1012 && statusCode <= 2999) {
buffer.readerIndex(idx);
代码示例来源:origin: traccar/traccar
format = formats.get(buf.getUnsignedByte(buf.readerIndex()));
} else if (!formats.isEmpty()) {
format = formats.values().iterator().next();
break;
case 0x07:
position.setLatitude(buf.readInt() * 0.000001);
break;
case 0x08:
position.setLongitude(buf.readInt() * 0.000001);
break;
case 0x09:
position.setAltitude(buf.readShort() * 0.1);
break;
case 0x0a:
position.setCourse(buf.readShort() * 0.1);
break;
case 0x0b:
break;
case 0x14:
position.set(Position.KEY_RSSI, buf.readShort());
break;
case 0x16:
代码示例来源:origin: runelite/runelite
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception
{
if (in.getByte(in.readerIndex()) != UpdateOpcodes.ENCRYPTION)
{
ctx.fireChannelRead(in.retain());
return;
}
in.readByte();
byte xorKey = in.readByte();
in.readShort(); // always 0
EncryptionPacket encryptionPacket = new EncryptionPacket();
encryptionPacket.setKey(xorKey);
out.add(encryptionPacket);
}
}
代码示例来源:origin: alibaba/fescar
@Override
public boolean decode(ByteBuf in) {
int i = in.readableBytes();
if (i < 1) {
return false;
short len = in.readShort();
if (len > 0) {
if (i < len) {
len = in.readShort();
if (len > 0) {
if (i < len) {
len = in.readShort();
if (len > 0) {
if (i < len) {
len = in.readShort();
if (len > 0) {
if (i < len) {
int iLen = in.readInt();
if (iLen > 0) {
if (i < iLen) {
代码示例来源:origin: traccar/traccar
position.setLatitude(buf.readInt() * 0.0000001);
position.setLongitude(buf.readInt() * 0.0000001);
if (type != MSG_MINI_EVENT_REPORT) {
position.setAltitude(buf.readInt() * 0.01);
position.setSpeed(UnitsConverter.knotsFromCps(buf.readUnsignedInt()));
position.setCourse(buf.readShort());
if (type == MSG_MINI_EVENT_REPORT) {
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
position.set(Position.KEY_SATELLITES, buf.getUnsignedByte(buf.readerIndex()) & 0xf);
position.setValid((buf.readUnsignedByte() & 0x20) == 0);
} else {
position.set(Position.KEY_RSSI, buf.readShort());
int accType = BitUtil.from(buf.getUnsignedByte(buf.readerIndex()), 6);
int accCount = BitUtil.to(buf.readUnsignedByte(), 6);
if (buf.readableBytes() >= 4) {
position.set("acc" + i, buf.readUnsignedInt());
代码示例来源:origin: weibocom/motan
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
if (in.readableBytes() <= MotanConstants.NETTY_HEADER) {
return;
}
in.markReaderIndex();
short type = in.readShort();
if (type != MotanConstants.NETTY_MAGIC_TYPE) {
in.resetReaderIndex();
throw new MotanFrameworkException("NettyDecoder transport header not support, type: " + type);
}
in.skipBytes(1);
int rpcVersion = (in.readByte() & 0xff) >>> 3;
switch (rpcVersion) {
case 0:
decodeV1(ctx, in, out);
break;
case 1:
decodeV2(ctx, in, out);
break;
default:
decodeV2(ctx, in, out);
}
}
代码示例来源:origin: mrniko/netty-socketio
int len = (int) readLong(frame, headEndIndex);
ByteBuf oldFrame = frame;
frame = frame.slice(oldFrame.readerIndex() + 1, len);
oldFrame.readerIndex(oldFrame.readerIndex() + 1 + len);
frame.readShort();
} else if (frame.getByte(0) == 4) {
frame.readByte();
attachBuf.release();
frame.readerIndex(frame.readerIndex() + frame.readableBytes());
slices.add(QUOTES);
source.readerIndex(pos + scanValue.readableBytes());
代码示例来源:origin: traccar/traccar
if (buf.getUnsignedByte(buf.readerIndex()) == 0) {
String imei = buf.toString(buf.readerIndex(), 15, StandardCharsets.US_ASCII);
position.setLongitude(buf.readInt() / 10000000.0);
position.setLatitude(buf.readInt() / 10000000.0);
position.setAltitude(buf.readShort());
position.setCourse(buf.readUnsignedShort());
代码示例来源:origin: runelite/runelite
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception
{
byte opcode = in.getByte(in.readerIndex());
if (opcode != UpdateOpcodes.ARCHIVE_REQUEST_HIGH
&& opcode != UpdateOpcodes.ARCHIVE_REQUEST_LOW)
{
ctx.fireChannelRead(in.retain());
return;
}
byte priority = in.readByte();
int index = in.readByte() & 0xFF;
int archiveId = in.readShort() & 0xFFFF;
ArchiveRequestPacket archiveRequest = new ArchiveRequestPacket();
archiveRequest.setPriority(priority == 1);
archiveRequest.setIndex(index);
archiveRequest.setArchive(archiveId);
out.add(archiveRequest);
}
内容来源于网络,如有侵权,请联系作者删除!