megamek.common.xml
Class PacketEncoder

java.lang.Object
  extended by megamek.common.xml.PacketEncoder

public class PacketEncoder
extends java.lang.Object

Objects of this class can encode a Packet object as XML into an output writer and decode one from a parsed XML node. It is used when saving games into a version- neutral format.

Author:
James Damour

Constructor Summary
PacketEncoder()
           
 
Method Summary
static Packet decode(gd.xml.tiny.ParsedXML node, IGame game)
          Decode a Packet object from the passed node.
static void encode(Packet packet, java.io.Writer out)
          Encode a Packet object to an output writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PacketEncoder

public PacketEncoder()
Method Detail

encode

public static void encode(Packet packet,
                          java.io.Writer out)
                   throws java.io.IOException
Encode a Packet object to an output writer.

Parameters:
packet - - the Packet to be encoded. This value must not be null.
out - - the Writer that will receive the XML. This value must not be null.
Throws:
IllegalArgumentException - if the node is null.
IOException - if there's any error on write.
java.io.IOException

decode

public static Packet decode(gd.xml.tiny.ParsedXML node,
                            IGame game)
Decode a Packet object from the passed node.

Parameters:
node - - the ParsedXML node for this object. This value must not be null.
game - - the IGame the decoded object belongs to.
Returns:
the Packet object based on the node.
Throws:
IllegalArgumentException - if the node is null.
IllegalStateException - if the node does not contain a valid Packet.
NumberFormatException - if the value of a numeric data element is not in a valid format.