Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Unified Diff: net/quic/core/quic_tag.cc

Issue 2517603003: Moves QuicTag typedefs, and QuicTag utility methods to quic_tag.{h,cc}. No behavior change. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/quic/core/quic_tag.h ('k') | net/quic/core/quic_tag_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/core/quic_tag.cc
diff --git a/net/quic/core/quic_tag.cc b/net/quic/core/quic_tag.cc
new file mode 100644
index 0000000000000000000000000000000000000000..584f582ebb49934d2563cbd3e9f06338fc6b03af
--- /dev/null
+++ b/net/quic/core/quic_tag.cc
@@ -0,0 +1,72 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/quic/core/quic_tag.h"
+
+#include <algorithm>
+
+#include "base/macros.h"
+#include "base/strings/string_number_conversions.h"
+
+namespace net {
+
+bool FindMutualQuicTag(const QuicTagVector& our_tags_vector,
+ const QuicTag* their_tags,
+ size_t num_their_tags,
+ QuicTag* out_result,
+ size_t* out_index) {
+ if (our_tags_vector.empty()) {
+ return false;
+ }
+ const size_t num_our_tags = our_tags_vector.size();
+ for (size_t i = 0; i < num_our_tags; i++) {
+ for (size_t j = 0; j < num_their_tags; j++) {
+ if (our_tags_vector[i] == their_tags[j]) {
+ *out_result = our_tags_vector[i];
+ if (out_index != nullptr) {
+ *out_index = j;
+ }
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+std::string QuicTagToString(QuicTag tag) {
+ char chars[sizeof tag];
+ bool ascii = true;
+ const QuicTag orig_tag = tag;
+
+ for (size_t i = 0; i < arraysize(chars); i++) {
+ chars[i] = static_cast<char>(tag);
+ if ((chars[i] == 0 || chars[i] == '\xff') && i == arraysize(chars) - 1) {
+ chars[i] = ' ';
+ }
+ if (!isprint(static_cast<unsigned char>(chars[i]))) {
+ ascii = false;
+ break;
+ }
+ tag >>= 8;
+ }
+
+ if (ascii) {
+ return std::string(chars, sizeof(chars));
+ }
+
+ return base::UintToString(orig_tag);
+}
+
+uint32_t MakeQuicTag(char a, char b, char c, char d) {
+ return static_cast<uint32_t>(a) | static_cast<uint32_t>(b) << 8 |
+ static_cast<uint32_t>(c) << 16 | static_cast<uint32_t>(d) << 24;
+}
+
+bool ContainsQuicTag(const QuicTagVector& tag_vector, QuicTag tag) {
+ return std::find(tag_vector.begin(), tag_vector.end(), tag) !=
+ tag_vector.end();
+}
+
+} // namespace net
« no previous file with comments | « net/quic/core/quic_tag.h ('k') | net/quic/core/quic_tag_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698