Update IETF QUIC Stop Sending to use varint for error code

Recent update to the IETF QUIC specification changed the serialization of
the Stop Sending frame's error code from uint16_t to varint ... this CL
implements that change.

Note that we still keep the error code as a uint16_t -- a later CL will update
the internal storage of error codes to uint64_t.

gfe-relnote: N/A change to IETF QUIC (V99) only.
PiperOrigin-RevId: 258404381
Change-Id: I4872cd5fce68454978880a8009c2de7ada43bdf8
diff --git a/quic/core/quic_framer.cc b/quic/core/quic_framer.cc
index 5324206..ffed8cc 100644
--- a/quic/core/quic_framer.cc
+++ b/quic/core/quic_framer.cc
@@ -665,7 +665,7 @@
 // static
 size_t QuicFramer::GetStopSendingFrameSize(const QuicStopSendingFrame& frame) {
   return kQuicFrameTypeSize + QuicDataWriter::GetVarInt62Len(frame.stream_id) +
-         sizeof(QuicApplicationErrorCode);
+         QuicDataWriter::GetVarInt62Len(frame.application_error_code);
 }
 
 // static
@@ -5853,10 +5853,20 @@
     return false;
   }
 
-  if (!reader->ReadUInt16(&stop_sending_frame->application_error_code)) {
+  uint64_t error_code;
+  if (!reader->ReadVarInt62(&error_code)) {
     set_detailed_error("Unable to read stop sending application error code.");
     return false;
   }
+  // TODO(fkastenholz): when error codes go to uint64_t, remove this.
+  if (error_code > 0xffff) {
+    stop_sending_frame->application_error_code = 0xffff;
+    QUIC_DLOG(ERROR) << "Stop sending error code (" << error_code
+                     << ") > 0xffff";
+  } else {
+    stop_sending_frame->application_error_code =
+        static_cast<uint16_t>(error_code);
+  }
   return true;
 }
 
@@ -5867,7 +5877,8 @@
     set_detailed_error("Can not write stop sending stream id");
     return false;
   }
-  if (!writer->WriteUInt16(stop_sending_frame.application_error_code)) {
+  if (!writer->WriteVarInt62(
+          static_cast<uint64_t>(stop_sending_frame.application_error_code))) {
     set_detailed_error("Can not write application error code");
     return false;
   }
diff --git a/quic/core/quic_framer_test.cc b/quic/core/quic_framer_test.cc
index 29ae36f..95b9187 100644
--- a/quic/core/quic_framer_test.cc
+++ b/quic/core/quic_framer_test.cc
@@ -11650,7 +11650,7 @@
       {"Unable to read stop sending stream id.",
        {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}},
       {"Unable to read stop sending application error code.",
-       {0x76, 0x54}},
+       {kVarInt62FourBytes + 0x00, 0x00, 0x76, 0x54}},
   };
   // clang-format on
 
@@ -11701,7 +11701,7 @@
     // Stream ID
     kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04,
     // Application error code
-    0xff, 0xff
+    kVarInt62FourBytes + 0x00, 0x00, 0xff, 0xff
   };
   // clang-format on