Change HTTP/3 frame type from 1 byte integer to variable length integer, and
allow partial delivery.

gfe-relnote: Used in version 99 only.
PiperOrigin-RevId: 244287295
Change-Id: Ic9a58f2822815006295f47f23f312b1f2c040f4e
diff --git a/quic/core/http/http_encoder.cc b/quic/core/http/http_encoder.cc
index beeef9b..df04be2 100644
--- a/quic/core/http/http_encoder.cc
+++ b/quic/core/http/http_encoder.cc
@@ -44,8 +44,6 @@
   }
 }
 
-// Length of the type field of a frame.
-static const size_t kFrameTypeLength = 1;
 // Length of the weight field of a priority frame.
 static const size_t kPriorityWeightLength = 1;
 // Length of a priority frame's first byte.
@@ -63,8 +61,9 @@
     QuicByteCount payload_length,
     std::unique_ptr<char[]>* output) {
   DCHECK_NE(0u, payload_length);
-  QuicByteCount header_length =
-      QuicDataWriter::GetVarInt62Len(payload_length) + kFrameTypeLength;
+  QuicByteCount header_length = QuicDataWriter::GetVarInt62Len(payload_length) +
+                                QuicDataWriter::GetVarInt62Len(
+                                    static_cast<uint64_t>(HttpFrameType::DATA));
 
   output->reset(new char[header_length]);
   QuicDataWriter writer(header_length, output->get());
@@ -80,7 +79,9 @@
     std::unique_ptr<char[]>* output) {
   DCHECK_NE(0u, payload_length);
   QuicByteCount header_length =
-      QuicDataWriter::GetVarInt62Len(payload_length) + kFrameTypeLength;
+      QuicDataWriter::GetVarInt62Len(payload_length) +
+      QuicDataWriter::GetVarInt62Len(
+          static_cast<uint64_t>(HttpFrameType::HEADERS));
 
   output->reset(new char[header_length]);
   QuicDataWriter writer(header_length, output->get());
@@ -99,7 +100,8 @@
       QuicDataWriter::GetVarInt62Len(priority.prioritized_element_id) +
       QuicDataWriter::GetVarInt62Len(priority.element_dependency_id) +
       kPriorityWeightLength;
-  QuicByteCount total_length = GetTotalLength(payload_length);
+  QuicByteCount total_length =
+      GetTotalLength(payload_length, HttpFrameType::PRIORITY);
 
   output->reset(new char[total_length]);
   QuicDataWriter writer(total_length, output->get());
@@ -130,7 +132,8 @@
     std::unique_ptr<char[]>* output) {
   QuicByteCount payload_length =
       QuicDataWriter::GetVarInt62Len(cancel_push.push_id);
-  QuicByteCount total_length = GetTotalLength(payload_length);
+  QuicByteCount total_length =
+      GetTotalLength(payload_length, HttpFrameType::CANCEL_PUSH);
 
   output->reset(new char[total_length]);
   QuicDataWriter writer(total_length, output->get());
@@ -152,7 +155,8 @@
     payload_length += QuicDataWriter::GetVarInt62Len(it->second);
   }
 
-  QuicByteCount total_length = GetTotalLength(payload_length);
+  QuicByteCount total_length =
+      GetTotalLength(payload_length, HttpFrameType::SETTINGS);
 
   output->reset(new char[total_length]);
   QuicDataWriter writer(total_length, output->get());
@@ -178,7 +182,9 @@
       push_promise.headers.length();
   // GetTotalLength() is not used because headers will not be serialized.
   QuicByteCount total_length =
-      QuicDataWriter::GetVarInt62Len(payload_length) + kFrameTypeLength +
+      QuicDataWriter::GetVarInt62Len(payload_length) +
+      QuicDataWriter::GetVarInt62Len(
+          static_cast<uint64_t>(HttpFrameType::PUSH_PROMISE)) +
       QuicDataWriter::GetVarInt62Len(push_promise.push_id);
 
   output->reset(new char[total_length]);
@@ -196,7 +202,8 @@
     std::unique_ptr<char[]>* output) {
   QuicByteCount payload_length =
       QuicDataWriter::GetVarInt62Len(goaway.stream_id);
-  QuicByteCount total_length = GetTotalLength(payload_length);
+  QuicByteCount total_length =
+      GetTotalLength(payload_length, HttpFrameType::GOAWAY);
 
   output->reset(new char[total_length]);
   QuicDataWriter writer(total_length, output->get());
@@ -213,7 +220,8 @@
     std::unique_ptr<char[]>* output) {
   QuicByteCount payload_length =
       QuicDataWriter::GetVarInt62Len(max_push_id.push_id);
-  QuicByteCount total_length = GetTotalLength(payload_length);
+  QuicByteCount total_length =
+      GetTotalLength(payload_length, HttpFrameType::MAX_PUSH_ID);
 
   output->reset(new char[total_length]);
   QuicDataWriter writer(total_length, output->get());
@@ -230,7 +238,8 @@
     std::unique_ptr<char[]>* output) {
   QuicByteCount payload_length =
       QuicDataWriter::GetVarInt62Len(duplicate_push.push_id);
-  QuicByteCount total_length = GetTotalLength(payload_length);
+  QuicByteCount total_length =
+      GetTotalLength(payload_length, HttpFrameType::DUPLICATE_PUSH);
 
   output->reset(new char[total_length]);
   QuicDataWriter writer(total_length, output->get());
@@ -247,11 +256,13 @@
                                    HttpFrameType type,
                                    QuicDataWriter* writer) {
   return writer->WriteVarInt62(length) &&
-         writer->WriteUInt8(static_cast<uint8_t>(type));
+         writer->WriteVarInt62(static_cast<uint64_t>(type));
 }
 
-QuicByteCount HttpEncoder::GetTotalLength(QuicByteCount payload_length) {
-  return QuicDataWriter::GetVarInt62Len(payload_length) + kFrameTypeLength +
+QuicByteCount HttpEncoder::GetTotalLength(QuicByteCount payload_length,
+                                          HttpFrameType type) {
+  return QuicDataWriter::GetVarInt62Len(payload_length) +
+         QuicDataWriter::GetVarInt62Len(static_cast<uint64_t>(type)) +
          payload_length;
 }