Example usage for io.netty.buffer ByteBuf writeShort

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

Introduction

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

Prototype

public abstract ByteBuf writeShort(int value);

Source Link

Document

Sets the specified 16-bit short integer at the current writerIndex and increases the writerIndex by 2 in this buffer.

Usage

From source file:org.dcache.xrootd.tpc.protocol.messages.OutboundOpenReadOnlyRequest.java

License:Open Source License

@Override
protected void getParams(ByteBuf buffer) {
    buffer.writeShort(kXR_ur | kXR_gr);
    buffer.writeShort(kXR_open_read | kXR_retstat);
    buffer.writeBytes(RESERVED);// www. jav  a 2s  . co m
    int len = path.length();
    buffer.writeInt(len);
    buffer.writeBytes(path.getBytes(US_ASCII));
}

From source file:org.dcache.xrootd.tpc.protocol.messages.OutboundProtocolRequest.java

License:Open Source License

@Override
public void writeTo(ChannelHandlerContext ctx, ChannelPromise promise) {
    ByteBuf buffer = ctx.alloc().buffer(24);
    try {/*from   w w w.  j av  a2 s  . c  o m*/
        buffer.writeShort(streamId);
        buffer.writeShort(kXR_protocol);
        buffer.writeInt(version);
        buffer.writeBytes(RESERVED);
        buffer.writeByte(kXR_secreqs);
        buffer.writeInt(0);
    } catch (Error | RuntimeException t) {
        promise.setFailure(t);
        buffer.release();
        return;
    }

    ctx.write(buffer, promise);
}

From source file:org.dcache.xrootd.tpc.protocol.messages.OutboundSigverRequest.java

License:Open Source License

@Override
protected void getParams(ByteBuf buffer) {
    buffer.writeShort(expectrid);
    buffer.writeByte(0);/*from ww w .j  av  a2s  .  c o m*/
    buffer.writeByte(0); // we do not send write requests, so no data = 0x0
    buffer.writeLong(seqno);
    buffer.writeByte(kXR_SHA256);
    buffer.writeBytes(RESERVED);
    buffer.writeInt(signature.length);
    buffer.writeBytes(signature);
}

From source file:org.dna.mqtt.moquette.parser.netty.SubAckEncoder.java

License:Open Source License

@Override
protected void encode(ChannelHandlerContext chc, SubAckMessage message, ByteBuf out) {
    if (message.types().isEmpty()) {
        throw new IllegalArgumentException("Found a suback message with empty topics");
    }//from  w w  w . ja v a2  s.  c  o  m

    int variableHeaderSize = 2 + message.types().size();
    ByteBuf buff = chc.alloc().buffer(6 + variableHeaderSize);
    try {
        buff.writeByte(AbstractMessage.SUBACK << 4);
        buff.writeBytes(Utils.encodeRemainingLength(variableHeaderSize));
        buff.writeShort(message.getMessageID());
        for (QOSType c : message.types()) {
            int qosValue = (c == QOSType.FAILURE) ? qosValue = 0x80 : c.ordinal();
            buff.writeByte(qosValue);
        }

        out.writeBytes(buff);
    } finally {
        buff.release();
    }
}

From source file:org.eclipse.moquette.parser.netty.SubAckDecoderTest.java

License:Open Source License

private void initHeaderQos(ByteBuf buff, int messageID, AbstractMessage.QOSType... qoss)
        throws IllegalAccessException {
    buff.clear().writeByte(AbstractMessage.SUBACK << 4)
            .writeBytes(Utils.encodeRemainingLength(2 + qoss.length));

    buff.writeShort(messageID);
    for (AbstractMessage.QOSType qos : qoss) {
        buff.writeByte(qos.ordinal());/*from  www .  j a v a 2s  .  c  o  m*/
    }
}

From source file:org.eclipse.moquette.parser.netty.SubscribeDecoderTest.java

License:Open Source License

private void initMultiTopic(ByteBuf buff, int messageID, SubscribeMessage.Couple... topics)
        throws IllegalAccessException {
    ByteBuf topicBuffer = Unpooled.buffer(4);
    topicBuffer.writeShort(messageID);
    for (SubscribeMessage.Couple couple : topics) {
        topicBuffer.writeBytes(Utils.encodeString(couple.getTopicFilter()));
        topicBuffer.writeByte(couple.getQos());
    }/*from ww w.  j  a  v a  2s  .  c o m*/

    buff.clear().writeByte(AbstractMessage.SUBSCRIBE << 4 | (byte) 0x02)
            .writeBytes(Utils.encodeRemainingLength(topicBuffer.readableBytes()));
    buff.writeBytes(topicBuffer);
}

From source file:org.eclipse.moquette.parser.netty.SubscribeDecoderTest.java

License:Open Source License

private void initPollutedTopic(ByteBuf buff, int messageID, SubscribeMessage.Couple topic)
        throws IllegalAccessException {
    ByteBuf topicBuffer = Unpooled.buffer(4);
    topicBuffer.writeShort(messageID);
    topicBuffer.writeBytes(Utils.encodeString(topic.getTopicFilter()));
    topicBuffer.writeByte(0xF0 | topic.getQos());

    buff.clear().writeByte(AbstractMessage.SUBSCRIBE << 4 | (byte) 0x02)
            .writeBytes(Utils.encodeRemainingLength(topicBuffer.readableBytes()));
    buff.writeBytes(topicBuffer);//w  ww .j  a  va 2  s .  co m
}

From source file:org.eclipse.neoscada.protocol.iec60870.apci.APDUEncoder.java

License:Open Source License

private void handleIFormat(final InformationTransfer msg, ByteBuf out) {
    final ByteBuf data = msg.getData();
    try {/*from   w  w  w . j ava2s . c o  m*/
        out = out.order(ByteOrder.LITTLE_ENDIAN);

        final int len = data.readableBytes();

        if (len > Constants.APCI_MAX_DATA_LENGTH) {
            throw new EncoderException(String.format("Packet too big - %s bytes", len));
        }

        out.ensureWritable(6 + len);
        out.writeByte(Constants.START_BYTE);
        out.writeByte(4 + len);
        out.writeShort(msg.getSendSequenceNumber() << 1);
        out.writeShort(msg.getReceiveSequenceNumber() << 1);
        out.writeBytes(data);
    } finally {
        ReferenceCountUtil.release(msg.getData());
    }
}

From source file:org.eclipse.neoscada.protocol.iec60870.apci.APDUEncoder.java

License:Open Source License

private void handleSFormat(final Supervisory msg, ByteBuf out) {
    out = out.order(ByteOrder.LITTLE_ENDIAN);

    out.ensureWritable(6);//  w  w  w.  jav  a 2  s .c  o m
    out.writeByte(Constants.START_BYTE);
    out.writeByte(4);
    out.writeBytes(new byte[] { 0x01, 0x00 });
    out.writeShort(msg.getReceiveSequenceNumber() << 1);
}

From source file:org.eclipse.neoscada.protocol.iec60870.asdu.types.ASDUAddress.java

License:Open Source License

public int[] toArray() {
    final ByteBuf buf = Unpooled.buffer(2);
    buf.writeShort(this.address);
    return new int[] { buf.getUnsignedByte(0), buf.getUnsignedByte(1) };
}