Java Code Examples for io.netty.buffer.ByteBuf#skipBytes()

The following examples show how to use io.netty.buffer.ByteBuf#skipBytes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpdyHeaderBlockZlibDecoder.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@Override
void decode(ByteBufAllocator alloc, ByteBuf headerBlock, SpdyHeadersFrame frame) throws Exception {
    int len = setInput(headerBlock);

    int numBytes;
    do {
        numBytes = decompress(alloc, frame);
    } while (numBytes > 0);

    // z_stream has an internal 64-bit hold buffer
    // it is always capable of consuming the entire input
    if (decompressor.getRemaining() != 0) {
        // we reached the end of the deflate stream
        throw INVALID_HEADER_BLOCK;
    }

    headerBlock.skipBytes(len);
}
 
Example 2
Source File: CanFrameChannelInboundHandler.java    From ClusterDeviceControlPlatform with MIT License 6 votes vote down vote up
@Override
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) {
    if (errorCount != 0) {
        logger.warn("接收到错误的 CAN 帧数量:" + errorCount);
    }
    if (msg.readableBytes() % 13 != 0) {
        errorCount++;
        logger.warn("读取到非整数个 CAN 帧");
        return;
    }

    while (msg.readableBytes() >= 13) {
        int bodyLength = msg.readByte() & 0x0F;
        msg.skipBytes(1);
        int msgId = msg.readByte();
        int boxId = msg.readByte();
        int groupId = msg.readByte();
        IMessage message = handleMessage(msgId, groupId, boxId, bodyLength, msg);
        ctx.fireChannelRead(message);
    }
}
 
Example 3
Source File: MldpP2mpLspParser.java    From bgpcep with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public MldpP2mpLsp parse(final ByteBuf buffer) {
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev200120.pmsi.tunnel.pmsi
            .tunnel.tunnel.identifier.mldp.p2mp.lsp.MldpP2mpLspBuilder mldpP2mpLsp =
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev200120.pmsi.tunnel
                    .pmsi.tunnel.tunnel.identifier.mldp.p2mp.lsp.MldpP2mpLspBuilder();
    buffer.skipBytes(RESERVED);
    final Class<? extends AddressFamily> addressFamily = this.addressFamilyRegistry
            .classForFamily(buffer.readUnsignedShort());
    if (addressFamily == null) {
        LOG.debug("Skipping serialization of TunnelIdentifier {}, address family type  supported",
                ByteBufUtil.hexDump(buffer));
        return null;
    }
    mldpP2mpLsp.setAddressFamily(addressFamily);
    final short rootNodeLength = buffer.readUnsignedByte();
    mldpP2mpLsp.setRootNodeAddress(parseIpAddress(rootNodeLength, buffer.readBytes(rootNodeLength)));
    final int opaqueValueLength = buffer.readUnsignedShort();
    mldpP2mpLsp.setOpaqueValue(OpaqueUtil.parseOpaqueList(buffer.readBytes(opaqueValueLength)));
    return new MldpP2mpLspBuilder().setMldpP2mpLsp(mldpP2mpLsp.build()).build();
}
 
Example 4
Source File: Ukcp.java    From java-Kcp with Apache License 2.0 6 votes vote down vote up
public void input(ByteBuf data,long current) throws IOException {
    //lastRecieveTime = System.currentTimeMillis();
    Snmp.snmp.InPkts.increment();
    Snmp.snmp.InBytes.add(data.readableBytes());

    if (fecDecode != null) {
        FecPacket fecPacket = FecPacket.newFecPacket(data);
        if (fecPacket.getFlag() == Fec.typeData) {
            data.skipBytes(2);
            input(data, true,current);
        }
        if (fecPacket.getFlag() == Fec.typeData || fecPacket.getFlag() == Fec.typeParity) {
            List<ByteBuf> byteBufs = fecDecode.decode(fecPacket);
            if (byteBufs != null) {
                for (ByteBuf byteBuf : byteBufs) {
                    input(byteBuf, false,current);
                    byteBuf.release();
                }
            }
        }
    } else {
        input(data, true,current);
    }
}
 
Example 5
Source File: GetSymbolInstanceAttributeListService.java    From ethernet-ip with Apache License 2.0 6 votes vote down vote up
@Override
public SymbolInstance decode(int instanceId, ByteBuf buffer) {
    // attribute 1 - symbol name
    int nameLength = buffer.readUnsignedShort();
    String name = buffer.toString(
        buffer.readerIndex(),
        nameLength,
        StandardCharsets.US_ASCII
    );
    buffer.skipBytes(nameLength);

    // attribute 2 - symbol type
    int type = buffer.readUnsignedShort();

    // attribute 8 - dimensions
    int d1Size = buffer.readInt();
    int d2Size = buffer.readInt();
    int d3Size = buffer.readInt();

    return new SymbolInstance(program, name, instanceId, type, d1Size, d2Size, d3Size);
}
 
