edu.harvard.deas.hyperenc
Class PlainTextMessageParser

java.lang.Object
  extended by edu.harvard.deas.hyperenc.MessageParser
      extended by edu.harvard.deas.hyperenc.PlainTextMessageParser

public class PlainTextMessageParser
extends MessageParser

Parses plain-text representations of hyper-encryption protocol messages according to the following specification:

Master reconciliation message: Each line contains one ID-hash pair. The integer ID comes first, followed by a single space, followed by the hash, encoded as a hexadecimal number using digits 0-9 and a-f (case-insensitive).

Slave reconciliation message: Each line contains one ID-code pair. The integer ID comes first, followed by a single space, followed by a result code, which must be one of the following single-character strings:

See Also:
SlaveRecResult

Constructor Summary
PlainTextMessageParser()
           
 
Method Summary
 String mrecToString(List<Pair<Integer,byte[]>> lst)
          Converts a master reconciliation message hash list into a string.
 List<Pair<Integer,byte[]>> parseMRec(String message)
          Converts the raw contents of a master reconciliation message into a list of pairs; each pair contains an integer ID identifying a page, and the hash of that page.
 List<Pair<Integer,SlaveRecResult>> parseSRec(String message)
          Converts the raw contents of a slave reconciliation message into a list of pairs; each pair contains an integer ID identifying a page, and a code indicating the result of the reconciliation.
 String srecToString(List<Pair<Integer,SlaveRecResult>> lst)
          Converts a slave reconciliation message hash list into a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PlainTextMessageParser

public PlainTextMessageParser()
Method Detail

parseMRec

public List<Pair<Integer,byte[]>> parseMRec(String message)
                                     throws MessageParseException
Description copied from class: MessageParser
Converts the raw contents of a master reconciliation message into a list of pairs; each pair contains an integer ID identifying a page, and the hash of that page.

Specified by:
parseMRec in class MessageParser
Parameters:
message - the raw message
Returns:
the message represented as a list of ID-hash pairs
Throws:
MessageParseException - if message cannot be parsed

parseSRec

public List<Pair<Integer,SlaveRecResult>> parseSRec(String message)
                                             throws MessageParseException
Description copied from class: MessageParser
Converts the raw contents of a slave reconciliation message into a list of pairs; each pair contains an integer ID identifying a page, and a code indicating the result of the reconciliation.

Specified by:
parseSRec in class MessageParser
Parameters:
message - the raw message
Returns:
the message represented as a list of ID-result code pairs
Throws:
MessageParseException - if message cannot be parsed

mrecToString

public String mrecToString(List<Pair<Integer,byte[]>> lst)
Description copied from class: MessageParser
Converts a master reconciliation message hash list into a string. Performs the opposite conversion as parseMRec; passing a list to this method, then parsing the returned string with parseMRec yields a list equivalent to the original.

Specified by:
mrecToString in class MessageParser
Parameters:
lst - a list of ID-hash pairs
Returns:
a string representing the given list

srecToString

public String srecToString(List<Pair<Integer,SlaveRecResult>> lst)
Converts a slave reconciliation message hash list into a string. Performs the opposite conversion as parseSRec; passing a list to this method, then parsing the returned string with parseSRec yields a list equivalent to the original.

Specified by:
srecToString in class MessageParser
Parameters:
lst - a list of ID-result code pairs
Returns:
a string representing the given list
Throws:
IllegalArgumentException - if a result in lst is not supported by this parser