本文整理汇总了Java中org.jboss.netty.buffer.ChannelBuffer.skipBytes方法的典型用法代码示例。如果您正苦于以下问题:Java ChannelBuffer.skipBytes方法的具体用法?Java ChannelBuffer.skipBytes怎么用?Java ChannelBuffer.skipBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jboss.netty.buffer.ChannelBuffer
的用法示例。
在下文中一共展示了ChannelBuffer.skipBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decode
import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
ChannelBuffer result = (ChannelBuffer) super.decode(ctx, channel, buf);
if (result != null) {
int index = result.indexOf(result.readerIndex(), result.writerIndex(), (byte) '$');
if (index == -1) {
return result;
} else {
result.skipBytes(index);
return result.readBytes(result.readableBytes());
}
}
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() < 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;
}
示例3: decodeLbs
import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
private boolean decodeLbs(Position position, ChannelBuffer buf, boolean hasLength) {
int length = 0;
if (hasLength) {
length = buf.readUnsignedByte();
if (length == 0) {
return false;
}
}
position.setNetwork(new Network(CellTower.from(
buf.readUnsignedShort(), buf.readUnsignedByte(), buf.readUnsignedShort(), buf.readUnsignedMedium())));
if (length > 0) {
buf.skipBytes(length - (hasLength ? 9 : 8));
}
return true;
}
示例4: decode
import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(
ChannelHandlerContext ctx,
Channel channel,
ChannelBuffer buf) throws Exception {
if (header && buf.readableBytes() >= HANDSHAKE_LENGTH) {
buf.skipBytes(HANDSHAKE_LENGTH);
header = false;
}
int end = 8; // IMEI
while (buf.readableBytes() >= end + 2 + 1 + 1 + 1) {
end += buf.getUnsignedShort(buf.readerIndex() + end) + 2;
if (buf.readableBytes() > end && checksum(buf, end) == buf.getByte(buf.readerIndex() + end)) {
return buf.readBytes(end + 1);
}
}
return null;
}
示例5: parseSubObjects
import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
/**
* Returns linked list of sub objects.
*
* @param cb of type channel buffer
* @return linked list of sub objects
* @throws PcepParseException while parsing subobjects from channel buffer
*/
protected static LinkedList<PcepValueType> parseSubObjects(ChannelBuffer cb) throws PcepParseException {
LinkedList<PcepValueType> llSubObjects = new LinkedList<>();
while (0 < cb.readableBytes()) {
//check the Type of the Subobjects.
byte yType = cb.readByte();
yType = (byte) (yType & (YTYPE_SHIFT_VALUE));
byte hLength = cb.readByte();
PcepValueType subObj;
switch (yType) {
case IPv4SubObject.TYPE:
subObj = IPv4SubObject.read(cb);
break;
default:
throw new PcepParseException("Invalid sub object. Type: " + (int) yType);
}
// Check for the padding
int pad = hLength % 4;
if (0 < pad) {
pad = 4 - pad;
if (pad <= cb.readableBytes()) {
cb.skipBytes(pad);
}
}
llSubObjects.add(subObj);
}
return llSubObjects;
}
示例6: decode
import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
if (buf.readableBytes() < 80) {
return null;
}
int beginIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("GPRMC"));
if (beginIndex == -1) {
beginIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("GNRMC"));
if (beginIndex == -1) {
return null;
}
}
int identifierIndex = buf.indexOf(beginIndex, buf.writerIndex(), new StringFinder("imei:"));
if (identifierIndex == -1) {
return null;
}
int endIndex = buf.indexOf(identifierIndex, buf.writerIndex(), (byte) ',');
if (endIndex == -1) {
return null;
}
buf.skipBytes(beginIndex - buf.readerIndex());
return buf.readBytes(endIndex - beginIndex + 1);
}
示例7: 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;
}
}
示例8: 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);
}
示例9: read
import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
/**
* Reads the channel buffer and returns object of AutonomousSystemTlv.
*
* @param c input channel buffer
* @param hLength length of subtlvs.
* @return object of AutonomousSystemTlv
* @throws PcepParseException if mandatory fields are missing
*/
public static PcepValueType read(ChannelBuffer c, short hLength) throws PcepParseException {
// Node Descriptor Sub-TLVs (variable)
List<PcepValueType> llNodeDescriptorSubTLVs = new LinkedList<>();
ChannelBuffer tempCb = c.readBytes(hLength);
while (TLV_HEADER_LENGTH <= tempCb.readableBytes()) {
PcepValueType tlv;
short hType = tempCb.readShort();
int iValue = 0;
short length = tempCb.readShort();
switch (hType) {
case AutonomousSystemSubTlv.TYPE:
iValue = tempCb.readInt();
tlv = new AutonomousSystemSubTlv(iValue);
break;
case BgpLsIdentifierSubTlv.TYPE:
iValue = tempCb.readInt();
tlv = new BgpLsIdentifierSubTlv(iValue);
break;
case OspfAreaIdSubTlv.TYPE:
iValue = tempCb.readInt();
tlv = new OspfAreaIdSubTlv(iValue);
break;
case IgpRouterIdSubTlv.TYPE:
tlv = IgpRouterIdSubTlv.read(tempCb, length);
break;
default:
throw new PcepParseException("Unsupported Sub TLV type :" + hType);
}
// Check for the padding
int pad = length % 4;
if (0 < pad) {
pad = 4 - pad;
if (pad <= tempCb.readableBytes()) {
tempCb.skipBytes(pad);
}
}
llNodeDescriptorSubTLVs.add(tlv);
}
if (0 < tempCb.readableBytes()) {
throw new PcepParseException("Sub Tlv parsing error. Extra bytes received.");
}
return new LocalNodeDescriptorsTlv(llNodeDescriptorSubTLVs);
}
示例10: 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 (channel != null) {
channel.write(ChannelBuffers.wrappedBuffer(new byte[] {0x06}), remoteAddress);
}
buf.readUnsignedByte(); // protocol
buf.readUnsignedShort(); // length
String imei = String.format("%08d", buf.readUnsignedInt()) + String.format("%07d", buf.readUnsignedMedium());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession == null) {
return null;
}
List<Position> positions = new LinkedList<>();
while (buf.readableBytes() > 2) {
Position position = new Position();
position.setProtocol(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
buf.readUnsignedByte(); // index
position.setValid(true);
position.setLatitude(buf.readInt() * 0.000001);
position.setLongitude(buf.readInt() * 0.000001);
DateBuilder dateBuilder = new DateBuilder()
.setDate(1980, 1, 6).addMillis(buf.readUnsignedInt() * 1000L);
position.setTime(dateBuilder.getDate());
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte() * 2));
position.setCourse(buf.readUnsignedByte() * 2);
int reason = buf.readUnsignedMedium();
position.set(Position.KEY_EVENT, reason);
int status = buf.readUnsignedShort();
position.set(Position.KEY_STATUS, status);
position.set(Position.PREFIX_IO + 1, buf.readUnsignedByte());
position.set(Position.PREFIX_ADC + 1, buf.readUnsignedByte());
position.set(Position.KEY_BATTERY, buf.readUnsignedByte());
position.set(Position.KEY_POWER, buf.readUnsignedByte());
buf.readUnsignedByte(); // max journey speed
buf.skipBytes(6); // accelerometer
position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedShort());
buf.readUnsignedShort(); // journey idle time
position.setAltitude(buf.readUnsignedByte() * 20);
int quality = buf.readUnsignedByte();
position.set(Position.KEY_SATELLITES, quality & 0xf);
position.set(Position.KEY_RSSI, quality >> 4);
buf.readUnsignedByte(); // geofence events
if (BitUtil.check(status, 8)) {
position.set(Position.KEY_DRIVER_UNIQUE_ID, buf.readBytes(7).toString(StandardCharsets.US_ASCII));
position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium() * 1000);
position.set(Position.KEY_HOURS, buf.readUnsignedShort());
}
if (BitUtil.check(status, 6)) {
Log.warning("Extension data is not supported");
return position;
}
positions.add(position);
}
return positions;
}
示例11: decodeTcp
import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
private Object decodeTcp(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) throws Exception {
if (buf.getUnsignedShort(0) > 0) {
parseIdentification(channel, remoteAddress, buf);
} else {
buf.skipBytes(4);
return parseData(channel, remoteAddress, buf, 0);
}
return null;
}
示例12: 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(4); // system code
int type = buf.readUnsignedByte();
long deviceUniqueId = buf.readUnsignedInt();
if (type != MSG_CLIENT_SERIAL) {
buf.readUnsignedShort(); // communication control
}
byte packetNumber = buf.readByte();
sendReply(channel, remoteAddress, deviceUniqueId, packetNumber);
if (type == MSG_CLIENT_STATUS) {
Position position = new Position();
position.setProtocol(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(deviceUniqueId));
if (deviceSession == null) {
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_VERSION_HW, buf.readUnsignedByte());
position.set(Position.KEY_VERSION_FW, buf.readUnsignedByte());
position.set("protocolVersion", buf.readUnsignedByte());
position.set(Position.KEY_STATUS, buf.getUnsignedByte(buf.readerIndex()) & 0x0f);
int operator = (buf.readUnsignedByte() & 0xf0) << 4;
operator += buf.readUnsignedByte();
buf.readUnsignedByte(); // reason data
position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte()));
position.set("mode", buf.readUnsignedByte());
position.set(Position.PREFIX_IO + 1, buf.readUnsignedInt());
operator <<= 8;
operator += buf.readUnsignedByte();
position.set(Position.KEY_OPERATOR, operator);
position.set(Position.PREFIX_ADC + 1, buf.readUnsignedInt());
position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium());
buf.skipBytes(6); // multi-purpose data
position.set(Position.KEY_GPS, buf.readUnsignedShort());
position.set("locationStatus", buf.readUnsignedByte());
position.set("mode1", buf.readUnsignedByte());
position.set("mode2", buf.readUnsignedByte());
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
position.setValid(true);
position.setLongitude(buf.readInt() / Math.PI * 180 / 100000000);
position.setLatitude(buf.readInt() / Math.PI * 180 / 100000000.0);
position.setAltitude(buf.readInt() * 0.01);
position.setSpeed(UnitsConverter.knotsFromMps(buf.readInt() * 0.01));
position.setCourse(buf.readUnsignedShort() / Math.PI * 180.0 / 1000.0);
DateBuilder dateBuilder = new DateBuilder()
.setTimeReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
.setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedShort());
position.setTime(dateBuilder.getDate());
return position;
}
return null;
}
示例13: decode
import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
char marker = (char) buf.getByte(buf.readerIndex());
while (marker != '*' && marker != '$' && marker != 'X' && buf.readableBytes() > 0) {
buf.skipBytes(1);
if (buf.readableBytes() > 0) {
marker = (char) buf.getByte(buf.readerIndex());
}
}
switch (marker) {
case '*':
// Return text message
int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '#');
if (index != -1) {
ChannelBuffer result = buf.readBytes(index + 1 - buf.readerIndex());
while (buf.readable()
&& (buf.getByte(buf.readerIndex()) == '\r' || buf.getByte(buf.readerIndex()) == '\n')) {
buf.readByte(); // skip new line
}
return result;
}
break;
case '$':
if (messageLength == 0) {
if (buf.readableBytes() == MESSAGE_LONG) {
messageLength = MESSAGE_LONG;
} else {
messageLength = MESSAGE_SHORT;
}
}
if (buf.readableBytes() >= messageLength) {
return buf.readBytes(messageLength);
}
break;
case 'X':
if (buf.readableBytes() >= MESSAGE_SHORT) {
return buf.readBytes(MESSAGE_SHORT);
}
break;
default:
return null;
}
return null;
}
示例14: read
import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
/**
* Reads the channel buffer and returns object of NodeAttributesTlv.
*
* @param c input channel buffer
* @param hLength length
* @return object of NodeAttributesTlv
* @throws PcepParseException if mandatory fields are missing
*/
public static PcepValueType read(ChannelBuffer c, short hLength) throws PcepParseException {
// Node Descriptor Sub-TLVs (variable)
List<PcepValueType> llNodeAttributesSubTLVs = new LinkedList<>();
ChannelBuffer tempCb = c.readBytes(hLength);
while (TLV_HEADER_LENGTH <= tempCb.readableBytes()) {
PcepValueType tlv;
short hType = tempCb.readShort();
int iValue = 0;
short length = tempCb.readShort();
switch (hType) {
case NodeFlagBitsSubTlv.TYPE:
byte cValue = tempCb.readByte();
tlv = new NodeFlagBitsSubTlv(cValue);
break;
case OpaqueNodePropertiesSubTlv.TYPE:
tlv = OpaqueNodePropertiesSubTlv.read(tempCb, length);
break;
case NodeNameSubTlv.TYPE:
tlv = NodeNameSubTlv.read(tempCb, length);
break;
case IsisAreaIdentifierSubTlv.TYPE:
tlv = IsisAreaIdentifierSubTlv.read(tempCb, length);
break;
case IPv4RouterIdOfLocalNodeSubTlv.TYPE:
iValue = tempCb.readInt();
tlv = new IPv4RouterIdOfLocalNodeSubTlv(iValue);
break;
case IPv6RouterIdofLocalNodeSubTlv.TYPE:
byte[] ipv6Value = new byte[IPv6RouterIdofLocalNodeSubTlv.VALUE_LENGTH];
tempCb.readBytes(ipv6Value, 0, IPv6RouterIdofLocalNodeSubTlv.VALUE_LENGTH);
tlv = new IPv6RouterIdofLocalNodeSubTlv(ipv6Value);
break;
default:
throw new PcepParseException("Unsupported Sub TLV type :" + hType);
}
// Check for the padding
int pad = length % 4;
if (0 < pad) {
pad = 4 - pad;
if (pad <= tempCb.readableBytes()) {
tempCb.skipBytes(pad);
}
}
llNodeAttributesSubTLVs.add(tlv);
}
if (0 < tempCb.readableBytes()) {
throw new PcepParseException("Sub Tlv parsing error. Extra bytes received.");
}
return new NodeAttributesTlv(llNodeAttributesSubTLVs);
}
示例15: decodeData
import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
private Position decodeData(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf, int type) {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession == null) {
return null;
}
if (BitUtil.to(type, 2) == 0) {
Position position = new Position();
position.setProtocol(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_VERSION_FW, buf.readUnsignedByte());
position.set(Position.KEY_INDEX, buf.readUnsignedShort());
int status = buf.readUnsignedShort();
position.set(Position.KEY_STATUS, status);
position.setValid(!BitUtil.check(status, 5));
position.setLatitude(buf.readFloat());
position.setLongitude(buf.readFloat());
position.setCourse(buf.readUnsignedShort() * 0.1);
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort() * 0.1));
position.set(Position.KEY_ACCELERATION, buf.readUnsignedByte() * 0.1);
position.setAltitude(buf.readUnsignedShort());
position.set(Position.KEY_HDOP, buf.readUnsignedByte() * 0.1);
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte() & 0x0f);
position.setTime(new Date(buf.readUnsignedInt() * 1000));
position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001);
position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
if (BitUtil.check(type, 2)) {
buf.readUnsignedByte(); // vib
buf.readUnsignedByte(); // vib_count
int out = buf.readUnsignedByte();
for (int i = 0; i <= 3; i++) {
position.set(Position.PREFIX_OUT + (i + 1), BitUtil.check(out, i) ? 1 : 0);
}
buf.readUnsignedByte(); // in_alarm
}
if (BitUtil.check(type, 3)) {
for (int i = 1; i <= 6; i++) {
position.set(Position.PREFIX_ADC + i, buf.readUnsignedShort() * 0.001);
}
}
if (BitUtil.check(type, 4)) {
for (int i = 1; i <= 2; i++) {
position.set(Position.PREFIX_COUNT + i, buf.readUnsignedInt());
}
}
if (BitUtil.check(type, 5)) {
for (int i = 1; i <= 3; i++) {
buf.readUnsignedShort(); // fuel level
}
for (int i = 1; i <= 3; i++) {
position.set(Position.PREFIX_TEMP + i, buf.readUnsignedByte());
}
}
if (BitUtil.check(type, 6)) {
buf.skipBytes(buf.getUnsignedByte(buf.readerIndex()));
}
if (BitUtil.check(type, 7)) {
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
}
return position;
}
return null;
}