src/main/java/pityoulish/sockets/client/TLVResponseParserImpl.java
protected void parseMessage(MsgBoardTLV msgtlv, Visitor visitor)
    throws Exception
  {
    // The order of elements within the message is not specified.
    // Parse them as they come, then check if something is missing.
    String originator = null;
    String timestamp = null;
    String text = null;

    MsgBoardTLV nested = msgtlv.getNestedTLV();
    while (nested != null)
     {
       if (nested.getEnd() > msgtlv.getEnd())
          throw new Exception
            (Catalog.OVERLONG_TLV_2.format(nested.getType(),
                                           nested.getStart()));

       switch (nested.getType())
        {
         case ORIGINATOR:
           if (originator != null)
              throw new Exception
                (Catalog.DUPLICATE_TLV_2.format(nested.getType(),
                                                nested.getStart()));
           originator = parseStringValue(nested, "US-ASCII");
           break;

         case TIMESTAMP:
           if (timestamp != null)
              throw new Exception
                (Catalog.DUPLICATE_TLV_2.format(nested.getType(),
                                                nested.getStart()));
           timestamp = parseStringValue(nested, "US-ASCII");
           break;

         case TEXT:
           if (text != null)
              throw new Exception
                (Catalog.DUPLICATE_TLV_2.format(nested.getType(),
                                                nested.getStart()));
           text = parseStringValue(nested, "UTF-8");
           break;

         default:
           throw new Exception
             (Catalog.UNEXPECTED_TLV_2.format(nested.getType(),
                                              nested.getStart()));
        }
       nested = nested.getNextTLV(msgtlv.getEnd());
     }

    if (originator == null)
       throw new Exception
         (Catalog.MISSING_NESTED_TLV_3.format(msgtlv.getType(),
                                              msgtlv.getStart(),
                                              MsgBoardType.ORIGINATOR));
    if (timestamp == null)
       throw new Exception
         (Catalog.MISSING_NESTED_TLV_3.format(msgtlv.getType(),
                                              msgtlv.getStart(),
                                              MsgBoardType.TIMESTAMP));
    if (text == null)
       throw new Exception
         (Catalog.MISSING_NESTED_TLV_3.format(msgtlv.getType(),
                                              msgtlv.getStart(),
                                              MsgBoardType.TEXT));

    visitor.visitMessage(originator, timestamp, text);
  }
/**
   * Parses a message and calls the visitor.
   *
   * @param msgtlv      the TLV with the message
   * @param visitor     the visitor to invoke on the message
   *
   * @throws Exception in case of a problem
   */
Parses a message and calls the visitor.
@param msgtlv      the TLV with the message
@param visitor     the visitor to invoke on the message

@throws Exception in case of a problem
Parses a message and calls the visitor . @param msgtlv the TLV with the message @param visitor the visitor to invoke on the message @throws Exception in case of a problem
protected void parseMessage(MsgBoardTLV msgtlv, Visitor visitor)
    throws Exception
  {
    String originator = null;
    String timestamp = null;
    String text = null;
    MsgBoardTLV nested = msgtlv.getNestedTLV();
    while (nested != null)
     {
       if (nested.getEnd() > msgtlv.getEnd())
          throw new Exception
            (Catalog.OVERLONG_TLV_2.format(nested.getType(),
                                           nested.getStart()));
       switch (nested.getType())
        {
         case ORIGINATOR:
           if (originator != null)
              throw new Exception
                (Catalog.DUPLICATE_TLV_2.format(nested.getType(),
                                                nested.getStart()));
           originator = parseStringValue(nested, "US-ASCII");
           break;
         case TIMESTAMP:
           if (timestamp != null)
              throw new Exception
                (Catalog.DUPLICATE_TLV_2.format(nested.getType(),
                                                nested.getStart()));
           timestamp = parseStringValue(nested, "US-ASCII");
           break;
         case TEXT:
           if (text != null)
              throw new Exception
                (Catalog.DUPLICATE_TLV_2.format(nested.getType(),
                                                nested.getStart()));
           text = parseStringValue(nested, "UTF-8");
           break;
         default:
           throw new Exception
             (Catalog.UNEXPECTED_TLV_2.format(nested.getType(),
                                              nested.getStart()));
        }
       nested = nested.getNextTLV(msgtlv.getEnd());
     }
    if (originator == null)
       throw new Exception
         (Catalog.MISSING_NESTED_TLV_3.format(msgtlv.getType(),
                                              msgtlv.getStart(),
                                              MsgBoardType.ORIGINATOR));
    if (timestamp == null)
       throw new Exception
         (Catalog.MISSING_NESTED_TLV_3.format(msgtlv.getType(),
                                              msgtlv.getStart(),
                                              MsgBoardType.TIMESTAMP));
    if (text == null)
       throw new Exception
         (Catalog.MISSING_NESTED_TLV_3.format(msgtlv.getType(),
                                              msgtlv.getStart(),
                                              MsgBoardType.TEXT));
    visitor.visitMessage(originator, timestamp, text);
  }
protected void parseMessage ( MsgBoardTLV msgtlv , Visitor visitor ) throws Exception { String originator = null ; String timestamp = null ; String text = null ; MsgBoardTLV nested = msgtlv . getNestedTLV ( ) ; while ( nested != null ) { if ( nested . getEnd ( ) > msgtlv . getEnd ( ) ) throw new Exception ( Catalog . OVERLONG_TLV_2 . format ( nested . getType ( ) , nested . getStart ( ) ) ) ; switch ( nested . getType ( ) ) { case ORIGINATOR : if ( originator != null ) throw new Exception ( Catalog . DUPLICATE_TLV_2 . format ( nested . getType ( ) , nested . getStart ( ) ) ) ; originator = parseStringValue ( nested , "US-ASCII" ) ; break ; case TIMESTAMP : if ( timestamp != null ) throw new Exception ( Catalog . DUPLICATE_TLV_2 . format ( nested . getType ( ) , nested . getStart ( ) ) ) ; timestamp = parseStringValue ( nested , "US-ASCII" ) ; break ; case TEXT : if ( text != null ) throw new Exception ( Catalog . DUPLICATE_TLV_2 . format ( nested . getType ( ) , nested . getStart ( ) ) ) ; text = parseStringValue ( nested , "UTF-8" ) ; break ; default : throw new Exception ( Catalog . UNEXPECTED_TLV_2 . format ( nested . getType ( ) , nested . getStart ( ) ) ) ; } nested = nested . getNextTLV ( msgtlv . getEnd ( ) ) ; } if ( originator == null ) throw new Exception ( Catalog . MISSING_NESTED_TLV_3 . format ( msgtlv . getType ( ) , msgtlv . getStart ( ) , MsgBoardType . ORIGINATOR ) ) ; if ( timestamp == null ) throw new Exception ( Catalog . MISSING_NESTED_TLV_3 . format ( msgtlv . getType ( ) , msgtlv . getStart ( ) , MsgBoardType . TIMESTAMP ) ) ; if ( text == null ) throw new Exception ( Catalog . MISSING_NESTED_TLV_3 . format ( msgtlv . getType ( ) , msgtlv . getStart ( ) , MsgBoardType . TEXT ) ) ; visitor . visitMessage ( originator , timestamp , text ) ; }
Parses a message and calls the visitor.
Parses a message and calls the visitor .
// The order of elements within the message is not specified. // Parse them as they come, then check if something is missing.