diff options
author | Michael Lutz <michi@icosahedron.de> | 2021-10-28 23:48:26 +0200 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2021-12-16 22:28:32 +0100 |
commit | a05fd7aa50ecbee425df2d6f9015ec3ea359232f (patch) | |
tree | 9b9208d39813670789635b638592a903a2aafaa4 /src/string.cpp | |
parent | b0990fcff7358e839468e5cf811ffddc8b9d73e2 (diff) | |
download | openttd-a05fd7aa50ecbee425df2d6f9015ec3ea359232f.tar.xz |
Change: [Network] Transfer command data as serialized byte stream without fixed structure.
The data will be transmitted as the length followed by the serialized data. This allows the command
data to be different for every command type in the future.
Diffstat (limited to 'src/string.cpp')
-rw-r--r-- | src/string.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/string.cpp b/src/string.cpp index d027cb7bf..aeac4fe84 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -19,6 +19,7 @@ #include <stdarg.h> #include <ctype.h> /* required for tolower() */ #include <sstream> +#include <iomanip> #ifdef _MSC_VER #include <errno.h> // required by vsnprintf implementation for MSVC @@ -161,6 +162,23 @@ char *CDECL str_fmt(const char *str, ...) } /** + * Format a byte array into a continuous hex string. + * @param data Array to format + * @return Converted string. + */ +std::string FormatArrayAsHex(span<const byte> data) +{ + std::ostringstream ss; + ss << std::uppercase << std::setfill('0') << std::setw(2) << std::hex; + + for (auto b : data) { + ss << b; + } + + return ss.str(); +} + +/** * Scan the string for old values of SCC_ENCODED and fix it to * it's new, static value. * @param str the string to scan |