本文整理匯總了Java中org.jboss.netty.buffer.ChannelBuffer.readUnsignedInt方法的典型用法代碼示例。如果您正苦於以下問題:Java ChannelBuffer.readUnsignedInt方法的具體用法?Java ChannelBuffer.readUnsignedInt怎麽用?Java ChannelBuffer.readUnsignedInt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jboss.netty.buffer.ChannelBuffer
的用法示例。
在下文中一共展示了ChannelBuffer.readUnsignedInt方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: readValue
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private long readValue(ChannelBuffer buf, int length, boolean signed) {
switch (length) {
case 1:
return signed ? buf.readByte() : buf.readUnsignedByte();
case 2:
return signed ? buf.readShort() : buf.readUnsignedShort();
case 4:
return signed ? buf.readInt() : buf.readUnsignedInt();
default:
return buf.readLong();
}
}
示例2: parseAttributeTypeLocalPref
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
* Parses BGP UPDATE Attribute Type LOCAL_PREF.
*
* @param bgpSession the BGP Session to use
* @param ctx the Channel Handler Context
* @param attrTypeCode the attribute type code
* @param attrLen the attribute length (in octets)
* @param attrFlags the attribute flags
* @param message the message to parse
* @return the parsed LOCAL_PREF value
* @throws BgpMessage.BgpParseException
*/
private static long parseAttributeTypeLocalPref(
BgpSession bgpSession,
ChannelHandlerContext ctx,
int attrTypeCode,
int attrLen,
int attrFlags,
ChannelBuffer message)
throws BgpMessage.BgpParseException {
// Check the Attribute Length
if (attrLen != BgpConstants.Update.LocalPref.LENGTH) {
// ERROR: Attribute Length Error
actionsBgpUpdateAttributeLengthError(
bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message);
String errorMsg = "Attribute Length Error";
throw new BgpMessage.BgpParseException(errorMsg);
}
long localPref = message.readUnsignedInt();
return localPref;
}
示例3: parseAttributeTypeMultiExitDisc
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
* Parses BGP UPDATE Attribute Type MULTI_EXIT_DISC.
*
* @param bgpSession the BGP Session to use
* @param ctx the Channel Handler Context
* @param attrTypeCode the attribute type code
* @param attrLen the attribute length (in octets)
* @param attrFlags the attribute flags
* @param message the message to parse
* @return the parsed MULTI_EXIT_DISC value
* @throws BgpMessage.BgpParseException
*/
private static long parseAttributeTypeMultiExitDisc(
BgpSession bgpSession,
ChannelHandlerContext ctx,
int attrTypeCode,
int attrLen,
int attrFlags,
ChannelBuffer message)
throws BgpMessage.BgpParseException {
// Check the Attribute Length
if (attrLen != BgpConstants.Update.MultiExitDisc.LENGTH) {
// ERROR: Attribute Length Error
actionsBgpUpdateAttributeLengthError(
bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message);
String errorMsg = "Attribute Length Error";
throw new BgpMessage.BgpParseException(errorMsg);
}
long multiExitDisc = message.readUnsignedInt();
return multiExitDisc;
}
示例4: decodeGps
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private boolean decodeGps(Position position, ChannelBuffer buf, boolean hasLength) {
DateBuilder dateBuilder = new DateBuilder(timeZone)
.setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
.setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
position.setTime(dateBuilder.getDate());
if (hasLength && buf.readUnsignedByte() == 0) {
return false;
}
position.set(Position.KEY_SATELLITES, BitUtil.to(buf.readUnsignedByte(), 4));
double latitude = buf.readUnsignedInt() / 60.0 / 30000.0;
double longitude = buf.readUnsignedInt() / 60.0 / 30000.0;
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
int flags = buf.readUnsignedShort();
position.setCourse(BitUtil.to(flags, 10));
position.setValid(BitUtil.check(flags, 12));
if (!BitUtil.check(flags, 10)) {
latitude = -latitude;
}
if (BitUtil.check(flags, 11)) {
longitude = -longitude;
}
position.setLatitude(latitude);
position.setLongitude(longitude);
if (BitUtil.check(flags, 14)) {
position.set(Position.KEY_IGNITION, BitUtil.check(flags, 15));
}
return true;
}
示例5: readPosition
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private Position readPosition(DeviceSession deviceSession, ChannelBuffer buf) {
Position position = new Position();
position.setProtocol(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder()
.setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
.setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
position.setTime(dateBuilder.getDate());
double lat = buf.readUnsignedInt() / 3600000.0;
double lon = buf.readUnsignedInt() / 3600000.0;
position.setSpeed(UnitsConverter.knotsFromCps(buf.readUnsignedShort()));
position.setCourse(buf.readUnsignedShort() * 0.1);
int flags = buf.readUnsignedByte();
if ((flags & 0x02) == 0) {
lat = -lat;
}
if ((flags & 0x01) == 0) {
lon = -lon;
}
position.setLatitude(lat);
position.setLongitude(lon);
position.setValid((flags & 0x0C) > 0);
position.set(Position.KEY_SATELLITES, flags >> 4);
return position;
}
示例6: decodeStat
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private void decodeStat(Position position, ChannelBuffer buf) {
buf.readUnsignedInt(); // ACC ON time
buf.readUnsignedInt(); // UTC time
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedInt());
position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedInt());
buf.readUnsignedShort(); // current fuel consumption
position.set(Position.KEY_STATUS, buf.readUnsignedInt());
buf.skipBytes(8);
}
示例7: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
if (buf.readableBytes() < 4) {
return null;
}
long length = buf.getUnsignedInt(buf.readerIndex());
if (length < 1024) {
if (buf.readableBytes() >= length + 4) {
buf.readUnsignedInt();
return buf.readBytes((int) length);
}
} else {
int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0);
if (endIndex >= 0) {
ChannelBuffer frame = buf.readBytes(endIndex - buf.readerIndex());
buf.readByte();
if (frame.readableBytes() > 0) {
return frame;
}
}
}
return null;
}
示例8: parseSnapshot4
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private Position parseSnapshot4(
DeviceSession deviceSession, ChannelBuffer buf, int sequenceNumber) {
Position position = new Position();
position.setProtocol(getProtocolName());
position.set(Position.KEY_INDEX, sequenceNumber);
position.setDeviceId(deviceSession.getDeviceId());
buf.readUnsignedByte(); // report trigger
buf.readUnsignedByte(); // position fix source
buf.readUnsignedByte(); // GNSS fix quality
buf.readUnsignedByte(); // GNSS assistance age
long flags = buf.readUnsignedInt();
position.setValid((flags & 0x0400) == 0x0400);
position.setTime(convertTimestamp(buf.readUnsignedInt()));
position.setLatitude(buf.readInt() * 0.0000001);
position.setLongitude(buf.readInt() * 0.0000001);
position.setAltitude(buf.readUnsignedShort());
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedByte());
position.setSpeed(buf.readUnsignedShort() * 0.194384);
position.setCourse(buf.readUnsignedShort() * 0.1);
position.set("maximumSpeed", buf.readUnsignedByte());
position.set("minimumSpeed", buf.readUnsignedByte());
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
position.set(Position.PREFIX_IO + 1, buf.readUnsignedByte()); // supply voltage 1
position.set(Position.PREFIX_IO + 2, buf.readUnsignedByte()); // supply voltage 2
position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
return position;
}
示例9: 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() < MESSAGE_HEADER) {
return null;
}
// Check for preamble
boolean hasPreamble = false;
if (buf.getUnsignedInt(buf.readerIndex()) == PREAMBLE) {
hasPreamble = true;
}
// Check length and return buffer
int length = buf.getUnsignedShort(buf.readerIndex() + 6);
if (buf.readableBytes() >= length) {
if (hasPreamble) {
buf.readUnsignedInt();
length -= 4;
}
return buf.readBytes(length);
}
return null;
}
示例10: decodeEventData
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private void decodeEventData(Position position, ChannelBuffer buf, int event) {
switch (event) {
case 2:
case 40:
buf.readUnsignedByte();
break;
case 9:
buf.readUnsignedMedium();
break;
case 31:
case 32:
buf.readUnsignedShort();
break;
case 38:
buf.skipBytes(4 * 9);
break;
case 113:
buf.readUnsignedInt();
buf.readUnsignedByte();
break;
case 121:
case 142:
buf.readLong();
break;
case 130:
buf.readUnsignedInt(); // incorrect
break;
case 188:
decodeEB(position, buf);
break;
default:
break;
}
}
示例11: decodeBinaryMessage
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private List<Position> decodeBinaryMessage(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
List<Position> positions = new LinkedList<>();
String flag = buf.toString(2, 1, StandardCharsets.US_ASCII);
int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',');
String imei = buf.toString(index + 1, 15, StandardCharsets.US_ASCII);
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession == null) {
return null;
}
buf.skipBytes(index + 1 + 15 + 1 + 3 + 1 + 2 + 2 + 4);
while (buf.readableBytes() >= 0x34) {
Position position = new Position();
position.setProtocol(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_EVENT, buf.readUnsignedByte());
position.setLatitude(buf.readInt() * 0.000001);
position.setLongitude(buf.readInt() * 0.000001);
position.setTime(new Date((946684800 + buf.readUnsignedInt()) * 1000)); // 946684800 = 2000-01-01
position.setValid(buf.readUnsignedByte() == 1);
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
int rssi = buf.readUnsignedByte();
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
position.setCourse(buf.readUnsignedShort());
position.set(Position.KEY_HDOP, buf.readUnsignedShort() * 0.1);
position.setAltitude(buf.readUnsignedShort());
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
position.set("runtime", buf.readUnsignedInt());
position.setNetwork(new Network(CellTower.from(
buf.readUnsignedShort(), buf.readUnsignedShort(),
buf.readUnsignedShort(), buf.readUnsignedShort(),
rssi)));
position.set(Position.KEY_STATUS, buf.readUnsignedShort());
position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.01);
position.set(Position.KEY_POWER, buf.readUnsignedShort());
buf.readUnsignedInt(); // geo-fence
positions.add(position);
}
if (channel != null) {
StringBuilder command = new StringBuilder("@@");
command.append(flag).append(27 + positions.size() / 10).append(",");
command.append(imei).append(",CCC,").append(positions.size()).append("*");
int checksum = 0;
for (int i = 0; i < command.length(); i += 1) {
checksum += command.charAt(i);
}
command.append(String.format("%02x", checksum & 0xff).toUpperCase());
command.append("\r\n");
channel.write(command.toString()); // delete processed data
}
return positions;
}
示例12: decodeInformation
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private Position decodeInformation(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
Position position = new Position();
position.setProtocol(getProtocolName());
int type = buf.readUnsignedByte();
buf.readUnsignedInt(); // mask
buf.readUnsignedShort(); // length
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.format("%015d", buf.readLong()));
if (deviceSession == null) {
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
buf.readUnsignedByte(); // device type
buf.readUnsignedShort(); // protocol version
position.set(Position.KEY_VERSION_FW, String.valueOf(buf.readUnsignedShort()));
if (type == MSG_INF_VER) {
buf.readUnsignedShort(); // hardware version
buf.readUnsignedShort(); // mcu version
buf.readUnsignedShort(); // reserved
}
buf.readUnsignedByte(); // motion status
buf.readUnsignedByte(); // reserved
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
buf.readUnsignedByte(); // mode
buf.skipBytes(7); // last fix time
buf.readUnsignedByte(); // reserved
buf.readUnsignedByte();
buf.readUnsignedShort(); // response report mask
buf.readUnsignedShort(); // ign interval
buf.readUnsignedShort(); // igf interval
buf.readUnsignedInt(); // reserved
buf.readUnsignedByte(); // reserved
if (type == MSG_INF_BAT) {
position.set(Position.KEY_CHARGE, buf.readUnsignedByte() != 0);
position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001);
position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
}
buf.skipBytes(10); // iccid
if (type == MSG_INF_CSQ) {
position.set(Position.KEY_RSSI, buf.readUnsignedByte());
buf.readUnsignedByte();
}
buf.readUnsignedByte(); // time zone flags
buf.readUnsignedShort(); // time zone offset
if (type == MSG_INF_GIR) {
buf.readUnsignedByte(); // gir trigger
buf.readUnsignedByte(); // cell number
position.setNetwork(new Network(CellTower.from(
buf.readUnsignedShort(), buf.readUnsignedShort(),
buf.readUnsignedShort(), buf.readUnsignedShort())));
buf.readUnsignedByte(); // ta
buf.readUnsignedByte(); // rx level
}
getLastLocation(position, decodeTime(buf));
return position;
}
示例13: decodePosition
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private Position decodePosition(DeviceSession deviceSession, int type, ChannelBuffer buf) {
Position position = new Position();
position.setDeviceId(deviceSession.getDeviceId());
position.setProtocol(getProtocolName());
position.setTime(new Date(buf.readUnsignedInt() * 1000));
if (type != MSG_MINI_EVENT_REPORT) {
buf.readUnsignedInt(); // fix time
}
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()));
}
if (type == MSG_MINI_EVENT_REPORT) {
position.set(Position.KEY_SATELLITES, buf.getUnsignedByte(buf.readerIndex()) & 0xf);
position.setValid((buf.readUnsignedByte() & 0x20) == 0);
} else {
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
position.setValid((buf.readUnsignedByte() & 0x08) == 0);
}
if (type != MSG_MINI_EVENT_REPORT) {
position.set("carrier", buf.readUnsignedShort());
position.set(Position.KEY_RSSI, buf.readShort());
}
position.set("modem", buf.readUnsignedByte());
if (type != MSG_MINI_EVENT_REPORT) {
position.set(Position.KEY_HDOP, buf.readUnsignedByte());
}
int input = buf.readUnsignedByte();
position.set(Position.KEY_INPUT, input);
position.set(Position.KEY_IGNITION, BitUtil.check(input, 0));
if (type != MSG_MINI_EVENT_REPORT) {
position.set(Position.KEY_STATUS, buf.readUnsignedByte());
}
if (type == MSG_EVENT_REPORT || type == MSG_MINI_EVENT_REPORT) {
if (type != MSG_MINI_EVENT_REPORT) {
buf.readUnsignedByte(); // event index
}
position.set(Position.KEY_EVENT, buf.readUnsignedByte());
}
int accType = BitUtil.from(buf.getUnsignedByte(buf.readerIndex()), 6);
int accCount = BitUtil.to(buf.readUnsignedByte(), 6);
if (type != MSG_MINI_EVENT_REPORT) {
position.set("append", buf.readUnsignedByte());
}
if (accType == 1) {
buf.readUnsignedInt(); // threshold
buf.readUnsignedInt(); // mask
}
for (int i = 0; i < accCount; i++) {
if (buf.readableBytes() >= 4) {
position.set("acc" + i, buf.readUnsignedInt());
}
}
return position;
}
示例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;
buf.skipBytes(2); // header
buf.readByte(); // size
Position position = new Position();
position.setProtocol(getProtocolName());
// Zero for location messages
int power = buf.readUnsignedByte();
int gsm = buf.readUnsignedByte();
String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1);
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession == null) {
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_INDEX, buf.readUnsignedShort());
int type = buf.readUnsignedByte();
if (type == MSG_HEARTBEAT) {
getLastLocation(position, null);
position.set(Position.KEY_POWER, power);
position.set(Position.KEY_RSSI, gsm);
if (channel != null) {
byte[] response = {0x54, 0x68, 0x1A, 0x0D, 0x0A};
channel.write(ChannelBuffers.wrappedBuffer(response));
}
} else if (type == MSG_DATA) {
DateBuilder dateBuilder = new DateBuilder()
.setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
.setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
position.setTime(dateBuilder.getDate());
double latitude = buf.readUnsignedInt() / (60.0 * 30000.0);
double longitude = buf.readUnsignedInt() / (60.0 * 30000.0);
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
position.setCourse(buf.readUnsignedShort());
buf.skipBytes(3); // reserved
long flags = buf.readUnsignedInt();
position.setValid(BitUtil.check(flags, 0));
if (!BitUtil.check(flags, 1)) {
latitude = -latitude;
}
if (!BitUtil.check(flags, 2)) {
longitude = -longitude;
}
position.setLatitude(latitude);
position.setLongitude(longitude);
} else if (type == MSG_RESPONSE) {
getLastLocation(position, null);
position.set(Position.KEY_RESULT,
buf.readBytes(buf.readUnsignedByte()).toString(StandardCharsets.US_ASCII));
} else {
return null;
}
return position;
}
示例15: decodeH
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private void decodeH(Position position, ChannelBuffer buf, int selector) {
if ((selector & 0x0004) != 0) {
getLastLocation(position, new Date(buf.readUnsignedInt() * 1000));
} else {
getLastLocation(position, null);
}
if ((selector & 0x0040) != 0) {
buf.readUnsignedInt(); // reset time
}
if ((selector & 0x2000) != 0) {
buf.readUnsignedShort(); // snapshot counter
}
int index = 1;
while (buf.readableBytes() > 0) {
position.set("h" + index + "Index", buf.readUnsignedByte());
buf.readUnsignedShort(); // length
int n = buf.readUnsignedByte();
int m = buf.readUnsignedByte();
position.set("h" + index + "XLength", n);
position.set("h" + index + "YLength", m);
if ((selector & 0x0008) != 0) {
position.set("h" + index + "XType", buf.readUnsignedByte());
position.set("h" + index + "YType", buf.readUnsignedByte());
position.set("h" + index + "Parameters", buf.readUnsignedByte());
}
boolean percentageFormat = (selector & 0x0020) != 0;
StringBuilder data = new StringBuilder();
for (int i = 0; i < n * m; i++) {
if (percentageFormat) {
data.append(buf.readUnsignedByte() * 0.5).append("%").append(" ");
} else {
data.append(buf.readUnsignedShort()).append(" ");
}
}
position.set("h" + index + "Data", data.toString().trim());
position.set("h" + index + "Total", buf.readUnsignedInt());
if ((selector & 0x0010) != 0) {
int k = buf.readUnsignedByte();
data = new StringBuilder();
for (int i = 1; i < n; i++) {
if (k == 1) {
data.append(buf.readByte()).append(" ");
} else if (k == 2) {
data.append(buf.readShort()).append(" ");
}
}
position.set("h" + index + "XLimits", data.toString().trim());
data = new StringBuilder();
for (int i = 1; i < m; i++) {
if (k == 1) {
data.append(buf.readByte()).append(" ");
} else if (k == 2) {
data.append(buf.readShort()).append(" ");
}
}
position.set("h" + index + "YLimits", data.toString().trim());
}
index += 1;
}
}