Refactor packet string charset
This commit is contained in:
@@ -47,12 +47,9 @@ public class ByteBufInPacket implements InPacket {
|
||||
@Override
|
||||
public String readString() {
|
||||
short length = readShort();
|
||||
char[] characters = new char[length];
|
||||
for(int i = 0; i < length; i++) {
|
||||
characters[i] = (char) readByte();
|
||||
}
|
||||
|
||||
return String.valueOf(characters);
|
||||
byte[] stringBytes = new byte[length];
|
||||
byteBuf.readBytes(stringBytes);
|
||||
return new String(stringBytes, STRING_CHARSET);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
package net.packet;
|
||||
|
||||
import java.awt.*;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public interface OutPacket extends Packet {
|
||||
Charset STRING_CHARSET = StandardCharsets.US_ASCII;
|
||||
|
||||
void writeByte(byte value);
|
||||
void writeByte(int value);
|
||||
void writeBytes(byte[] value);
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package net.packet;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public interface Packet {
|
||||
Charset STRING_CHARSET = StandardCharsets.US_ASCII;
|
||||
|
||||
byte[] getBytes();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user