eckit icon indicating copy to clipboard operation
eckit copied to clipboard

Add offset method to URI?

Open ChrisspyB opened this issue 1 year ago • 1 comments

Would be nice to be able to have an offset method in the URI class, such that:

eckit::Offset o = uri.offset().

Ideally this would be implemented by storing offset as a member (as we do with host and port) with a sensible default (0).

From my understanding, offsets are normally encoded in the "fragment". This means they have to be extracted on the client code via a function like

eckit::Offset getOffset(const eckit::URI& uri) {
        const std::string& fragment = uri.fragment();
        eckit::Offset offset;
        try {
            offset = std::stoll(fragment);
        } catch (std::invalid_argument& e) {
            throw eckit::BadValue("Invalid offset: '" + fragment + "' in URI: " + uri.asString(), Here());
        }
        return offset;
    }

which imo isn't very nice.

ChrisspyB avatar Nov 26 '24 11:11 ChrisspyB

The challenge for this, in terms of implementing it on the URI class, is that offset() is not a standardised part of the URI spec. Whereas host/port is.

simondsmart avatar Nov 26 '24 11:11 simondsmart