code: public void generateWholeFrame(Frame frame, ByteBuffer buf) {
          buf.put(generateHeaderBytes(frame));
          if (frame.hasPayload()) {
              if (readOnly) {
                  buf.put(frame.getPayload().slice());
              } else {
                  buf.put(frame.getPayload());
              }
          }
      }
docs: Generate the whole frame (header + payload copy) into a single ByteBuffer.
  <p>
  Note: This is slow, moves lots of memory around. Only use this if you must (such as in unit testing).
  
  @param frame the frame to generate
  @param buf   the buffer to output the generated frame to