xref: /aosp_15_r20/external/webrtc/net/dcsctp/packet/chunk/reconfig_chunk.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_CHUNK_RECONFIG_CHUNK_H_
11 #define NET_DCSCTP_PACKET_CHUNK_RECONFIG_CHUNK_H_
12 #include <stddef.h>
13 #include <stdint.h>
14 
15 #include <string>
16 #include <utility>
17 #include <vector>
18 
19 #include "absl/strings/string_view.h"
20 #include "api/array_view.h"
21 #include "net/dcsctp/packet/chunk/chunk.h"
22 #include "net/dcsctp/packet/parameter/parameter.h"
23 #include "net/dcsctp/packet/tlv_trait.h"
24 
25 namespace dcsctp {
26 
27 // https://tools.ietf.org/html/rfc6525#section-3.1
28 struct ReConfigChunkConfig : ChunkConfig {
29   static constexpr int kType = 130;
30   static constexpr size_t kHeaderSize = 4;
31   static constexpr size_t kVariableLengthAlignment = 1;
32 };
33 
34 class ReConfigChunk : public Chunk, public TLVTrait<ReConfigChunkConfig> {
35  public:
36   static constexpr int kType = ReConfigChunkConfig::kType;
37 
ReConfigChunk(Parameters parameters)38   explicit ReConfigChunk(Parameters parameters)
39       : parameters_(std::move(parameters)) {}
40 
41   static absl::optional<ReConfigChunk> Parse(
42       rtc::ArrayView<const uint8_t> data);
43 
44   void SerializeTo(std::vector<uint8_t>& out) const override;
45   std::string ToString() const override;
46 
parameters()47   const Parameters& parameters() const { return parameters_; }
extract_parameters()48   Parameters extract_parameters() { return std::move(parameters_); }
49 
50  private:
51   Parameters parameters_;
52 };
53 
54 }  // namespace dcsctp
55 
56 #endif  // NET_DCSCTP_PACKET_CHUNK_RECONFIG_CHUNK_H_
57