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_ERROR_CAUSE_MISSING_MANDATORY_PARAMETER_CAUSE_H_ 11 #define NET_DCSCTP_PACKET_ERROR_CAUSE_MISSING_MANDATORY_PARAMETER_CAUSE_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/error_cause/error_cause.h" 21 #include "net/dcsctp/packet/tlv_trait.h" 22 23 namespace dcsctp { 24 25 // https://tools.ietf.org/html/rfc4960#section-3.3.10.2 26 struct MissingMandatoryParameterCauseConfig : public ParameterConfig { 27 static constexpr int kType = 2; 28 static constexpr size_t kHeaderSize = 8; 29 static constexpr size_t kVariableLengthAlignment = 2; 30 }; 31 32 class MissingMandatoryParameterCause 33 : public Parameter, 34 public TLVTrait<MissingMandatoryParameterCauseConfig> { 35 public: 36 static constexpr int kType = MissingMandatoryParameterCauseConfig::kType; 37 MissingMandatoryParameterCause(rtc::ArrayView<const uint16_t> missing_parameter_types)38 explicit MissingMandatoryParameterCause( 39 rtc::ArrayView<const uint16_t> missing_parameter_types) 40 : missing_parameter_types_(missing_parameter_types.begin(), 41 missing_parameter_types.end()) {} 42 43 static absl::optional<MissingMandatoryParameterCause> Parse( 44 rtc::ArrayView<const uint8_t> data); 45 46 void SerializeTo(std::vector<uint8_t>& out) const override; 47 std::string ToString() const override; 48 missing_parameter_types()49 rtc::ArrayView<const uint16_t> missing_parameter_types() const { 50 return missing_parameter_types_; 51 } 52 53 private: 54 static constexpr size_t kMissingParameterSize = 2; 55 std::vector<uint16_t> missing_parameter_types_; 56 }; 57 58 } // namespace dcsctp 59 60 #endif // NET_DCSCTP_PACKET_ERROR_CAUSE_MISSING_MANDATORY_PARAMETER_CAUSE_H_ 61