Add LengthPrefixedConnectionId support to QuicDataReader and Writer

This is currently only used in v99 NEW_CONNECTION_ID frames but will soon be used to parse the new connection ID invariants

gfe-relnote: n/a, protected by disabled v99 flag
PiperOrigin-RevId: 258684056
Change-Id: I666d150b9392e195a073272d2c5e79bd970d5862
diff --git a/quic/core/quic_framer.cc b/quic/core/quic_framer.cc
index 1280f2e..5c9887d 100644
--- a/quic/core/quic_framer.cc
+++ b/quic/core/quic_framer.cc
@@ -6053,12 +6053,7 @@
     set_detailed_error("Can not write New Connection ID retire_prior_to");
     return false;
   }
-  if (!writer->WriteUInt8(frame.connection_id.length())) {
-    set_detailed_error(
-        "Can not write New Connection ID frame connection ID Length");
-    return false;
-  }
-  if (!writer->WriteConnectionId(frame.connection_id)) {
+  if (!writer->WriteLengthPrefixedConnectionId(frame.connection_id)) {
     set_detailed_error("Can not write New Connection ID frame connection ID");
     return false;
   }
@@ -6089,30 +6084,23 @@
     set_detailed_error("Retire_prior_to > sequence_number.");
     return false;
   }
-  uint8_t connection_id_length;
-  if (!reader->ReadUInt8(&connection_id_length)) {
-    set_detailed_error(
-        "Unable to read new connection ID frame connection id length.");
+
+  if (!reader->ReadLengthPrefixedConnectionId(&frame->connection_id)) {
+    set_detailed_error("Unable to read new connection ID frame connection id.");
     return false;
   }
 
-  if (connection_id_length > kQuicMaxConnectionIdLength) {
+  if (frame->connection_id.length() > kQuicMaxConnectionIdLength) {
     set_detailed_error("New connection ID length too high.");
     return false;
   }
 
-  if (connection_id_length != kQuicDefaultConnectionIdLength &&
-      !QuicUtils::VariableLengthConnectionIdAllowedForVersion(
-          transport_version())) {
+  if (!QuicUtils::IsConnectionIdValidForVersion(frame->connection_id,
+                                                transport_version())) {
     set_detailed_error("Invalid new connection ID length for version.");
     return false;
   }
 
-  if (!reader->ReadConnectionId(&frame->connection_id, connection_id_length)) {
-    set_detailed_error("Unable to read new connection ID frame connection id.");
-    return false;
-  }
-
   if (!reader->ReadBytes(&frame->stateless_reset_token,
                          sizeof(frame->stateless_reset_token))) {
     set_detailed_error("Can not read new connection ID frame reset token.");