|
2 | 2 |
|
3 | 3 | #include <string> |
4 | 4 | #include <cstring> |
| 5 | +#include <regex> |
5 | 6 |
|
6 | 7 | #include <simple_lib/common.h> |
7 | 8 |
|
8 | 9 | namespace simpleApp |
9 | 10 | { |
10 | | - size_t proceedMsg(uint8_t* in, size_t len, uint8_t* out) |
| 11 | + int proceedMsg(char* in, size_t len, char* out) |
11 | 12 | { |
12 | | - // TODO replace this with required logic |
13 | | - const msg_headers buffHeader = msg_headers::server_msg; |
14 | | - const char* msg = "DELIVERED"; |
15 | | - const size_t size = sizeof("DELIVERED"); |
| 13 | + auto msgReceived = std::string(in, len); |
| 14 | + bool isFound = false; |
| 15 | + unsigned long value = 0; |
16 | 16 |
|
17 | | - |
18 | | - std::memcpy(out, &buffHeader, sizeof(buffHeader)); |
19 | | - std::memcpy(out + static_cast<ptrdiff_t>(sizeof(buffHeader)), msg, size); |
| 17 | + const std::regex r("[0123456789]+"); |
20 | 18 |
|
21 | | - return sizeof(buffHeader) + size; |
| 19 | + for (std::sregex_iterator it = std::sregex_iterator(msgReceived.begin(), msgReceived.end(), r); |
| 20 | + it != std::sregex_iterator(); it++) |
| 21 | + { |
| 22 | + isFound = true; |
| 23 | + std::smatch match; |
| 24 | + match = *it; |
| 25 | + value += std::stoi(match.str()); |
| 26 | + } |
| 27 | + if (isFound) |
| 28 | + { |
| 29 | + auto line = std::to_string(value); |
| 30 | + std::memcpy(out, line.c_str(), line.size()); |
| 31 | + return line.size(); |
| 32 | + } |
| 33 | + else |
| 34 | + { |
| 35 | + std::memcpy(out, in, len); |
| 36 | + return len; |
| 37 | + } |
22 | 38 | } |
23 | 39 | } |
0 commit comments