Encodes a Variant value to a byte array. Encoding objects is allowed (and can potentially include executable code). Deserialization can be done with [method bytes_to_var_with_objects].
Note: Encoding Callable is not supported and will result in an empty value, regardless of the data.