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:
@@ -2,6 +2,7 @@ package network;
|
||||
|
||||
|
||||
import network.Exceptions.InvalidMessageException;
|
||||
import network.Exceptions.InvalidMessageTypeException;
|
||||
import network.MessageDecoders.*;
|
||||
import network.Messages.*;
|
||||
import network.Messages.Enums.MessageType;
|
||||
@@ -130,16 +131,26 @@ public class BinaryMessageDecoder {
|
||||
//Now we create the message object based on what is actually in the message body.
|
||||
MessageType mType = MessageType.fromByte(headerMessageType);
|
||||
|
||||
/*MessageDecoder decoder = null;
|
||||
try {
|
||||
decoder = DecoderFactory.create(mType);
|
||||
} catch (InvalidMessageTypeException e) {
|
||||
throw new InvalidMessageException("Could not create decoder for MessageType: " + mType, e);
|
||||
}
|
||||
|
||||
return decoder.decode(messageBody);*/
|
||||
|
||||
|
||||
switch(mType) {
|
||||
case HEARTBEAT:
|
||||
//System.out.println("Decoding HeartBeat Message!");
|
||||
HeartBeatDecoder heartBeatDecoder = new HeartBeatDecoder(messageBody);
|
||||
return heartBeatDecoder.getMessage();
|
||||
HeartBeatDecoder heartBeatDecoder = new HeartBeatDecoder();
|
||||
return heartBeatDecoder.decode(messageBody);
|
||||
|
||||
case RACESTATUS:
|
||||
//System.out.println("Race Status Message");
|
||||
RaceStatusDecoder rsdecoder = new RaceStatusDecoder(messageBody);
|
||||
return rsdecoder.getMessage();
|
||||
RaceStatusDecoder rsdecoder = new RaceStatusDecoder();
|
||||
return rsdecoder.decode(messageBody);
|
||||
|
||||
case DISPLAYTEXTMESSAGE:
|
||||
//System.out.println("Display Text Message");
|
||||
@@ -148,8 +159,8 @@ public class BinaryMessageDecoder {
|
||||
|
||||
case XMLMESSAGE:
|
||||
//System.out.println("XML Message!");
|
||||
XMLMessageDecoder xmdecoder = new XMLMessageDecoder(messageBody);
|
||||
return xmdecoder.getMessage();
|
||||
XMLMessageDecoder xmdecoder = new XMLMessageDecoder();
|
||||
return xmdecoder.decode(messageBody);
|
||||
|
||||
case RACESTARTSTATUS:
|
||||
//System.out.println("Race Start Status Message");
|
||||
@@ -173,8 +184,8 @@ public class BinaryMessageDecoder {
|
||||
|
||||
case BOATLOCATION:
|
||||
//System.out.println("Boat Location Message!");
|
||||
BoatLocationDecoder blDecoder = new BoatLocationDecoder(messageBody);
|
||||
return blDecoder.getMessage();
|
||||
BoatLocationDecoder blDecoder = new BoatLocationDecoder();
|
||||
return blDecoder.decode(messageBody);
|
||||
|
||||
case MARKROUNDING:
|
||||
//System.out.println("Mark Rounding Message!");
|
||||
@@ -183,8 +194,8 @@ public class BinaryMessageDecoder {
|
||||
|
||||
case COURSEWIND:
|
||||
//System.out.println("Course Wind Message!");
|
||||
CourseWindDecoder cwDecoder = new CourseWindDecoder(messageBody);
|
||||
return new CourseWinds(cwDecoder.getMessageVersionNumber(), cwDecoder.getByteWindID(), cwDecoder.getLoopMessages());
|
||||
CourseWindsDecoder cwDecoder = new CourseWindsDecoder();
|
||||
return cwDecoder.decode(messageBody);
|
||||
|
||||
case AVGWIND:
|
||||
//System.out.println("Average Wind Message!");
|
||||
@@ -192,8 +203,8 @@ public class BinaryMessageDecoder {
|
||||
return awDecoder.getAverageWind();
|
||||
|
||||
case BOATACTION:
|
||||
BoatActionDecoder baDecoder = new BoatActionDecoder(messageBody);
|
||||
return new BoatAction(baDecoder.getBoatAction());
|
||||
BoatActionDecoder baDecoder = new BoatActionDecoder();
|
||||
return baDecoder.decode(messageBody);
|
||||
|
||||
default:
|
||||
//System.out.println("Broken Message!");
|
||||
|
||||
Reference in New Issue
Block a user