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) {
String msg = "No suitable PacketSerializer was found for packet: " + outgoingPacketClass;
LOGGER.error(msg);
throw new IllegalStateException(msg);
}
// Use the PacketMarshaller to fill the ByteBuffer with the data from this packet instance
foundPacketMarshaller.serialize(packet, buffer);
if(LOGGER.isInfoEnabled() && !this.logBlackList.contains(outgoingPacketClass)) {
LOGGER.info("Packet: {}", packet);
}