xref: /aosp_15_r20/external/webrtc/net/dcsctp/packet/error_cause/unrecognized_chunk_type_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_UNRECOGNIZED_CHUNK_TYPE_CAUSE_H_
11 #define NET_DCSCTP_PACKET_ERROR_CAUSE_UNRECOGNIZED_CHUNK_TYPE_CAUSE_H_
12 #include <stddef.h>
13 #include <stdint.h>
14 
15 #include <cstdint>
16 #include <string>
17 #include <utility>
18 #include <vector>
19 
20 #include "absl/strings/string_view.h"
21 #include "api/array_view.h"
22 #include "net/dcsctp/packet/error_cause/error_cause.h"
23 #include "net/dcsctp/packet/tlv_trait.h"
24 
25 namespace dcsctp {
26 
27 // https://tools.ietf.org/html/rfc4960#section-3.3.10.6
28 struct UnrecognizedChunkTypeCauseConfig : public ParameterConfig {
29   static constexpr int kType = 6;
30   static constexpr size_t kHeaderSize = 4;
31   static constexpr size_t kVariableLengthAlignment = 1;
32 };
33 
34 class UnrecognizedChunkTypeCause
35     : public Parameter,
36       public TLVTrait<UnrecognizedChunkTypeCauseConfig> {
37  public:
38   static constexpr int kType = UnrecognizedChunkTypeCauseConfig::kType;
39 
UnrecognizedChunkTypeCause(std::vector<uint8_t> unrecognized_chunk)40   explicit UnrecognizedChunkTypeCause(std::vector<uint8_t> unrecognized_chunk)
41       : unrecognized_chunk_(std::move(unrecognized_chunk)) {}
42 
43   static absl::optional<UnrecognizedChunkTypeCause> 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 
unrecognized_chunk()49   rtc::ArrayView<const uint8_t> unrecognized_chunk() const {
50     return unrecognized_chunk_;
51   }
52 
53  private:
54   std::vector<uint8_t> unrecognized_chunk_;
55 };
56 
57 }  // namespace dcsctp
58 
59 #endif  // NET_DCSCTP_PACKET_ERROR_CAUSE_UNRECOGNIZED_CHUNK_TYPE_CAUSE_H_
60