1 /*
2 * Copyright (c) 2021 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 #include "logging/rtc_event_log/events/rtc_event_end_log.h"
12
13 #include "absl/strings/string_view.h"
14
15 namespace webrtc {
16 constexpr RtcEvent::Type RtcEventEndLog::kType;
17 constexpr EventParameters RtcEventEndLog::event_params_;
18
RtcEventEndLog(Timestamp timestamp)19 RtcEventEndLog::RtcEventEndLog(Timestamp timestamp)
20 : RtcEvent(timestamp.us()) {}
21
RtcEventEndLog(const RtcEventEndLog & other)22 RtcEventEndLog::RtcEventEndLog(const RtcEventEndLog& other)
23 : RtcEvent(other.timestamp_us_) {}
24
25 RtcEventEndLog::~RtcEventEndLog() = default;
26
Encode(rtc::ArrayView<const RtcEvent * > batch)27 std::string RtcEventEndLog::Encode(rtc::ArrayView<const RtcEvent*> batch) {
28 EventEncoder encoder(event_params_, batch);
29 return encoder.AsString();
30 }
31
Parse(absl::string_view encoded_bytes,bool batched,std::vector<LoggedStopEvent> & output)32 RtcEventLogParseStatus RtcEventEndLog::Parse(
33 absl::string_view encoded_bytes,
34 bool batched,
35 std::vector<LoggedStopEvent>& output) {
36 EventParser parser;
37 auto status = parser.Initialize(encoded_bytes, batched);
38 if (!status.ok())
39 return status;
40
41 rtc::ArrayView<LoggedStopEvent> output_batch =
42 ExtendLoggedBatch(output, parser.NumEventsInBatch());
43
44 constexpr FieldParameters timestamp_params{
45 "timestamp_ms", FieldParameters::kTimestampField, FieldType::kVarInt, 64};
46 RtcEventLogParseStatusOr<rtc::ArrayView<uint64_t>> result =
47 parser.ParseNumericField(timestamp_params);
48 if (!result.ok())
49 return result.status();
50 status = PopulateRtcEventTimestamp(result.value(),
51 &LoggedStopEvent::timestamp, output_batch);
52 if (!status.ok())
53 return status;
54
55 return RtcEventLogParseStatus::Success();
56 }
57
58 } // namespace webrtc
59