wide_columns_helper.cc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright (c) Meta Platforms, Inc. and affiliates.
  2. // This source code is licensed under both the GPLv2 (found in the
  3. // COPYING file in the root directory) and Apache 2.0 License
  4. // (found in the LICENSE.Apache file in the root directory).
  5. #include "db/wide/wide_columns_helper.h"
  6. #include <ios>
  7. #include "db/wide/wide_column_serialization.h"
  8. namespace ROCKSDB_NAMESPACE {
  9. void WideColumnsHelper::DumpWideColumns(const WideColumns& columns,
  10. std::ostream& os, bool hex) {
  11. if (columns.empty()) {
  12. return;
  13. }
  14. const std::ios_base::fmtflags orig_flags = os.flags();
  15. if (hex) {
  16. os << std::hex;
  17. }
  18. auto it = columns.begin();
  19. os << *it;
  20. for (++it; it != columns.end(); ++it) {
  21. os << ' ' << *it;
  22. }
  23. os.flags(orig_flags);
  24. }
  25. Status WideColumnsHelper::DumpSliceAsWideColumns(const Slice& value,
  26. std::ostream& os, bool hex) {
  27. WideColumns columns;
  28. Slice value_copy = value;
  29. const Status s = WideColumnSerialization::Deserialize(value_copy, columns);
  30. if (s.ok()) {
  31. DumpWideColumns(columns, os, hex);
  32. }
  33. return s;
  34. }
  35. } // namespace ROCKSDB_NAMESPACE