Example 6
Source File: RROIpv6PrefixSubobjectParser.java    From bgpcep with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Subobject parseSubobject(final ByteBuf buffer) throws PCEPDeserializerException {
    checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
    if (buffer.readableBytes() != CONTENT_LENGTH) {
        throw new PCEPDeserializerException(
                "Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
    }
    final int length = buffer.getUnsignedByte(PREFIX_F_OFFSET);
    final IpPrefixBuilder prefix = new IpPrefixBuilder().setIpPrefix(
            new IpPrefix(Ipv6Util.prefixForBytes(ByteArray.readBytes(buffer, Ipv6Util.IPV6_LENGTH), length)));
    buffer.skipBytes(PREFIX_F_LENGTH);
    final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
    final SubobjectBuilder builder = new SubobjectBuilder()
            .setProtectionAvailable(flags.get(LPA_F_OFFSET))
            .setProtectionInUse(flags.get(LPIU_F_OFFSET))
            .setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(prefix.build()).build());
    return builder.build();
}
 
Example 7
Source File: RfbClient38Decoder.java    From jfxvnc with Apache License 2.0 6 votes vote down vote up
private PixelFormat parsePixelFormat(ByteBuf m) {

    PixelFormat pf = new PixelFormat();

    pf.setBitPerPixel(m.readUnsignedByte());
    pf.setDepth(m.readUnsignedByte());
    pf.setBigEndian(m.readUnsignedByte() == 1);
    pf.setTrueColor(m.readUnsignedByte() == 1);
    pf.setRedMax(m.readUnsignedShort());
    pf.setGreenMax(m.readUnsignedShort());
    pf.setBlueMax(m.readUnsignedShort());

    pf.setRedShift(m.readUnsignedByte());
    pf.setGreenShift(m.readUnsignedByte());
    pf.setBlueShift(m.readUnsignedByte());
    m.skipBytes(3);

    return pf;
  }
 
Example 8
Source File: HttpContentEncoderTest.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@Override
protected Result beginEncode(HttpResponse headers, String acceptEncoding) {
    return new Result("test", new EmbeddedChannel(new MessageToByteEncoder<ByteBuf>() {
        @Override
        protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception {
            out.writeBytes(String.valueOf(in.readableBytes()).getBytes(CharsetUtil.US_ASCII));
            in.skipBytes(in.readableBytes());
        }
    }));
}
 
Example 9
Source File: PduCodec.java    From herddb with Apache License 2.0 5 votes vote down vote up
public static byte[] readToken(Pdu pdu) {
    ByteBuf buffer = pdu.buffer;
    buffer.readerIndex(0);
    buffer.skipBytes(VERSION_SIZE
            + FLAGS_SIZE
            + TYPE_SIZE
            + MSGID_SIZE);
    byte tokenPresent = buffer.readByte();
    if (tokenPresent == NULLABLE_FIELD_PRESENT) {
        return ByteBufUtils.readArray(buffer);
    } else {
        return null;
    }
}
 
Example 10
Source File: ZclDataUtil.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
private static Object readBag(ByteBuf input) throws IOException {
   log.warn("cannot currently decode zigbee bag data types, skipping");

   Object len = readBit16(input, true, false);
   if (len == NONE) return NONE;

   int length = ((Short)len).shortValue() & 0xFFFF;
   input.skipBytes(length);

   return NONE;
}
 
Example 11
Source File: UnknownRectDecoder.java    From jfxvnc with Apache License 2.0 5 votes vote down vote up
@Override
public boolean decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
  if (!in.isReadable(capacity)) {
    return false;
  }
  in.skipBytes(capacity);
  return true;
}
 
Example 12
Source File: LegacyPingDecoder.java    From Velocity with MIT License 5 votes vote down vote up
private static LegacyPing readExtended16Data(ByteBuf in) {
  in.skipBytes(1);
  String channelName = readLegacyString(in);
  if (!channelName.equals(MC_1_6_CHANNEL)) {
    throw new IllegalArgumentException("Didn't find correct channel");
  }
  in.skipBytes(3);
  String hostname = readLegacyString(in);
  int port = in.readInt();

  return new LegacyPing(LegacyMinecraftPingVersion.MINECRAFT_1_6, InetSocketAddress
      .createUnresolved(hostname, port));
}
 
