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.bgp4j.netty.protocol.update.UpdatePacket.java

License:Apache License

@Override
protected void encodePayload(ByteBuf buffer) {
    int withdrawnRoutesLengthIndex = buffer.writerIndex();

    buffer.writeShort(0); // placeholder for withdrawn routes length
    encodeWithdrawnRoutes(buffer);/*from   w  w  w  .  ja  v  a 2 s .c o m*/
    buffer.setShort(withdrawnRoutesLengthIndex, buffer.writerIndex() - withdrawnRoutesLengthIndex - 2);

    int pathAttributesLengthIndex = buffer.writerIndex();

    buffer.writeShort(0); // placeholder for path attributes length
    encodePathAttributes(buffer);
    buffer.setShort(pathAttributesLengthIndex, buffer.writerIndex() - pathAttributesLengthIndex - 2);

    encodeNlris(buffer);
}

From source file:org.blockartistry.DynSurround.network.PacketThunder.java

License:MIT License

@Override
public void toBytes(@Nonnull final ByteBuf buf) {
    buf.writeShort(this.dimension);
    buf.writeBoolean(this.doFlash);
    buf.writeInt(this.pos.getX());
    buf.writeInt(this.pos.getY());
    buf.writeInt(this.pos.getZ());
}

From source file:org.blockartistry.DynSurround.network.PacketWeatherUpdate.java

License:MIT License

@Override
public void toBytes(@Nonnull final ByteBuf buf) {
    buf.writeShort(this.dimension);
    buf.writeFloat(this.intensity);
    buf.writeFloat(this.maxIntensity);
    buf.writeInt(this.nextRainChange);
    buf.writeFloat(this.thunderStrength);
    buf.writeInt(this.thunderChange);
    buf.writeInt(this.thunderEvent);
}

From source file:org.dcache.xrootd.protocol.messages.AbstractXrootdResponse.java

License:Open Source License

@Override
public void writeTo(ChannelHandlerContext ctx, ChannelPromise promise) {
    int dlen = getDataLength();
    ByteBuf buffer = ctx.alloc().buffer(8 + dlen);
    try {//w  ww .j  a  va  2  s  .  c  o  m
        buffer.writeShort(request.getStreamId());
        buffer.writeShort(stat);
        buffer.writeInt(dlen);
        getBytes(buffer);
    } catch (Error | RuntimeException t) {
        promise.setFailure(t);
        buffer.release();
        return;
    } finally {
        ReferenceCountUtil.release(this);
    }
    ctx.write(buffer, promise);
}

From source file:org.dcache.xrootd.protocol.messages.AsyncResponse.java

License:Open Source License

@Override
public void writeTo(ChannelHandlerContext ctx, final ChannelPromise promise) {
    try {/* w w w .ja v  a2 s .c o  m*/
        int dlen = getDataLength();
        ByteBuf header = ctx.alloc().buffer(8 + dlen);
        try {
            header.writeShort(0);
            header.writeShort(kXR_attn);
            header.writeInt(dlen);
            header.writeInt(kXR_asynresp);
            header.writeInt(0);
        } catch (Error | RuntimeException t) {
            promise.setFailure(t);
            header.release();
            return;
        }
        ctx.write(header).addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture future) throws Exception {
                if (!future.isSuccess()) {
                    promise.tryFailure(future.cause());
                }
            }
        });

        ChannelPromise channelPromise = ctx.newPromise();
        channelPromise.addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture future) throws Exception {
                if (future.isSuccess()) {
                    promise.trySuccess();
                } else {
                    promise.tryFailure(future.cause());
                }
            }
        });
        ReferenceCountUtil.retain(response).writeTo(ctx, channelPromise);
    } finally {
        release();
    }
}

From source file:org.dcache.xrootd.protocol.messages.ReadResponse.java

License:Open Source License

@Override
public void writeTo(ChannelHandlerContext ctx, ChannelPromise promise) {
    checkState(refCnt() > 0);//w  w w .  j  a v a 2s  .  c om

    ByteBuf header = ctx.alloc().buffer(8);
    header.writeShort(request.getStreamId());
    header.writeShort(stat);
    header.writeInt(data.readableBytes());

    ctx.write(ctx.alloc().compositeBuffer(2).addComponents(header, data).writerIndex(8 + data.readableBytes()),
            promise);
}

From source file:org.dcache.xrootd.protocol.messages.ReadVResponse.java

License:Open Source License

@Override
public void writeTo(ChannelHandlerContext ctx, ChannelPromise promise) {
    checkState(refCnt() > 0);//ww w.  j  ava  2s . com

    CompositeByteBuf buffer = ctx.alloc().compositeBuffer(2 * length + 1);

    ByteBuf header = ctx.alloc().buffer(8);
    header.writeShort(request.getStreamId());
    header.writeShort(stat);
    header.writeInt(getDataLength());
    buffer.addComponent(header);

    for (int i = 0; i < length; i++) {
        header = ctx.alloc().buffer(READ_LIST_HEADER_SIZE);
        header.writeInt(requests[index + i].getFileHandle());
        header.writeInt(data[index + i].readableBytes());
        header.writeLong(requests[index + i].getOffset());
        buffer.addComponent(header);
        buffer.addComponent(data[index + i].retain());
    }

    buffer.writerIndex(buffer.capacity());
    ctx.write(buffer, promise);

    release();
}

From source file:org.dcache.xrootd.protocol.messages.ZeroCopyReadResponse.java

License:Open Source License

@Override
public void writeTo(ChannelHandlerContext ctx, final ChannelPromise promise) {
    ByteBuf header = ctx.alloc().buffer(8);
    header.writeShort(request.getStreamId());
    header.writeShort(kXR_ok);/*from  w  w w  .  j a  v a2 s  .c  o  m*/
    header.writeInt(count);
    ctx.write(header).addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(ChannelFuture future) throws Exception {
            if (!future.isSuccess()) {
                promise.tryFailure(future.cause());
            }
        }
    });
    ctx.write(new DefaultFileRegion(file, request.getReadOffset(), count))
            .addListener(new ChannelFutureListener() {
                @Override
                public void operationComplete(ChannelFuture future) throws Exception {
                    if (future.isSuccess()) {
                        promise.trySuccess();
                    } else {
                        promise.tryFailure(future.cause());
                    }
                }
            });
}

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

License:Open Source License

protected void writeToBuffer(ByteBuf buffer) {
    buffer.writeShort(streamId);
    buffer.writeShort(requestId);
    getParams(buffer);
}

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

License:Open Source License

@Override
protected void getParams(ByteBuf buffer) {
    buffer.writeShort(kXR_Qcksum);
    buffer.writeBytes(RESERVED);//from  ww w.  j  av a2s . co  m
    buffer.writeInt(path.length());
    buffer.writeBytes(path.getBytes(StandardCharsets.US_ASCII));
}