src/main/java/pityoulish/sockets/server/TLVResponseBuilderImpl.java
protected void appendMessage(MsgBoardTLV parent, Message msg)
  {
    if (parent == null)
       throw new NullPointerException("MsgBoardTLV");
    if (msg == null)
       throw new NullPointerException("Message");

    MsgBoardTLV msgtlv = parent.appendTLV(MsgBoardType.MESSAGE);

    // The binary protocol doesn't specify the order in which to append
    // the three elements of a message. Just for the heck of it, randomize.

    MsgBoardType[] order = new MsgBoardType[]{
      MsgBoardType.ORIGINATOR, MsgBoardType.TIMESTAMP, MsgBoardType.TEXT
    };
    // determine which element to put first... three choices
    int first = ThreadLocalRandom.current().nextInt(3);
    if (first > 0)
     {
       MsgBoardType mbt = order[0];
       order[0] = order[first];
       order[first] = mbt;
     }
    // determine which element to put next... two choices
    if (ThreadLocalRandom.current().nextInt(2) > 0)
     {
       MsgBoardType mbt = order[1];
       order[1] = order[2];
       order[2] = mbt;
     }


    for (MsgBoardType mbt: order)
     {
       switch (mbt)
        {
         case ORIGINATOR:
           appendString(msgtlv, mbt, msg.getOriginator(), false);
           break;

         case TIMESTAMP:
           appendString(msgtlv, mbt, msg.getTimestamp(), false);
           break;

         case TEXT:
           appendString(msgtlv, mbt, msg.getText(), true);
           break;
        }
     }

    parent.addToLength(msgtlv.getSize());
  }
/**
   * Appends a TLV-encoded message to the content of a TLV.
   *
   * @param parent      the TLV to append to
   * @param msg         the message to append
   */
Appends a TLV-encoded message to the content of a TLV.
@param parent      the TLV to append to
@param msg         the message to append
Appends a TLV - encoded message to the content of a TLV . @param parent the TLV to append to @param msg the message to append
protected void appendMessage(MsgBoardTLV parent, Message msg)
  {
    if (parent == null)
       throw new NullPointerException("MsgBoardTLV");
    if (msg == null)
       throw new NullPointerException("Message");
    MsgBoardTLV msgtlv = parent.appendTLV(MsgBoardType.MESSAGE);
    MsgBoardType[] order = new MsgBoardType[]{
      MsgBoardType.ORIGINATOR, MsgBoardType.TIMESTAMP, MsgBoardType.TEXT
    };
    int first = ThreadLocalRandom.current().nextInt(3);
    if (first > 0)
     {
       MsgBoardType mbt = order[0];
       order[0] = order[first];
       order[first] = mbt;
     }
    if (ThreadLocalRandom.current().nextInt(2) > 0)
     {
       MsgBoardType mbt = order[1];
       order[1] = order[2];
       order[2] = mbt;
     }
    for (MsgBoardType mbt: order)
     {
       switch (mbt)
        {
         case ORIGINATOR:
           appendString(msgtlv, mbt, msg.getOriginator(), false);
           break;
         case TIMESTAMP:
           appendString(msgtlv, mbt, msg.getTimestamp(), false);
           break;
         case TEXT:
           appendString(msgtlv, mbt, msg.getText(), true);
           break;
        }
     }
    parent.addToLength(msgtlv.getSize());
  }
protected void appendMessage ( MsgBoardTLV parent , Message msg ) { if ( parent == null ) throw new NullPointerException ( "MsgBoardTLV" ) ; if ( msg == null ) throw new NullPointerException ( "Message" ) ; MsgBoardTLV msgtlv = parent . appendTLV ( MsgBoardType . MESSAGE ) ; MsgBoardType [ ] order = new MsgBoardType [ ] { MsgBoardType . ORIGINATOR , MsgBoardType . TIMESTAMP , MsgBoardType . TEXT } ; int first = ThreadLocalRandom . current ( ) . nextInt ( 3 ) ; if ( first > 0 ) { MsgBoardType mbt = order [ 0 ] ; order [ 0 ] = order [ first ] ; order [ first ] = mbt ; } if ( ThreadLocalRandom . current ( ) . nextInt ( 2 ) > 0 ) { MsgBoardType mbt = order [ 1 ] ; order [ 1 ] = order [ 2 ] ; order [ 2 ] = mbt ; } for ( MsgBoardType mbt : order ) { switch ( mbt ) { case ORIGINATOR : appendString ( msgtlv , mbt , msg . getOriginator ( ) , false ) ; break ; case TIMESTAMP : appendString ( msgtlv , mbt , msg . getTimestamp ( ) , false ) ; break ; case TEXT : appendString ( msgtlv , mbt , msg . getText ( ) , true ) ; break ; } } parent . addToLength ( msgtlv . getSize ( ) ) ; }
Appends a TLV-encoded message to the content of a TLV.
Appends a TLV - encoded message to the content of a TLV .
// The binary protocol doesn't specify the order in which to append // the three elements of a message. Just for the heck of it, randomize. // determine which element to put first... three choices // determine which element to put next... two choices