Added MessageDecoder interface. All decoder implement this.

Added DecoderFactory. This creates an appropriate decoder based on a MessageType.
BoatActionDecoder implements MessageDecoder.
BoatLocationDecoder implements MessageDecoder.
HeartBeatDecoder implements MessageDecoder.
JoinAcceptance implements MessageDecoder.
RaceStatusDecoder implements MessageDecoder.
RequestToJoinDecoder implements MessageDecoder.
XMLMessageDecoder implements MessageDecoder.
Refactored CourseWind decoder/encoder. CourseWind decoder/encoder is for an individual CourseWind.
CourseWinds decoder/encoder is for the combined message from the API.
Documented BoatAction, and it now contains a BoatActionEnum instead of a byte.
Refactored CourseWind and CourseWinds classes. They now expose correct units, instead of packed units.
Added CourseWindDecoderTest, and updated CourseWindsDecoderTest.
issue #35 #36
#story[1095]
This commit is contained in:
fjc40
2017-08-06 18:51:13 +12:00
parent 1fbdd09d70
commit 750ea5c141
32 changed files with 840 additions and 234 deletions
@@ -2,6 +2,7 @@ package visualiser.gameController;
import network.BinaryMessageDecoder;
import network.MessageDecoders.BoatActionDecoder;
import network.Messages.BoatAction;
import network.Messages.Enums.BoatActionEnum;
import visualiser.gameController.Keys.ControlKey;
import visualiser.gameController.Keys.KeyFactory;
@@ -47,9 +48,10 @@ public class ControllerServer implements Runnable {
if (inputStream.available() > 0) {
inputStream.read(message);
BinaryMessageDecoder encodedMessage = new BinaryMessageDecoder(message);
BoatActionDecoder boatActionDecoder = new BoatActionDecoder(encodedMessage.getMessageBody());
BoatActionEnum decodedMessage = boatActionDecoder.getBoatAction();
System.out.println("Received key: " + decodedMessage);
BoatActionDecoder boatActionDecoder = new BoatActionDecoder();
boatActionDecoder.decode(encodedMessage.getMessageBody());
BoatAction boatAction = boatActionDecoder.getMessage();
System.out.println("Received key: " + boatAction.getBoatAction());
}
} catch (IOException e) {
e.printStackTrace();