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.TranscoderHelper.java

License:Open Source License

void encodeHeartBeat(HeartBeat heartBeat, ByteBuf out) {
    out.writeInt(heartBeat.getLoad());
}

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

License:Open Source License

void encodeAdmin(Admin admin, ByteBuf out) {
    out.writeInt(admin.getAdminCommand().value());
    ChannelBufferUtils.writeStringToOctetString(admin.getBoxId(), out, Charsets.UTF_8);
}

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

License:Open Source License

void encodeSms(Sms sms, ByteBuf out) {
    Charset messageCharset = sms.getCharset() == null ? Charsets.UTF_8 : sms.getCharset();

    ChannelBufferUtils.writeStringToOctetString(sms.getSender(), out, Charsets.UTF_8);
    ChannelBufferUtils.writeStringToOctetString(sms.getReceiver(), out, Charsets.UTF_8);
    ChannelBufferUtils.writeBytesToOctetString(sms.getUdhData(), out);
    ChannelBufferUtils.writeStringToOctetString(sms.getMsgData(), out, messageCharset);
    out.writeInt(sms.getTime());
    ChannelBufferUtils.writeStringToOctetString(sms.getSmscId(), out, Charsets.UTF_8);
    ChannelBufferUtils.writeStringToOctetString(sms.getSmscNumber(), out, Charsets.UTF_8);
    ChannelBufferUtils.writeStringToOctetString(sms.getForeignId(), out, Charsets.UTF_8);
    ChannelBufferUtils.writeStringToOctetString(sms.getService(), out, Charsets.UTF_8);
    ChannelBufferUtils.writeStringToOctetString(sms.getAccount(), out, Charsets.UTF_8);
    ChannelBufferUtils.writeUUIDToOctetString(sms.getId(), out, Charsets.UTF_8);
    out.writeInt(sms.getSmsType().value());
    out.writeInt(sms.getMessageClass().value());
    out.writeInt(sms.getMwi().value());/*from ww  w.java 2 s  . c  o m*/
    out.writeInt(sms.getCoding().value());
    out.writeInt(sms.getCompress().value());
    out.writeInt(sms.getValidity());
    out.writeInt(sms.getDeferred());
    out.writeInt(sms.getDlrMask());
    ChannelBufferUtils.writeStringToOctetString(sms.getDlrUrl(), out, Charsets.UTF_8);
    out.writeInt(sms.getPid());
    out.writeInt(sms.getAltDcs());
    out.writeInt(sms.getRpi().value());
    ChannelBufferUtils.writeStringToOctetString(messageCharset.displayName(), out, Charsets.UTF_8);
    ChannelBufferUtils.writeStringToOctetString(sms.getBoxId(), out, Charsets.UTF_8);
    ChannelBufferUtils.writeStringToOctetString(sms.getBillingInfo(), out, Charsets.UTF_8);
    out.writeInt(sms.getMsgLeft());
    out.writeInt(sms.getPriority());
    out.writeInt(sms.getResendTry());
    out.writeInt(sms.getResendTime());
    ChannelBufferUtils.writeStringToOctetString(sms.getMetaData(), out, Charsets.UTF_8);
}

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

License:Open Source License

@Test
public void testDecodeHeartBeatDecodesCorrectly() throws Exception {
    ByteBuf encodedMessage = Unpooled.buffer();
    encodedMessage.writeInt(124);

    HeartBeat heartBeat = transcoderHelper.decodeHeartBeat(encodedMessage);
    assertEquals("HeartBeat load is incorrect", 124, heartBeat.getLoad());
    encodedMessage.release();// w w  w.  ja  va  2  s. c o  m
}

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

License:Open Source License

@Test
public void testDecodeAdminDecodesCorrectly() throws Exception {
    ByteBuf encodedMessage = Unpooled.buffer();
    encodedMessage.writeInt(1);
    ChannelBufferUtils.writeStringToOctetString("", encodedMessage, Charsets.UTF_8);

    Admin admin = transcoderHelper.decodeAdmin(encodedMessage);
    Assert.assertEquals("Type of admin command is incorrect", AdminCommand.SUSPEND, admin.getAdminCommand());
    assertEquals("Box name is incorrect", "", admin.getBoxId());
    encodedMessage.release();/*from ww w.  j  av  a2 s  . c  o m*/
}

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

License:Open Source License

@Test(expected = UnknownAdminCommandException.class)
public void testDecodeAdminThrowsWhenAdminCommandIsUnkwown() throws Exception {
    ByteBuf encodedMessage = Unpooled.buffer();
    encodedMessage.writeInt(5);
    ChannelBufferUtils.writeStringToOctetString("", encodedMessage, Charsets.UTF_8);

    try {/*from  ww w .j a v  a 2  s.  c o  m*/
        transcoderHelper.decodeAdmin(encodedMessage);
    } finally {
        encodedMessage.release();
    }
}

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

License:Open Source License

@Test
public void testDecodeDatagramDecodesCorrectly() throws Exception {
    ByteBuf encodedMessage = Unpooled.buffer();
    ChannelBufferUtils.writeStringToOctetString("", encodedMessage, Charsets.UTF_8);
    encodedMessage.writeInt(4444);
    ChannelBufferUtils.writeStringToOctetString("?", encodedMessage, Charsets.UTF_8);
    encodedMessage.writeInt(5555);/*  w  w  w. j av  a2  s .  com*/
    byte[] payload = { 0x14, 0x79 };
    ByteBuf payloadBuffer = Unpooled.copiedBuffer(payload);
    ChannelBufferUtils.writeBytesToOctetString(payloadBuffer, encodedMessage);

    Datagram datagram = transcoderHelper.decodeDatagram(encodedMessage);
    assertEquals("Source address is incorrect", "", datagram.getSourceAddress());
    assertEquals("Source port is incorrect", 4444, datagram.getSourcePort());
    assertEquals("Source address is incorrect", "?", datagram.getDestinationAddress());
    assertEquals("Source port is incorrect", 5555, datagram.getDestinationPort());
    assertEquals("Data payload is incorrect", payloadBuffer.readerIndex(0), datagram.getUserData());
    encodedMessage.release();
    payloadBuffer.release();
}

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

