Package top.focess.qq.api.net
Class PacketPreCodec
- java.lang.Object
-
- top.focess.qq.api.net.PacketPreCodec
-
public class PacketPreCodec extends Object
This class is used to prehandle the packet.
-
-
Constructor Summary
Constructors Constructor Description PacketPreCodec()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]getBytes()Get all bytes of the packetvoidpush(byte[] buffer, int length)Push the data to the precodecvoidpush(byte[] buffer, int offset, int length)Push the data to the precodecbytereadByte()Read a bytedoublereadDouble()Read a doublefloatreadFloat()Read a floatintreadInt()Read a integerlongreadLong()Read a long@Nullable PacketreadPacket()Read a packetshortreadShort()Read a shortStringreadString()Read a stringstatic <T extends Packet>
voidregister(int packetId, PacketCodec<T> packetCodec)Register the packet codec for the special packet idvoidwriteByte(byte b)Write a bytevoidwriteDouble(double v)Write a doublevoidwriteFloat(float v)Write a floatvoidwriteInt(int v)Write a integervoidwriteLong(long v)Write a long<T extends Packet>
booleanwritePacket(T packet)Write a packetvoidwriteShort(short v)Write a shortvoidwriteString(@NotNull String v)Write a string
-
-
-
Method Detail
-
register
public static <T extends Packet> void register(int packetId, PacketCodec<T> packetCodec)
Register the packet codec for the special packet id- Type Parameters:
T- the packet type- Parameters:
packetId- the packet idpacketCodec- the packet codec
-
readInt
public int readInt()
Read a integer- Returns:
- the integer read from precodec
-
readLong
public long readLong()
Read a long- Returns:
- the long read from precodec
-
writeInt
public void writeInt(int v)
Write a integer- Parameters:
v- the integer
-
writeLong
public void writeLong(long v)
Write a long- Parameters:
v- the long
-
writeString
public void writeString(@NotNull @NotNull String v)Write a string- Parameters:
v- the string
-
readString
public String readString()
Read a string- Returns:
- the string read from precodec
-
writeFloat
public void writeFloat(float v)
Write a float- Parameters:
v- the float
-
readFloat
public float readFloat()
Read a float- Returns:
- the float read from precodec
-
writeDouble
public void writeDouble(double v)
Write a double- Parameters:
v- the double
-
readDouble
public double readDouble()
Read a double- Returns:
- the double read from precodec
-
readByte
public byte readByte()
Read a byte- Returns:
- the byte read from precodec
-
writeByte
public void writeByte(byte b)
Write a byte- Parameters:
b- the byte
-
readShort
public short readShort()
Read a short- Returns:
- the short read from precodec
-
writeShort
public void writeShort(short v)
Write a short- Parameters:
v- the short
-
getBytes
public byte[] getBytes()
Get all bytes of the packet- Returns:
- all bytes of the packet
-
readPacket
@Nullable public @Nullable Packet readPacket()
Read a packet- Returns:
- the packet read from precodec
-
writePacket
public <T extends Packet> boolean writePacket(@NotNull T packet)
Write a packet- Type Parameters:
T- the packet type- Parameters:
packet- the packet- Returns:
- true if the packet has been written successfully, false otherwise
-
push
public void push(byte[] buffer, int offset, int length)Push the data to the precodec- Parameters:
buffer- the dataoffset- the offset of the datalength- the length of the data- See Also:
push(byte[], int)
-
push
public void push(byte[] buffer, int length)Push the data to the precodec- Parameters:
buffer- the datalength- the length of the data- See Also:
push(byte[], int, int)
-
-