code: public static IoBufferEx doEncode(IoBufferAllocatorEx<?> allocator, int flags, WsMessage message, int maskValue) {
          final boolean mask = true;
  
          IoBufferEx ioBuf = getBytes(allocator, flags, message);
          ByteBuffer buf = ioBuf.buf();
  
      	boolean fin = message.isFin();
  
      	int remaining = buf.remaining();
  
      	int offset = 2 + (mask ? 4 : 0) + calculateLengthSize(remaining);
      		ByteBuffer b = allocator.allocate(offset + remaining, flags);
  
  		int start = b.position();
  
  		byte b1 = (byte) (fin ? 0x80 : 0x00);
  		byte b2 = (byte) (mask ? 0x80 : 0x00);
  
  		b1 = doEncodeOpcode(b1, message);
  		b2 |= lenBits(remaining);
  
  		b.put(b1).put(b2);
  
  		doEncodeLength(b, remaining);
  
  		if (mask) {
  			b.putInt(maskValue);
  		}
  
  		if ( mask ) {
              WsFrameUtils.xor(buf, b, maskValue);
          }
              // reset buffer position after write in case of reuse
              // (KG-8125) if shared, duplicate to ensure we don't affect other threads
              if (ioBuf.isShared()) {
                  b.put(buf.duplicate());
              }
              else {
                  int bufPos = buf.position();
                  b.put(buf);
                  buf.position(bufPos);
              }
              b.limit(b.position());
              b.position(start);
      		return allocator.wrap(b, flags);
  	}
docs: Encode WebSocket message as a single frame, with the provided masking value applied.