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:
Michael Rausch
2017-04-25 21:49:51 +12:00
parent 6874f288ee
commit 1f8f1f0f86
12 changed files with 573 additions and 121 deletions
@@ -1,11 +1,12 @@
package seng302.server.messages;
import java.io.DataOutputStream;
import java.nio.ByteBuffer;
/**
* The status of each boat, sent within a race status message
*/
public class BoatSubMessage {
public class BoatSubMessage{
private final int MESSAGE_SIZE = 20;
private long sourceId;
@@ -57,22 +58,22 @@ public class BoatSubMessage {
buff.position(buffPos);
// Boat Status, 1 byte
buff.put(ByteBuffer.allocate(1).put((byte) boatStatus.getCode()).array());
buff.put(ByteBuffer.allocate(1).put((byte) (boatStatus.getCode() & 0xff)).array());
buffPos += 1;
buff.position(buffPos);
// Leg number, 1 byte
buff.put(ByteBuffer.allocate(1).put((byte) legNumber).array());
buff.put(ByteBuffer.allocate(1).put((byte) (legNumber & 0xff)).array());
buffPos += 1;
buff.position(buffPos);
// Number of penalties awarded, 1 byte
buff.put(ByteBuffer.allocate(1).put((byte) numberPenaltiesAwarded).array());
buff.put(ByteBuffer.allocate(1).put((byte) (numberPenaltiesAwarded & 0xff)).array());
buffPos += 1;
buff.position(buffPos);
// Number of penalties served, 1 byte
buff.put(ByteBuffer.allocate(1).put((byte) numberPenaltiesServed).array());
buff.put(ByteBuffer.allocate(1).put((byte) (numberPenaltiesServed & 0xff)).array());
buffPos += 1;
buff.position(buffPos);