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

Unified Diff: net/http2/hpack/decoder/hpack_string_collector.cc

Issue 2293613002: Add new HTTP/2 and HPACK decoder in net/http2/. (Closed)
Patch Set: Replace LOG(INFO) by VLOG(2) in DecodeBufferTest.SlowDecodeTestStruct so that trybots do not fail. Created 4 years 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/http2/hpack/decoder/hpack_string_collector.h ('k') | net/http2/hpack/decoder/hpack_string_decoder.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http2/hpack/decoder/hpack_string_collector.cc
diff --git a/net/http2/hpack/decoder/hpack_string_collector.cc b/net/http2/hpack/decoder/hpack_string_collector.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e7e8195f748a96760c86cbba4b9bd5c282c93396
--- /dev/null
+++ b/net/http2/hpack/decoder/hpack_string_collector.cc
@@ -0,0 +1,127 @@
+// Copyright 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/http2/hpack/decoder/hpack_string_collector.h"
+
+#include <stddef.h>
+
+#include <iosfwd>
+#include <ostream>
+#include <string>
+
+#include "net/base/escape.h"
+#include "net/http2/tools/failure.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using base::StringPiece;
+
+namespace net {
+namespace test {
+namespace {
+
+std::ostream& operator<<(std::ostream& out,
+ HpackStringCollector::CollectorState v) {
+ switch (v) {
+ case HpackStringCollector::CollectorState::kGenesis:
+ return out << "kGenesis";
+ case HpackStringCollector::CollectorState::kStarted:
+ return out << "kStarted";
+ case HpackStringCollector::CollectorState::kEnded:
+ return out << "kEnded";
+ }
+ return out << "UnknownCollectorState";
+}
+
+} // namespace
+
+HpackStringCollector::HpackStringCollector() {
+ Clear();
+}
+
+HpackStringCollector::HpackStringCollector(const std::string& str, bool huffman)
+ : s(str), len(str.size()), huffman_encoded(huffman), state(kEnded) {}
+
+void HpackStringCollector::Clear() {
+ s = "";
+ len = 0;
+ huffman_encoded = false;
+ state = kGenesis;
+}
+
+bool HpackStringCollector::IsClear() const {
+ return s == "" && len == 0 && huffman_encoded == false && state == kGenesis;
+}
+
+bool HpackStringCollector::IsInProgress() const {
+ return state == kStarted;
+}
+
+bool HpackStringCollector::HasEnded() const {
+ return state == kEnded;
+}
+
+void HpackStringCollector::OnStringStart(bool huffman, size_t length) {
+ EXPECT_TRUE(IsClear()) << ToString();
+ state = kStarted;
+ huffman_encoded = huffman;
+ len = length;
+ return;
+}
+
+void HpackStringCollector::OnStringData(const char* data, size_t length) {
+ StringPiece sp(data, length);
+ EXPECT_TRUE(IsInProgress()) << ToString();
+ EXPECT_LE(sp.size(), len) << ToString();
+ sp.AppendToString(&s);
+ EXPECT_LE(s.size(), len) << ToString();
+}
+
+void HpackStringCollector::OnStringEnd() {
+ EXPECT_TRUE(IsInProgress()) << ToString();
+ EXPECT_EQ(s.size(), len) << ToString();
+ state = kEnded;
+}
+
+::testing::AssertionResult HpackStringCollector::Collected(
+ StringPiece str,
+ bool is_huffman_encoded) const {
+ VERIFY_TRUE(HasEnded());
+ VERIFY_EQ(str.size(), len);
+ VERIFY_EQ(is_huffman_encoded, huffman_encoded);
+ VERIFY_EQ(str, s);
+ return ::testing::AssertionSuccess();
+}
+
+std::string HpackStringCollector::ToString() const {
+ std::stringstream ss;
+ ss << *this;
+ return ss.str();
+}
+
+bool operator==(const HpackStringCollector& a, const HpackStringCollector& b) {
+ return a.s == b.s && a.len == b.len &&
+ a.huffman_encoded == b.huffman_encoded && a.state == b.state;
+}
+
+bool operator!=(const HpackStringCollector& a, const HpackStringCollector& b) {
+ return !(a == b);
+}
+
+std::ostream& operator<<(std::ostream& out, const HpackStringCollector& v) {
+ out << "HpackStringCollector(state=" << v.state;
+ if (v.state == HpackStringCollector::kGenesis) {
+ return out << ")";
+ }
+ if (v.huffman_encoded) {
+ out << ", Huffman Encoded";
+ }
+ out << ", Length=" << v.len;
+ if (!v.s.empty() && v.len != v.s.size()) {
+ out << " (" << v.s.size() << ")";
+ }
+ return out << ", String=\"" << EscapeQueryParamValue(v.s, false) << "\")";
+}
+
+} // namespace test
+} // namespace net
« no previous file with comments | « net/http2/hpack/decoder/hpack_string_collector.h ('k') | net/http2/hpack/decoder/hpack_string_decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698