VLink  2.0.0
A high-performance communication middleware
url_parser.h File Reference

Strict subset of an RFC 3986 URL parser used by the VLink transport layer. More...

#include <cstdint>
#include <map>
#include <string>
#include "../base/macros.h"
Include dependency graph for url_parser.h:

Go to the source code of this file.

Classes

class  vlink::UrlParser
 Immutable URL decomposition used by the VLink transport router. More...
 

Namespaces

 

Detailed Description

Strict subset of an RFC 3986 URL parser used by the VLink transport layer.

This is an internal implementation header used by Protocol and the URL-driven transport routing path; application code does not interact with it directly. UrlParser decomposes a VLink topic URL into the parts that Url needs to select a transport Conf and to configure the resulting NodeImpl. Typical inputs look like:

dds://my_domain/vehicle/speed?domain=1&qos=best_effort
intra://my_topic
someip://127.0.0.1:30490/my_service?instance_id=1
URL grammar
Component Example Description
transport dds URI scheme / VLink transport prefix before ://
content //host/path Full content portion after the scheme separator
username user Optional credential before host
password pass Optional credential after :
host 127.0.0.1 Hostname or IP address
port 30490 TCP / UDP port number
path vehicle/speed Topic path; leading slash stored separately
query domain=1&qos=... Raw query string after ?
fragment section1 Fragment identifier after #
Parser outputs
Accessor Resulting type
get_transport() const const std::string&
get_category() const Category
get_content() const const std::string& (non-hierarchical)
get_username() const const std::string& (hierarchical)
get_password() const const std::string& (hierarchical)
get_host() const const std::string& (hierarchical)
get_port() const int64_t (hierarchical)
get_path() const const std::string& (hierarchical)
get_query() const const std::string&
get_query_dictionary() const const std::map<std::string,std::string>&
get_fragment() const const std::string&
to_string() const std::string (reconstructed URL)
Query dictionary
The raw query string is split into a std::map<std::string,std::string> using either & (default) or ; as the key/value pair separator. Each token is split on the first = character; keys without a value become empty strings.
Category
  • kHierarchical: standard scheme://authority/path?query::fragment URL.
  • kNonHierarchical: opaque scheme:content form (e.g. mailto:user(at)host).
Example
vlink::UrlParser parser("dds://10.0.0.1:7400/cars/1?qos=best_effort#stats");
parser.get_transport(); // "dds"
parser.get_host(); // "10.0.0.1"
parser.get_port(); // 7400
parser.get_path(); // "cars/1"
parser.get_query_dictionary(); // {"qos" -> "best_effort"}
parser.get_fragment(); // "stats"
Note
UrlParser is a value type; parsing happens once during construction and accessors return references valid for the lifetime of the object.