// TJP COPYRIGHT HEADER #pragma once #include #include #include namespace tjp::core::internet { using DataBlock = Vector; using DataView = StringView; struct Data { mutable Optional block; mutable Optional string; Data() {} Data(DataBlock &&block_) : block(std::move(block_)) {} Data(String &&string_) : string(std::move(string_)) {} operator String &() const { if (!string.has_value()) { if (block.has_value()) string = String(block->data(), block->size()); else string = String(); } return *string; } operator DataView () const { if (block.has_value()) return StringView(block->data(), block->size()); if (string.has_value()) return *string; return {}; } ; const char *data() const { DataView view = *this; return view.data(); } const char *c_str() const { String &view = *this; return view.c_str(); } const auto size() const { DataView view = *this; return view.size(); } }; } // namespace