Added XMLMessageEncoder.

Refactored XMLMessageDecoder to be consistent with other decoders - only needs to expose the XMLMessage.
Refactored BoatLocationDecoder to be consistent with other decoders - only needs to expose the BoatLocation.
Updated XMLMessageDecoderTest to use new encoder/decoder. Also tests all three message types.
Removed XMLMessageEncoderTest as it was redundant.
Updated BinaryMessageDecoderTest.xmlMessageTest() to use updated XMLMessage encoder/decoder.
issue #35 #36
#story[1095]
This commit is contained in:
fjc40
2017-08-06 01:01:05 +12:00
parent 8ef906472b
commit b486f99dbe
13 changed files with 535 additions and 317 deletions
@@ -134,11 +134,12 @@ public class MockOutput implements Runnable
* Encodes/serialises a XMLMessage message, and returns it.
* @param xmlMessage The XMLMessage message to serialise.
* @return The XMLMessage message in a serialised form.
* @throws InvalidMessageException Thrown if the message cannot be encoded.
*/
private synchronized byte[] parseXMLMessage(XMLMessage xmlMessage) {
private synchronized byte[] parseXMLMessage(XMLMessage xmlMessage) throws InvalidMessageException {
//Serialize the xml message.
byte[] encodedXML = RaceVisionByteEncoder.xmlMessage(xmlMessage);
byte[] encodedXML = RaceVisionByteEncoder.encode(xmlMessage);
//Place the message in a packet.
BinaryMessageEncoder binaryMessageEncoder = new BinaryMessageEncoder(
@@ -262,15 +263,23 @@ public class MockOutput implements Runnable
//Send XML messages.
if (!sentXMLs) {
//Serialise them.
byte[] raceXMLBlob = parseXMLMessage(latestMessages.getRaceXMLMessage());
byte[] regattaXMLBlob = parseXMLMessage(latestMessages.getRegattaXMLMessage());
byte[] boatsXMLBlob = parseXMLMessage(latestMessages.getBoatXMLMessage());
//Send them.
outToVisualiser.write(raceXMLBlob);
outToVisualiser.write(regattaXMLBlob);
outToVisualiser.write(boatsXMLBlob);
sentXMLs = true;
try {
byte[] raceXMLBlob = parseXMLMessage(latestMessages.getRaceXMLMessage());
byte[] regattaXMLBlob = parseXMLMessage(latestMessages.getRegattaXMLMessage());
byte[] boatsXMLBlob = parseXMLMessage(latestMessages.getBoatXMLMessage());
//Send them.
outToVisualiser.write(raceXMLBlob);
outToVisualiser.write(regattaXMLBlob);
outToVisualiser.write(boatsXMLBlob);
sentXMLs = true;
} catch (InvalidMessageException e) {
Logger.getGlobal().log(Level.WARNING, "Could not encode XMLMessage: " + latestMessages.getRaceXMLMessage(), e);
continue; //Go to next iteration.
}
}
//Sends the RaceStatus message.