xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/moqt/moqt_framer.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright (c) 2023 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef QUICHE_QUIC_MOQT_MOQT_FRAMER_H_
6 #define QUICHE_QUIC_MOQT_MOQT_FRAMER_H_
7 
8 #include <cstddef>
9 #include <optional>
10 
11 #include "absl/strings/string_view.h"
12 #include "quiche/quic/core/quic_types.h"
13 #include "quiche/quic/moqt/moqt_messages.h"
14 #include "quiche/common/platform/api/quiche_export.h"
15 #include "quiche/common/quiche_buffer_allocator.h"
16 
17 namespace moqt {
18 
19 // Serialize structured message data into a wire image. When the message format
20 // is different per |perspective| or |using_webtrans|, it will omit unnecessary
21 // fields. However, it does not enforce the presence of parameters that are
22 // required for a particular mode.
23 //
24 // There can be one instance of this per session. This framer does not enforce
25 // that these Serialize() calls are made in a logical order, as they can be on
26 // different streams.
27 class QUICHE_EXPORT MoqtFramer {
28  public:
MoqtFramer(quiche::QuicheBufferAllocator * allocator,bool using_webtrans)29   MoqtFramer(quiche::QuicheBufferAllocator* allocator, bool using_webtrans)
30       : allocator_(allocator), using_webtrans_(using_webtrans) {}
31 
32   // Serialize functions. Takes structured data and serializes it into a
33   // QuicheBuffer for delivery to the stream.
34 
35   // Serializes the header for an object, including the appropriate stream
36   // header if `is_first_in_stream` is set to true.
37   quiche::QuicheBuffer SerializeObjectHeader(const MoqtObject& message,
38                                              bool is_first_in_stream);
39   quiche::QuicheBuffer SerializeObjectDatagram(const MoqtObject& message,
40                                                absl::string_view payload);
41   quiche::QuicheBuffer SerializeClientSetup(const MoqtClientSetup& message);
42   quiche::QuicheBuffer SerializeServerSetup(const MoqtServerSetup& message);
43   // Returns an empty buffer if there is an illegal combination of locations.
44   quiche::QuicheBuffer SerializeSubscribe(const MoqtSubscribe& message);
45   quiche::QuicheBuffer SerializeSubscribeOk(const MoqtSubscribeOk& message);
46   quiche::QuicheBuffer SerializeSubscribeError(
47       const MoqtSubscribeError& message);
48   quiche::QuicheBuffer SerializeUnsubscribe(const MoqtUnsubscribe& message);
49   quiche::QuicheBuffer SerializeSubscribeDone(const MoqtSubscribeDone& message);
50   quiche::QuicheBuffer SerializeAnnounce(const MoqtAnnounce& message);
51   quiche::QuicheBuffer SerializeAnnounceOk(const MoqtAnnounceOk& message);
52   quiche::QuicheBuffer SerializeAnnounceError(const MoqtAnnounceError& message);
53   quiche::QuicheBuffer SerializeUnannounce(const MoqtUnannounce& message);
54   quiche::QuicheBuffer SerializeGoAway(const MoqtGoAway& message);
55 
56  private:
57   quiche::QuicheBufferAllocator* allocator_;
58   bool using_webtrans_;
59 };
60 
61 }  // namespace moqt
62 
63 #endif  // QUICHE_QUIC_MOQT_MOQT_FRAMER_H_
64