36 [[nodiscard]]
bool offer(
const std::string& text,
const BYTE* image,
size_t imageSize)
38 const size_t textHash = hash(text);
39 const size_t offerHash = textHash ^ (hash(image, imageSize) << 1);
40 const bool isLastOffer = (offerHash == _offered);
41 const bool isServerText = !imageSize && !text.empty() && (textHash == _received);
42 if (_serverOwns && (isLastOffer || isServerText))
49 void serverAnnounced()
55 void serverSentText(
const std::string& text)
58 _received = hash(text);
61 void serverSentImage()
67 static size_t hash(
const std::string& text)
69 return std::hash<std::string>{}(text);
72 static size_t hash(
const BYTE* data,
size_t size)
74 return std::hash<std::string_view>{}(
75 std::string_view(
reinterpret_cast<const char*
>(data), data ? size : 0));
78 bool _serverOwns =
false;
79 std::optional<size_t> _offered;
80 std::optional<size_t> _received;