'Converts a v4 Key to a v3 Reference.
Args:
v4_key: an entity_v4_pb.Key
v3_ref: an entity_pb.Reference to populate'

def v4_to_v3_reference(self, v4_key, v3_ref):

    v3_ref.Clear()
    if v4_key.has_partition_id():
        if v4_key.partition_id().has_dataset_id():
            v3_ref.set_app(v4_key.partition_id().dataset_id())
        if v4_key.partition_id().has_namespace():
            v3_ref.set_name_space(v4_key.partition_id().namespace())
    for v4_element in v4_key.path_element_list():
        v3_element = v3_ref.mutable_path().add_element()
        v3_element.set_type(v4_element.kind())
        if v4_element.has_id():
            v3_element.set_id(v4_element.id())
        if v4_element.has_name():
            v3_element.set_name(v4_element.name())
