Example usage for io.netty.buffer ByteBuf readShort

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

Introduction

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

Prototype

public abstract short readShort();

Source Link

Document

Gets a 16-bit short integer at the current readerIndex and increases the readerIndex by 2 in this buffer.

Usage

From source file:alluxio.network.protocol.RPCBlockReadResponse.java

License:Apache License

/**
 * Decodes the input {@link ByteBuf} into a {@link RPCBlockReadResponse} object and returns it.
 *
 * @param in the input {@link ByteBuf}//from   w  w w . java  2s  . c  o m
 * @return The decoded RPCBlockReadResponse object
 */
public static RPCBlockReadResponse decode(ByteBuf in) {
    long blockId = in.readLong();
    long offset = in.readLong();
    long length = in.readLong();
    short status = in.readShort();

    DataBuffer data = null;
    if (length > 0) {
        // use DataNettyBuffer instead of DataByteBuffer to avoid copying
        data = new DataNettyBuffer(in, (int) length);
    }
    return new RPCBlockReadResponse(blockId, offset, length, data, Status.fromShort(status));
}

From source file:alluxio.network.protocol.RPCBlockWriteResponse.java

License:Apache License

/**
 * Decodes the input {@link ByteBuf} into a {@link RPCBlockWriteResponse} object and returns it.
 *
 * @param in the input {@link ByteBuf}//w  w w .  j a v  a  2  s  .  c om
 * @return the decoded RPCBlockWriteResponse object
 */
public static RPCBlockWriteResponse decode(ByteBuf in) {
    long sessionId = in.readLong();
    long blockId = in.readLong();
    long offset = in.readLong();
    long length = in.readLong();
    short status = in.readShort();
    return new RPCBlockWriteResponse(sessionId, blockId, offset, length, Status.fromShort(status));
}

From source file:alluxio.network.protocol.RPCErrorResponse.java

License:Apache License

/**
 * Decodes the input {@link ByteBuf} into a {@link RPCErrorResponse} object and returns it.
 *
 * @param in The input {@link ByteBuf}/*from  www.  j  ava 2 s. com*/
 * @return The decoded RPCErrorResponse object
 */
public static RPCErrorResponse decode(ByteBuf in) {
    return new RPCErrorResponse(Status.fromShort(in.readShort()));
}

From source file:alluxio.network.protocol.RPCFileReadResponse.java

License:Apache License

/**
 * Decodes the input {@link ByteBuf} into a {@link RPCFileReadResponse} object and returns it.
 *
 * @param in the input {@link ByteBuf}/*from w ww .j a va 2s  .c  o m*/
 * @return The decoded RPCFileReadResponse object
 */
public static RPCFileReadResponse decode(ByteBuf in) {
    long tempUfsFileId = in.readLong();
    long offset = in.readLong();
    long length = in.readLong();
    short status = in.readShort();

    DataBuffer data = null;
    if (length > 0) {
        data = new DataNettyBuffer(in, (int) length);
    }
    return new RPCFileReadResponse(tempUfsFileId, offset, length, data, Status.fromShort(status));
}

From source file:alluxio.network.protocol.RPCFileWriteResponse.java

License:Apache License

/**
 * Decodes the input {@link ByteBuf} into a {@link RPCFileWriteResponse} object and returns it.
 *
 * @param in the input {@link ByteBuf}/*w w  w.j av  a2s . co m*/
 * @return the decoded RPCFileWriteResponse object
 */
public static RPCFileWriteResponse decode(ByteBuf in) {
    long tempUfsFileId = in.readLong();
    long offset = in.readLong();
    long length = in.readLong();
    short status = in.readShort();
    return new RPCFileWriteResponse(tempUfsFileId, offset, length, Status.fromShort(status));
}

From source file:appeng.core.sync.packets.PacketPartialItem.java

License:Open Source License

public PacketPartialItem(final ByteBuf stream) {
    this.pageNum = stream.readShort();
    stream.readBytes(this.data = new byte[stream.readableBytes()]);
}

