Permit strings, tokens, and byte sequences to be moved out of Items So that they can be used without copies. PiperOrigin-RevId: 482804429
diff --git a/quiche/common/structured_headers.h b/quiche/common/structured_headers.h index 9d94e90..8e0520b 100644 --- a/quiche/common/structured_headers.h +++ b/quiche/common/structured_headers.h
@@ -9,6 +9,7 @@ #include <map> #include <string> #include <tuple> +#include <utility> #include <vector> #include "absl/strings/string_view.h" @@ -119,6 +120,20 @@ return *value; } + // Transfers ownership of the underlying String, Token, or Byte Sequence. + std::string TakeString() && { + struct Visitor { + std::string* operator()(absl::monostate&) { return nullptr; } + std::string* operator()(int64_t&) { return nullptr; } + std::string* operator()(double&) { return nullptr; } + std::string* operator()(std::string& value) { return &value; } + std::string* operator()(bool&) { return nullptr; } + }; + std::string* value = absl::visit(Visitor(), value_); + QUICHE_CHECK(value); + return std::move(*value); + } + ItemType Type() const { return static_cast<ItemType>(value_.index()); } private: