Add << operator for QUIC Encryption levels to make debugging easier.

No behavior change. not protected.

PiperOrigin-RevId: 313501790
Change-Id: Id4a831d0449489ee18dbd348545de914acf59cbf
diff --git a/quic/core/frames/quic_crypto_frame.cc b/quic/core/frames/quic_crypto_frame.cc
index 81b3e18..bef5f28 100644
--- a/quic/core/frames/quic_crypto_frame.cc
+++ b/quic/core/frames/quic_crypto_frame.cc
@@ -32,8 +32,7 @@
 
 std::ostream& operator<<(std::ostream& os,
                          const QuicCryptoFrame& stream_frame) {
-  os << "{ level: " << EncryptionLevelToString(stream_frame.level)
-     << ", offset: " << stream_frame.offset
+  os << "{ level: " << stream_frame.level << ", offset: " << stream_frame.offset
      << ", length: " << stream_frame.data_length << " }\n";
   return os;
 }
diff --git a/quic/core/quic_coalesced_packet.cc b/quic/core/quic_coalesced_packet.cc
index c18369e..3b22180 100644
--- a/quic/core/quic_coalesced_packet.cc
+++ b/quic/core/quic_coalesced_packet.cc
@@ -61,7 +61,7 @@
     return false;
   }
   QUIC_DVLOG(1) << "Successfully coalesced packet: encryption_level: "
-                << EncryptionLevelToString(packet.encryption_level)
+                << packet.encryption_level
                 << ", encrypted_length: " << packet.encrypted_length
                 << ", current length: " << length_
                 << ", max_packet_length: " << max_packet_length_;
diff --git a/quic/core/quic_connection.cc b/quic/core/quic_connection.cc
index 9b5274b..d6c75bf 100644
--- a/quic/core/quic_connection.cc
+++ b/quic/core/quic_connection.cc
@@ -1763,8 +1763,7 @@
     // anti-amplification limit is used, client needs to send something to avoid
     // handshake deadlock.
     QUIC_DVLOG(1) << ENDPOINT << "Failed to send control frame: " << frame
-                  << " at encryption level: "
-                  << EncryptionLevelToString(encryption_level_);
+                  << " at encryption level: " << encryption_level_;
     return false;
   }
   ScopedPacketFlusher flusher(this);
@@ -1838,9 +1837,9 @@
   QUIC_DVLOG(1) << ENDPOINT << "Received undecryptable packet of length "
                 << packet.length() << " with"
                 << (has_decryption_key ? "" : "out") << " key at level "
-                << EncryptionLevelToString(decryption_level)
+                << decryption_level
                 << " while connection is at encryption level "
