Introduce QuicUtils::InvertPerspective and refactor code to use it

gfe-relnote: quic perspective refactor, no behavior change
PiperOrigin-RevId: 255318447
Change-Id: I10a7cb3478382f851d3f5a1293a248918ec95844
diff --git a/quic/core/quic_utils.h b/quic/core/quic_utils.h
index bac025e..294f52f 100644
--- a/quic/core/quic_utils.h
+++ b/quic/core/quic_utils.h
@@ -85,6 +85,12 @@
   // Creates an iovec pointing to the same data as |data|.
   static struct iovec MakeIovec(QuicStringPiece data);
 
+  // Returns the opposite Perspective of the |perspective| passed in.
+  static constexpr Perspective InvertPerspective(Perspective perspective) {
+    return perspective == Perspective::IS_CLIENT ? Perspective::IS_SERVER
+                                                 : Perspective::IS_CLIENT;
+  }
+
   // Returns true if a packet is ackable. A packet is unackable if it can never
   // be acked. Occurs when a packet is never sent, after it is acknowledged
   // once, or if it's a crypto packet we never expect to receive an ack for.