• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SUPPORTED_EXTENSIONS_PARAMETER_H_
11 #define NET_DCSCTP_PACKET_PARAMETER_SUPPORTED_EXTENSIONS_PARAMETER_H_
12 #include <stddef.h>
13 
14 #include <algorithm>
15 #include <cstdint>
16 #include <iterator>
17 #include <string>
18 #include <utility>
19 #include <vector>
20 
21 #include "absl/strings/string_view.h"
22 #include "api/array_view.h"
23 #include "net/dcsctp/packet/parameter/parameter.h"
24 #include "net/dcsctp/packet/tlv_trait.h"
25 
26 namespace dcsctp {
27 
28 // https://tools.ietf.org/html/rfc5061#section-4.2.7
29 struct SupportedExtensionsParameterConfig : ParameterConfig {
30   static constexpr int kType = 0x8008;
31   static constexpr size_t kHeaderSize = 4;
32   static constexpr size_t kVariableLengthAlignment = 1;
33 };
34 
35 class SupportedExtensionsParameter
36     : public Parameter,
37       public TLVTrait<SupportedExtensionsParameterConfig> {
38  public:
39   static constexpr int kType = SupportedExtensionsParameterConfig::kType;
40 
SupportedExtensionsParameter(std::vector<uint8_t> chunk_types)41   explicit SupportedExtensionsParameter(std::vector<uint8_t> chunk_types)
42       : chunk_types_(std::move(chunk_types)) {}
43 
44   static absl::optional<SupportedExtensionsParameter> Parse(
45       rtc::ArrayView<const uint8_t> data);
46 
47   void SerializeTo(std::vector<uint8_t>& out) const override;
48   std::string ToString() const override;
49 
supports(uint8_t chunk_type)50   bool supports(uint8_t chunk_type) const {
51     return std::find(chunk_types_.begin(), chunk_types_.end(), chunk_type) !=
52            chunk_types_.end();
53   }
54 
chunk_types()55   rtc::ArrayView<const uint8_t> chunk_types() const { return chunk_types_; }
56 
57  private:
58   std::vector<uint8_t> chunk_types_;
59 };
60 }  // namespace dcsctp
61 
62 #endif  // NET_DCSCTP_PACKET_PARAMETER_SUPPORTED_EXTENSIONS_PARAMETER_H_
63