import hashlib


def r_pb_fs(file_path, read_pb_class):
    """
    Utility function to read pb from disk and return
      the xxxRecord that wraps the pb.  Checks hash if present

    Args:
        file_path (str):
        read_pb_class:

    Returns:
        instance of read_pb_class

    """
    with open(file_path, 'rb') as f:
        contents = f.read()
        pb_record = read_pb_class.from_str_bytes(contents)

    old_hash = pb_record.pb.hash
    pb_record.pb.ClearField('hash')
    new_hash = hashlib.md5(pb_record.pb.SerializeToString()).hexdigest()

    assert(old_hash == new_hash)
    pb_record.pb.hash = old_hash

    return pb_record