blob: 80622e5460df2d8b345cf040ab8a6b07ed2b853d [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_QPACK_QPACK_ENCODER_STREAM_RECEIVER_H_
6#define QUICHE_QUIC_CORE_QPACK_QPACK_ENCODER_STREAM_RECEIVER_H_
7
8#include <cstdint>
vasilvv872e7a32019-03-12 16:42:44 -07009#include <string>
QUICHE teama6ef0a62019-03-07 20:34:33 -050010
11#include "net/third_party/quiche/src/quic/core/qpack/qpack_instruction_decoder.h"
renjietangb932f952019-06-28 11:33:11 -070012#include "net/third_party/quiche/src/quic/core/qpack/qpack_stream_receiver.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050013#include "net/third_party/quiche/src/quic/platform/api/quic_export.h"
QUICHE team11f55d42019-12-11 10:36:09 -080014#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050015
16namespace quic {
17
18// This class decodes data received on the encoder stream.
19class QUIC_EXPORT_PRIVATE QpackEncoderStreamReceiver
renjietangb932f952019-06-28 11:33:11 -070020 : public QpackInstructionDecoder::Delegate,
21 public QpackStreamReceiver {
QUICHE teama6ef0a62019-03-07 20:34:33 -050022 public:
23 // An interface for handling instructions decoded from the encoder stream, see
24 // https://quicwg.org/base-drafts/draft-ietf-quic-qpack.html#rfc.section.5.2
dschinazif25169a2019-10-23 08:12:18 -070025 class QUIC_EXPORT_PRIVATE Delegate {
QUICHE teama6ef0a62019-03-07 20:34:33 -050026 public:
27 virtual ~Delegate() = default;
28
29 // 5.2.1. Insert With Name Reference
30 virtual void OnInsertWithNameReference(bool is_static,
31 uint64_t name_index,
QUICHE team11f55d42019-12-11 10:36:09 -080032 quiche::QuicheStringPiece value) = 0;
QUICHE teama6ef0a62019-03-07 20:34:33 -050033 // 5.2.2. Insert Without Name Reference
QUICHE team11f55d42019-12-11 10:36:09 -080034 virtual void OnInsertWithoutNameReference(
35 quiche::QuicheStringPiece name,
36 quiche::QuicheStringPiece value) = 0;
QUICHE teama6ef0a62019-03-07 20:34:33 -050037 // 5.2.3. Duplicate
38 virtual void OnDuplicate(uint64_t index) = 0;
39 // 5.2.4. Set Dynamic Table Capacity
40 virtual void OnSetDynamicTableCapacity(uint64_t capacity) = 0;
41 // Decoding error
QUICHE team11f55d42019-12-11 10:36:09 -080042 virtual void OnErrorDetected(quiche::QuicheStringPiece error_message) = 0;
QUICHE teama6ef0a62019-03-07 20:34:33 -050043 };
44
45 explicit QpackEncoderStreamReceiver(Delegate* delegate);
46 QpackEncoderStreamReceiver() = delete;
47 QpackEncoderStreamReceiver(const QpackEncoderStreamReceiver&) = delete;
48 QpackEncoderStreamReceiver& operator=(const QpackEncoderStreamReceiver&) =
49 delete;
50 ~QpackEncoderStreamReceiver() override = default;
51
renjietangb932f952019-06-28 11:33:11 -070052 // Implements QpackStreamReceiver::Decode().
QUICHE teama6ef0a62019-03-07 20:34:33 -050053 // Decode data and call appropriate Delegate method after each decoded
54 // instruction. Once an error occurs, Delegate::OnErrorDetected() is called,
55 // and all further data is ignored.
QUICHE team11f55d42019-12-11 10:36:09 -080056 void Decode(quiche::QuicheStringPiece data) override;
QUICHE teama6ef0a62019-03-07 20:34:33 -050057
58 // QpackInstructionDecoder::Delegate implementation.
59 bool OnInstructionDecoded(const QpackInstruction* instruction) override;
QUICHE team11f55d42019-12-11 10:36:09 -080060 void OnError(quiche::QuicheStringPiece error_message) override;
QUICHE teama6ef0a62019-03-07 20:34:33 -050061
62 private:
63 QpackInstructionDecoder instruction_decoder_;
64 Delegate* const delegate_;
65
66 // True if a decoding error has been detected.
67 bool error_detected_;
68};
69
70} // namespace quic
71
72#endif // QUICHE_QUIC_CORE_QPACK_QPACK_ENCODER_STREAM_RECEIVER_H_