From source file:appeng.core.sync.packets.PacketProgressBar.java

License:Open Source License

public PacketProgressBar(final ByteBuf stream) {
    this.id = stream.readShort();
    this.value = stream.readLong();
}

From source file:appeng.parts.CableBusContainer.java

License:Open Source License

public boolean readFromStream(final ByteBuf data) throws IOException {
    final byte sides = data.readByte();

    boolean updateBlock = false;

    for (int x = 0; x < 7; x++) {
        AEPartLocation side = AEPartLocation.fromOrdinal(x);
        if (((sides & (1 << x)) == (1 << x))) {
            IPart p = this.getPart(side);

            final short itemID = data.readShort();
            final short dmgValue = data.readShort();

            final Item myItem = Item.getItemById(itemID);

            final ItemStack current = p != null ? p.getItemStack(PartItemStack.NETWORK) : null;
            if (current != null && current.getItem() == myItem && current.getItemDamage() == dmgValue) {
                if (p.readFromStream(data)) {
                    updateBlock = true;/*from   w w  w  .ja v a 2  s. c  o m*/
                }
            } else {
                this.removePart(side, false);
                side = this.addPart(new ItemStack(myItem, 1, dmgValue), side, null, null);
                if (side != null) {
                    p = this.getPart(side);
                    p.readFromStream(data);
                } else {
                    throw new IllegalStateException("Invalid Stream For CableBus Container.");
                }
            }
        } else if (this.getPart(side) != null) {
            this.removePart(side, false);
        }
    }

    if (this.getFacadeContainer().readFromStream(data)) {
        return true;
    }

    return updateBlock;
}

From source file:appeng.util.item.AEItemStack.java

License:Open Source License

public static IAEItemStack loadItemStackFromPacket(final ByteBuf data) throws IOException {
    final byte mask = data.readByte();
    // byte PriorityType = (byte) (mask & 0x03);
    final byte stackType = (byte) ((mask & 0x0C) >> 2);
    final byte countReqType = (byte) ((mask & 0x30) >> 4);
    final boolean isCraftable = (mask & 0x40) > 0;
    final boolean hasTagCompound = (mask & 0x80) > 0;

    // don't send this...
    final NBTTagCompound d = new NBTTagCompound();

    // For some insane reason, Vanilla can only parse numeric item ids if they are strings
    short itemNumericId = data.readShort();
    d.setString("id", String.valueOf(itemNumericId));
    d.setShort("Damage", data.readShort());
    d.setByte("Count", (byte) 0);

    if (hasTagCompound) {
        final int len = data.readInt();

        final byte[] bd = new byte[len];
        data.readBytes(bd);/*  w w  w  . j  a v  a  2  s  .  c  om*/

        final ByteArrayInputStream di = new ByteArrayInputStream(bd);
        d.setTag("tag", CompressedStreamTools.read(new DataInputStream(di)));
    }

    // long priority = getPacketValue( PriorityType, data );
    final long stackSize = getPacketValue(stackType, data);
    final long countRequestable = getPacketValue(countReqType, data);

    final ItemStack itemstack = ItemStack.loadItemStackFromNBT(d);
    if (itemstack == null) {
        return null;
    }

    final AEItemStack item = AEItemStack.create(itemstack);
    // item.priority = (int) priority;
    item.setStackSize(stackSize);
    item.setCountRequestable(countRequestable);
    item.setCraftable(isCraftable);
    return item;
}

From source file:appeng.util.item.AEStack.java

License:Open Source License

static long getPacketValue(final byte type, final ByteBuf tag) {
    if (type == 0) {
        long l = tag.readByte();
        l -= Byte.MIN_VALUE;/*from  w  w w .j a v  a 2 s. co  m*/
        return l;
    } else if (type == 1) {
        long l = tag.readShort();
        l -= Short.MIN_VALUE;
        return l;
    } else if (type == 2) {
        long l = tag.readInt();
        l -= Integer.MIN_VALUE;
        return l;
    }

    return tag.readLong();
}