mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Added boat location, and race start messages to the mock data interface
- Added proper support for signed and unsigned types. This includes automatic conversion to the correct data type (long to int, short, or byte). - Moved code related to adding values into the byte buffer into the abstract Message class Tags: #story[29]
This commit is contained in:
@@ -26,24 +26,15 @@ public class Heartbeat extends Message {
|
||||
public void send(DataOutputStream outputStream) {
|
||||
setHeader(new Header(MessageType.HEARTBEAT, 0x01, (short) getSize()));
|
||||
|
||||
ByteBuffer buff = ByteBuffer.allocate(Header.getSize() + getSize() + getSize());
|
||||
allocateBuffer();
|
||||
writeHeaderToBuffer();
|
||||
|
||||
// Write header
|
||||
buff.put(getHeader().getByteBuffer());
|
||||
buff.position(Header.getSize());
|
||||
putUnsignedInt(seqNo, 4);
|
||||
|
||||
// Write seq num
|
||||
buff.put(ByteBuffer.allocate(4).putInt(seqNo).array());
|
||||
buff.position(Header.getSize()+4);
|
||||
|
||||
// Write CRC
|
||||
CRC32 crc = new CRC32();
|
||||
crc.update(buff.array());
|
||||
|
||||
buff.put(ByteBuffer.allocate(4).putInt((short)crc.getValue()).array());
|
||||
writeCRC();
|
||||
|
||||
try {
|
||||
outputStream.write(buff.array());
|
||||
outputStream.write(getBuffer().array());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user