Example 13
Source File: CompatibleMarshallingDecoder.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@Override
protected void decodeLast(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception {
    switch (buffer.readableBytes()) {
    case 0:
        return;
    case 1:
        // Ignore the last TC_RESET
        if (buffer.getByte(buffer.readerIndex()) == ObjectStreamConstants.TC_RESET) {
            buffer.skipBytes(1);
            return;
        }
    }

    decode(ctx, buffer, out);
}
 
Example 14
Source File: DefinitionMetadataMessage.java    From r2dbc-mysql with Apache License 2.0 5 votes vote down vote up
private static DefinitionMetadataMessage decode320(ByteBuf buf, ConnectionContext context) {
    CharCollation collation = context.getClientCollation();
    Charset charset = collation.getCharset();
    String table = readVarIntSizedString(buf, charset);
    String column = readVarIntSizedString(buf, charset);

    buf.skipBytes(1); // Constant 0x3
    int size = buf.readUnsignedMediumLE();

    buf.skipBytes(1); // Constant 0x1
    short type = buf.readUnsignedByte();

    buf.skipBytes(1); // Constant 0x3
    short definitions = buf.readShortLE();
    short decimals = buf.readUnsignedByte();

    return new DefinitionMetadataMessage(
        null,
        table,
        null,
        column,
        null,
        collation.getId(),
        size,
        type,
        definitions,
        decimals
    );
}
 
Example 15
Source File: FrameDecoderHandler.java    From jfxvnc with Apache License 2.0 5 votes vote down vote up
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
  if (!in.isReadable()) {
    return;
  }

  FrameDecoder decoder;
  switch (state) {
    case NEXT:
      serverEvent = ServerEvent.valueOf(in.getUnsignedByte(0));
      decoder = frameDecoder.get(serverEvent);

      if (decoder == null) {
        logger.error("not handled server message type: {} ({})", serverEvent, in.getUnsignedByte(0));
        in.skipBytes(in.readableBytes());
        return;
      }
      if (!decoder.decode(ctx, in, out)) {
        state = State.FRAME;
      }
    case FRAME:
      decoder = frameDecoder.get(serverEvent);

      if (decoder == null) {
        logger.error("not handled server message type: {} ({})", serverEvent, in.getUnsignedByte(0));
        in.skipBytes(in.readableBytes());
        return;
      }
      if (decoder.decode(ctx, in, out)) {
        state = State.NEXT;
      }
      break;
    default:
      logger.warn("unknown state: {}", state);
      break;
  }
}
 
Example 16
Source File: LocalTimeCodec.java    From r2dbc-mysql with Apache License 2.0 5 votes vote down vote up
private static LocalTime decodeBinary(ByteBuf buf) {
    int bytes = buf.readableBytes();

    if (bytes < TIME_SIZE) {
        return LocalTime.MIDNIGHT;
    }

    boolean isNegative = buf.readBoolean();

    // Skip day part.
    buf.skipBytes(Integer.BYTES);

    byte hour = buf.readByte();
    byte minute = buf.readByte();
    byte second = buf.readByte();

    if (bytes < MICRO_TIME_SIZE) {
        if (isNegative) {
            return negativeCircle(hour, minute, second);
        } else {
            return LocalTime.of(hour % HOURS_OF_DAY, minute, second);
        }
    }

    long nano = buf.readUnsignedIntLE() * NANOS_OF_MICRO;

    if (isNegative) {
        return negativeCircle(hour, minute, second, nano);
    } else {
        return LocalTime.of(hour % HOURS_OF_DAY, minute, second, (int) nano);
    }
}
 
Example 17
Source File: PullService.java    From qmq with Apache License 2.0 5 votes vote down vote up
private List<BaseMessage> deserializeBaseMessage(ByteBuf input) {
    if (input.readableBytes() == 0) return Collections.emptyList();
    List<BaseMessage> result = Lists.newArrayList();

    long pullLogOffset = input.readLong();
    //ignore consumer offset
    input.readLong();

    while (input.isReadable()) {
        BaseMessage message = new BaseMessage();
        byte flag = input.readByte();
        input.skipBytes(8 + 8);
        String subject = PayloadHolderUtils.readString(input);
        String messageId = PayloadHolderUtils.readString(input);
        readTags(input, message, flag);
        int bodyLen = input.readInt();
        ByteBuf body = input.readSlice(bodyLen);
        HashMap<String, Object> attrs = deserializeMapWrapper(subject, messageId, body);
        message.setMessageId(messageId);
        message.setSubject(subject);
        message.setAttrs(attrs);
        message.setProperty(BaseMessage.keys.qmq_pullOffset, pullLogOffset);
        result.add(message);

        pullLogOffset++;
    }
    return result;
}
 
Example 18
Source File: Eof41Message.java    From r2dbc-mysql with Apache License 2.0 4 votes vote down vote up
static Eof41Message decode(ByteBuf buf) {
    buf.skipBytes(1); // skip generic header 0xFE of EOF messages

    int warnings = buf.readUnsignedShortLE();
    return new Eof41Message(warnings, buf.readShortLE());
}
 
Example 19
Source File: PositionSerializer.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void skipPosition(ByteBuf from) {
	from.skipBytes(Long.BYTES);
}
 
Example 20
Source File: SpdyHeaderBlockRawDecoder.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
private static int readLengthField(ByteBuf buffer) {
    int length = getSignedInt(buffer, buffer.readerIndex());
    buffer.skipBytes(LENGTH_FIELD_SIZE);
    return length;
}