java.lang.Object
com.thecoderscorner.menu.remote.protocol.TagValTextParser

public class TagValTextParser extends Object
This is the parser implementation that understands tag value format and can convert the tags back into a series of tags and values suitable for the protocol to decode messages.
  • Field Details

  • Constructor Details

    • TagValTextParser

      public TagValTextParser(ByteBuffer buffer) throws IOException
      Creates an instance that contains all the tags and values in a map, that can then be used to extract the message.
      Parameters:
      buffer - a buffer containing a message.
      Throws:
      IOException - if the buffer is invalid
  • Method Details

    • getValue

      public String getValue(String keyMsgType) throws TcProtocolException
      Gets the value associated with the key from the message. This version throws an exception if the key is not available and should be used for mandatory fields
      Parameters:
      keyMsgType - the key to obtain
      Returns:
      the associated value
      Throws:
      TcProtocolException
    • getValueWithDefault

      public String getValueWithDefault(String keyMsgType, String defaultVal)
      Gets the value associated with the key from the message if it exists in the underlying map. This version returns the default value if it does not exist.
      Parameters:
      keyMsgType - the key to obtain
      Returns:
      the associated value or the default
    • getValueAsInt

      public int getValueAsInt(String keyIdField) throws TcProtocolException
      Calls the getValue method first and the converts to an integer.
      Parameters:
      keyIdField - the key to obtain
      Returns:
      the integer value associated
      Throws:
      TcProtocolException
    • getValueAsIntWithDefault

      public int getValueAsIntWithDefault(String keyIdField, int defaultVal) throws TcProtocolException
      Calls the getValue method first and the converts to an integer.
      Parameters:
      keyIdField - the key to obtain
      Returns:
      the integer value associated
      Throws:
      TcProtocolException
    • toString

      public String toString()
      Overrides:
      toString in class Object