blob: cfa32dc0ecd175b68a66b163b0fcc748e8017384 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// 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
vasilvv45819082020-07-08 08:48:25 -07008#include <type_traits>
9
QUICHE teama6ef0a62019-03-07 20:34:33 -050010#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
13namespace 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.
19template <typename DerivedT>
20struct QUIC_EXPORT_PRIVATE QuicInlinedFrame {
vasilvv45819082020-07-08 08:48:25 -070021 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 teama6ef0a62019-03-07 20:34:33 -050025 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 teama6ef0a62019-03-07 20:34:33 -050030};
31
32} // namespace quic
33
34#endif // QUICHE_QUIC_CORE_FRAMES_QUIC_INLINED_FRAME_H_