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_PACKET_PARAMETER_HEARTBEAT_INFO_PARAMETER_H_ 11 #define NET_DCSCTP_PACKET_PARAMETER_HEARTBEAT_INFO_PARAMETER_H_ 12 #include <stddef.h> 13 14 #include <cstdint> 15 #include <string> 16 #include <vector> 17 18 #include "absl/strings/string_view.h" 19 #include "api/array_view.h" 20 #include "net/dcsctp/packet/parameter/parameter.h" 21 #include "net/dcsctp/packet/tlv_trait.h" 22 23 namespace dcsctp { 24 25 // https://tools.ietf.org/html/rfc4960#section-3.3.5 26 struct HeartbeatInfoParameterConfig : ParameterConfig { 27 static constexpr int kType = 1; 28 static constexpr size_t kHeaderSize = 4; 29 static constexpr size_t kVariableLengthAlignment = 1; 30 }; 31 32 class HeartbeatInfoParameter : public Parameter, 33 public TLVTrait<HeartbeatInfoParameterConfig> { 34 public: 35 static constexpr int kType = HeartbeatInfoParameterConfig::kType; 36 HeartbeatInfoParameter(rtc::ArrayView<const uint8_t> info)37 explicit HeartbeatInfoParameter(rtc::ArrayView<const uint8_t> info) 38 : info_(info.begin(), info.end()) {} 39 40 static absl::optional<HeartbeatInfoParameter> Parse( 41 rtc::ArrayView<const uint8_t> data); 42 43 void SerializeTo(std::vector<uint8_t>& out) const override; 44 std::string ToString() const override; 45 info()46 rtc::ArrayView<const uint8_t> info() const { return info_; } 47 48 private: 49 std::vector<uint8_t> info_; 50 }; 51 52 } // namespace dcsctp 53 54 #endif // NET_DCSCTP_PACKET_PARAMETER_HEARTBEAT_INFO_PARAMETER_H_ 55