QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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 | |
vasilvv | 4581908 | 2020-07-08 08:48:25 -0700 | [diff] [blame] | 8 | #include <type_traits> |
| 9 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10 | #include "net/third_party/quiche/src/quic/core/quic_types.h" |
| 11 | #include "net/third_party/quiche/src/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 { |
vasilvv | 4581908 | 2020-07-08 08:48:25 -0700 | [diff] [blame] | 21 | 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"); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | } // namespace quic |
| 33 | |
| 34 | #endif // QUICHE_QUIC_CORE_FRAMES_QUIC_INLINED_FRAME_H_ |