License:Open Source License

@Test
public void testDecodeAckDecodesCorrectly() throws Exception {
    ByteBuf encodedMessage = Unpooled.buffer();
    encodedMessage.writeInt(1);
    encodedMessage.writeInt(9);/*from  w  w  w  .j a va 2  s .  co m*/
    UUID uuid = UUID.randomUUID();
    ChannelBufferUtils.writeUUIDToOctetString(uuid, encodedMessage, Charsets.UTF_8);

    Ack ack = transcoderHelper.decodeAck(encodedMessage);
    Assert.assertEquals("Type of ack response is incorrect", AckType.FAILED, ack.getResponse());
    assertEquals("The time is incorrect", 9, ack.getTime());
    assertEquals("Ack id is incorrect", uuid, ack.getId());
    encodedMessage.release();
}

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

License:Open Source License

@Test(expected = UnknownAckTypeException.class)
public void testDecodeAckThrowsWhenAckTypeIsUnknown() throws Exception {
    ByteBuf encodedMessage = Unpooled.buffer();
    encodedMessage.writeInt(111);
    encodedMessage.writeInt(9);//from  www.  j av a2  s.c om
    UUID uuid = UUID.randomUUID();
    ChannelBufferUtils.writeUUIDToOctetString(uuid, encodedMessage, Charsets.UTF_8);

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

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

License:Open Source License

@Test
public void testDecodeSmsDecodesCorrectly() throws Exception {
    ByteBuf encodedMessage = Unpooled.buffer();
    UUID uuid = UUID.randomUUID();
    ChannelBufferUtils.writeStringToOctetString("from", encodedMessage, Charsets.UTF_8);
    ChannelBufferUtils.writeStringToOctetString("to", encodedMessage, Charsets.UTF_8);
    byte[] payload = { 0x14, 0x79 };
    ByteBuf payloadBuffer = Unpooled.copiedBuffer(payload);

    ChannelBufferUtils.writeBytesToOctetString(payloadBuffer, encodedMessage);
    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(1);//  w ww . jav a 2s  .c o  m
    encodedMessage.writeInt(2);
    encodedMessage.writeInt(3);
    encodedMessage.writeInt(2);
    encodedMessage.writeInt(1);
    encodedMessage.writeInt(6);
    encodedMessage.writeInt(7);
    encodedMessage.writeInt(8);
    ChannelBufferUtils.writeStringToOctetString("dlrUrl", encodedMessage, Charsets.UTF_8);
    encodedMessage.writeInt(9);
    encodedMessage.writeInt(10);
    encodedMessage.writeInt(1);
    ChannelBufferUtils.writeStringToOctetString("UTF-8", 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);

    Sms sms = transcoderHelper.decodeSms(encodedMessage);
    assertEquals("The  from is incorrect", "from", sms.getSender());
    assertEquals("The to is incorrect", "to", sms.getReceiver());
    assertEquals("The udhdata is incorrect", payloadBuffer.readerIndex(0), sms.getUdhData());
    assertEquals("The message data is incorrect", "content", sms.getMsgData());
    assertEquals("The time is incorrect", 0, sms.getTime());
    assertEquals("The smsc is incorrect", "smsc", sms.getSmscId());
    assertEquals("The smscNumber is incorrect", "smscNumber", sms.getSmscNumber());
    assertEquals("The foreignId is incorrect", "foreignId", sms.getForeignId());
    assertEquals("The service is incorrect", "service", sms.getService());
    assertEquals("The account is incorrect", "account", sms.getAccount());
    assertEquals("The id is incorrect", uuid, sms.getId());
    assertEquals("The sms type is incorrect", 1, sms.getSmsType().value());
    assertEquals("The m class is incorrect", 2, sms.getMessageClass().value());
    assertEquals("The mwi is incorrect", 3, sms.getMwi().value());
    assertEquals("The coding is incorrect", 2, sms.getCoding().value());
    assertEquals("The compress is incorrect", 1, sms.getCompress().value());
    assertEquals("The validity is incorrect", 6, sms.getValidity());
    assertEquals("The deferred is incorrect", 7, sms.getDeferred());
    assertEquals("The dlr mask is incorrect", 8, sms.getDlrMask());
    assertEquals("The dlr url is incorrect", "dlrUrl", sms.getDlrUrl());

    assertEquals("The pid is incorrect", 9, sms.getPid());
    assertEquals("The alt dcs is incorrect", 10, sms.getAltDcs());
    assertEquals("The rpi is incorrect", 1, sms.getRpi().value());
    assertEquals("The charset is incorrect", Charsets.UTF_8, sms.getCharset());
    assertEquals("The box id is incorrect", "boxcid", sms.getBoxId());
    assertEquals("The binfo is incorrect", "binfo", sms.getBillingInfo());

    assertEquals("The msgLeft is incorrect", 12, sms.getMsgLeft());
    assertEquals("The priority is incorrect", 13, sms.getPriority());
    assertEquals("The resend try is incorrect", 14, sms.getResendTry());
    assertEquals("The resend time is incorrect", 15, sms.getResendTime());
    assertEquals("The meta data is incorrect", "metaData", sms.getMetaData());

    encodedMessage.release();
    payloadBuffer.release();
}