Example usage for io.netty.buffer ByteBuf writeLong

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

Introduction

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

Prototype

public abstract ByteBuf writeLong(long value);

Source Link

Document

Sets the specified 64-bit long integer at the current writerIndex and increases the writerIndex by 8 in this buffer.

Usage

From source file:com.heliosapm.streams.metrics.StreamedMetricValue.java

License:Apache License

/**
 * Returns a byte array containing the serialized streammetric
 * @return a byte array // w  w  w  .  j  a  v a  2  s .  co m
 */
@Override
public byte[] toByteArray() {
    final ByteBuf buff = BufferManager.getInstance().directBuffer(byteSize);
    try {
        buff.writeByte(TYPE_CODE);
        writeByteArray(buff);
        if (isDoubleValue) {
            buff.writeByte(0);
            buff.writeDouble(doubleValue);
        } else {
            buff.writeByte(1);
            buff.writeLong(longValue);
        }
        return ByteBufUtil.getBytes(buff, 0, buff.readableBytes());
    } finally {
        try {
            buff.release();
        } catch (Exception x) {
            /* No Op */}
    }
}

From source file:com.heliosapm.streams.metrics.StreamedMetricValue.java

License:Apache License

/**
 * Returns this streamed metric serialized into a byte buf
 * @return the byte buf//from w w  w  .  j  ava2 s. c  o  m
 */
@Override
public ByteBuf toByteBuff() {
    final ByteBuf buff = BufferManager.getInstance().directBuffer(byteSize);
    buff.writeByte(TYPE_CODE);
    writeByteArray(buff);
    if (isDoubleValue) {
        buff.writeByte(0);
        buff.writeDouble(doubleValue);
    } else {
        buff.writeByte(1);
        buff.writeLong(longValue);
    }
    return buff;
}

From source file:com.heliosapm.streams.metrics.StreamedMetricValue.java

License:Apache License

/**
 * Writes this metric into the passed buffer
 * @param buff The buffer to write this metric into
 *///from  w w  w  .j a v a  2 s .c  o m
@Override
public void intoByteBuf(final ByteBuf buff) {
    buff.writeByte(TYPE_CODE);
    writeByteArray(buff);
    if (isDoubleValue) {
        buff.writeByte(0);
        buff.writeDouble(doubleValue);
    } else {
        buff.writeByte(1);
        buff.writeLong(longValue);
    }
}

From source file:com.ibm.crail.datanode.netty.rpc.RdmaMsgHeader.java

License:Apache License

public void encode(ByteBuf target) {
    target.writeLong(address);
    target.writeInt(opLength);/*from w  ww . j  a  v  a2s  .co  m*/
    target.writeInt(stag);
    target.writeInt(type);
    target.writeInt(status);
    target.writeLong(cookie);
}

From source file:com.ibm.crail.namenode.rpc.netty.common.NettyRequest.java

License:Apache License

public int write(ByteBuf buffer) throws IOException {
    buffer.writeLong(cookie); //8
    buffer.writeShort(cmd); //2
    buffer.writeShort(type); //2
    int written = 12;

    nioBuffer.clear();//from   www.j a v a2s.  co  m
    switch (type) {
    case NameNodeProtocol.REQ_CREATE_FILE:
        written += createFileReq.write(nioBuffer);
        break;
    case NameNodeProtocol.REQ_GET_FILE:
        written += fileReq.write(nioBuffer);
        break;
    case NameNodeProtocol.REQ_SET_FILE:
        written += setFileReq.write(nioBuffer);
        break;
    case NameNodeProtocol.REQ_REMOVE_FILE:
        written += removeReq.write(nioBuffer);
        break;
    case NameNodeProtocol.REQ_RENAME_FILE:
        written += renameFileReq.write(nioBuffer);
        break;
    case NameNodeProtocol.REQ_GET_BLOCK:
        written += getBlockReq.write(nioBuffer);
        break;
    case NameNodeProtocol.REQ_GET_LOCATION:
        written += getLocationReq.write(nioBuffer);
        break;
    case NameNodeProtocol.REQ_SET_BLOCK:
        written += setBlockReq.write(nioBuffer);
        break;
    case NameNodeProtocol.REQ_GET_DATANODE:
        written += getDataNodeReq.write(nioBuffer);
        break;
    case NameNodeProtocol.REQ_DUMP_NAMENODE:
        written += dumpNameNodeReq.write(nioBuffer);
        break;
    case NameNodeProtocol.REQ_PING_NAMENODE:
        written += pingNameNodeReq.write(nioBuffer);
        break;
    }
    /* instead of flip you want to clear it */
    nioBuffer.clear();
    buffer.writeBytes(nioBuffer);
    return written;
}

From source file:com.ibm.crail.namenode.rpc.netty.common.NettyResponse.java

License:Apache License

