blob: 8da3147d1ea2505c5ba812c587eb17598a8094ce [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 <string>
#include "net/third_party/quiche/src/quic/core/qpack/qpack_instruction_decoder.h"
#include "net/third_party/quiche/src/quic/core/qpack/qpack_stream_receiver.h"
#include "net/third_party/quiche/src/quic/platform/api/quic_export.h"
#include "net/third_party/quiche/src/quic/platform/api/quic_string_piece.h"
namespace quic {
// This class decodes data received on the encoder stream.
class QUIC_EXPORT_PRIVATE QpackEncoderStreamReceiver
: public QpackInstructionDecoder::Delegate,
public QpackStreamReceiver {
// An interface for handling instructions decoded from the encoder stream, see
class Delegate {
virtual ~Delegate() = default;
// 5.2.1. Insert With Name Reference
virtual void OnInsertWithNameReference(bool is_static,
uint64_t name_index,
QuicStringPiece value) = 0;
// 5.2.2. Insert Without Name Reference
virtual void OnInsertWithoutNameReference(QuicStringPiece name,
QuicStringPiece value) = 0;
// 5.2.3. Duplicate
virtual void OnDuplicate(uint64_t index) = 0;
// 5.2.4. Set Dynamic Table Capacity
virtual void OnSetDynamicTableCapacity(uint64_t capacity) = 0;
// Decoding error
virtual void OnErrorDetected(QuicStringPiece error_message) = 0;
explicit QpackEncoderStreamReceiver(Delegate* delegate);
QpackEncoderStreamReceiver() = delete;
QpackEncoderStreamReceiver(const QpackEncoderStreamReceiver&) = delete;
QpackEncoderStreamReceiver& operator=(const QpackEncoderStreamReceiver&) =
~QpackEncoderStreamReceiver() override = default;
// Implements QpackStreamReceiver::Decode().
// Decode data and call appropriate Delegate method after each decoded
// instruction. Once an error occurs, Delegate::OnErrorDetected() is called,
// and all further data is ignored.
void Decode(QuicStringPiece data) override;
// QpackInstructionDecoder::Delegate implementation.
bool OnInstructionDecoded(const QpackInstruction* instruction) override;
void OnError(QuicStringPiece error_message) override;
QpackInstructionDecoder instruction_decoder_;
Delegate* const delegate_;
// True if a decoding error has been detected.
bool error_detected_;
} // namespace quic