MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ parse_port()

std::optional< uint16_t > MayaFlux::Transitive::Protocol::parse_port ( std::string_view text)
nodiscardconstexprnoexcept

Read a port number, 1 to 65535.

Digits only, with no sign, no spaces and no leading or trailing text. Zero is refused, since it means "any port" to the system and names nothing to connect to.

Parameters
textCandidate text.
Returns
The port, or nothing when the text is not one.

Definition at line 27 of file HostPort.hpp.

28{
29 if (text.empty() || text.size() > 5) {
30 return std::nullopt;
31 }
32
33 uint32_t value = 0;
34 for (const char c : text) {
35 if (c < '0' || c > '9') {
36 return std::nullopt;
37 }
38 value = value * 10U + static_cast<uint32_t>(c - '0');
39 }
40
41 if (value == 0 || value > 65535U) {
42 return std::nullopt;
43 }
44 return static_cast<uint16_t>(value);
45}

Referenced by MayaFlux::choose_endpoint(), and parse_host_port().

Here is the caller graph for this function: