Example usage for io.netty.buffer ByteBuf readSlice

List of usage examples for io.netty.buffer ByteBuf readSlice

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf readSlice.

Prototype

public abstract ByteBuf readSlice(int length);

Source Link

Document

Returns a new slice of this buffer's sub-region starting at the current readerIndex and increases the readerIndex by the size of the new slice (= length ).

Usage

From source file:com.antsdb.saltedfish.server.mysql.packet.LongDataPacket.java

License:Open Source License

@Override
public void read(MysqlServerHandler handler, ByteBuf in) {
    this.content = in.readSlice(this.packetLength);
    content.retain();// ww  w.  j  av a2  s .  com
}

From source file:com.cloudhopper.smpp.transcoder.DefaultPduTranscoder.java

License:Apache License

@Override
public Pdu decode(ByteBuf buffer) throws UnrecoverablePduException, RecoverablePduException {
    // wait until the length prefix is available
    if (buffer.readableBytes() < SmppConstants.PDU_INT_LENGTH) {
        return null;
    }/*from  w w  w. j  av  a 2 s.  c om*/

    // parse the command length (first 4 bytes)
    int commandLength = buffer.getInt(buffer.readerIndex());
    //logger.trace("PDU commandLength [" + commandLength + "]");

    // valid command length is >= 16 bytes
    if (commandLength < SmppConstants.PDU_HEADER_LENGTH) {
        throw new UnrecoverablePduException(
                "Invalid PDU length [0x" + HexUtil.toHexString(commandLength) + "] parsed");
    }

    // wait until the whole pdu is available (entire pdu)
    if (buffer.readableBytes() < commandLength) {
        return null;
    }

    // at this point, we have the entire PDU and length already in the buffer
    // we'll create a new "view" of this PDU and read the data from the actual buffer
    // NOTE: this should be super fast since the underlying byte array doesn't get copied
    ByteBuf buffer0 = buffer.readSlice(commandLength);

    return doDecode(commandLength, buffer0);
}

From source file:com.datastax.driver.core.CBUtil.java

License:Apache License

public static ByteBuffer readValue(ByteBuf cb) {
    int length = cb.readInt();
    if (length < 0)
        return null;
    ByteBuf slice = cb.readSlice(length);

    return ByteBuffer.wrap(readRawBytes(slice));
}

From source file:com.digitalpetri.modbus.codec.ModbusRequestDecoder.java

License:Apache License

private WriteMultipleCoilsRequest decodeWriteMultipleCoils(ByteBuf buffer) {
    int address = buffer.readUnsignedShort();
    int quantity = buffer.readUnsignedShort();
    int byteCount = buffer.readUnsignedByte();
    ByteBuf values = buffer.readSlice(byteCount).retain();

    return new WriteMultipleCoilsRequest(address, quantity, values);
}

From source file:com.digitalpetri.modbus.codec.ModbusRequestDecoder.java

License:Apache License

private WriteMultipleRegistersRequest decodeWriteMultipleRegisters(ByteBuf buffer) {
    int address = buffer.readUnsignedShort();
    int quantity = buffer.readUnsignedShort();
    int byteCount = buffer.readByte();
    ByteBuf values = buffer.readSlice(byteCount).retain();

    return new WriteMultipleRegistersRequest(address, quantity, values);
}

From source file:com.digitalpetri.modbus.codec.ModbusResponseDecoder.java

License:Apache License

public ReadCoilsResponse decodeReadCoils(ByteBuf buffer) {
    int byteCount = buffer.readUnsignedByte();
    ByteBuf coilStatus = buffer.readSlice(byteCount).retain();

    return new ReadCoilsResponse(coilStatus);
}

From source file:com.digitalpetri.modbus.codec.ModbusResponseDecoder.java

License:Apache License

public ReadDiscreteInputsResponse decodeReadDiscreteInputs(ByteBuf buffer) {
    int byteCount = buffer.readUnsignedByte();
    ByteBuf inputStatus = buffer.readSlice(byteCount).retain();

    return new ReadDiscreteInputsResponse(inputStatus);
}

From source file:com.digitalpetri.modbus.codec.ModbusResponseDecoder.java

License:Apache License

public ReadHoldingRegistersResponse decodeReadHoldingRegisters(ByteBuf buffer) {
    int byteCount = buffer.readUnsignedByte();
    ByteBuf registers = buffer.readSlice(byteCount).retain();

    return new ReadHoldingRegistersResponse(registers);
}

From source file:com.digitalpetri.modbus.codec.ModbusResponseDecoder.java

License:Apache License

public ReadInputRegistersResponse decodeReadInputRegisters(ByteBuf buffer) {
    int byteCount = buffer.readUnsignedByte();
    ByteBuf registers = buffer.readSlice(byteCount).retain();

    return new ReadInputRegistersResponse(registers);
}

From source file:com.digitalpetri.opcua.stack.client.handlers.UaTcpClientAcknowledgeHandler.java

License:Apache License

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception {
    buffer = buffer.order(ByteOrder.LITTLE_ENDIAN);

    while (buffer.readableBytes() >= HEADER_LENGTH && buffer.readableBytes() >= getMessageLength(buffer)) {

        int messageLength = getMessageLength(buffer);
        MessageType messageType = MessageType.fromMediumInt(buffer.getMedium(buffer.readerIndex()));

        switch (messageType) {
        case Acknowledge:
            onAcknowledge(ctx, buffer.readSlice(messageLength));
            break;

        case Error:
            onError(ctx, buffer.readSlice(messageLength));
            break;

        default:/*from w  w  w . j a va  2  s  .c  om*/
            out.add(buffer.readSlice(messageLength).retain());
        }
    }
}