Given a path (string or Path object) to a GTFSR feed file,
    return the corresponding GTFS feed (FeedMessage instance).
    If ``from_json``, then assume the feed file is in JSON format;
    otherwise, assume the feed file is in Protocol Buffer format.

def read_gtfsr(path, *, from_json=False):
    """
    Given a path (string or Path object) to a GTFSR feed file,
    return the corresponding GTFS feed (FeedMessage instance).
    If ``from_json``, then assume the feed file is in JSON format;
    otherwise, assume the feed file is in Protocol Buffer format.
    """
    path = Path(path)
    feed = gtfs_realtime_pb2.FeedMessage()

    with path.open('rb') as src:
        if from_json:
            feed = json_format.Parse(src.read(), feed)
        else:
            feed.ParseFromString(src.read())

    return feed