from typing import Dict
from typing import Any
import json


def _serialize_content_with_header(content: Dict[str, Any]) -> bytes:
  """Writes serialized LSP message that includes a header and content."""
  serialized_content = json.dumps(content).encode("utf-8")
  # Each header parameter is terminated by \r\n, and the header itself is also
  # terminated by \r\n.
  header = (f"Content-Length: {len(serialized_content)}\r\n"
            "Content-Type: application/vscode-jsonrpc;charset=utf-8\r\n"
            "\r\n")
  return header.encode("utf-8") + serialized_content