why much code if less do trick

This commit is contained in:
sirjonasxx 2020-04-24 21:15:39 +02:00
parent 7862828633
commit 750fff662f

View File

@ -18,24 +18,15 @@ public class PayloadBuffer {
} }
public HPacket[] receive() { public HPacket[] receive() {
if (buffer.length < 6) return new HPacket[0]; if (buffer.length < 6) return new HPacket[0];
HPacket total = new HPacket(buffer); HPacket total = new HPacket(buffer);
if (total.getBytesLength() - 4 == total.length()) {
buffer = new byte[0]; ArrayList<HPacket> all = new ArrayList<>();
return new HPacket[]{total}; while (total.getBytesLength() >= 4 && total.getBytesLength() - 4 >= total.length()){
} all.add(new HPacket(Arrays.copyOfRange(buffer, 0, total.length() + 4)));
else if (total.getBytesLength() - 4 > total.length()) { buffer = Arrays.copyOfRange(buffer, total.length() + 4, buffer.length);
ArrayList<HPacket> all = new ArrayList<>(); total = new HPacket(buffer);
while (total.getBytesLength() >= 4 && total.getBytesLength() - 4 >= total.length()){
all.add(new HPacket(Arrays.copyOfRange(buffer, 0, total.length() + 4)));
buffer = Arrays.copyOfRange(buffer, total.length() + 4, buffer.length);
total = new HPacket(buffer);
}
return all.toArray(new HPacket[all.size()]);
}
else {
return new HPacket[0];
} }
return all.toArray(new HPacket[all.size()]);
} }