Example usage for io.netty.buffer ByteBuf writeShort

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

Introduction

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

Prototype

public abstract ByteBuf writeShort(int value);

Source Link

Document

Sets the specified 16-bit short integer at the current writerIndex and increases the writerIndex by 2 in this buffer.

Usage

From source file:com.mobius.software.mqtt.parser.test.TestParser.java

License:Open Source License

@Test(expected = MalformedMessageException.class)
public void testNegativeNext() throws MalformedMessageException {
    ByteBuf buf = Unpooled.buffer(103);
    buf.writeByte(0x82);/*  ww w. j av a 2  s .  c  o m*/
    buf.writeByte(0x66); //encoded l=104, actual l=103
    buf.writeShort(10);
    buf.writeShort(97);
    buf.writeBytes(new byte[96]);
    buf.writeByte(1);
    MQParser.next(buf);
}

From source file:com.mobius.software.mqtt.parser.test.TestParser.java

License:Open Source License

@Test
public void testNegativeNextIndexNotReset() throws MalformedMessageException {
    ByteBuf buf = Unpooled.buffer(103);
    buf.writeByte(0x82);/* ww w  .  j ava2 s.c om*/
    buf.writeByte(0x66); //encoded l=104, actual l=103
    buf.writeShort(10);
    buf.writeShort(97);
    buf.writeBytes(new byte[96]);
    buf.writeByte(1);
    try {
        MQParser.next(buf);
    } catch (MalformedMessageException e) {

    }
    assertEquals("buffer index was not reset", 0, buf.readerIndex());
}

From source file:com.mobius.software.mqtt.parser.test.TestParser.java

License:Open Source License

@Test
public void testSubackCodeNull() throws UnsupportedEncodingException, MalformedMessageException {
    expectedEx.expect(MalformedMessageException.class);
    ByteBuf buf = Unpooled.buffer(3);
    buf.writeByte(0x90);//  w w  w.j av a2s .  co m
    buf.writeByte(3);
    buf.writeShort(10);
    buf.writeByte(3);
    MQParser.decode(buf);
}

From source file:com.mobius.software.mqtt.parser.test.TestParser.java

License:Open Source License

@Test
public void testDecodeLengthOne() {
    ByteBuf buf = Unpooled.buffer(114);
    buf.writeByte(0x82);// w ww  .j  av  a2  s .  c  o  m
    buf.writeByte(0x66);
    buf.writeShort(10);
    buf.writeShort(97);
    buf.writeBytes(new byte[96]);
    buf.writeByte(1);
    buf.writeByte(0);
}

From source file:com.mobius.software.mqtt.parser.test.TestParser.java

License:Open Source License

@Test
public void testDecodeLengthTwo() {
    ByteBuf buf = Unpooled.buffer(205);
    buf.writeByte(0x82);//from ww w  .j a  v a 2  s  .  c  o m
    buf.writeByte(0xCA);
    buf.writeByte(0x01);
    buf.writeShort(10);
    buf.writeShort(197);
    buf.writeBytes(new byte[196]);
    buf.writeByte(1);
    buf.writeByte(0);
}

From source file:com.mobius.software.mqtt.parser.test.TestParser.java

License:Open Source License

@Test
public void testDecodeLengthThree() {
    ByteBuf buf = Unpooled.buffer(20206);
    buf.writeByte(0x82);/*from  w  w w.  ja  va 2 s .  c om*/
    buf.writeByte(0xEA);
    buf.writeByte(0x9D);
    buf.writeByte(0x01);
    buf.writeShort(10);
    buf.writeShort(20197);
    buf.writeBytes(new byte[20196]);
    buf.writeByte(1);
    buf.writeByte(0);
}

From source file:com.mobius.software.mqtt.parser.test.TestParser.java

License:Open Source License

@Test
public void testDecodeLengthFour() {
    ByteBuf buf = Unpooled.buffer(2097159);
    buf.writeByte(0x82);/*from   ww  w .  j a  v  a2s  . co  m*/
    buf.writeByte(0x82);
    buf.writeByte(0x80);
    buf.writeByte(0x80);
    buf.writeByte(0x01);
    buf.writeShort(10);
    for (int i = 0; i < 32; i++) {
        buf.writeShort(65533);
        buf.writeBytes(new byte[65532]);
        buf.writeByte(1);
        buf.writeByte(0);
    }
}

From source file:com.mpush.api.protocol.Packet.java

License:Apache License

public static void encodePacket(Packet packet, ByteBuf out) {
    if (packet.cmd == Command.HEARTBEAT.cmd) {
        out.writeByte(Packet.HB_PACKET_BYTE);
    } else {//from  w ww.  j  a v a2s .  com
        out.writeInt(packet.getBodyLength());
        out.writeByte(packet.cmd);
        out.writeShort(packet.cc);
        out.writeByte(packet.flags);
        out.writeInt(packet.sessionId);
        out.writeByte(packet.lrc);
        if (packet.getBodyLength() > 0) {
            out.writeBytes(packet.body);
        }
    }
    packet.body = null;
}

From source file:com.mpush.common.message.ByteBufMessage.java

License:Apache License

public void encodeBytes(ByteBuf body, byte[] field) {
    if (field == null || field.length == 0) {
        body.writeShort(0);
    } else if (field.length < Short.MAX_VALUE) {
        body.writeShort(field.length).writeBytes(field);
    } else {//from  w w  w.  ja v  a 2 s .c  o  m
        body.writeShort(Short.MAX_VALUE).writeInt(field.length - Short.MAX_VALUE).writeBytes(field);
    }
}

From source file:com.ogarproject.ogar.server.net.packet.outbound.PacketOutDrawLine.java

License:Open Source License

@Override
public void writeData(ByteBuf buf) {
    buf.writeShort(x);
    buf.writeShort(y);
}