35 lines
835 B
Java
35 lines
835 B
Java
/*
|
|
* DmitriyMX <dimon550@gmail.com>
|
|
* 2017-04-26
|
|
*/
|
|
package asys.mcsmanager.packets;
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
public abstract class Packet {
|
|
public String readString(ByteBuf buffer) {
|
|
int length = buffer.readUnsignedShort();
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
for (int i = 0; i < length; i++) {
|
|
sb.append(buffer.readChar());
|
|
}
|
|
|
|
return sb.toString();
|
|
}
|
|
|
|
public void writeString(ByteBuf buffer, String string) {
|
|
int length = string.length();
|
|
buffer.writeShort(length);
|
|
|
|
if (length > 0) {
|
|
for (int i = 0; i < length; i++) {
|
|
buffer.writeChar(string.charAt(i));
|
|
}
|
|
}
|
|
}
|
|
|
|
public abstract void readSelfData(ByteBuf buffer);
|
|
public abstract void writeSelfData(ByteBuf buffer);
|
|
}
|