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