xref: /aosp_15_r20/external/webrtc/net/dcsctp/public/text_pcap_packet_observer.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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 #ifndef NET_DCSCTP_PUBLIC_TEXT_PCAP_PACKET_OBSERVER_H_
11 #define NET_DCSCTP_PUBLIC_TEXT_PCAP_PACKET_OBSERVER_H_
12 
13 #include <string>
14 
15 #include "absl/strings/string_view.h"
16 #include "api/array_view.h"
17 #include "net/dcsctp/public/packet_observer.h"
18 #include "net/dcsctp/public/types.h"
19 
20 namespace dcsctp {
21 
22 // Print outs all sent and received packets to the logs, at LS_VERBOSE severity.
23 class TextPcapPacketObserver : public dcsctp::PacketObserver {
24  public:
TextPcapPacketObserver(absl::string_view name)25   explicit TextPcapPacketObserver(absl::string_view name) : name_(name) {}
26 
27   // Implementation of `dcsctp::PacketObserver`.
28   void OnSentPacket(dcsctp::TimeMs now,
29                     rtc::ArrayView<const uint8_t> payload) override;
30 
31   void OnReceivedPacket(dcsctp::TimeMs now,
32                         rtc::ArrayView<const uint8_t> payload) override;
33 
34   // Prints a packet to the log. Exposed to allow it to be used in compatibility
35   // tests suites that don't use PacketObserver.
36   static void PrintPacket(absl::string_view prefix,
37                           absl::string_view socket_name,
38                           dcsctp::TimeMs now,
39                           rtc::ArrayView<const uint8_t> payload);
40 
41  private:
42   const std::string name_;
43 };
44 
45 }  // namespace dcsctp
46 #endif  // NET_DCSCTP_PUBLIC_TEXT_PCAP_PACKET_OBSERVER_H_
47