Refactor ExpansionOnNewFrameWithLastFrame out from ExpansionOnNewFrame. This new function will be used later.

PiperOrigin-RevId: 318464492
Change-Id: I37a7d4aa77350f277def804a1675e3b33d5568e4
diff --git a/quic/core/quic_packet_creator.cc b/quic/core/quic_packet_creator.cc
index 07be112..a31b179 100644
--- a/quic/core/quic_packet_creator.cc
+++ b/quic/core/quic_packet_creator.cc
@@ -704,22 +704,23 @@
 size_t QuicPacketCreator::ExpansionOnNewFrame() const {
   // If the last frame in the packet is a message frame, then it will expand to
   // include the varint message length when a new frame is added.
-  const bool has_trailing_message_frame =
-      !queued_frames_.empty() && queued_frames_.back().type == MESSAGE_FRAME;
-  if (has_trailing_message_frame) {
-    return QuicDataWriter::GetVarInt62Len(
-        queued_frames_.back().message_frame->message_length);
+  if (queued_frames_.empty()) {
+    return 0;
   }
-  // If the last frame in the packet is a stream frame, then it will expand to
-  // include the stream_length field when a new frame is added.
-  const bool has_trailing_stream_frame =
-      !queued_frames_.empty() && queued_frames_.back().type == STREAM_FRAME;
-  if (!has_trailing_stream_frame) {
+  return ExpansionOnNewFrameWithLastFrame(queued_frames_.back());
+}
+
+size_t QuicPacketCreator::ExpansionOnNewFrameWithLastFrame(
+    const QuicFrame& last_frame) const {
+  if (last_frame.type == MESSAGE_FRAME) {
+    return QuicDataWriter::GetVarInt62Len(
+        last_frame.message_frame->message_length);
+  }
+  if (last_frame.type != STREAM_FRAME) {
     return 0;
   }
   if (VersionHasIetfQuicFrames(framer_->transport_version())) {
-    return QuicDataWriter::GetVarInt62Len(
-        queued_frames_.back().stream_frame.data_length);
+    return QuicDataWriter::GetVarInt62Len(last_frame.stream_frame.data_length);
   }
   return kQuicStreamPayloadLengthSize;
 }
diff --git a/quic/core/quic_packet_creator.h b/quic/core/quic_packet_creator.h
index 76d6557..ddc5e2d 100644
--- a/quic/core/quic_packet_creator.h
+++ b/quic/core/quic_packet_creator.h
@@ -190,6 +190,10 @@
   // amount of expected expansion.
   size_t ExpansionOnNewFrame() const;
 
+  // Returns the number of bytes that the packet will expand by when a new frame
+  // is going to be added. |last_frame| is the last frame of the packet.
+  size_t ExpansionOnNewFrameWithLastFrame(const QuicFrame& last_frame) const;
+
   // Returns the number of bytes in the current packet, including the header,
   // if serialized with the current frames.  Adding a frame to the packet
   // may change the serialized length of existing frames, as per the comment