Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
kcenon::network::protocols::http2::settings_frame Class Reference

SETTINGS frame (RFC 7540 Section 6.5) More...

#include <frame.h>

Inheritance diagram for kcenon::network::protocols::http2::settings_frame:
Inheritance graph
Collaboration diagram for kcenon::network::protocols::http2::settings_frame:
Collaboration graph

Public Member Functions

 settings_frame (std::vector< setting_parameter > settings={}, bool ack=false)
 Construct SETTINGS frame.
 
auto settings () const -> const std::vector< setting_parameter > &
 Get settings parameters.
 
auto is_ack () const -> bool
 Check if this is an ACK frame.
 
- Public Member Functions inherited from kcenon::network::protocols::http2::frame
 frame ()=default
 Default constructor.
 
 frame (const frame_header &hdr, std::vector< uint8_t > payload)
 Construct frame with header and payload.
 
auto serialize () const -> std::vector< uint8_t >
 Serialize frame to bytes.
 
auto header () const -> const frame_header &
 Get frame header.
 
auto payload () const -> std::span< const uint8_t >
 Get frame payload.
 
virtual ~frame ()=default
 Virtual destructor.
 

Static Public Member Functions

static auto parse (const frame_header &hdr, std::span< const uint8_t > payload) -> Result< std::unique_ptr< settings_frame > >
 Parse SETTINGS frame from raw bytes.
 
- Static Public Member Functions inherited from kcenon::network::protocols::http2::frame
static auto parse (std::span< const uint8_t > data) -> Result< std::unique_ptr< frame > >
 Parse frame from raw bytes.
 

Private Attributes

std::vector< setting_parametersettings_
 Settings parameters.
 

Additional Inherited Members

- Protected Attributes inherited from kcenon::network::protocols::http2::frame
frame_header header_
 Frame header.
 
std::vector< uint8_t > payload_
 Frame payload.
 

Detailed Description

SETTINGS frame (RFC 7540 Section 6.5)

SETTINGS frames convey configuration parameters that affect how endpoints communicate.

Definition at line 264 of file frame.h.

Constructor & Destructor Documentation

◆ settings_frame()

kcenon::network::protocols::http2::settings_frame::settings_frame ( std::vector< setting_parameter > settings = {},
bool ack = false )
explicit

Construct SETTINGS frame.

Parameters
settingsVector of settings parameters
ackTrue if this is an acknowledgment

Definition at line 353 of file frame.cpp.

354 : settings_(std::move(settings))
355 {
356 header_.stream_id = 0;
359
360 if (!ack)
361 {
362 for (const auto& setting : settings_)
363 {
364 auto id_bytes = write_uint32_be(static_cast<uint32_t>(setting.identifier));
365 payload_.insert(payload_.end(), id_bytes.begin() + 2, id_bytes.end());
366
367 auto value_bytes = write_uint32_be(setting.value);
368 payload_.insert(payload_.end(), value_bytes.begin(), value_bytes.end());
369 }
370 }
371
372 header_.length = static_cast<uint32_t>(payload_.size());
373 }
std::vector< uint8_t > payload_
Frame payload.
Definition frame.h:128
frame_header header_
Frame header.
Definition frame.h:127
std::vector< setting_parameter > settings_
Settings parameters.
Definition frame.h:297
auto settings() const -> const std::vector< setting_parameter > &
Get settings parameters.
Definition frame.cpp:411
uint32_t stream_id
Stream identifier (31 bits, MSB reserved)
Definition frame.h:58
uint32_t length
Payload length (24 bits)
Definition frame.h:55

References kcenon::network::protocols::http2::frame_flags::ack, kcenon::network::protocols::http2::frame_header::flags, kcenon::network::protocols::http2::frame::header_, kcenon::network::protocols::http2::frame_header::length, kcenon::network::protocols::http2::frame_flags::none, kcenon::network::protocols::http2::frame::payload_, kcenon::network::protocols::http2::settings, settings_, kcenon::network::protocols::http2::frame_header::stream_id, and kcenon::network::protocols::http2::frame_header::type.

Member Function Documentation

◆ is_ack()

auto kcenon::network::protocols::http2::settings_frame::is_ack ( ) const -> bool

Check if this is an ACK frame.

Returns
True if ACK flag is set

Definition at line 416 of file frame.cpp.

417 {
419 }

References kcenon::network::protocols::http2::frame_flags::ack, kcenon::network::protocols::http2::frame_header::flags, and kcenon::network::protocols::http2::frame::header_.

◆ parse()

auto kcenon::network::protocols::http2::settings_frame::parse ( const frame_header & hdr,
std::span< const uint8_t > payload ) -> Result<std::unique_ptr<settings_frame>>
static

Parse SETTINGS frame from raw bytes.

Parameters
hdrFrame header (must be SETTINGS type)
payloadFrame payload
Returns
Result containing parsed SETTINGS frame or error

Definition at line 375 of file frame.cpp.

377 {
378 if (hdr.stream_id != 0)
379 {
380 return error_info(10, "SETTINGS frame must have zero stream ID", "http2");
381 }
382
383 if (hdr.flags & frame_flags::ack)
384 {
385 if (!payload.empty())
386 {
387 return error_info(11, "SETTINGS ACK must have empty payload", "http2");
388 }
389
390 return std::make_unique<settings_frame>(std::vector<setting_parameter>{}, true);
391 }
392
393 if (payload.size() % 6 != 0)
394 {
395 return error_info(12, "Invalid SETTINGS frame payload size", "http2");
396 }
397
398 std::vector<setting_parameter> settings;
399 for (size_t i = 0; i < payload.size(); i += 6)
400 {
401 uint16_t identifier = (static_cast<uint16_t>(payload[i]) << 8) |
402 static_cast<uint16_t>(payload[i + 1]);
403 uint32_t value = read_uint32_be(payload.subspan(i + 2, 4));
404
405 settings.push_back({identifier, value});
406 }
407
408 return std::make_unique<settings_frame>(std::move(settings), false);
409 }
auto payload() const -> std::span< const uint8_t >
Get frame payload.
Definition frame.cpp:185
simple_error error_info

References kcenon::network::protocols::http2::frame_flags::ack, and kcenon::network::protocols::http2::settings.

Referenced by kcenon::network::protocols::http2::frame::parse().

Here is the caller graph for this function:

◆ settings()

auto kcenon::network::protocols::http2::settings_frame::settings ( ) const -> const std::vector<setting_parameter>&

Get settings parameters.

Returns
Vector of settings

Definition at line 411 of file frame.cpp.

412 {
413 return settings_;
414 }

References settings_.

Member Data Documentation

◆ settings_

std::vector<setting_parameter> kcenon::network::protocols::http2::settings_frame::settings_
private

Settings parameters.

Definition at line 297 of file frame.h.

Referenced by settings(), and settings_frame().


The documentation for this class was generated from the following files: