blob: 7b7eb47b884f4322151fb8b0968ee7453a9de47c [file] [log] [blame]
// Copyright (c) 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <cstdint>
#include <tuple>
#include <vector>
#include "net/third_party/quiche/src/quic/platform/api/quic_export.h"
#include "net/third_party/quiche/src/quic/platform/api/quic_string.h"
namespace quic {
// Each instruction is identified with an opcode in the first byte.
// |mask| determines which bits are part of the opcode.
// |value| is the value of these bits. (Other bits in value must be zero.)
struct QUIC_EXPORT_PRIVATE QpackInstructionOpcode {
uint8_t value;
uint8_t mask;
bool operator==(const QpackInstructionOpcode& a,
const QpackInstructionOpcode& b);
// Possible types of an instruction field. Decoding a static bit does not
// consume the current byte. Decoding an integer or a length-prefixed string
// literal consumes all bytes containing the field value.
enum class QpackInstructionFieldType {
// A single bit indicating whether the index refers to the static table, or
// indicating the sign of Delta Base. Called "S" bit because both "static"
// and "sign" start with the letter "S".
// An integer encoded with variable length encoding. This could be an index,
// stream ID, maximum size, or Encoded Required Insert Count.
// A second integer encoded with variable length encoding. This could be
// Delta Base.
// A header name or header value encoded as:
// a bit indicating whether it is Huffman encoded;
// the encoded length of the string;
// the header name or value optionally Huffman encoded.
// Each instruction field has a type and a parameter.
// The meaning of the parameter depends on the field type.
struct QUIC_EXPORT_PRIVATE QpackInstructionField {
QpackInstructionFieldType type;
// For a kSbit field, |param| is a mask with exactly one bit set.
// For kVarint fields, |param| is the prefix length of the integer encoding.
// For kName and kValue fields, |param| is the prefix length of the length of
// the string, and the bit immediately preceding the prefix is interpreted as
// the Huffman bit.
uint8_t param;
using QpackInstructionFields = std::vector<QpackInstructionField>;
// A QPACK instruction consists of an opcode identifying the instruction,
// followed by a non-empty list of fields. The last field must be integer or
// string literal type to guarantee that all bytes of the instruction are
// consumed.
struct QUIC_EXPORT_PRIVATE QpackInstruction {
QpackInstruction(const QpackInstruction&) = delete;
const QpackInstruction& operator=(const QpackInstruction&) = delete;
QpackInstructionOpcode opcode;
QpackInstructionFields fields;
// A language is a collection of instructions. The order does not matter.
// Every possible input must match exactly one instruction.
using QpackLanguage = std::vector<const QpackInstruction*>;
// TODO(bnc): Move this into HpackVarintEncoder.
// The integer encoder can encode up to 2^64-1, which can take up to 10 bytes
// (each carrying 7 bits) after the prefix.
const uint8_t kMaxExtensionBytesForVarintEncoding = 10;
// Wire format defined in
// 5.2 Encoder stream instructions
// 5.2.1 Insert With Name Reference
const QpackInstruction* InsertWithNameReferenceInstruction();
// 5.2.2 Insert Without Name Reference
const QpackInstruction* InsertWithoutNameReferenceInstruction();
// 5.2.3 Duplicate
const QpackInstruction* DuplicateInstruction();
// 5.2.4 Dynamic Table Size Update
const QpackInstruction* SetDynamicTableCapacityInstruction();
// Encoder stream language.
const QpackLanguage* QpackEncoderStreamLanguage();
// 5.3 Decoder stream instructions
// 5.3.1 Insert Count Increment
const QpackInstruction* InsertCountIncrementInstruction();
// 5.3.2 Header Acknowledgement
const QpackInstruction* HeaderAcknowledgementInstruction();
// 5.3.3 Stream Cancellation
const QpackInstruction* StreamCancellationInstruction();
// Decoder stream language.
const QpackLanguage* QpackDecoderStreamLanguage();
// 5.4.1. Header data prefix instructions
const QpackInstruction* QpackPrefixInstruction();
const QpackLanguage* QpackPrefixLanguage();
// 5.4.2. Request and push stream instructions
// Indexed Header Field
const QpackInstruction* QpackIndexedHeaderFieldInstruction();
// Indexed Header Field With Post-Base Index
const QpackInstruction* QpackIndexedHeaderFieldPostBaseInstruction();
// Literal Header Field With Name Reference
const QpackInstruction* QpackLiteralHeaderFieldNameReferenceInstruction();
// Literal Header Field With Post-Base Name Reference
const QpackInstruction* QpackLiteralHeaderFieldPostBaseInstruction();
// Literal Header Field Without Name Reference
const QpackInstruction* QpackLiteralHeaderFieldInstruction();
// Request and push stream language.
const QpackLanguage* QpackRequestStreamLanguage();
} // namespace quic