Example usage for io.netty.buffer ByteBuf readLong

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

Introduction

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

Prototype

public abstract long readLong();

Source Link

Document

Gets a 64-bit integer at the current readerIndex and increases the readerIndex by 8 in this buffer.

Usage

From source file:server.operation.OperationServerHandler.java

License:Apache License

@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {

    ByteBuf buf = (ByteBuf) msg;
    System.out.println("? : " + (ByteBufUtil.hexDump(buf)));

    startTm = System.currentTimeMillis();

    /*/*from  ww w  . j  ava2s . c  o  m*/
     * if (buf.readableBytes() <= 20) {
     * System.out.println("buf.readableBytes() : " + buf.readableBytes() +
     * "?? ? 20? ?. "); return; }
     */

    // 1. ? ?
    headerSize = buf.readInt();
    if (headerSize >= 100 || headerSize < 0) {
        System.out.println("fileNameSize : " + headerSize);
        // System.out.println((ByteBufUtil.hexDump(buf)));
        return;
    }

    headerBody = buf.readBytes(headerSize).toString(CharsetUtil.UTF_8);
    dataSize = buf.readLong();
    System.out.println(
            "headerSize : " + headerSize + ", headerBody : " + headerBody + ", dataSize : " + dataSize);

    headerRead = true;

    // 2. ?  ? ?   : operation or file

    if (headerBody.startsWith(OperationCommand.OP_CODE_JOIN)) {
        operationCode = headerBody;
    } else {
        System.err.println("? Header Body . : " + headerBody);
        return;
    }

    int a = buf.readableBytes();
    int b = (int) Math.min(dataSize - offset, a);
    System.out.println("ReadableBytes : " + a + ", To-Read Bytes : " + b);

    operationData += buf.readBytes(b).toString(CharsetUtil.UTF_8);
    System.out.println("OP Data   : " + operationData);

    offset += b;

    if (offset >= dataSize) {
        offset = 0;
        headerRead = false;

        if (headerBody.startsWith(OperationCommand.OP_CODE_JOIN)) {
            // ?? ? ??
            agentName = operationData + "(" + ctx.channel().id().toString() + ")";

            // WebApplicationContext context =
            // ContextLoader.getCurrentWebApplicationContext();
            // WsHandler wsHandler =
            // (WsHandler)context.getBean("websocket.WsHandler.class");
            // WebApplicationContext wac = BootServer.wac;
            // WsHandler wsHandler = (WsHandler)wac.getBean("wsHandler");
            // WsHandler.sendMessage(agentName + "("
            // +ctx.channel().id().toString() + ")");

        }

        //ChannelManager.map.remove(ctx.channel().id().toString());
        ChannelManager.map.put(agentName, ctx.channel());

        // ?  
        publishEvent(EventType.Connected, agentName, "");

        //   
        // WsHandler ws = (WsHandler)
        // applicationContext.getBean("wsHandler");
        // ws.sendMessage(agentName + "(" + ctx.channel().id().toString() +
        // ") is connected");
        // System.out.println(this.getClass() + agentName + "(" +
        // ctx.channel().id().toString() + ") is connected");

        System.out.println("OP Data : " + operationData);
        System.out.println(
                "OP Data  : " + ((System.currentTimeMillis() - startTm) / 1000.0f) + "");

        operationData = ""; // 

        return;
    }

}

From source file:tachyon.network.protocol.RPCBlockReadRequest.java

License:Apache License

/**
 * Decodes the input {@link ByteBuf} into a {@link RPCBlockReadRequest} object and returns it.
 *
 * @param in the input {@link ByteBuf}//w  w w  .j  a v  a 2  s.co  m
 * @return The decoded RPCBlockReadRequest object
 */
public static RPCBlockReadRequest decode(ByteBuf in) {
    long blockId = in.readLong();
    long offset = in.readLong();
    long length = in.readLong();
    return new RPCBlockReadRequest(blockId, offset, length);
}

From source file:tachyon.network.protocol.RPCBlockRequest.java

License:Apache License

/**
 * Decode the input {@link ByteBuf} into a {@link RPCBlockRequest} object and return it.
 *
 * @param in the input {@link ByteBuf}//from ww  w  .j  a va  2 s.co  m
 * @return The decoded RPCBlockRequest object
 */
public static RPCBlockRequest decode(ByteBuf in) {
    // TODO: remove this short when client also uses netty.
    in.readShort();
    long blockId = in.readLong();
    long offset = in.readLong();
    long length = in.readLong();
    return new RPCBlockRequest(blockId, offset, length);
}

From source file:tachyon.network.protocol.RPCBlockResponse.java

License:Apache License

/**
 * Decode the input {@link ByteBuf} into a {@link RPCBlockResponse} object and return it.
 *
 * @param in the input {@link ByteBuf}//  w ww.j  a va  2 s .c om
 * @return The decoded RPCBlockResponse object
 */
