Избавляемся от ByteArrayOutputNetStream
т.к. в этой реализации протокола. он лишний
This commit is contained in:
@@ -1,119 +0,0 @@
|
|||||||
/*
|
|
||||||
* DmitriyMX <dimon550@gmail.com>
|
|
||||||
* 2018-04-08
|
|
||||||
*/
|
|
||||||
package mc.core.network.proto_125;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
public class ByteArrayOutputNetStream extends NetStream_p125 {
|
|
||||||
private ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean readBoolean() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public byte readByte() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readBytes(byte[] buffer) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int readUnsignedByte() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int readUnsignedShort() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public short readShort() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int readInt() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public float readFloat() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double readDouble() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeBoolean(boolean value) {
|
|
||||||
baos.write(value ? 1 : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeByte(int value) {
|
|
||||||
baos.write(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeBytes(byte[] buffer) {
|
|
||||||
baos.write(buffer, 0, buffer.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeShort(int value) {
|
|
||||||
baos.write((byte) value >>> 8);
|
|
||||||
baos.write((byte) value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeInt(int value) {
|
|
||||||
baos.write((byte)((int)(value >>> 24)));
|
|
||||||
baos.write((byte)((int)(value >>> 16)));
|
|
||||||
baos.write((byte)((int)(value >>> 8)));
|
|
||||||
baos.write((byte)((int)(value)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeLong(long value) {
|
|
||||||
baos.write((byte)((int)(value >>> 56)));
|
|
||||||
baos.write((byte)((int)(value >>> 48)));
|
|
||||||
baos.write((byte)((int)(value >>> 40)));
|
|
||||||
baos.write((byte)((int)(value >>> 32)));
|
|
||||||
baos.write((byte)((int)(value >>> 24)));
|
|
||||||
baos.write((byte)((int)(value >>> 16)));
|
|
||||||
baos.write((byte)((int)(value >>> 8)));
|
|
||||||
baos.write((byte)((int)(value)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeFloat(float value) {
|
|
||||||
writeInt(Float.floatToIntBits(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeDouble(double value) {
|
|
||||||
writeLong(Double.doubleToLongBits(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void skipBytes(int count) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] toByteArray() {
|
|
||||||
return baos.toByteArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,6 +9,7 @@ import io.netty.channel.ChannelHandlerContext;
|
|||||||
import io.netty.handler.codec.MessageToByteEncoder;
|
import io.netty.handler.codec.MessageToByteEncoder;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import mc.core.network.SCPacket;
|
import mc.core.network.SCPacket;
|
||||||
|
import mc.core.network.proto_125.netty.wrappers.WrapperNetStream;
|
||||||
import mc.core.network.proto_125.packets.PacketManager;
|
import mc.core.network.proto_125.packets.PacketManager;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -21,9 +22,8 @@ public class PacketEncoder extends MessageToByteEncoder<SCPacket> {
|
|||||||
log.warn("Not defined ID packet \"{}\"", pkt.getClass().getSimpleName());
|
log.warn("Not defined ID packet \"{}\"", pkt.getClass().getSimpleName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
byte[] bytes = pkt.toByteArray();
|
|
||||||
|
|
||||||
out.writeByte(id);
|
out.writeByte(id);
|
||||||
out.writeBytes(bytes);
|
pkt.writeSelf(new WrapperNetStream(out));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user