mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-01-19 16:57:20 +07:00
Implemented headerSize and fragmentSize fields
This commit is contained in:
parent
4ec51a427d
commit
990910393b
@ -189,6 +189,9 @@ public abstract class Packet {
|
||||
public int fragmentId;
|
||||
public int numFragments;
|
||||
|
||||
int headerSize;
|
||||
int fragmentSize;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
@ -208,6 +211,8 @@ public abstract class Packet {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int startIndex = bb.readerIndex();
|
||||
|
||||
if (bb.readableBytes() < FRAGMENT_HEADER_SIZE) {
|
||||
logError("buffer too small for fragment header");
|
||||
return -1;
|
||||
@ -244,16 +249,24 @@ public abstract class Packet {
|
||||
}
|
||||
ack = packetHeader.ack;
|
||||
ackBits = packetHeader.ackBits;
|
||||
fragmentSize = bb.readableBytes();
|
||||
} else {
|
||||
ack = 0;
|
||||
ackBits = 0;
|
||||
fragmentSize = bb.readableBytes();
|
||||
}
|
||||
|
||||
// TODO: validate fragmentBytes <= fragmentSize
|
||||
// TODO: validate size of fragmentId == fragmentSize
|
||||
if (fragmentSize > config.fragmentSize) {
|
||||
logError("fragment bytes %d > fragment size %d", fragmentSize, config.fragmentSize);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// TODO: implement support
|
||||
int headerSize = 0;
|
||||
if (fragmentId != numFragments - 1 && fragmentSize != config.fragmentSize) {
|
||||
logError("fragment %d is %d bytes, which is not the expected fragment size %d bytes", fragmentId, fragmentSize, config.fragmentSize);
|
||||
return -1;
|
||||
}
|
||||
|
||||
headerSize = bb.readerIndex() - startIndex + 1; // include prefixByte
|
||||
return headerSize;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user