delta_encoding.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef LOGGING_RTC_EVENT_LOG_ENCODER_DELTA_ENCODING_H_
  11. #define LOGGING_RTC_EVENT_LOG_ENCODER_DELTA_ENCODING_H_
  12. #include <stddef.h>
  13. #include <stdint.h>
  14. #include <string>
  15. #include <vector>
  16. #include "absl/types/optional.h"
  17. namespace webrtc {
  18. // Encode |values| as a sequence of deltas following on |base| and return it.
  19. // If all of the values were equal to the base, an empty string will be
  20. // returned; this is a valid encoding of that edge case.
  21. // |base| is not guaranteed to be written into |output|, and must therefore
  22. // be provided separately to the decoder.
  23. // This function never fails.
  24. // TODO(eladalon): Split into optional and non-optional variants (efficiency).
  25. std::string EncodeDeltas(absl::optional<uint64_t> base,
  26. const std::vector<absl::optional<uint64_t>>& values);
  27. // EncodeDeltas() and DecodeDeltas() are inverse operations;
  28. // invoking DecodeDeltas() over the output of EncodeDeltas(), will return
  29. // the input originally given to EncodeDeltas().
  30. // |num_of_deltas| must be greater than zero. If input is not a valid encoding
  31. // of |num_of_deltas| elements based on |base|, the function returns an empty
  32. // vector, which signals an error.
  33. // TODO(eladalon): Split into optional and non-optional variants (efficiency).
  34. std::vector<absl::optional<uint64_t>> DecodeDeltas(
  35. const std::string& input,
  36. absl::optional<uint64_t> base,
  37. size_t num_of_deltas);
  38. } // namespace webrtc
  39. #endif // LOGGING_RTC_EVENT_LOG_ENCODER_DELTA_ENCODING_H_