secondary_index_helper.h 950 B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright (c) Meta Platforms, Inc. and affiliates.
  2. //
  3. // This source code is licensed under both the GPLv2 (found in the
  4. // COPYING file in the root directory) and Apache 2.0 License
  5. // (found in the LICENSE.Apache file in the root directory).
  6. #pragma once
  7. #include <string>
  8. #include <variant>
  9. #include "rocksdb/rocksdb_namespace.h"
  10. #include "rocksdb/slice.h"
  11. #include "util/overload.h"
  12. namespace ROCKSDB_NAMESPACE {
  13. class SecondaryIndexHelper {
  14. public:
  15. static Slice AsSlice(const std::variant<Slice, std::string>& var) {
  16. return std::visit([](const auto& value) -> Slice { return value; }, var);
  17. }
  18. static std::string AsString(const std::variant<Slice, std::string>& var) {
  19. return std::visit(
  20. overload{
  21. [](const Slice& value) -> std::string { return value.ToString(); },
  22. [](const std::string& value) -> std::string { return value; }},
  23. var);
  24. }
  25. };
  26. } // namespace ROCKSDB_NAMESPACE