tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

delta_encoding.h (2019B)


      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 <optional>
     18 #include <string>
     19 #include <vector>
     20 
     21 #include "absl/strings/string_view.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(std::optional<uint64_t> base,
     33                         const std::vector<std::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<std::optional<uint64_t>> DecodeDeltas(absl::string_view input,
     43                                                  std::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_