def load_protobuf(file, pb_cls):
    """
    Instantiates protobuf object and loads data from file into object.
    :param file: file containing serialized protobuf contents
    :param pb_cls: class from generated client
    :return: instance of pb_cls
    """
    obj = pb_cls()
    if hasattr(file, "read"):
        contents = file.read()
    else:
        with open(file, "rb") as f:
            contents = f.read()
    obj.ParseFromString(contents)
    return obj