Package io.netty.buffer

Examples of io.netty.buffer.ByteBuf.order()


  @Override
  public ByteBuf encode(T message) {
    byte[] bytes = message.getPayload().getBytes(CharsetUtil.US_ASCII);
    ByteBuf buffer = Unpooled.buffer(bytes.length + 2);
    buffer.order(ByteOrder.LITTLE_ENDIAN);
    buffer.writeBytes(bytes);
    buffer.writeByte(0);
    buffer.writeByte(0);
    return buffer;
  }
View Full Code Here


        remainderLength++;
      }

      // appearance!
      ByteBuf buffer = Unpooled.buffer(512);
      buffer = buffer.order(ByteOrder.LITTLE_ENDIAN);
      buffer.writeShort(6);
      buffer.writeShort(mapId);
      RawConverter.writeUnsignedByteArray(new short[] { 0x33, 0x36, 0x31, 0x30 }, buffer);
      buffer.writeByte((character.getLookHeight() << 4) | character.getLookSex());
      buffer.writeByte((character.getLookHairColor() << 4) | character.getLookSkinColor());
View Full Code Here

  }

  private ByteBuf marshallPacket(Packet packet) {
    ByteBuf buffer = Unpooled.buffer(256);
    // Bytes leave in little endian order (the first byte being the least significant)
    buffer = buffer.order(ByteOrder.LITTLE_ENDIAN);
    // Find the correct PacketMarshaller for this packet (using the unique class name)
    Class<? extends Packet> outgoingPacketClass = packet.getClass();
    PacketSerializer foundPacketMarshaller = packetMarshallers.get(outgoingPacketClass);
    // If the PacketMarshaller corresponding to the class cannot be found, processing cannot continue
    if (foundPacketMarshaller == null) {
View Full Code Here

      // TODO: Servers that are unavailable will be detected here in a catch(some exception) and REMOVED from the list + logs
      // TODO: Game Servers that are full should warn the login server when they're good again

      // Redirect the client to the chosen Game Server
      ByteBuf buffer = Unpooled.buffer(24);
      buffer = buffer.order(ByteOrder.LITTLE_ENDIAN);
      // Why we need this is unknown
      buffer.writeShort(2);

      int selectedGameServerPort = selectedGameServer.getHostAndPort().getPort();
View Full Code Here

      buffer.writeShort(2);

      int selectedGameServerPort = selectedGameServer.getHostAndPort().getPort();

      // The bytes of the port must be reversed
      buffer = buffer.order(ByteOrder.BIG_ENDIAN);
      buffer.writeShort(selectedGameServerPort);
      buffer = buffer.order(ByteOrder.LITTLE_ENDIAN);

      // the GS should pass its public IP when it registers itself to the LS
      byte[] ipBytes = selectedGameServer.getHostAndPort().getAddress().getAddress();
View Full Code Here

      int selectedGameServerPort = selectedGameServer.getHostAndPort().getPort();

      // The bytes of the port must be reversed
      buffer = buffer.order(ByteOrder.BIG_ENDIAN);
      buffer.writeShort(selectedGameServerPort);
      buffer = buffer.order(ByteOrder.LITTLE_ENDIAN);

      // the GS should pass its public IP when it registers itself to the LS
      byte[] ipBytes = selectedGameServer.getHostAndPort().getAddress().getAddress();

      LOGGER.info("The Game Server's IP: {}.{}.{}.{}", new Object[] { ipBytes[0] & 0xFF, ipBytes[1] & 0xFF, ipBytes[2] & 0xFF, ipBytes[3] & 0xFF });
View Full Code Here

      return null;
    }

    // We found the character, load its data
    ByteBuf appearance = Unpooled.buffer(24);
    appearance = appearance.order(ByteOrder.LITTLE_ENDIAN);
    byte professionPrimary = character.getProfessionprimary();
    byte professionSecondary = character.getProfessionSecondary();
    int level = character.getLevel();
    int skillPointsFree = character.getSkillPointsFree();
    int skillPointsTotal = character.getSkillPointsTotal();
View Full Code Here

        ReflectionPacketDeserializer packetDeserializer = new ReflectionPacketDeserializer(8, P008_TestPacket.class);
       
        // build the fake inputstream
        // The stream represents the data shown in the "assertEqual" tests
        ByteBuf buffer = Unpooled.buffer();
        buffer = buffer.order(ByteOrder.LITTLE_ENDIAN);
        String source = "0 0 1 0 0 0 2 0 0 0 3 0 20 21 22 23 24 25 4 0 116 0 111 0 116 0 111 0 4 0 26 27 28 29 5 0 0 0 5 0 30 31 32 33 34 6 7 0 0 0 4 0 116 0 105 0 116 0 105 0";
        String[] bytes = source.split("\\s");
        for (String byteString : bytes) {
            buffer.writeByte(Byte.parseByte(byteString));
        }
View Full Code Here

        testIncomingPacket.setUnsignedInteger4(7);
        testIncomingPacket.setString2("titi");

        // build the buffer that will contain all the correct output data inserted manually
        ByteBuf neededOutputBytes = Unpooled.buffer(65);
        neededOutputBytes = neededOutputBytes.order(ByteOrder.LITTLE_ENDIAN);

        String output = "8 0 1 0 0 0 2 0 0 0 3 0 20 21 22 23 24 25 4 0 116 0 111 0 116 0 111 0 4 0 26 27 28 29 5 0 0 0 5 0 30 31 32 33 34 6 7 0 0 0 4 0 116 0 105 0 116 0 105 0";
        String[] bytes = output.split("\\s");
        for (String byteString : bytes) {
            neededOutputBytes.writeByte(Byte.parseByte(byteString));
View Full Code Here

            neededOutputBytes.writeByte(Byte.parseByte(byteString));
        }
       
        // build the buffer that will contain all the generated output data
        ByteBuf generatedOutputBytes = Unpooled.buffer(65);
        generatedOutputBytes = generatedOutputBytes.order(ByteOrder.LITTLE_ENDIAN);
        // serialize the given packet
        packetSerializer.serialize(testIncomingPacket, generatedOutputBytes);

        // compare the size of each bufffer
        assertEquals(neededOutputBytes.writerIndex(), generatedOutputBytes.writerIndex());
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.