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 11 #ifndef LOGGING_RTC_EVENT_LOG_ENCODER_DELTA_ENCODING_H_ 12 #define LOGGING_RTC_EVENT_LOG_ENCODER_DELTA_ENCODING_H_ 13 14 #include <stddef.h> 15 #include <stdint.h> 16 17 #include <string> 18 #include <vector> 19 20 #include "absl/strings/string_view.h" 21 #include "absl/types/optional.h" 22 23 namespace webrtc { 24 25 // Encode `values` as a sequence of deltas following on `base` and return it. 26 // If all of the values were equal to the base, an empty string will be 27 // returned; this is a valid encoding of that edge case. 28 // `base` is not guaranteed to be written into `output`, and must therefore 29 // be provided separately to the decoder. 30 // This function never fails. 31 // TODO(eladalon): Split into optional and non-optional variants (efficiency). 32 std::string EncodeDeltas(absl::optional<uint64_t> base, 33 const std::vector<absl::optional<uint64_t>>& values); 34 35 // EncodeDeltas() and DecodeDeltas() are inverse operations; 36 // invoking DecodeDeltas() over the output of EncodeDeltas(), will return 37 // the input originally given to EncodeDeltas(). 38 // `num_of_deltas` must be greater than zero. If input is not a valid encoding 39 // of `num_of_deltas` elements based on `base`, the function returns an empty 40 // vector, which signals an error. 41 // TODO(eladalon): Split into optional and non-optional variants (efficiency). 42 std::vector<absl::optional<uint64_t>> DecodeDeltas( 43 absl::string_view input, 44 absl::optional<uint64_t> base, 45 size_t num_of_deltas); 46 47 } // namespace webrtc 48 49 #endif // LOGGING_RTC_EVENT_LOG_ENCODER_DELTA_ENCODING_H_ 50