Example usage for io.netty.buffer ByteBuf writeInt

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

Introduction

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

Prototype

public abstract ByteBuf writeInt(int value);

Source Link

Document

Sets the specified 32-bit integer at the current writerIndex and increases the writerIndex by 4 in this buffer.

Usage

From source file:com.github.spapageo.jannel.transcode.TranscoderHelperTest.java

License:Open Source License

@Test(expected = UnknownSmsTypeException.class)
public void testDecodeSmsThrowsWhenSmsTypeIsInvalid() throws Exception {
    ByteBuf encodedMessage = Unpooled.buffer();
    UUID uuid = UUID.randomUUID();
    ChannelBufferUtils.writeStringToOctetString("from", encodedMessage, Charsets.UTF_8);
    ChannelBufferUtils.writeStringToOctetString("to", encodedMessage, Charsets.UTF_8);
    ChannelBufferUtils.writeStringToOctetString("udhdata", encodedMessage, Charsets.UTF_8);
    ChannelBufferUtils.writeStringToOctetString("content", encodedMessage, Charsets.UTF_8);
    encodedMessage.writeInt(0);
    ChannelBufferUtils.writeStringToOctetString("smsc", encodedMessage, Charsets.UTF_8);
    ChannelBufferUtils.writeStringToOctetString("smscNumber", encodedMessage, Charsets.UTF_8);
    ChannelBufferUtils.writeStringToOctetString("foreignId", encodedMessage, Charsets.UTF_8);
    ChannelBufferUtils.writeStringToOctetString("service", encodedMessage, Charsets.UTF_8);
    ChannelBufferUtils.writeStringToOctetString("account", encodedMessage, Charsets.UTF_8);
    ChannelBufferUtils.writeUUIDToOctetString(uuid, encodedMessage, Charsets.UTF_8);
    encodedMessage.writeInt(155);// w w w  .  ja v  a 2s. c  om
    encodedMessage.writeInt(2);
    encodedMessage.writeInt(3);
    encodedMessage.writeInt(4);
    encodedMessage.writeInt(5);
    encodedMessage.writeInt(6);
    encodedMessage.writeInt(7);
    encodedMessage.writeInt(8);
    ChannelBufferUtils.writeStringToOctetString("dlrUrl", encodedMessage, Charsets.UTF_8);
    encodedMessage.writeInt(9);
    encodedMessage.writeInt(10);
    encodedMessage.writeInt(11);
    ChannelBufferUtils.writeStringToOctetString("charset", encodedMessage, Charsets.UTF_8);
    ChannelBufferUtils.writeStringToOctetString("boxcid", encodedMessage, Charsets.UTF_8);
    ChannelBufferUtils.writeStringToOctetString("binfo", encodedMessage, Charsets.UTF_8);
    encodedMessage.writeInt(12);
    encodedMessage.writeInt(13);
    encodedMessage.writeInt(14);
    encodedMessage.writeInt(15);
    ChannelBufferUtils.writeStringToOctetString("metaData", encodedMessage, Charsets.UTF_8);

    try {
        transcoderHelper.decodeSms(encodedMessage);
    } finally {
        encodedMessage.release();
    }

}

From source file:com.github.sparkfy.network.protocol.OneWayMessage.java

License:Apache License

@Override
public void encode(ByteBuf buf) {
    // See comment in encodedLength().
    buf.writeInt((int) body().size());
}

From source file:com.github.sparkfy.network.protocol.RpcRequest.java

License:Apache License

@Override
public void encode(ByteBuf buf) {
    buf.writeLong(requestId);/*from   w  w  w. ja v a  2 s.co m*/
    // See comment in encodedLength().
    buf.writeInt((int) body().size());
}

From source file:com.github.sparkfy.network.protocol.StreamChunkId.java

License:Apache License

public void encode(ByteBuf buffer) {
    buffer.writeLong(streamId);
    buffer.writeInt(chunkIndex);
}

From source file:com.gmail.socraticphoenix.forge.randore.packet.RandoresSeedPacket.java

