send options in Datagram3
Some checks failed
Build Debian packages / bookworm (push) Has been cancelled
Build Debian packages / bullseye (push) Has been cancelled
Build Debian packages / trixie (push) Has been cancelled
Build on FreeBSD / with UPnP (push) Has been cancelled
Build on OSX / With USE_UPNP=no (push) Has been cancelled
Build on OSX / With USE_UPNP=yes (push) Has been cancelled
Build on Windows / clang-x86_64 (push) Has been cancelled
Build on Windows / i686 (push) Has been cancelled
Build on Windows / ucrt-x86_64 (push) Has been cancelled
Build on Windows / x86_64 (push) Has been cancelled
Build on Windows / CMake clang-x86_64 (push) Has been cancelled
Build on Windows / CMake i686 (push) Has been cancelled
Build on Windows / CMake ucrt-x86_64 (push) Has been cancelled
Build on Windows / CMake x86_64 (push) Has been cancelled
Build on Windows / XP (push) Has been cancelled
Build on Ubuntu / Make with USE_UPNP=no (push) Has been cancelled
Build on Ubuntu / Make with USE_UPNP=yes (push) Has been cancelled
Build on Ubuntu / CMake with -DWITH_UPNP=OFF (push) Has been cancelled
Build on Ubuntu / CMake with -DWITH_UPNP=ON (push) Has been cancelled
Build containers / Building container for linux/amd64 (push) Has been cancelled
Build containers / Building container for linux/arm64 (push) Has been cancelled
Build containers / Building container for linux/arm/v7 (push) Has been cancelled
Build containers / Building container for linux/386 (push) Has been cancelled
Build containers / Pushing merged manifest (push) Has been cancelled

This commit is contained in:
orignal 2025-09-30 19:01:12 -04:00
parent dc9cdf941d
commit cd841f7219
4 changed files with 35 additions and 9 deletions

View file

@ -17,6 +17,7 @@
#include <mutex>
#include <thread>
#include <utility>
#include <charconv>
#include <boost/asio.hpp>
#ifdef ANDROID
@ -234,7 +235,7 @@ namespace util
Mapping () = default;
size_t FromBuffer (const uint8_t * buf, size_t len);
size_t FromBuffer (size_t size, const uint8_t * buf, size_t len); //without 2 bytes size
size_t ToBuffer (uint8_t * buf, size_t len);
size_t ToBuffer (uint8_t * buf, size_t len) const;
std::string_view operator[](std::string_view param) const;
bool Insert (std::string_view param, std::string_view value);
@ -244,6 +245,20 @@ namespace util
static std::string_view ExtractString (const uint8_t * buf, size_t len);
static size_t WriteString (std::string_view str, uint8_t * buf, size_t len);
static size_t WriteOption (std::string_view param, std::string_view value, uint8_t * buf, size_t len);
template<typename T>
bool Get(std::string_view param, T& value)
{
auto s = (*this)[param];
if (s.empty ()) return false;
auto res = std::from_chars(s.data(), s.data() + s.size(), value);
return res.ec != std::errc();
}
template<typename T>
bool Put (std::string_view param, T value)
{
return Insert (param, std::to_string (value));
}
private: