Refactor QpackEncoder::EncodeHeaderList().
FirstPassEncode() currently is only 42 lines long, but soon it is going to grow
to about 200 lines. It is beneficial to break EncodeHeaderList() into two
pieces, not only because it would otherwise be getting too long, but also to
better highlight what information is the product of the first pass and what gets
passed into the second pass.
Also change from list<InstructionWithValues> to vector<InstructionWithValues>, because reserve() can be called with the final size at construction time, making vector more efficient.
Also add TODO to send dynamic table capacity update.
gfe-relnote: n/a, change to QUIC v99-only code. Protected by existing disabled gfe2_reloadable_flag_quic_enable_version_99.
PiperOrigin-RevId: 262659191
Change-Id: I61a5fbcd6816238a8436d49fc85b2d7dae5089c6
diff --git a/quic/core/qpack/qpack_encoder.cc b/quic/core/qpack/qpack_encoder.cc
index 1252845..ddceef0 100644
--- a/quic/core/qpack/qpack_encoder.cc
+++ b/quic/core/qpack/qpack_encoder.cc
@@ -4,7 +4,7 @@
#include "net/third_party/quiche/src/quic/core/qpack/qpack_encoder.h"
-#include <list>
+#include <utility>
#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"
@@ -25,13 +25,10 @@
QpackEncoder::~QpackEncoder() {}
-std::string QpackEncoder::EncodeHeaderList(
- QuicStreamId /* stream_id */,
+QpackEncoder::Instructions QpackEncoder::FirstPassEncode(
const spdy::SpdyHeaderBlock* header_list) {
- // First pass.
-
- // Encode into |instructions| which will be serialized during the second pass.
- std::list<InstructionWithValues> instructions;
+ Instructions instructions;
+ instructions.reserve(header_list->size());
for (const auto& header : ValueSplittingHeaderList(header_list)) {
QuicStringPiece name = header.first;
@@ -71,11 +68,12 @@
}
}
- // TODO(bnc): Implement dynamic entries and set Required Insert Count
- // accordingly.
- const uint64_t required_insert_count = 0;
+ return instructions;
+}
- // Second pass.
+std::string QpackEncoder::SecondPassEncode(
+ QpackEncoder::Instructions instructions,
+ uint64_t required_insert_count) const {
QpackInstructionEncoder instruction_encoder;
std::string encoded_headers;
@@ -97,8 +95,24 @@
return encoded_headers;
}
+std::string QpackEncoder::EncodeHeaderList(
+ QuicStreamId /* stream_id */,
+ const spdy::SpdyHeaderBlock* header_list) {
+ // First pass: encode into |instructions|.
+ Instructions instructions = FirstPassEncode(header_list);
+
+ // TODO(bnc): Implement dynamic entries and set Required Insert Count
+ // accordingly.
+ const uint64_t required_insert_count = 0;
+
+ // Second pass.
+ return SecondPassEncode(std::move(instructions), required_insert_count);
+}
+
void QpackEncoder::SetMaximumDynamicTableCapacity(
uint64_t maximum_dynamic_table_capacity) {
+ // TODO(b/112770235): Send set dynamic table capacity instruction on encoder
+ // stream.
header_table_.SetMaximumDynamicTableCapacity(maximum_dynamic_table_capacity);
}
diff --git a/quic/core/qpack/qpack_encoder.h b/quic/core/qpack/qpack_encoder.h
index 20f7f5f..1ced7fa 100644
--- a/quic/core/qpack/qpack_encoder.h
+++ b/quic/core/qpack/qpack_encoder.h
@@ -8,6 +8,7 @@
#include <cstdint>
#include <memory>
#include <string>
+#include <vector>
#include "net/third_party/quiche/src/quic/core/qpack/qpack_decoder_stream_receiver.h"
#include "net/third_party/quiche/src/quic/core/qpack/qpack_encoder_stream_sender.h"
@@ -53,6 +54,8 @@
// Set maximum capacity of dynamic table, measured in bytes.
// Called when SETTINGS_QPACK_MAX_TABLE_CAPACITY is received.
+ // Sends set dynamic table capacity instruction on encoder stream.
+ // TODO(b/112770235): Actually send set dynamic table capacity instruction.
void SetMaximumDynamicTableCapacity(uint64_t maximum_dynamic_table_capacity);
// Set maximum number of blocked streams.
@@ -91,6 +94,17 @@
const QpackInstruction* instruction;
QpackInstructionEncoder::Values values;
};
+ using Instructions = std::vector<InstructionWithValues>;
+
+ // Perform first pass of two-pass encoding: represent each header field as a
+ // reference to an existing entry, the name of an existing entry with a
+ // literal value, or a literal name and value pair.
+ Instructions FirstPassEncode(const spdy::SpdyHeaderBlock* header_list);
+
+ // Perform second pass of two-pass encoding: serialize representations
+ // generated in first pass.
+ std::string SecondPassEncode(Instructions instructions,
+ uint64_t required_insert_count) const;
DecoderStreamErrorDelegate* const decoder_stream_error_delegate_;
QpackDecoderStreamReceiver decoder_stream_receiver_;