-                << EncryptionLevelToString(encryption_level_);
+                << encryption_level_;
   DCHECK(EncryptionLevelIsValid(decryption_level));
   if (encryption_level_ != ENCRYPTION_FORWARD_SECURE) {
     ++stats_.undecryptable_packets_received_before_handshake_complete;
@@ -2237,9 +2236,8 @@
   QuicFrame updated_ack_frame = GetUpdatedAckFrame();
   QUIC_BUG_IF(updated_ack_frame.ack_frame->packets.Empty())
       << ENDPOINT << "Attempted to opportunistically bundle an empty "
-      << EncryptionLevelToString(encryption_level_) << " ACK, "
-      << (has_pending_ack ? "" : "!") << "has_pending_ack, stop_waiting_count_ "
-      << stop_waiting_count_;
+      << encryption_level_ << " ACK, " << (has_pending_ack ? "" : "!")
+      << "has_pending_ack, stop_waiting_count_ " << stop_waiting_count_;
   frames.push_back(updated_ack_frame);
 
   if (!no_stop_waiting_frames_) {
@@ -2355,8 +2353,7 @@
                 << (IsRetransmittable(*packet) == HAS_RETRANSMITTABLE_DATA
                         ? "data bearing "
                         : " ack only ")
-                << ", encryption level: "
-                << EncryptionLevelToString(packet->encryption_level)
+                << ", encryption level: " << packet->encryption_level
                 << ", encrypted length:" << encrypted_length
                 << ", fate: " << SerializedPacketFateToString(fate);
   QUIC_DVLOG(2) << ENDPOINT << "packet(" << packet_number << "): " << std::endl
@@ -2895,8 +2892,7 @@
 
 void QuicConnection::SetDefaultEncryptionLevel(EncryptionLevel level) {
   QUIC_DVLOG(1) << ENDPOINT << "Setting default encryption level from "
-                << EncryptionLevelToString(encryption_level_) << " to "
-                << EncryptionLevelToString(level);
+                << encryption_level_ << " to " << level;
   if (level != encryption_level_ && packet_creator_.HasPendingFrames()) {
     // Flush all queued frames when encryption level changes.
     ScopedPacketFlusher flusher(this);
@@ -3110,8 +3106,8 @@
     if (!framer_.HasEncrypterOfEncryptionLevel(level)) {
       continue;
     }
-    QUIC_DLOG(INFO) << ENDPOINT << "Sending connection close packet at level: "
-                    << EncryptionLevelToString(level);
+    QUIC_DLOG(INFO) << ENDPOINT
+                    << "Sending connection close packet at level: " << level;
     SetDefaultEncryptionLevel(level);
     // Bundle an ACK of the corresponding packet number space for debugging
     // purpose.
@@ -3983,7 +3979,7 @@
     // A forward secure packet has been received.
     QUIC_BUG_IF(encryption_level_ != ENCRYPTION_FORWARD_SECURE)
         << ENDPOINT << "Unexpected connection close encryption level "
-        << EncryptionLevelToString(encryption_level_);
+        << encryption_level_;
     return ENCRYPTION_FORWARD_SECURE;
   }
   if (framer_.HasEncrypterOfEncryptionLevel(ENCRYPTION_ZERO_RTT)) {
diff --git a/quic/core/quic_framer.cc b/quic/core/quic_framer.cc
index b05b457..e2139cf 100644
--- a/quic/core/quic_framer.cc
+++ b/quic/core/quic_framer.cc
@@ -4097,8 +4097,7 @@
   DCHECK_GE(level, decrypter_level_);
   DCHECK(!version_.KnowsWhichDecrypterToUse());
   QUIC_DVLOG(1) << ENDPOINT << "Setting decrypter from level "
-                << EncryptionLevelToString(decrypter_level_) << " to "
-                << EncryptionLevelToString(level);
+                << decrypter_level_ << " to " << level;
   decrypter_[decrypter_level_] = nullptr;
   decrypter_[level] = std::move(decrypter);
   decrypter_level_ = level;
@@ -4111,8 +4110,7 @@
   DCHECK_NE(level, decrypter_level_);
   DCHECK(!version_.KnowsWhichDecrypterToUse());
   QUIC_DVLOG(1) << ENDPOINT << "Setting alternative decrypter from level "
-                << EncryptionLevelToString(alternative_decrypter_level_)
-                << " to " << EncryptionLevelToString(level);
+                << alternative_decrypter_level_ << " to " << level;
   if (alternative_decrypter_level_ != NUM_ENCRYPTION_LEVELS) {
     decrypter_[alternative_decrypter_level_] = nullptr;
   }
@@ -4124,15 +4122,13 @@
 void QuicFramer::InstallDecrypter(EncryptionLevel level,
                                   std::unique_ptr<QuicDecrypter> decrypter) {
   DCHECK(version_.KnowsWhichDecrypterToUse());
-  QUIC_DVLOG(1) << ENDPOINT << "Installing decrypter at level "
-                << EncryptionLevelToString(level);
+  QUIC_DVLOG(1) << ENDPOINT << "Installing decrypter at level " << level;
   decrypter_[level] = std::move(decrypter);
 }
 
 void QuicFramer::RemoveDecrypter(EncryptionLevel level) {
   DCHECK(version_.KnowsWhichDecrypterToUse());
-  QUIC_DVLOG(1) << ENDPOINT << "Removing decrypter at level "
-                << EncryptionLevelToString(level);
+  QUIC_DVLOG(1) << ENDPOINT << "Removing decrypter at level " << level;
   decrypter_[level] = nullptr;
 }
 
@@ -4156,14 +4152,12 @@
                               std::unique_ptr<QuicEncrypter> encrypter) {
   DCHECK_GE(level, 0);
   DCHECK_LT(level, NUM_ENCRYPTION_LEVELS);
-  QUIC_DVLOG(1) << ENDPOINT << "Setting encrypter at level "
-                << EncryptionLevelToString(level);
+  QUIC_DVLOG(1) << ENDPOINT << "Setting encrypter at level " << level;
   encrypter_[level] = std::move(encrypter);
 }
 
 void QuicFramer::RemoveEncrypter(EncryptionLevel level) {
-  QUIC_DVLOG(1) << ENDPOINT << "Removing encrypter of "
-                << EncryptionLevelToString(level);
+  QUIC_DVLOG(1) << ENDPOINT << "Removing encrypter of " << level;
   encrypter_[level] = nullptr;
 }
 
@@ -4185,7 +4179,7 @@
   if (encrypter_[level] == nullptr) {
     QUIC_BUG << ENDPOINT
              << "Attempted to encrypt in place without encrypter at level "
-             << EncryptionLevelToString(level);
+             << level;
     RaiseError(QUIC_ENCRYPTION_FAILURE);
     return 0;
   }
@@ -4248,7 +4242,7 @@
     QUIC_BUG
         << ENDPOINT
         << "Attempted to apply header protection without encrypter at level "
-        << EncryptionLevelToString(level) << " using " << version_;
+        << level << " using " << version_;
     return false;
   }
 
@@ -4318,7 +4312,7 @@
     QUIC_DVLOG(1)
         << ENDPOINT
         << "No decrypter available for removing header protection at level "
-        << EncryptionLevelToString(expected_decryption_level);
+        << expected_decryption_level;
     return false;
   }
 
@@ -4439,7 +4433,7 @@
   DCHECK(packet_number.IsInitialized());
   if (encrypter_[level] == nullptr) {
     QUIC_BUG << ENDPOINT << "Attempted to encrypt without encrypter at level "
-             << EncryptionLevelToString(level);
+             << level;
     RaiseError(QUIC_ENCRYPTION_FAILURE);
     return 0;
   }
@@ -4474,7 +4468,7 @@
   if (encrypter_[level] == nullptr) {
     QUIC_BUG << ENDPOINT
              << "Attempted to get ciphertext size without encrypter at level "
-             << EncryptionLevelToString(level) << " using " << version_;
+             << level << " using " << version_;
     return plaintext_size;
   }
   return encrypter_[level]->GetCiphertextSize(plaintext_size);
diff --git a/quic/core/quic_packet_creator.cc b/quic/core/quic_packet_creator.cc
index d364ed3..83da774 100644
--- a/quic/core/quic_packet_creator.cc
+++ b/quic/core/quic_packet_creator.cc
@@ -47,10 +47,10 @@
     case ENCRYPTION_FORWARD_SECURE:
       QUIC_BUG
           << "Try to derive long header type for packet with encryption level: "
-          << EncryptionLevelToString(level);
+          << level;
       return INVALID_PACKET_TYPE;
     default:
-      QUIC_BUG << EncryptionLevelToString(level);
+      QUIC_BUG << level;
       return INVALID_PACKET_TYPE;
   }
 }
