react-http2/src/Frame/SettingsFrame.php

55 lines
1.4 KiB
PHP

<?php
namespace NoccyLabs\React\Http2\Frame;
class SettingsFrame extends Frame
{
const SETTINGS_HEADER_TABLE_SIZE = 0x1;
const SETTINGS_ENABLE_PUSH = 0x2;
const SETTINGS_MAX_CONCURRENT_STREAMS = 0x3;
const SETTINGS_INITIAL_WINDOW_SIZE = 0x4;
const SETTINGS_MAX_FRAME_SIZE = 0x5;
const SETTINGS_MAX_HEADER_LIST_SIZE = 0x6;
protected int $frameType = self::FRAME_SETTINGS;
protected array $settings = [];
/**
* Set a setting to a specific value. This method intentionally does not do any bounds
* checking on the setting id to allow for extensions.
*
* @param int $setting
* @param int $value
* @return self
*/
public function set(int $setting, int $value): self
{
$this->settings[$setting] = $value;
return $this;
}
public function get(int $setting): ?int
{
return $this->settings[$setting]??null;
}
public function toBinary(): string
{
$packed = '';
foreach ($this->settings as $setting=>$value) {
$packed .= pack('vV', $setting, $value);
}
return $packed;
}
public function fromBinary(string $data): void
{
for ($n = 0; $n < strlen($data) - 3; $n = $n + 3) {
$unpacked = unpack('vsetting/Vvalue', substr($data,$n,3));
$this->set($unpacked['setting'], $unpacked['value']);
}
}
}