code: protected ByteBuffer calculatePrefixBytes(int payloadLength, byte opCode) {
  
  
          int totalOffset = 2 + WsUtils.calculateEncodedLengthSize(payloadLength);
  
          ByteBuffer binary = ByteBuffer.allocate(totalOffset);
          binary.put(opCode);
          WsUtils.encodeLength(binary, payloadLength);
  
          //the only possible escaped byte in prefix bytes is the last byte
  
          switch(binary.get(binary.position() - 1)) {
              case 0x00:
                  binary.put(binary.position() - 1,(byte) 0x7f);
                  binary.put((byte) 0x30);
              break;
              case 0x0a:
                  binary.put(binary.position() - 1,(byte) 0x7f);
                  binary.put((byte) 0x6e);
              break;
              case 0x0d:
                  binary.put(binary.position() - 1,(byte) 0x7f);
                  binary.put((byte) 0x72);
              break;
              case 0x7f:
                  binary.put(binary.position() - 1,(byte) 0x7f);
                  binary.put((byte) 0x7f);
              break;
          }
          binary.flip();
          return binary;
  
      }
docs: quick calculate WsebFrame prefix bytes