License:Open Source License

@Override
public void toBytes(ByteBuf buf) {
    buf.writeLong(this.getSeed());
    buf.writeInt(this.getOreCount());
}

From source file:com.hazelcast.simulator.protocol.core.ResponseCodec.java

License:Open Source License

public static void encodeByteBuf(Response response, ByteBuf buffer) {
    buffer.writeInt(HEADER_SIZE + response.size() * DATA_ENTRY_SIZE);
    buffer.writeInt(MAGIC_BYTES);/*from w  w w  .ja v  a  2s .  co  m*/

    buffer.writeLong(response.getMessageId());
    SimulatorAddressCodec.encodeByteBuf(response.getDestination(), buffer);

    for (Map.Entry<SimulatorAddress, ResponseType> entry : response.entrySet()) {
        SimulatorAddressCodec.encodeByteBuf(entry.getKey(), buffer);
        buffer.writeInt(entry.getValue().toInt());
    }
}

From source file:com.hazelcast.simulator.protocol.core.SimulatorAddressCodec.java

License:Open Source License

static void encodeByteBuf(SimulatorAddress address, ByteBuf buffer) {
    buffer.writeInt(address.getAddressLevel().toInt()).writeInt(address.getAgentIndex())
            .writeInt(address.getWorkerIndex()).writeInt(address.getTestIndex());
}

From source file:com.hazelcast.simulator.protocol.core.SimulatorMessageCodec.java

License:Open Source License

public static void encodeByteBuf(SimulatorMessage msg, ByteBuf buffer) {
    byte[] data = msg.getOperationData().getBytes(UTF_8);

    buffer.writeInt(HEADER_SIZE + data.length);
    buffer.writeInt(MAGIC_BYTES);//from w ww .j  ava  2s.  co  m

    SimulatorAddressCodec.encodeByteBuf(msg.getDestination(), buffer);
    SimulatorAddressCodec.encodeByteBuf(msg.getSource(), buffer);

    buffer.writeLong(msg.getMessageId());
    buffer.writeInt(msg.getOperationType().toInt());

    buffer.writeBytes(data);
}

From source file:com.heelenyc.im.coder.MessageEncoder.java

License:Apache License

@Override
protected void encode(ChannelHandlerContext ctx, Message 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 www  .jav a2 s . co m*/
    byte[] keyArray = null;
    Object value = null;
    for (Map.Entry<String, Object> param : msg.getHeader().getAttachment().entrySet()) {
        // write key
        key = param.getKey();
        keyArray = key.getBytes(Constans.ATTACHMENT_KEY_CHARACTSET);
        sendBuf.writeInt(keyArray.length);
        sendBuf.writeBytes(keyArray);
        // write value
        value = param.getValue();
        encoder.encode(value, sendBuf);
    }
    key = null;
    keyArray = null;
    value = null;
    if (msg.getBody() != null) {
        encoder.encode(msg.getBody(), sendBuf);
    } else
        sendBuf.writeInt(0);
    int totalSize = sendBuf.readableBytes() - Constans.MESSAGE_LENGTH_FIELD_OFFSET
            - Constans.MESSAGE_LENGTH_FIELD_LENGTH;
    // fix head length field
    msg.getHeader().setLength(totalSize);
    // ?
    sendBuf.setInt(Constans.MESSAGE_LENGTH_FIELD_OFFSET, totalSize);
    logger.debug("encode :" + msg);
}

From source file:com.heliosapm.ohcrs.core.AbstractDriverCodec.java

License:Apache License

/**
 * {@inheritDoc}//  w  ww  . j  a v  a  2  s .  c  o m
 * @see com.heliosapm.ohcrs.core.DriverCodec#write(int, io.netty.buffer.ByteBuf)
 */
@Override
public int write(final Integer p, final ByteBuf b) throws SQLException {
    prefix(p, DBType.INTEGER, b);
    b.writeInt(p);
    return b.writerIndex();
}