Class Packet
- java.lang.Object
-
- de.dytanic.cloudnet.driver.network.protocol.Packet
-
- All Implemented Interfaces:
IPacket
- Direct Known Subclasses:
ChunkedPacket,PacketClientAuthorization,PacketClientDriverAPI,PacketClientServerChannelMessage,PacketClientServerServiceInfoPublisher,PacketServerSetGlobalLogLevel,PacketServerUpdatePermissions
public class Packet extends java.lang.Object implements IPacket
The default simple implementation of the IPacket interface. You can create with the constructor all new packets or use the class as superclass from an another for specific constructor usage.All packets require a channel, header and a body.
The channel id is the id from that the listeners should be filter The header has the specify information or the data that is important The body has binary packet information like for files, or zip compressed data
-
-
Field Summary
Fields Modifier and Type Field Description protected ProtocolBufferbodyprotected intchannelprotected longcreationMillisstatic PacketEMPTYstatic byte[]EMPTY_PACKET_BYTE_ARRAYAn one length size byte[] for empty packet bodiesprotected de.dytanic.cloudnet.common.document.gson.JsonDocumentheaderprotected java.util.UUIDuniqueId
-
Constructor Summary
Constructors Constructor Description Packet()Packet(int channel, @NotNull de.dytanic.cloudnet.common.document.gson.JsonDocument header)Packet(int channel, @NotNull de.dytanic.cloudnet.common.document.gson.JsonDocument header, byte[] body)Packet(int channel, @NotNull de.dytanic.cloudnet.common.document.gson.JsonDocument header, ProtocolBuffer body)Packet(int channel, @NotNull java.util.UUID uniqueId, @NotNull de.dytanic.cloudnet.common.document.gson.JsonDocument header)Packet(int channel, @NotNull java.util.UUID uniqueId, @NotNull de.dytanic.cloudnet.common.document.gson.JsonDocument header, byte[] body)Packet(int channel, @NotNull java.util.UUID uniqueId, @NotNull de.dytanic.cloudnet.common.document.gson.JsonDocument header, ProtocolBuffer body)Packet(int channel, ProtocolBuffer body)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static PacketcreateResponseFor(IPacket packet)static PacketcreateResponseFor(IPacket packet, de.dytanic.cloudnet.common.document.gson.JsonDocument header)static PacketcreateResponseFor(IPacket packet, de.dytanic.cloudnet.common.document.gson.JsonDocument header, ProtocolBuffer body)static PacketcreateResponseFor(IPacket packet, ProtocolBuffer body)byte[]getBodyAsArray()ProtocolBuffergetBuffer()Returns the packet body, for transport for extra data, like files or zip archives or something elseintgetChannel()Returns the channel id, in that the IPacketListenerRegistry class should the listeners work with that packetlonggetCreationMillis()de.dytanic.cloudnet.common.document.gson.JsonDocumentgetHeader()The header, contain all important information from the packet, to specify the packet type as channel does and/or can has the data, which that are important to handle with@NotNull java.util.UUIDgetUniqueId()Returns the uuid of the packet.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.dytanic.cloudnet.driver.network.protocol.IPacket
isShowDebug
-
-
-
-
Field Detail
-
EMPTY_PACKET_BYTE_ARRAY
public static final byte[] EMPTY_PACKET_BYTE_ARRAY
An one length size byte[] for empty packet bodies
-
EMPTY
public static final Packet EMPTY
-
creationMillis
protected final long creationMillis
-
channel
protected int channel
-
uniqueId
protected java.util.UUID uniqueId
-
header
protected de.dytanic.cloudnet.common.document.gson.JsonDocument header
-
body
protected ProtocolBuffer body
-
-
Constructor Detail
-
Packet
public Packet(int channel, @NotNull @NotNull de.dytanic.cloudnet.common.document.gson.JsonDocument header)
-
Packet
public Packet(int channel, @NotNull @NotNull de.dytanic.cloudnet.common.document.gson.JsonDocument header, byte[] body)
-
Packet
public Packet(int channel, @NotNull @NotNull java.util.UUID uniqueId, @NotNull @NotNull de.dytanic.cloudnet.common.document.gson.JsonDocument header, byte[] body)
-
Packet
public Packet(int channel, ProtocolBuffer body)
-
Packet
public Packet(int channel, @NotNull @NotNull de.dytanic.cloudnet.common.document.gson.JsonDocument header, ProtocolBuffer body)
-
Packet
public Packet(int channel, @NotNull @NotNull java.util.UUID uniqueId, @NotNull @NotNull de.dytanic.cloudnet.common.document.gson.JsonDocument header)
-
Packet
public Packet(int channel, @NotNull @NotNull java.util.UUID uniqueId, @NotNull @NotNull de.dytanic.cloudnet.common.document.gson.JsonDocument header, ProtocolBuffer body)
-
Packet
public Packet()
-
-
Method Detail
-
createResponseFor
public static Packet createResponseFor(IPacket packet, de.dytanic.cloudnet.common.document.gson.JsonDocument header, ProtocolBuffer body)
-
createResponseFor
public static Packet createResponseFor(IPacket packet, de.dytanic.cloudnet.common.document.gson.JsonDocument header)
-
createResponseFor
public static Packet createResponseFor(IPacket packet, ProtocolBuffer body)
-
getChannel
public int getChannel()
Description copied from interface:IPacketReturns the channel id, in that the IPacketListenerRegistry class should the listeners work with that packet- Specified by:
getChannelin interfaceIPacket- Returns:
- the channel id in that the packet is defined
-
getUniqueId
@NotNull public @NotNull java.util.UUID getUniqueId()
Description copied from interface:IPacketReturns the uuid of the packet. Each packet should has a own defined UUID instance, less the callback packets for synchronized messages between client and server- Specified by:
getUniqueIdin interfaceIPacket- Returns:
- the own uniqueId
-
getHeader
public de.dytanic.cloudnet.common.document.gson.JsonDocument getHeader()
Description copied from interface:IPacketThe header, contain all important information from the packet, to specify the packet type as channel does and/or can has the data, which that are important to handle withThe encoding should be UTF-8
-
getBuffer
public ProtocolBuffer getBuffer()
Description copied from interface:IPacketReturns the packet body, for transport for extra data, like files or zip archives or something else
-
getBodyAsArray
public byte[] getBodyAsArray()
- Specified by:
getBodyAsArrayin interfaceIPacket- Returns:
- the body as a byte array
-
getCreationMillis
public long getCreationMillis()
- Specified by:
getCreationMillisin interfaceIPacket- Returns:
- the creation milliseconds of this packet
-
-