Change HTTP/3 frames from Lengh-Type-Value to Type-Length-Value.

Updating to IETF draft 19.

gfe-relnote: n/a --version 99 only, not yet enabled.
PiperOrigin-RevId: 244687780
Change-Id: Id8f42caad0c1dd2978e1a0a45aa2f462dcd0bcf8
diff --git a/quic/core/http/http_decoder.cc b/quic/core/http/http_decoder.cc
index 653652f..eff9efc 100644
--- a/quic/core/http/http_decoder.cc
+++ b/quic/core/http/http_decoder.cc
@@ -33,7 +33,7 @@
 
 HttpDecoder::HttpDecoder()
     : visitor_(nullptr),
-      state_(STATE_READING_FRAME_LENGTH),
+      state_(STATE_READING_FRAME_TYPE),
       current_frame_type_(0),
       current_length_field_size_(0),
       remaining_length_field_length_(0),
@@ -51,12 +51,12 @@
   while (error_ == QUIC_NO_ERROR &&
          (reader.BytesRemaining() != 0 || state_ == STATE_FINISH_PARSING)) {
     switch (state_) {
-      case STATE_READING_FRAME_LENGTH:
-        ReadFrameLength(&reader);
-        break;
       case STATE_READING_FRAME_TYPE:
         ReadFrameType(&reader);
         break;
+      case STATE_READING_FRAME_LENGTH:
+        ReadFrameLength(&reader);
+        break;
       case STATE_READING_FRAME_PAYLOAD:
         ReadFramePayload(&reader);
         break;
@@ -77,24 +77,6 @@
   return len - reader.BytesRemaining();
 }
 
-void HttpDecoder::ReadFrameLength(QuicDataReader* reader) {
-  DCHECK_NE(0u, reader->BytesRemaining());
-  BufferFrameLength(reader);
-  if (remaining_length_field_length_ != 0) {
-    return;
-  }
-  QuicDataReader length_reader(length_buffer_.data(),
-                               current_length_field_size_);
-  if (!length_reader.ReadVarInt62(&current_frame_length_)) {
-    RaiseError(QUIC_INTERNAL_ERROR, "Unable to read frame length");
-    visitor_->OnError(this);
-    return;
-  }
-
-  state_ = STATE_READING_FRAME_TYPE;
-  remaining_frame_length_ = current_frame_length_;
-}
-
 void HttpDecoder::ReadFrameType(QuicDataReader* reader) {
   DCHECK_NE(0u, reader->BytesRemaining());
   if (current_type_field_length_ == 0) {
@@ -132,6 +114,23 @@
     }
   }
 
+  state_ = STATE_READING_FRAME_LENGTH;
+}
+
+void HttpDecoder::ReadFrameLength(QuicDataReader* reader) {
+  DCHECK_NE(0u, reader->BytesRemaining());
+  BufferFrameLength(reader);
+  if (remaining_length_field_length_ != 0) {
+    return;
+  }
+  QuicDataReader length_reader(length_buffer_.data(),
+                               current_length_field_size_);
+  if (!length_reader.ReadVarInt62(&current_frame_length_)) {
+    RaiseError(QUIC_INTERNAL_ERROR, "Unable to read frame length");
+    visitor_->OnError(this);
+    return;
+  }
+
   if (current_frame_length_ > MaxFrameLength(current_frame_type_)) {
     RaiseError(QUIC_INTERNAL_ERROR, "Frame is too large");
     visitor_->OnError(this);
@@ -154,6 +153,7 @@
         current_frame_length_));
   }
 
+  remaining_frame_length_ = current_frame_length_;
   state_ = (remaining_frame_length_ == 0) ? STATE_FINISH_PARSING
                                           : STATE_READING_FRAME_PAYLOAD;
 }
@@ -266,6 +266,7 @@
       QUIC_FALLTHROUGH_INTENDED;
     default:
       DiscardFramePayload(reader);
+      return;
   }
 
   if (remaining_frame_length_ == 0) {
@@ -365,7 +366,7 @@
 
   current_length_field_size_ = 0;
   current_type_field_length_ = 0;
-  state_ = STATE_READING_FRAME_LENGTH;
+  state_ = STATE_READING_FRAME_TYPE;
 }
 
 void HttpDecoder::DiscardFramePayload(QuicDataReader* reader) {
@@ -378,7 +379,7 @@
   }
   remaining_frame_length_ -= payload.length();
   if (remaining_frame_length_ == 0) {
-    state_ = STATE_READING_FRAME_LENGTH;
+    state_ = STATE_READING_FRAME_TYPE;
     current_length_field_size_ = 0;
     current_type_field_length_ = 0;
   }