wide_column_serialization.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #pragma once
  6. #include <cstdint>
  7. #include <string>
  8. #include "rocksdb/rocksdb_namespace.h"
  9. #include "rocksdb/status.h"
  10. #include "rocksdb/wide_columns.h"
  11. namespace ROCKSDB_NAMESPACE {
  12. class Slice;
  13. // Wide-column serialization/deserialization primitives.
  14. //
  15. // The two main parts of the layout are 1) a sorted index containing the column
  16. // names and column value sizes and 2) the column values themselves. Keeping the
  17. // index and the values separate will enable selectively reading column values
  18. // down the line. Note that currently the index has to be fully parsed in order
  19. // to find out the offset of each column value.
  20. //
  21. // Legend: cn = column name, cv = column value, cns = column name size, cvs =
  22. // column value size.
  23. //
  24. // +----------+--------------+----------+-------+----------+---...
  25. // | version | # of columns | cns 1 | cn 1 | cvs 1 |
  26. // +----------+--------------+------------------+--------- +---...
  27. // | varint32 | varint32 | varint32 | bytes | varint32 |
  28. // +----------+--------------+----------+-------+----------+---...
  29. //
  30. // ... continued ...
  31. //
  32. // ...---+----------+-------+----------+-------+---...---+-------+
  33. // | cns N | cn N | cvs N | cv 1 | | cv N |
  34. // ...---+----------+-------+----------+-------+---...---+-------+
  35. // | varint32 | bytes | varint32 | bytes | | bytes |
  36. // ...---+----------+-------+----------+-------+---...---+-------+
  37. class WideColumnSerialization {
  38. public:
  39. static Status Serialize(const WideColumns& columns, std::string& output);
  40. static Status Deserialize(Slice& input, WideColumns& columns);
  41. static Status GetValueOfDefaultColumn(Slice& input, Slice& value);
  42. static constexpr uint32_t kCurrentVersion = 1;
  43. };
  44. } // namespace ROCKSDB_NAMESPACE