xref: /aosp_15_r20/external/webrtc/net/dcsctp/packet/parameter/add_outgoing_streams_request_parameter.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_PACKET_PARAMETER_ADD_OUTGOING_STREAMS_REQUEST_PARAMETER_H_
11 #define NET_DCSCTP_PACKET_PARAMETER_ADD_OUTGOING_STREAMS_REQUEST_PARAMETER_H_
12 #include <stddef.h>
13 #include <stdint.h>
14 
15 #include <string>
16 #include <vector>
17 
18 #include "absl/strings/string_view.h"
19 #include "api/array_view.h"
20 #include "net/dcsctp/common/internal_types.h"
21 #include "net/dcsctp/packet/parameter/parameter.h"
22 #include "net/dcsctp/packet/tlv_trait.h"
23 
24 namespace dcsctp {
25 
26 // https://tools.ietf.org/html/rfc6525#section-4.5
27 struct AddOutgoingStreamsRequestParameterConfig : ParameterConfig {
28   static constexpr int kType = 17;
29   static constexpr size_t kHeaderSize = 12;
30   static constexpr size_t kVariableLengthAlignment = 0;
31 };
32 
33 class AddOutgoingStreamsRequestParameter
34     : public Parameter,
35       public TLVTrait<AddOutgoingStreamsRequestParameterConfig> {
36  public:
37   static constexpr int kType = AddOutgoingStreamsRequestParameterConfig::kType;
38 
AddOutgoingStreamsRequestParameter(ReconfigRequestSN request_sequence_number,uint16_t nbr_of_new_streams)39   explicit AddOutgoingStreamsRequestParameter(
40       ReconfigRequestSN request_sequence_number,
41       uint16_t nbr_of_new_streams)
42       : request_sequence_number_(request_sequence_number),
43         nbr_of_new_streams_(nbr_of_new_streams) {}
44 
45   static absl::optional<AddOutgoingStreamsRequestParameter> Parse(
46       rtc::ArrayView<const uint8_t> data);
47 
48   void SerializeTo(std::vector<uint8_t>& out) const override;
49   std::string ToString() const override;
50 
request_sequence_number()51   ReconfigRequestSN request_sequence_number() const {
52     return request_sequence_number_;
53   }
nbr_of_new_streams()54   uint16_t nbr_of_new_streams() const { return nbr_of_new_streams_; }
55 
56  private:
57   ReconfigRequestSN request_sequence_number_;
58   uint16_t nbr_of_new_streams_;
59 };
60 
61 }  // namespace dcsctp
62 
63 #endif  // NET_DCSCTP_PACKET_PARAMETER_ADD_OUTGOING_STREAMS_REQUEST_PARAMETER_H_
64