src/main/java/pityoulish/sockets/server/TLVRequestParserImpl.java
protected MsgBoardRequest parseGeneric(MsgBoardRequest.ReqType retype,
                                         MsgBoardTLV reqtlv,
                                         EnumSet<MsgBoardType> expected)
    throws ProtocolException
  {
    EnumMap<MsgBoardType,String> params = new EnumMap<>(MsgBoardType.class);

    for (MsgBoardTLV nested = reqtlv.getNestedTLV();
         nested != null;
         nested = nested.getNextTLV(reqtlv.getEnd())
         )
     {
       if (nested.getEnd() > reqtlv.getEnd())
          throw failOverlongTLV(nested);
       if (!expected.contains(nested.getType()))
          throw failUnexpectedTLV(nested);
       if (params.containsKey(nested.getType()))
          throw failDuplicateTLV(nested);

       String value = null;
       switch (nested.getType())
        {
         case TEXT:
           value = parseStringValue(nested, "UTF-8");
           break;

         case ORIGINATOR:
         case MARKER:
         case TICKET:
           value = parseStringValue(nested, "US-ASCII");
           break;

           // LIMIT is not a string value
           // TIMESTAMP and MISSED do not appear in requests

         default:
           // can only happen if 'expected' contains an unsupported element
           throw new IllegalArgumentException
             ("EnumSet<MsgBoardType>::"+nested.getType());
        }

       params.put(nested.getType(), value);
     }

    // check for absence of a mandatory parameter
    EnumSet<MsgBoardType> missing = EnumSet.copyOf(expected);
    missing.removeAll(params.keySet());
    if (!missing.isEmpty())
     {
       // several could be missing, just pick one to report...
       throw Catalog.MISSING_NESTED_TLV_3.asPX
         (reqtlv.getType(), reqtlv.getStart(), missing.iterator().next());
     }

    return new MsgBoardRequestImpl
      (retype, null,
       params.get(MsgBoardType.MARKER),
       params.get(MsgBoardType.TICKET),
       params.get(MsgBoardType.TEXT),
       params.get(MsgBoardType.ORIGINATOR)
       );
  }
/**
   * Parses any request with all-mandatory, all-string parameters.
   * Does not support non-string parameters.
   * Does not support optional parameters.
   *
   * @param retype      the type for the object to return
   * @param reqtlv      the request to parse
   * @param expected    the mandatory string parameters.
   *                    Only primitive TLV types that contain a string value
   *                    are supported in this set.
   *
   * @return the parsed request
   *
   * @throws ProtocolException  in case of a problem
   */
Parses any request with all-mandatory, all-string parameters.
Does not support non-string parameters.
Does not support optional parameters.

@param retype      the type for the object to return
@param reqtlv      the request to parse
@param expected    the mandatory string parameters.
Only primitive TLV types that contain a string value
are supported in this set.

@return the parsed request

@throws ProtocolException  in case of a problem
Parses any request with all - mandatory all - string parameters . Does not support non - string parameters . Does not support optional parameters . @param retype the type for the object to return @param reqtlv the request to parse @param expected the mandatory string parameters . Only primitive TLV types that contain a string value are supported in this set . @return the parsed request @throws ProtocolException in case of a problem
protected MsgBoardRequest parseGeneric(MsgBoardRequest.ReqType retype,
                                         MsgBoardTLV reqtlv,
                                         EnumSet<MsgBoardType> expected)
    throws ProtocolException
  {
    EnumMap<MsgBoardType,String> params = new EnumMap<>(MsgBoardType.class);
    for (MsgBoardTLV nested = reqtlv.getNestedTLV();
         nested != null;
         nested = nested.getNextTLV(reqtlv.getEnd())
         )
     {
       if (nested.getEnd() > reqtlv.getEnd())
          throw failOverlongTLV(nested);
       if (!expected.contains(nested.getType()))
          throw failUnexpectedTLV(nested);
       if (params.containsKey(nested.getType()))
          throw failDuplicateTLV(nested);
       String value = null;
       switch (nested.getType())
        {
         case TEXT:
           value = parseStringValue(nested, "UTF-8");
           break;
         case ORIGINATOR:
         case MARKER:
         case TICKET:
           value = parseStringValue(nested, "US-ASCII");
           break;
         default:
           throw new IllegalArgumentException
             ("EnumSet<MsgBoardType>::"+nested.getType());
        }
       params.put(nested.getType(), value);
     }
    EnumSet<MsgBoardType> missing = EnumSet.copyOf(expected);
    missing.removeAll(params.keySet());
    if (!missing.isEmpty())
     {
       throw Catalog.MISSING_NESTED_TLV_3.asPX
         (reqtlv.getType(), reqtlv.getStart(), missing.iterator().next());
     }
    return new MsgBoardRequestImpl
      (retype, null,
       params.get(MsgBoardType.MARKER),
       params.get(MsgBoardType.TICKET),
       params.get(MsgBoardType.TEXT),
       params.get(MsgBoardType.ORIGINATOR)
       );
  }
protected MsgBoardRequest parseGeneric ( MsgBoardRequest . ReqType retype , MsgBoardTLV reqtlv , EnumSet < MsgBoardType > expected ) throws ProtocolException { EnumMap < MsgBoardType , String > params = new EnumMap < > ( MsgBoardType . class ) ; for ( MsgBoardTLV nested = reqtlv . getNestedTLV ( ) ; nested != null ; nested = nested . getNextTLV ( reqtlv . getEnd ( ) ) ) { if ( nested . getEnd ( ) > reqtlv . getEnd ( ) ) throw failOverlongTLV ( nested ) ; if ( ! expected . contains ( nested . getType ( ) ) ) throw failUnexpectedTLV ( nested ) ; if ( params . containsKey ( nested . getType ( ) ) ) throw failDuplicateTLV ( nested ) ; String value = null ; switch ( nested . getType ( ) ) { case TEXT : value = parseStringValue ( nested , "UTF-8" ) ; break ; case ORIGINATOR : case MARKER : case TICKET : value = parseStringValue ( nested , "US-ASCII" ) ; break ; default : throw new IllegalArgumentException ( "EnumSet<MsgBoardType>::" + nested . getType ( ) ) ; } params . put ( nested . getType ( ) , value ) ; } EnumSet < MsgBoardType > missing = EnumSet . copyOf ( expected ) ; missing . removeAll ( params . keySet ( ) ) ; if ( ! missing . isEmpty ( ) ) { throw Catalog . MISSING_NESTED_TLV_3 . asPX ( reqtlv . getType ( ) , reqtlv . getStart ( ) , missing . iterator ( ) . next ( ) ) ; } return new MsgBoardRequestImpl ( retype , null , params . get ( MsgBoardType . MARKER ) , params . get ( MsgBoardType . TICKET ) , params . get ( MsgBoardType . TEXT ) , params . get ( MsgBoardType . ORIGINATOR ) ) ; }
Parses any request with all-mandatory, all-string parameters.
Parses any request with all - mandatory all - string parameters .
// LIMIT is not a string value // TIMESTAMP and MISSED do not appear in requests // can only happen if 'expected' contains an unsupported element // check for absence of a mandatory parameter // several could be missing, just pick one to report...