@@ -741,14 +741,13 @@
 
   QUIC_DVLOG(2) << ENDPOINT << "Serializing packet " << header
                 << QuicFramesToString(queued_frames_) << " at encryption_level "
-                << EncryptionLevelToString(packet_.encryption_level);
+                << packet_.encryption_level;
 
   if (!framer_->HasEncrypterOfEncryptionLevel(packet_.encryption_level)) {
     QUIC_BUG << ENDPOINT << "Attempting to serialize " << header
              << QuicFramesToString(queued_frames_)
-             << " at missing encryption_level "
-             << EncryptionLevelToString(packet_.encryption_level) << " using "
-             << framer_->version();
+             << " at missing encryption_level " << packet_.encryption_level
+             << " using " << framer_->version();
     return;
   }
 
@@ -760,8 +759,7 @@
                                packet_size_, packet_.encryption_level);
   if (length == 0) {
     QUIC_BUG << "Failed to serialize " << QuicFramesToString(queued_frames_)
-             << " at encryption_level: "
-             << EncryptionLevelToString(packet_.encryption_level)
+             << " at encryption_level: " << packet_.encryption_level
              << ", needs_full_padding_: " << needs_full_padding_
              << ", packet_.num_padding_bytes: " << packet_.num_padding_bytes
              << ", pending_padding_bytes_: " << pending_padding_bytes_;
@@ -1348,8 +1346,7 @@
       // The only pending data in the packet is non-retransmittable frames. I'm
       // assuming here that they won't occupy so much of the packet that a
       // CRYPTO frame won't fit.
-      QUIC_BUG << "Failed to ConsumeCryptoData at level "
-               << EncryptionLevelToString(level);
+      QUIC_BUG << "Failed to ConsumeCryptoData at level " << level;
       return 0;
     }
     total_bytes_consumed += frame.crypto_frame->data_length;
diff --git a/quic/core/quic_sent_packet_manager.cc b/quic/core/quic_sent_packet_manager.cc
index b407b0b..6b54afc 100644
--- a/quic/core/quic_sent_packet_manager.cc
+++ b/quic/core/quic_sent_packet_manager.cc
@@ -1362,8 +1362,7 @@
                  << ", least_unacked: " << unacked_packets_.GetLeastUnacked()
                  << ", packets_acked_: " << packets_acked_;
       } else {
-        QUIC_PEER_BUG << "Received "
-                      << EncryptionLevelToString(ack_decrypted_level)
+        QUIC_PEER_BUG << "Received " << ack_decrypted_level
                       << " ack for unackable packet: "
                       << acked_packet.packet_number << " with state: "
                       << QuicUtils::SentPacketStateToString(info->state);
@@ -1376,8 +1375,7 @@
       }
       continue;
     }
-    QUIC_DVLOG(1) << ENDPOINT << "Got an "
-                  << EncryptionLevelToString(ack_decrypted_level)
+    QUIC_DVLOG(1) << ENDPOINT << "Got an " << ack_decrypted_level
                   << " ack for packet " << acked_packet.packet_number
                   << " , state: "
                   << QuicUtils::SentPacketStateToString(info->state);
