Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add offset method to URI? #153

Open
ChrisspyB opened this issue Nov 26, 2024 · 1 comment
Open

Add offset method to URI? #153

ChrisspyB opened this issue Nov 26, 2024 · 1 comment

Comments

@ChrisspyB
Copy link
Member

ChrisspyB commented Nov 26, 2024

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.

@simondsmart
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants