Example usage for io.netty.buffer Unpooled buffer

List of usage examples for io.netty.buffer Unpooled buffer

Introduction

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

Prototype

public static ByteBuf buffer(int initialCapacity) 

Source Link

Document

Creates a new big-endian Java heap buffer with the specified capacity , which expands its capacity boundlessly on demand.

Usage

From source file:eu.xworlds.util.raknet.protocol.OpenConnectionReply1.java

License:Open Source License

@Override
public ByteBuf encode() {
    int size = 1 + this.magic.length + SIZE_GUID + 1 + 2;
    if (this.hasSecurity) {
        size += 4 + this.publicKey.length;
    }// ww w.ja  va 2  s.  c om
    final ByteBuf result = Unpooled.buffer(size);
    result.order(ByteOrder.BIG_ENDIAN);
    result.writeByte(ID);
    result.writeBytes(this.magic);
    writeGuid(result, this.serverGuid);
    result.writeBoolean(this.hasSecurity);
    if (this.hasSecurity) {
        result.writeInt(this.securityCookie);
        result.writeBytes(this.publicKey);
    }
    writeUnsignedShort(result, this.mtuSize);
    return result;
}

From source file:eu.xworlds.util.raknet.protocol.OpenConnectionReply2.java

License:Open Source License

@Override
public ByteBuf encode() {
    int size = 1 + this.magic.length + SIZE_GUID + 2 + 2 + 1;
    if (this.doSecurity) {
        size += this.securityAnswer.length;
    }//from   www. j  av  a  2 s.c  o m
    final ByteBuf buf = Unpooled.buffer(size);
    buf.order(ByteOrder.BIG_ENDIAN);
    buf.writeByte(ID);
    buf.writeBytes(this.magic);
    writeGuid(buf, this.serverGuid);
    writeUnsignedShort(buf, this.port);
    writeUnsignedShort(buf, this.mtuSize);
    buf.writeBoolean(this.doSecurity);
    if (this.doSecurity) {
        buf.writeBytes(this.securityAnswer);
    }
    return buf;
}

From source file:eu.xworlds.util.raknet.protocol.OpenConnectionRequest1.java

License:Open Source License

@Override
public ByteBuf encode() {
    final ByteBuf result = Unpooled.buffer(1 + 16 + this.magic.length + 1 + this.mtuPayload.length);
    result.order(ByteOrder.BIG_ENDIAN);
    result.writeByte(ID);/*from  ww w  .ja v a  2s.  c  om*/
    result.writeBytes(this.magic);
    result.writeByte(this.procotolVersion);
    result.writeBytes(this.mtuPayload);
    return result;
}

From source file:eu.xworlds.util.raknet.protocol.OpenConnectionRequest2.java

License:Open Source License

@Override
public ByteBuf encode() {
    int size = 1 + this.magic.length + SIZE_IPV4_ADDRESS + 2 + SIZE_GUID;
    if (this.useSecurity) {
        size += 4 + 1;// w w  w .jav a  2  s  .  c  o m
        if (this.clientWroteChallenge) {
            size += this.clientChallenge.length;
        }
    }
    final ByteBuf buf = Unpooled.buffer(size);
    buf.order(ByteOrder.BIG_ENDIAN);
    buf.writeByte(ID);
    buf.writeBytes(this.magic);
    if (this.useSecurity) {
        buf.writeInt(this.cookie);
        buf.writeBoolean(this.clientWroteChallenge);
        if (this.clientWroteChallenge) {
            buf.writeBytes(this.clientChallenge);
        }
    }
    writeIpv4Address(buf, this.bindingAddress);
    writeUnsignedShort(buf, this.mtuSize);
    writeGuid(buf, this.guid);
    return buf;
}

From source file:eu.xworlds.util.raknet.protocol.OutOfBandInternal.java

License:Open Source License

@Override
public ByteBuf encode() {
    int size = 1 + SIZE_GUID + this.magic.length;
    if (this.oobData != null) {
        size += this.oobData.length;
    }//from   w  w w .  j a  va 2  s  .  co  m
    final ByteBuf buf = Unpooled.buffer(size);
    buf.order(ByteOrder.BIG_ENDIAN);
    buf.writeByte(ID);
    writeGuid(buf, this.guid);
    buf.writeBytes(this.magic);
    if (this.oobData != null) {
        buf.writeBytes(this.oobData);
    }
    return buf;
}

From source file:eu.xworlds.util.raknet.protocol.RemoteSystemRequiresPublicKey.java

License:Open Source License

@Override
public ByteBuf encode() {
    final ByteBuf buf = Unpooled.buffer(1 + 1);
    buf.order(ByteOrder.BIG_ENDIAN);
    buf.writeByte(ID);// w  w  w  .j av  a 2s. co m
    buf.writeByte(this.error.ordinal());
    return buf;
}

From source file:eu.xworlds.util.raknet.protocol.SndReceiptAcked.java

License:Open Source License

@Override
public ByteBuf encode() {
    final ByteBuf buf = Unpooled.buffer(1 + 4);
    buf.order(ByteOrder.BIG_ENDIAN);
    buf.writeByte(ID);/*  w  w w.  ja v  a2 s. c o m*/
    writeUnsignedInt(buf, this.serial);
    return buf;
}

From source file:eu.xworlds.util.raknet.protocol.UnconnectedPing.java

License:Open Source License

@Override
public ByteBuf encode() {

    final ByteBuf result = Unpooled.buffer(1 + SIZE_TIME + this.magic.length);
    result.order(ByteOrder.BIG_ENDIAN);
    result.writeByte(ID);//from   w w w. j a  v  a 2  s .c o m
    writeTime(result, this.time);
    result.writeBytes(this.magic);
    return result;
}

From source file:gribbit.http.utils.UTF8.java

License:Open Source License

public static ByteBuf stringToUTF8ByteBuf(String str) {
    ByteBuf byteBuf = Unpooled.buffer(str.length() * 2);
    byteBuf.writeBytes(stringToUTF8(str));
    return byteBuf;
}

From source file:gwlpr.protocol.SerializationTest.java

License:Open Source License

@Test
public void test() {
    // fake register our test packet as inbound login server packet...
    // this should be done statically in the packet
    LoginServerCodec.registerInbound(P008_TestPacket.class);

    LoginServerCodec codec = new LoginServerCodec();

    // enable this for profiling
    //        for (int i = 0; i < 1000000; i++) 
    //        {//from www.j  av a2 s  .c  o  m
    // create a new empty TestIncomingPacket and the buffer
    P008_TestPacket outgoing = P008_TestPacket.getMockUp();
    ByteBuf buffer = Unpooled.buffer(512);

    // DISABLED BECAUSE WE WOULD NEED TO MOCK A CHANNEL CONTEXT
    // serialize it
    //            codec.encode(null, outgoing, buffer);

    // deserialize it (dont forget the header!)
    //            List<Object> incoming = new ArrayList<>();
    //            codec.decode(null, buffer, incoming);

    // compare them (disable this when profiling)
    //            P008_TestPacket.assertCompare(outgoing, (P008_TestPacket)incoming.get(0));
    //        }        
}