summaryrefslogtreecommitdiffstats
path: root/net/spdy/hpack_entry.cc
blob: 169298e1c52d76d661f07e9b5456690642802f97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2014 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/spdy/hpack_entry.h"

#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "net/spdy/hpack_string_util.h"

namespace net {

using base::StringPiece;

const size_t HpackEntry::kSizeOverhead = 32;

HpackEntry::HpackEntry(StringPiece name,
                       StringPiece value,
                       bool is_static,
                       size_t insertion_index)
    : name_(name.data(), name.size()),
      value_(value.data(), value.size()),
      insertion_index_(insertion_index),
      type_(is_static ? STATIC : DYNAMIC) {
}

HpackEntry::HpackEntry(StringPiece name, StringPiece value)
    : name_(name.data(), name.size()),
      value_(value.data(), value.size()),
      insertion_index_(0),
      type_(LOOKUP) {
}

HpackEntry::HpackEntry()
    : insertion_index_(0),
      type_(LOOKUP) {
}

HpackEntry::~HpackEntry() {}

// static
size_t HpackEntry::Size(StringPiece name, StringPiece value) {
  return name.size() + value.size() + kSizeOverhead;
}
size_t HpackEntry::Size() const {
  return Size(name(), value());
}

std::string HpackEntry::GetDebugString() const {
  return "{ name: \"" + name_ +
      "\", value: \"" + value_ +
      "\", " + (IsStatic() ? "static" : "dynamic") + " }";
}

}  // namespace net