public static RPCBlockResponse decode(ByteBuf in) {
    // TODO: remove this short when client also uses netty.
    in.readShort();
    long blockId = in.readLong();
    long offset = in.readLong();
    long length = in.readLong();
    DataBuffer data = null;
    if (length > 0) {
        // TODO: look into accessing Netty ByteBuf directly, to avoid copying the data.
        ByteBuffer buffer = ByteBuffer.allocate((int) length);
        in.readBytes(buffer);
        data = new DataByteBuffer(buffer, (int) length);
    }
    return new RPCBlockResponse(blockId, offset, length, data);
}

From source file:tachyon.network.protocol.RPCBlockWriteRequest.java

License:Apache License

/**
 * Decodes the input {@link ByteBuf} into a {@link RPCBlockWriteRequest} object and returns it.
 *
 * @param in the input {@link ByteBuf}/*from  w  w w  .java  2  s .c o m*/
 * @return The decoded RPCBlockWriteRequest object
 */
public static RPCBlockWriteRequest decode(ByteBuf in) {
    long sessionId = in.readLong();
    long blockId = in.readLong();
    long offset = in.readLong();
    long length = in.readLong();
    DataBuffer data = null;
    if (length > 0) {
        // TODO(hy): Look into accessing Netty ByteBuf directly, to avoid copying the data.
        ByteBuffer buffer = ByteBuffer.allocate((int) length);
        in.readBytes(buffer);
        data = new DataByteBuffer(buffer, (int) length);
    }
    return new RPCBlockWriteRequest(sessionId, blockId, offset, length, data);
}

From source file:tachyon.worker.netty.protocol.RPCBlockResponse.java

License:Apache License

/**
 * Decode the input {@link ByteBuf} into a {@link RPCBlockResponse} object and return it.
 *
 * @param in the input {@link ByteBuf}/*from   w  w w  .j av  a  2  s.  c  o m*/
 * @return The decoded RPCBlockResponse object
 */
public static RPCBlockResponse decode(ByteBuf in) {
    // TODO: remove this short when client also uses netty.
    in.readShort();
    long blockId = in.readLong();
    long offset = in.readLong();
    long length = in.readLong();
    DataBuffer data = null;
    if (length > 0) {
        ByteBuffer buffer = ByteBuffer.allocate((int) length);
        in.readBytes(buffer);
        data = new DataByteBuffer(buffer, (int) length);
    }
    return new RPCBlockResponse(blockId, offset, length, data);
}

From source file:therogue.storehouse.network.CGuiUpdateTEPacket.java

License:Open Source License

@Override
public void fromBytes(ByteBuf buf) {
    this.pos = BlockPos.fromLong(buf.readLong());
    this.nbt = NetworkUtils.readNBTTagCompound(buf);
}

From source file:therogue.storehouse.network.SGuiUpdateTEPacket.java

License:Open Source License

@Override
public void fromBytes(ByteBuf buf) {
    this.item = buf.readByte();
    this.pos = BlockPos.fromLong(buf.readLong());
    this.nbt = NetworkUtils.readNBTTagCompound(buf);
}

From source file:util.NettyMessageDecoder.java

@Override
protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
    ByteBuf frame = (ByteBuf) super.decode(ctx, in);

    if (frame == null) {
        return null;
    }/*from   w  w  w.  ja  v a 2s . co  m*/

    NettyMessage message = new NettyMessage();
    Header header = new Header();

    header.setCrcCode(frame.readInt());
    header.setLength(frame.readInt());
    header.setSessionID(frame.readLong());
    header.setType(frame.readByte());
    header.setPriority(frame.readByte());

    int size = frame.readInt();

    if (size > 0) {
        Map<String, Object> attach = new HashMap<String, Object>(size);
        int keySize = 0;
        byte[] keyArray = null;
        String key = null;

        for (int i = 0; i < size; i++) {
            keySize = frame.readInt();
            keyArray = new byte[keySize];
            frame.readBytes(keyArray);
            key = new String(keyArray, "UTF-8");
            attach.put(key, marshallingDecoder.decode(frame));
        }

        keyArray = null;
        key = null;
        header.setAttachment(attach);
    }

    if (frame.readableBytes() > 4) {
        message.setBody(marshallingDecoder.decode(frame));
    }

    message.setHeader(header);
    return message;
}

From source file:vazkii.botania.common.entity.EntityDoppleganger.java

License:Open Source License

@Override
@SideOnly(Side.CLIENT)//from www .  j a v  a  2  s .c  o  m
public void readSpawnData(ByteBuf additionalData) {
    playerCount = additionalData.readInt();
    hardMode = additionalData.readBoolean();
    source = BlockPos.fromLong(additionalData.readLong());
    long msb = additionalData.readLong();
    long lsb = additionalData.readLong();
    bossInfoUUID = new UUID(msb, lsb);
    Minecraft.getMinecraft().getSoundHandler().playSound(new DopplegangerMusic(this));
}