/* * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ #ifndef LOGGING_RTC_EVENT_LOG_EVENTS_RTC_EVENT_FIELD_ENCODING_H_ #define LOGGING_RTC_EVENT_LOG_EVENTS_RTC_EVENT_FIELD_ENCODING_H_ #include <cstddef> #include <cstdint> #include <string> #include <type_traits> #include <vector> #include "absl/strings/string_view.h" #include "absl/types/optional.h" #include "api/array_view.h" #include "api/rtc_event_log/rtc_event.h" #include "logging/rtc_event_log/events/fixed_length_encoding_parameters_v3.h" #include "logging/rtc_event_log/events/rtc_event_field_extraction.h" #include "rtc_base/checks.h" namespace webrtc { // To maintain backwards compatibility with past (or future) logs, // the constants in this enum must not be changed. // New field types with numerical IDs 5-7 can be added, but old // parsers will fail to parse events containing the new fields. enum class FieldType : uint8_t { … }; // EventParameters map an event name to a numerical ID. struct EventParameters { … }; // FieldParameters define the encoding for a field. struct FieldParameters { … }; // The EventEncoder is used to encode a batch of events. class EventEncoder { … }; std::string EncodeSingleValue(uint64_t value, FieldType field_type); std::string EncodeDeltasV3(FixedLengthEncodingParametersV3 params, uint64_t base, rtc::ArrayView<const uint64_t> values); // Given a batch of RtcEvents and a member pointer, extract that // member from each event in the batch. Signed integer members are // encoded as unsigned, and the bitsize increased so the result can // represented as a std::vector<uint64_t>. // This is intended to be used in conjuction with // EventEncoder::EncodeField to encode a batch of events as follows: // auto values = ExtractRtcEventMember(batch, RtcEventFoo::timestamp_ms); // encoder.EncodeField(timestamp_params, values) template <typename T, typename E, std::enable_if_t<std::is_integral<T>::value, bool> = true> std::vector<uint64_t> ExtractRtcEventMember( rtc::ArrayView<const RtcEvent*> batch, const T E::*member) { … } // Extract an optional field from a batch of RtcEvents. // The function returns a vector of positions in addition to the vector of // values. The vector `positions` has the same length as the batch where // `positions[i] == true` iff the batch[i]->member has a value. // The values vector only contains the values that exists, so it // may be shorter than the batch. template <typename T, typename E, std::enable_if_t<std::is_integral<T>::value, bool> = true> ValuesWithPositions ExtractRtcEventMember(rtc::ArrayView<const RtcEvent*> batch, const absl::optional<T> E::*member) { … } // Extract an enum field from a batch of RtcEvents. // Requires specializing RtcEventLogEnum<T> for the enum type T. template <typename T, typename E, std::enable_if_t<std::is_enum<T>::value, bool> = true> std::vector<uint64_t> ExtractRtcEventMember( rtc::ArrayView<const RtcEvent*> batch, const T E::*member) { … } // Extract a string field from a batch of RtcEvents. template <typename E> std::vector<absl::string_view> ExtractRtcEventMember( rtc::ArrayView<const RtcEvent*> batch, const std::string E::*member) { … } } // namespace webrtc #endif // LOGGING_RTC_EVENT_LOG_EVENTS_RTC_EVENT_FIELD_ENCODING_H_