diff --git a/quic/core/quic_session.cc b/quic/core/quic_session.cc
index 56914eb..52cbd2b 100644
--- a/quic/core/quic_session.cc
+++ b/quic/core/quic_session.cc
@@ -1507,8 +1507,7 @@
   if (connection_->version().handshake_protocol == PROTOCOL_TLS1_3 &&
       (perspective() == Perspective::IS_CLIENT ||
        GetQuicReloadableFlag(quic_change_default_encryption_level))) {
-    QUIC_DVLOG(1) << ENDPOINT << "Set default encryption level to "
-                  << EncryptionLevelToString(level);
+    QUIC_DVLOG(1) << ENDPOINT << "Set default encryption level to " << level;
     QUIC_RELOADABLE_FLAG_COUNT(quic_change_default_encryption_level);
     connection()->SetDefaultEncryptionLevel(level);
     return;
@@ -1518,16 +1517,14 @@
       level == ENCRYPTION_FORWARD_SECURE) {
     // Set connection's default encryption level once 1-RTT write key is
     // available.
-    QUIC_DVLOG(1) << ENDPOINT << "Set default encryption level to "
-                  << EncryptionLevelToString(level);
+    QUIC_DVLOG(1) << ENDPOINT << "Set default encryption level to " << level;
     connection()->SetDefaultEncryptionLevel(level);
   }
 }
 
 void QuicSession::SetDefaultEncryptionLevel(EncryptionLevel level) {
   DCHECK_EQ(PROTOCOL_QUIC_CRYPTO, connection_->version().handshake_protocol);
-  QUIC_DVLOG(1) << ENDPOINT << "Set default encryption level to "
-                << EncryptionLevelToString(level);
+  QUIC_DVLOG(1) << ENDPOINT << "Set default encryption level to " << level;
   connection()->SetDefaultEncryptionLevel(level);
 
   switch (level) {
@@ -1552,8 +1549,7 @@
       }
       break;
     default:
-      QUIC_BUG << "Unknown encryption level: "
-               << EncryptionLevelToString(level);
+      QUIC_BUG << "Unknown encryption level: " << level;
   }
 }
 
@@ -1582,8 +1578,7 @@
 }
 
 void QuicSession::DiscardOldEncryptionKey(EncryptionLevel level) {
-  QUIC_DVLOG(1) << ENDPOINT << "Discard keys of "
-                << EncryptionLevelToString(level);
+  QUIC_DVLOG(1) << ENDPOINT << "Discard keys of " << level;
   if (connection()->version().handshake_protocol == PROTOCOL_TLS1_3) {
     connection()->RemoveEncrypter(level);
   }
@@ -1600,8 +1595,7 @@
       QUIC_BUG << "Tries to drop 1-RTT keys";
       break;
     default:
-      QUIC_BUG << "Unknown encryption level: "
-               << EncryptionLevelToString(level);
+      QUIC_BUG << "Unknown encryption level: " << level;
   }
 }
 
diff --git a/quic/core/quic_types.cc b/quic/core/quic_types.cc
index b44ef84..3b3f725 100644
--- a/quic/core/quic_types.cc
+++ b/quic/core/quic_types.cc
@@ -277,6 +277,11 @@
   }
 }
 
+std::ostream& operator<<(std::ostream& os, EncryptionLevel level) {
+  os << EncryptionLevelToString(level);
+  return os;
+}
+
 std::string QuicConnectionCloseTypeString(QuicConnectionCloseType type) {
   switch (type) {
     RETURN_STRING_LITERAL(GOOGLE_QUIC_CONNECTION_CLOSE);
diff --git a/quic/core/quic_types.h b/quic/core/quic_types.h
index da7ea3b..7d5930b 100644
--- a/quic/core/quic_types.h
+++ b/quic/core/quic_types.h
@@ -438,6 +438,9 @@
 
 QUIC_EXPORT_PRIVATE std::string EncryptionLevelToString(EncryptionLevel level);
 
+QUIC_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
+                                             EncryptionLevel level);
+
 // Enumeration of whether a server endpoint will request a client certificate,
 // and whether that endpoint requires a valid client certificate to establish a
 // connection.
diff --git a/quic/core/quic_utils.cc b/quic/core/quic_utils.cc
index 15424b6..1b736da 100644
--- a/quic/core/quic_utils.cc
+++ b/quic/core/quic_utils.cc
@@ -629,7 +629,7 @@
       return APPLICATION_DATA;
     default:
       QUIC_BUG << "Try to get packet number space of encryption level: "
-               << EncryptionLevelToString(encryption_level);
+               << encryption_level;
       return NUM_PACKET_NUMBER_SPACES;
   }
 }