docs: private final DataSlice encodePayloadPartToSlice(JsMsgPart jsPart, CommsConnection conn) throws MessageEncodeFailedException {
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "encodePayloadPartToSlice", new Object[]{jsPart, conn});
  
      boolean beans = false;
      DataSlice slice = null;
  
      // For a payload which isn't Beans, we also hope that it is already encoded so we can
      // just get it from JMF. A Beans payload part always needs re-encoding as it may
      // be in SOAP where JMF is required, or vice versa.
      // Figuring it out is a bit messy:
      //    - if this is a payload part, the message must be a JsMessage
      //    - the ProducerType will be API for a Beans message, whether or not it is wrapped by JMS
      //    - but we'll still have to look at the format field to see if is Beans
      if (  (((JsMessage)theMessage).getProducerType() != ProducerType.API)
         || payloadPart.getField(JsPayloadAccess.FORMAT) == null // XMS might not set the format
         || !(((String)payloadPart.getField(JsPayloadAccess.FORMAT)).startsWith("Bean:"))
         ) {
        slice = ((JMFMessage)jsPart.jmfPart).getAssembledContent();
      }
  
      // If it is beans, leave slice == null and set a flag.
      else {
        beans = true;
      }
  
      // If we haven't already got some existing content, we have to encode it now.
      if (slice == null) {
  
        // We need to put the whole lot in a try/finally block to ensure we clear the
        // thread local data even if something goes wrong.
        try {
  
          // We need to ensure noone updates any vital aspects of the message part
          // during the call to encodePart()                                 d364050
          // In the case of a Beans payload, we also need to ensure no-one else
          // encodes the message after we unassemble it & before we encode it.
          synchronized (getPartLockArtefact(jsPart)) {
  
            // If we have a Beans message payload, so we need to set the
            // thread's partner level from the value in the CommsConnection, if present,
            // and unassemble the payload data to ensure that it does get re-encoded in the next step.
            if (beans) {
  
              // Set the thread's partner level from the value in the Connection MetaData, if present
              if (conn != null) MfpThreadDataImpl.setPartnerLevel(conn.getMetaData().getProtocolVersion());
  
              try {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "unassembling Beans message");
                ((JMFNativePart)jsPart.getField(JsPayloadAccess.PAYLOAD_DATA)).unassemble();
              }
              catch (JMFException e) {
                // This shouldn't be possible. If we get an Exception something disastrous
                // must have happened so FFDC it & throw it on wrappered.
                // Dump the message part to give us some clue what's going on.
                FFDCFilter.processException(e, "com.ibm.ws.sib.mfp.impl.JsMsgObject.encodePayloadPartToSlice", "jmo620", this,
                      new Object[] { MfpConstants.DM_MESSAGE, jsPart.jmfPart, theMessage }
                );
  
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "encodePayloadPartToSlice unassemble failed: " + e);
                throw new MessageEncodeFailedException(e);
              }
            }
  
            // Whatever sort of message we have, we now need to encode it.
            byte[] buff = encodePart(jsPart);
            slice = new DataSlice(buff, 0, buff.length);
  
          } // end of synchronized block
  
        }
        // We must ALWAYS reset the thread local partnerLevel once a payload encode
        // is no longer in progress, otherwise a future flatten on this thread could
        // encode to the wrong level.
        // (It doesn't matter if we didn't actually set it earlier - clearing it is harmless)
        finally {
          MfpThreadDataImpl.clearPartnerLevel();
        }
  
      }
  
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "encodePayloadPartToSlice", slice);
      return slice;
    }