def METHOD_NAME(
    avro_encoder: "AvroObjectEncoder",
    content: Mapping[str, Any],
    raw_input_schema: str,
    schema_id: str,
    message_type: Optional[Type[MessageType]] = None,
    **kwargs: Any,
) -> Union[MessageType, MessageContent]:
    content_type = f"{AVRO_MIME_TYPE}+{schema_id}"
    try:
        content_bytes = avro_encoder.encode(content, raw_input_schema)
    except Exception as exc:  # pylint:disable=broad-except
        raise InvalidContentError(
            f"Cannot encode value '{content}' for the following schema with schema ID {schema_id}:"
            f"{raw_input_schema}",
            details={"schema_id": f"{schema_id}"},
        ) from exc
    stream = BytesIO()
    stream.write(content_bytes)
    stream.flush()
    payload = stream.getvalue()
    stream.close()
    if message_type:
        try:
            return cast(
                MessageType,
                message_type.from_message_content(payload, content_type, **kwargs),
            )
        except AttributeError as exc:
            raise TypeError(
                f"""Cannot set content and content type on model object. The content model
                    {str(message_type)} must be a subtype of the MessageType protocol.
                    If using an Azure SDK model class, please check the README.md for the full list
                    of supported Azure SDK models and their corresponding versions.""",
                {"content": payload, "content_type": content_type},
            ) from exc
    return MessageContent({"content": payload, "content_type": content_type})