001 package edu.harvard.deas.hyperenc; 002 003 import java.util.List; 004 005 import edu.harvard.deas.hyperenc.util.Pair; 006 007 /** 008 * Parses the contents of protocol messages. 009 */ 010 public abstract class MessageParser { 011 /** 012 * Converts the raw contents of a master reconciliation message into a list of 013 * pairs; each pair contains an integer ID identifying a page, and the hash of 014 * that page. 015 * 016 * @param message the raw message 017 * @return the message represented as a list of ID-hash pairs 018 * @throws MessageParseException if <code>message</code> cannot be parsed 019 */ 020 public abstract List<Pair<Integer,byte[]>> parseMRec(String message) 021 throws MessageParseException; 022 023 /** 024 * Converts the raw contents of a slave reconciliation message into a list of 025 * pairs; each pair contains an integer ID identifying a page, and a code 026 * indicating the result of the reconciliation. 027 * 028 * @param message the raw message 029 * @return the message represented as a list of ID-result code pairs 030 * @throws MessageParseException if <code>message</code> cannot be parsed 031 */ 032 public abstract List<Pair<Integer,SlaveRecResult>> parseSRec(String message) 033 throws MessageParseException; 034 035 /** 036 * Converts a master reconciliation message hash list into a string. Performs 037 * the opposite conversion as <code>parseMRec</code>; passing a list to this 038 * method, then parsing the returned string with <code>parseMRec</code> yields 039 * a list equivalent to the original. 040 * 041 * @param lst a list of ID-hash pairs 042 * @return a string representing the given list 043 */ 044 public abstract String mrecToString(List<Pair<Integer,byte[]>> lst); 045 046 /** 047 * Converts a slave reconciliation message hash list into a string. Performs 048 * the opposite conversion as <code>parseSRec</code>; passing a list to this 049 * method, then parsing the returned string with <code>parseSRec</code> yields 050 * a list equivalent to the original. 051 * 052 * @param lst a list of ID-result code pairs 053 * @return a string representing the given list 054 */ 055 public abstract String srecToString(List<Pair<Integer,SlaveRecResult>> lst); 056 }