• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2018 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_CORE_FRAMES_QUIC_INLINED_FRAME_H_
6 #define QUICHE_QUIC_CORE_FRAMES_QUIC_INLINED_FRAME_H_
7 
8 #include <type_traits>
9 
10 #include "quiche/quic/core/quic_types.h"
11 #include "quiche/quic/platform/api/quic_export.h"
12 
13 namespace quic {
14 
15 // QuicInlinedFrame is the base class of all frame types that is inlined in the
16 // QuicFrame class. It gurantees all inlined frame types contain a 'type' field
17 // at offset 0, such that QuicFrame.type can get the correct frame type for both
18 // inline and out-of-line frame types.
19 template <typename DerivedT>
20 struct QUIC_EXPORT_PRIVATE QuicInlinedFrame {
QuicInlinedFrameQuicInlinedFrame21   QuicInlinedFrame(QuicFrameType type) {
22     static_cast<DerivedT*>(this)->type = type;
23     static_assert(std::is_standard_layout<DerivedT>::value,
24                   "Inlined frame must have a standard layout");
25     static_assert(offsetof(DerivedT, type) == 0,
26                   "type must be the first field.");
27     static_assert(sizeof(DerivedT) <= 24,
28                   "Frames larger than 24 bytes should not be inlined.");
29   }
30 };
31 
32 }  // namespace quic
33 
34 #endif  // QUICHE_QUIC_CORE_FRAMES_QUIC_INLINED_FRAME_H_
35