Project import generated by Copybara.
PiperOrigin-RevId: 237361882
Change-Id: I109a68f44db867b20f8c6a7732b0ce657133e52a
diff --git a/quic/core/qpack/qpack_decoder_stream_receiver.cc b/quic/core/qpack/qpack_decoder_stream_receiver.cc
new file mode 100644
index 0000000..559ce43
--- /dev/null
+++ b/quic/core/qpack/qpack_decoder_stream_receiver.cc
@@ -0,0 +1,52 @@
+// 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 "net/third_party/quiche/src/quic/core/qpack/qpack_decoder_stream_receiver.h"
+
+#include "net/third_party/quiche/src/http2/decoder/decode_buffer.h"
+#include "net/third_party/quiche/src/http2/decoder/decode_status.h"
+#include "net/third_party/quiche/src/quic/core/qpack/qpack_constants.h"
+
+namespace quic {
+
+QpackDecoderStreamReceiver::QpackDecoderStreamReceiver(Delegate* delegate)
+ : instruction_decoder_(QpackDecoderStreamLanguage(), this),
+ delegate_(delegate),
+ error_detected_(false) {
+ DCHECK(delegate_);
+}
+
+void QpackDecoderStreamReceiver::Decode(QuicStringPiece data) {
+ if (data.empty() || error_detected_) {
+ return;
+ }
+
+ instruction_decoder_.Decode(data);
+}
+
+bool QpackDecoderStreamReceiver::OnInstructionDecoded(
+ const QpackInstruction* instruction) {
+ if (instruction == InsertCountIncrementInstruction()) {
+ delegate_->OnInsertCountIncrement(instruction_decoder_.varint());
+ return true;
+ }
+
+ if (instruction == HeaderAcknowledgementInstruction()) {
+ delegate_->OnHeaderAcknowledgement(instruction_decoder_.varint());
+ return true;
+ }
+
+ DCHECK_EQ(instruction, StreamCancellationInstruction());
+ delegate_->OnStreamCancellation(instruction_decoder_.varint());
+ return true;
+}
+
+void QpackDecoderStreamReceiver::OnError(QuicStringPiece error_message) {
+ DCHECK(!error_detected_);
+
+ error_detected_ = true;
+ delegate_->OnErrorDetected(error_message);
+}
+
+} // namespace quic