mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-23 00:40:51 +01:00
why much code if less do trick
This commit is contained in:
parent
7862828633
commit
750fff662f
@ -18,24 +18,15 @@ public class PayloadBuffer {
|
||||
}
|
||||
public HPacket[] receive() {
|
||||
if (buffer.length < 6) return new HPacket[0];
|
||||
|
||||
HPacket total = new HPacket(buffer);
|
||||
if (total.getBytesLength() - 4 == total.length()) {
|
||||
buffer = new byte[0];
|
||||
return new HPacket[]{total};
|
||||
}
|
||||
else if (total.getBytesLength() - 4 > total.length()) {
|
||||
ArrayList<HPacket> all = new ArrayList<>();
|
||||
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];
|
||||
|
||||
ArrayList<HPacket> all = new ArrayList<>();
|
||||
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()]);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user