xref: /aosp_15_r20/external/webrtc/net/dcsctp/packet/error_cause/invalid_stream_identifier_cause.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_ERROR_CAUSE_INVALID_STREAM_IDENTIFIER_CAUSE_H_
11 #define NET_DCSCTP_PACKET_ERROR_CAUSE_INVALID_STREAM_IDENTIFIER_CAUSE_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/packet/error_cause/error_cause.h"
21 #include "net/dcsctp/packet/tlv_trait.h"
22 #include "net/dcsctp/public/types.h"
23 
24 namespace dcsctp {
25 
26 // https://tools.ietf.org/html/rfc4960#section-3.3.10.1
27 struct InvalidStreamIdentifierCauseConfig : public ParameterConfig {
28   static constexpr int kType = 1;
29   static constexpr size_t kHeaderSize = 8;
30   static constexpr size_t kVariableLengthAlignment = 0;
31 };
32 
33 class InvalidStreamIdentifierCause
34     : public Parameter,
35       public TLVTrait<InvalidStreamIdentifierCauseConfig> {
36  public:
37   static constexpr int kType = InvalidStreamIdentifierCauseConfig::kType;
38 
InvalidStreamIdentifierCause(StreamID stream_id)39   explicit InvalidStreamIdentifierCause(StreamID stream_id)
40       : stream_id_(stream_id) {}
41 
42   static absl::optional<InvalidStreamIdentifierCause> Parse(
43       rtc::ArrayView<const uint8_t> data);
44 
45   void SerializeTo(std::vector<uint8_t>& out) const override;
46   std::string ToString() const override;
47 
stream_id()48   StreamID stream_id() const { return stream_id_; }
49 
50  private:
51   StreamID stream_id_;
52 };
53 
54 }  // namespace dcsctp
55 
56 #endif  // NET_DCSCTP_PACKET_ERROR_CAUSE_INVALID_STREAM_IDENTIFIER_CAUSE_H_
57