import warnings


def _encode_link_field(value):
    """
    Encode the field of a `RiakObject.links` entry as bytes if necessary.
    """
    if isinstance(value, bytes):
        warnings.warn(
            "Passing `RiakObject.links` fields as bytes is deprecated "
            "and may be removed in a future release. Pass the fields as "
            "strings instead.",
            category=DeprecationWarning
        )
        return value

    return value.encode()