public int write(ByteBuf buffer) {
    buffer.writeLong(cookie);
    buffer.writeShort(type);//  w ww. j a va  2  s  . co  m
    buffer.writeShort(error);

    int written = 12;
    nioBuffer.clear();
    switch (type) {
    case NameNodeProtocol.RES_VOID:
        written += voidRes.write(nioBuffer);
        break;
    case NameNodeProtocol.RES_CREATE_FILE:
        written += createFileRes.write(nioBuffer);
        break;
    case NameNodeProtocol.RES_GET_FILE:
        written += getFileRes.write(nioBuffer);
        break;
    case NameNodeProtocol.RES_DELETE_FILE:
        written += delFileRes.write(nioBuffer);
        break;
    case NameNodeProtocol.RES_RENAME_FILE:
        written += renameRes.write(nioBuffer);
        break;
    case NameNodeProtocol.RES_GET_BLOCK:
        written += getBlockRes.write(nioBuffer);
        break;
    case NameNodeProtocol.RES_GET_LOCATION:
        written += getLocationRes.write(nioBuffer);
        break;
    case NameNodeProtocol.RES_GET_DATANODE:
        written += getDataNodeRes.write(nioBuffer);
        break;
    case NameNodeProtocol.RES_PING_NAMENODE:
        written += pingNameNodeRes.write(nioBuffer);
        break;
    }
    /* reset and copy becuase we want to copy the whole capacity of the nio buffer */
    nioBuffer.clear();
    buffer.writeBytes(nioBuffer);
    return written;
}

From source file:com.irh.material.basics.netty.chapter14_1.codec.NettyMessageEncoder.java

License:Apache License

@Override
protected void encode(ChannelHandlerContext ctx, NettyMessage msg, ByteBuf sendBuf) throws Exception {
    if (msg == null || msg.getHeader() == null) {
        throw new Exception("The encode message is null");
    }/*from w w w  .jav  a 2 s  .c om*/
    sendBuf.writeInt((msg.getHeader().getCrcCode()));
    sendBuf.writeInt((msg.getHeader().getLength()));
    sendBuf.writeLong((msg.getHeader().getSessionID()));
    sendBuf.writeByte((msg.getHeader().getType()));
    sendBuf.writeByte((msg.getHeader().getPriority()));
    sendBuf.writeInt((msg.getHeader().getAttachment().size()));
    String key = null;
    byte[] keyArray = null;
    Object value = null;
    for (Map.Entry<String, Object> param : msg.getHeader().getAttachment().entrySet()) {
        key = param.getKey();
        keyArray = key.getBytes("UTF-8");
        sendBuf.writeInt(keyArray.length);
        sendBuf.writeBytes(keyArray);
        value = param.getValue();
        marshallingEncoder.encode(value, sendBuf);
    }
    key = null;
    keyArray = null;
    value = null;
    if (msg.getBody() != null) {
        marshallingEncoder.encode(msg.getBody(), sendBuf);
    } else
        sendBuf.writeInt(0);
    sendBuf.setInt(4, sendBuf.readableBytes() - 8);
}

From source file:com.ldp.nettydemo.netty.codec.NettyMessageEncoder.java

License:Apache License

@Override
protected void encode(ChannelHandlerContext ctx, NettyMessage msg, ByteBuf sendBuf) throws Exception {
    if (msg == null || msg.getHeader() == null)
        throw new Exception("The encode message is null");
    sendBuf.writeInt((msg.getHeader().getCrcCode()));
    sendBuf.writeInt((msg.getHeader().getLength()));
    sendBuf.writeLong((msg.getHeader().getSessionID()));
    sendBuf.writeByte((msg.getHeader().getType()));
    sendBuf.writeByte((msg.getHeader().getPriority()));
    sendBuf.writeInt((msg.getHeader().getAttachment().size()));
    String key = null;//from w  w w.  j  av  a2s. co  m
    byte[] keyArray = null;
    Object value = null;
    for (Map.Entry<String, Object> param : msg.getHeader().getAttachment().entrySet()) {
        key = param.getKey();
        keyArray = key.getBytes("UTF-8");
        sendBuf.writeInt(keyArray.length);
        sendBuf.writeBytes(keyArray);
        value = param.getValue();
        sendBuf.writeBytes(ByteObjConverter.ObjectToByte(value));
        //         marshallingEncoder.encode(value, sendBuf);
    }
    key = null;
    keyArray = null;
    value = null;
    if (msg.getBody() != null) {
        sendBuf.writeBytes(ByteObjConverter.ObjectToByte(msg.getBody()));
        //         marshallingEncoder.encode(msg.getBody(), sendBuf);
    } else
        sendBuf.writeInt(0);
    sendBuf.setInt(4, sendBuf.readableBytes() - 8);
}

From source file:com.ltln.modules.openflow.core.protocol.ver13.OFBsnPktinFlagSerializerVer13.java

public static void writeTo(ByteBuf bb, Set<OFBsnPktinFlag> set) {
    bb.writeLong(toWireValue(set));
}

From source file:com.ltln.modules.openflow.core.types.U64.java

License:Apache License

@Override
public void writeTo(ByteBuf bb) {
    bb.writeLong(raw);
}