Remove QpackProgressiveEncoder.
Since encoding is not done incrementally any more, there is no need to keep a
lot of state about encoding progress in class members: local variables suffice.
This CL inlines QpackProgressiveEncoder's functionality into QpackEncoder and
removes QpackProgressiveEncoder. No functional change.
gfe-relnote: n/a, QUIC v99-only change.
PiperOrigin-RevId: 254377802
Change-Id: I8d7b36748f6c7124f1b6e7a05e1beb0b27ef34ae
diff --git a/quic/core/qpack/qpack_encoder.cc b/quic/core/qpack/qpack_encoder.cc
index 67e409e..d5bea0d 100644
--- a/quic/core/qpack/qpack_encoder.cc
+++ b/quic/core/qpack/qpack_encoder.cc
@@ -6,7 +6,9 @@
#include <string>
-#include "net/third_party/quiche/src/quic/core/qpack/qpack_progressive_encoder.h"
+#include "net/third_party/quiche/src/quic/core/qpack/qpack_constants.h"
+#include "net/third_party/quiche/src/quic/core/qpack/qpack_instruction_encoder.h"
+#include "net/third_party/quiche/src/quic/core/qpack/value_splitting_header_list.h"
#include "net/third_party/quiche/src/quic/platform/api/quic_logging.h"
#include "net/third_party/quiche/src/quic/platform/api/quic_ptr_util.h"
@@ -25,16 +27,69 @@
QpackEncoder::~QpackEncoder() {}
std::string QpackEncoder::EncodeHeaderList(
- QuicStreamId stream_id,
+ QuicStreamId /* stream_id */,
const spdy::SpdyHeaderBlock* header_list) {
+ QpackInstructionEncoder instruction_encoder;
std::string encoded_headers;
- auto progressive_encoder = QuicMakeUnique<QpackProgressiveEncoder>(
- stream_id, &header_table_, &encoder_stream_sender_, header_list);
- while (progressive_encoder->HasNext()) {
- progressive_encoder->Next(
- /* max_encoded_bytes = */ std::numeric_limits<size_t>::max(),
- &encoded_headers);
+
+ // TODO(bnc): Implement dynamic entries and set Required Insert Count and
+ // Delta Base accordingly.
+ instruction_encoder.set_varint(0);
+ instruction_encoder.set_varint2(0);
+ instruction_encoder.set_s_bit(false);
+
+ instruction_encoder.Encode(QpackPrefixInstruction());
+ DCHECK(instruction_encoder.HasNext());
+ instruction_encoder.Next(std::numeric_limits<size_t>::max(),
+ &encoded_headers);
+ DCHECK(!instruction_encoder.HasNext());
+
+ for (const auto& header : ValueSplittingHeaderList(header_list)) {
+ QuicStringPiece name = header.first;
+ QuicStringPiece value = header.second;
+
+ bool is_static;
+ uint64_t index;
+
+ auto match_type =
+ header_table_.FindHeaderField(name, value, &is_static, &index);
+
+ switch (match_type) {
+ case QpackHeaderTable::MatchType::kNameAndValue:
+ DCHECK(is_static) << "Dynamic table entries not supported yet.";
+
+ instruction_encoder.set_s_bit(is_static);
+ instruction_encoder.set_varint(index);
+
+ instruction_encoder.Encode(QpackIndexedHeaderFieldInstruction());
+
+ break;
+ case QpackHeaderTable::MatchType::kName:
+ DCHECK(is_static) << "Dynamic table entries not supported yet.";
+
+ instruction_encoder.set_s_bit(is_static);
+ instruction_encoder.set_varint(index);
+ instruction_encoder.set_value(value);
+
+ instruction_encoder.Encode(
+ QpackLiteralHeaderFieldNameReferenceInstruction());
+
+ break;
+ case QpackHeaderTable::MatchType::kNoMatch:
+ instruction_encoder.set_name(name);
+ instruction_encoder.set_value(value);
+
+ instruction_encoder.Encode(QpackLiteralHeaderFieldInstruction());
+
+ break;
+ }
+
+ DCHECK(instruction_encoder.HasNext());
+ instruction_encoder.Next(std::numeric_limits<size_t>::max(),
+ &encoded_headers);
+ DCHECK(!instruction_encoder.HasNext());
}
+
return encoded_headers;
}