Factorization of setPayloadSize and getPayloadSize
This commit is contained in:
parent
855e4ed73e
commit
04457fdac5
@ -21,8 +21,7 @@ public class FileList extends Payload {
|
|||||||
if (RequestResponseCode.fromCode(datagram[RequestResponseCode.RRCODE_POSITION]) != RequestResponseCode.LIST_RESPONSE) {
|
if (RequestResponseCode.fromCode(datagram[RequestResponseCode.RRCODE_POSITION]) != RequestResponseCode.LIST_RESPONSE) {
|
||||||
throw new InternalError();
|
throw new InternalError();
|
||||||
}
|
}
|
||||||
int size = (datagram[PAYLOAD_SIZE_POSITON] << (8*3)) | (datagram[PAYLOAD_SIZE_POSITON+1] << (8*2)) | (datagram[PAYLOAD_SIZE_POSITON+2] << 8) | datagram[PAYLOAD_SIZE_POSITON+3];
|
int size = getPayloadSize(datagram);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** To datagram with padding */
|
/** To datagram with padding */
|
||||||
@ -34,9 +33,7 @@ public class FileList extends Payload {
|
|||||||
// bits 16-31 are reserved for future use
|
// bits 16-31 are reserved for future use
|
||||||
//TODO size
|
//TODO size
|
||||||
int size = ;
|
int size = ;
|
||||||
for(i=0;i<4;i++) {
|
datagram = setPayloadSize(size, datagram);
|
||||||
datagram[Payload.PAYLOAD_SIZE_POSITON + i] = (byte) (size >> (8 * (3 - i)) & 0xFF);
|
|
||||||
}
|
|
||||||
//TODO content
|
//TODO content
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ public class FilePart extends Payload {
|
|||||||
if (RequestResponseCode.fromCode(datagram[RequestResponseCode.RRCODE_POSITION]) != RequestResponseCode.LOAD_RESPONSE) {
|
if (RequestResponseCode.fromCode(datagram[RequestResponseCode.RRCODE_POSITION]) != RequestResponseCode.LOAD_RESPONSE) {
|
||||||
throw new InternalError();
|
throw new InternalError();
|
||||||
}
|
}
|
||||||
int size = (datagram[PAYLOAD_SIZE_POSITON] << (8*3)) | (datagram[PAYLOAD_SIZE_POSITON+1] << (8*2)) | (datagram[PAYLOAD_SIZE_POSITON+2] << 8) | datagram[PAYLOAD_SIZE_POSITON+3];
|
int size = getPayloadSize(datagram);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** To datagram with padding */
|
/** To datagram with padding */
|
||||||
@ -38,9 +38,7 @@ public class FilePart extends Payload {
|
|||||||
// bits 16-31 are reserved for future use
|
// bits 16-31 are reserved for future use
|
||||||
//TODO size
|
//TODO size
|
||||||
int size = ;
|
int size = ;
|
||||||
for(i=0;i<4;i++) {
|
datagram = setPayloadSize(size, datagram);
|
||||||
datagram[Payload.PAYLOAD_SIZE_POSITON + i] = (byte) (size >> (8 * (3 - i)) & 0xFF);
|
|
||||||
}
|
|
||||||
//TODO content
|
//TODO content
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,4 +43,20 @@ public class Payload {
|
|||||||
// bits 16-31 are reserved for future use
|
// bits 16-31 are reserved for future use
|
||||||
// payload size is 0 (this is what java have initialized datagram)
|
// payload size is 0 (this is what java have initialized datagram)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static byte[] setPayloadSize(int size, byte[] datagram) {
|
||||||
|
for(int i=0;i<4;i++) {
|
||||||
|
datagram[Payload.PAYLOAD_SIZE_POSITON + i] = (byte) (size >> (8 * (3 - i)) & 0xFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return datagram;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static int getPayloadSize(byte[] datagram) {
|
||||||
|
int size = 0;
|
||||||
|
for(int i=0;i<4;i++) {
|
||||||
|
size |= ((int)datagram[PAYLOAD_SIZE_POSITON + i]) << (8* i);
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user