QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 1 | // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/third_party/quiche/src/http2/hpack/hpack_string.h" |
| 6 | |
| 7 | #include <utility> |
| 8 | |
QUICHE team | 61940b4 | 2019-03-07 23:32:27 -0500 | [diff] [blame] | 9 | #include "net/third_party/quiche/src/http2/platform/api/http2_logging.h" |
bnc | 252403d | 2020-01-15 08:39:53 -0800 | [diff] [blame] | 10 | #include "net/third_party/quiche/src/common/platform/api/quiche_str_cat.h" |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 11 | |
| 12 | namespace http2 { |
| 13 | |
| 14 | HpackString::HpackString(const char* data) : str_(data) {} |
bnc | 74646d1 | 2019-12-13 09:21:19 -0800 | [diff] [blame] | 15 | HpackString::HpackString(quiche::QuicheStringPiece str) |
| 16 | : str_(std::string(str)) {} |
bnc | 4790400 | 2019-08-16 11:49:48 -0700 | [diff] [blame] | 17 | HpackString::HpackString(std::string str) : str_(std::move(str)) {} |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 18 | HpackString::HpackString(const HpackString& other) = default; |
| 19 | HpackString::~HpackString() = default; |
| 20 | |
bnc | 74646d1 | 2019-12-13 09:21:19 -0800 | [diff] [blame] | 21 | quiche::QuicheStringPiece HpackString::ToStringPiece() const { |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 22 | return str_; |
| 23 | } |
| 24 | |
| 25 | bool HpackString::operator==(const HpackString& other) const { |
| 26 | return str_ == other.str_; |
| 27 | } |
bnc | 74646d1 | 2019-12-13 09:21:19 -0800 | [diff] [blame] | 28 | bool HpackString::operator==(quiche::QuicheStringPiece str) const { |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 29 | return str == str_; |
| 30 | } |
| 31 | |
bnc | 74646d1 | 2019-12-13 09:21:19 -0800 | [diff] [blame] | 32 | bool operator==(quiche::QuicheStringPiece a, const HpackString& b) { |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 33 | return b == a; |
| 34 | } |
bnc | 74646d1 | 2019-12-13 09:21:19 -0800 | [diff] [blame] | 35 | bool operator!=(quiche::QuicheStringPiece a, const HpackString& b) { |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 36 | return !(b == a); |
| 37 | } |
| 38 | bool operator!=(const HpackString& a, const HpackString& b) { |
| 39 | return !(a == b); |
| 40 | } |
bnc | 74646d1 | 2019-12-13 09:21:19 -0800 | [diff] [blame] | 41 | bool operator!=(const HpackString& a, quiche::QuicheStringPiece b) { |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 42 | return !(a == b); |
| 43 | } |
| 44 | std::ostream& operator<<(std::ostream& out, const HpackString& v) { |
| 45 | return out << v.ToString(); |
| 46 | } |
| 47 | |
| 48 | HpackStringPair::HpackStringPair(const HpackString& name, |
| 49 | const HpackString& value) |
| 50 | : name(name), value(value) { |
QUICHE team | 61940b4 | 2019-03-07 23:32:27 -0500 | [diff] [blame] | 51 | HTTP2_DVLOG(3) << DebugString() << " ctor"; |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 52 | } |
| 53 | |
bnc | 74646d1 | 2019-12-13 09:21:19 -0800 | [diff] [blame] | 54 | HpackStringPair::HpackStringPair(quiche::QuicheStringPiece name, |
| 55 | quiche::QuicheStringPiece value) |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 56 | : name(name), value(value) { |
QUICHE team | 61940b4 | 2019-03-07 23:32:27 -0500 | [diff] [blame] | 57 | HTTP2_DVLOG(3) << DebugString() << " ctor"; |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | HpackStringPair::~HpackStringPair() { |
QUICHE team | 61940b4 | 2019-03-07 23:32:27 -0500 | [diff] [blame] | 61 | HTTP2_DVLOG(3) << DebugString() << " dtor"; |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 62 | } |
| 63 | |
bnc | 4790400 | 2019-08-16 11:49:48 -0700 | [diff] [blame] | 64 | std::string HpackStringPair::DebugString() const { |
bnc | 252403d | 2020-01-15 08:39:53 -0800 | [diff] [blame] | 65 | return quiche::QuicheStrCat("HpackStringPair(name=", name.ToString(), |
| 66 | ", value=", value.ToString(), ")"); |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | std::ostream& operator<<(std::ostream& os, const HpackStringPair& p) { |
| 70 | os << p.DebugString(); |
| 71 | return os; |
| 72 | } |
| 73 | |
| 74 | } // namespace http2 |