本文整理匯總了Java中org.jboss.netty.buffer.ChannelBuffer.getUnsignedByte方法的典型用法代碼示例。如果您正苦於以下問題:Java ChannelBuffer.getUnsignedByte方法的具體用法?Java ChannelBuffer.getUnsignedByte怎麽用?Java ChannelBuffer.getUnsignedByte使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jboss.netty.buffer.ChannelBuffer
的用法示例。
在下文中一共展示了ChannelBuffer.getUnsignedByte方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
// Strip not '$' (0x24) bytes from the beginning
while (buf.readable() && buf.getUnsignedByte(buf.readerIndex()) != 0x24) {
buf.readByte();
}
// Check length and return buffer
if (buf.readableBytes() >= MESSAGE_HEADER) {
int length = buf.getUnsignedShort(buf.readerIndex() + 2);
if (buf.readableBytes() >= length) {
return buf.readBytes(length);
}
}
return null;
}
示例2: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(
ChannelHandlerContext ctx,
Channel channel,
ChannelBuffer buf) throws Exception {
if (buf.readableBytes() < 4 + 2) {
return null;
}
int length;
if (buf.getUnsignedByte(buf.readerIndex()) == 0) {
length = 2 + buf.getUnsignedShort(buf.readerIndex());
} else {
length = 4 + 2 + buf.getUnsignedShort(buf.readerIndex() + 4) + 2;
}
if (buf.readableBytes() >= length) {
return buf.readBytes(length);
}
return null;
}
示例3: readCoordinate
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private static double readCoordinate(ChannelBuffer buf, boolean lon) {
int degrees = BcdUtil.readInteger(buf, 2);
if (lon) {
degrees = degrees * 10 + (buf.getUnsignedByte(buf.readerIndex()) >> 4);
}
double result = 0;
if (lon) {
result = buf.readUnsignedByte() & 0x0f;
}
int length = 6;
if (lon) {
length = 5;
}
result = result * 10 + BcdUtil.readInteger(buf, length) * 0.0001;
result /= 60;
result += degrees;
return result;
}
示例4: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
if (buf.readableBytes() < BINARY_HEADER) {
return null;
}
if (buf.getUnsignedByte(buf.readerIndex()) == 0xbf) {
buf.skipBytes(BINARY_HEADER);
}
int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '\r');
if (index != -1 && index + 1 < buf.writerIndex()) {
ChannelBuffer result = buf.readBytes(index - buf.readerIndex());
buf.skipBytes(2);
return result;
}
return null;
}
示例5: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
if (buf.readableBytes() >= MESSAGE_HEADER) {
int length = Integer.parseInt(buf.toString(2, 2, StandardCharsets.US_ASCII)) + 5;
if (buf.readableBytes() >= length) {
ChannelBuffer frame = buf.readBytes(length);
while (buf.readable() && buf.getUnsignedByte(buf.readerIndex()) != '$') {
buf.readByte();
}
return frame;
}
}
return null;
}
示例6: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(
ChannelHandlerContext ctx,
Channel channel,
ChannelBuffer buf) throws Exception {
if (buf.readableBytes() < 20) {
return null;
}
// Swap byte order for legacy protocol
if (buf.getUnsignedByte(buf.readerIndex()) == 0x80) {
int length = buf.readableBytes();
byte[] bytes = new byte[length];
buf.getBytes(buf.readerIndex(), bytes);
ChannelBuffer result = (ChannelBuffer) super.decode(
ctx, channel, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, bytes));
if (result != null) {
buf.skipBytes(result.readableBytes());
}
return result;
}
return super.decode(ctx, channel, buf);
}
示例7: readFloat
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
public float readFloat(ChannelBuffer buf) {
switch (buf.getUnsignedByte(buf.readerIndex()) >> 6) {
case 0:
previousFloat = buf.readInt() << 2;
break;
case 1:
previousFloat = (previousFloat & 0xffffff00) + ((buf.readUnsignedByte() & 0x3f) << 2);
break;
case 2:
previousFloat = (previousFloat & 0xffff0000) + ((buf.readUnsignedShort() & 0x3fff) << 2);
break;
case 3:
previousFloat = (previousFloat & 0xff000000) + ((buf.readUnsignedMedium() & 0x3fffff) << 2);
break;
default:
Log.warning(new IllegalArgumentException());
break;
}
return Float.intBitsToFloat(previousFloat);
}
示例8: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
// Skip Alive message
while (buf.readable() && Character.isDigit(buf.getByte(buf.readerIndex()))) {
buf.readByte();
}
// Check minimum length
if (buf.readableBytes() < 11) {
return null;
}
// Read flags
int version = buf.getUnsignedByte(buf.readerIndex() + 1);
int offset = 1 + 1 + 3;
if ((version & 0x80) != 0) {
offset += 4;
}
// Get data length
int length = buf.getUnsignedShort(buf.readerIndex() + offset);
offset += 2;
if ((version & 0x40) != 0) {
offset += 3;
}
length += offset; // add header
// Return buffer
if (buf.readableBytes() >= length) {
return buf.readBytes(length);
}
return null;
}
示例9: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
if (buf.readableBytes() < 10) {
return null;
}
char type = (char) buf.getByte(buf.readerIndex());
if (type == '$') {
boolean longFormat = buf.getUnsignedByte(buf.readerIndex() + 1) == 0x75;
int length = buf.getUnsignedShort(buf.readerIndex() + (longFormat ? 8 : 7)) + 10;
if (length >= buf.readableBytes()) {
return buf.readBytes(length);
}
} else if (type == '(') {
int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ')');
if (endIndex != -1) {
return buf.readBytes(endIndex + 1);
}
} else {
throw new ParseException(null, 0); // unknown message
}
return null;
}
示例10: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(
ChannelHandlerContext ctx,
Channel channel,
ChannelBuffer buf) throws Exception {
// Check minimum length
if (buf.readableBytes() < 12) {
return null;
}
int length;
switch (buf.getUnsignedByte(buf.readerIndex())) {
case AutoFonProtocolDecoder.MSG_LOGIN:
length = 12;
break;
case AutoFonProtocolDecoder.MSG_LOCATION:
length = 78;
break;
case AutoFonProtocolDecoder.MSG_HISTORY:
length = 257;
break;
case AutoFonProtocolDecoder.MSG_45_LOGIN:
length = 19;
break;
case AutoFonProtocolDecoder.MSG_45_LOCATION:
length = 34;
break;
default:
length = 0;
break;
}
// Check length and return buffer
if (length != 0 && buf.readableBytes() >= length) {
return buf.readBytes(length);
}
return null;
}
示例11: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
if (buf.readableBytes() < 5) {
return null;
}
int length = 2 + 2; // head and tail
if (buf.getByte(buf.readerIndex()) == 0x78) {
length += 1 + buf.getUnsignedByte(buf.readerIndex() + 2);
} else {
length += 2 + buf.getUnsignedShort(buf.readerIndex() + 2);
}
if (buf.readableBytes() >= length && buf.getUnsignedShort(buf.readerIndex() + length - 2) == 0x0d0a) {
return buf.readBytes(length);
}
int endIndex = buf.readerIndex() - 1;
do {
endIndex = buf.indexOf(endIndex + 1, buf.writerIndex(), (byte) 0x0d);
if (endIndex > 0 && buf.writerIndex() > endIndex + 1 && buf.getByte(endIndex + 1) == 0x0a) {
return buf.readBytes(endIndex + 2 - buf.readerIndex());
}
} while (endIndex > 0);
return null;
}
示例12: decodeObd
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private void decodeObd(Position position, ChannelBuffer buf, int length) {
int end = buf.readerIndex() + length;
while (buf.readerIndex() < end) {
int parameterLength = buf.getUnsignedByte(buf.readerIndex()) >> 4;
int mode = buf.readUnsignedByte() & 0x0F;
position.add(ObdDecoder.decode(mode, ChannelBuffers.hexDump(buf.readBytes(parameterLength - 1))));
}
}
示例13: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
if (buf.getUnsignedByte(buf.readerIndex()) == 0xF8) {
if (channel != null) {
ChannelBuffer response = ChannelBuffers.dynamicBuffer();
response.writeByte(0xF8);
response.writeByte(DATA_GPS);
response.writeByte(0xFE);
response.writeShort(buf.getShort(response.writerIndex() - 1 - 2));
response.writeShort(Checksum.crc16(Checksum.CRC16_XMODEM, response.toByteBuffer(1, 4)));
response.writeByte(0xF8);
channel.write(response);
}
return decodeBinary(channel, remoteAddress, buf);
} else {
if (channel != null) {
channel.write(ChannelBuffers.copiedBuffer(String.format("*TS01,ACK:%04X#",
Checksum.crc16(Checksum.CRC16_XMODEM, buf.toByteBuffer(1, buf.writerIndex() - 2))),
StandardCharsets.US_ASCII));
}
return decodeText(channel, remoteAddress, buf.toString(StandardCharsets.US_ASCII));
}
}
示例14: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
if (buf.getUnsignedByte(buf.readerIndex()) == 0x7e) {
return decodeArMessage(channel, remoteAddress, buf);
} else {
return decodeMgMessage(channel, remoteAddress, buf);
}
}
示例15: checksum
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private static short checksum(ChannelBuffer buf) {
short sum = 0;
for (int i = 0; i < buf.readableBytes(); i++) {
sum ^= buf.getUnsignedByte(i);
}
return sum;
}