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

Side by Side Diff: net/spdy/hpack_output_stream.cc

Issue 537663002: HPACK: encode :pseudo and indexed headers first. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months 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 unified diff | Download patch
« no previous file with comments | « net/spdy/hpack_encoder_test.cc ('k') | net/spdy/hpack_round_trip_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/spdy/hpack_output_stream.h" 5 #include "net/spdy/hpack_output_stream.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 9
10 namespace net { 10 namespace net {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 void HpackOutputStream::AppendPrefix(HpackPrefix prefix) { 42 void HpackOutputStream::AppendPrefix(HpackPrefix prefix) {
43 AppendBits(prefix.bits, prefix.bit_size); 43 AppendBits(prefix.bits, prefix.bit_size);
44 } 44 }
45 45
46 void HpackOutputStream::AppendBytes(StringPiece buffer) { 46 void HpackOutputStream::AppendBytes(StringPiece buffer) {
47 DCHECK_EQ(bit_offset_, 0u); 47 DCHECK_EQ(bit_offset_, 0u);
48 buffer_.append(buffer.data(), buffer.size()); 48 buffer_.append(buffer.data(), buffer.size());
49 } 49 }
50 50
51 void HpackOutputStream::AppendUint32(uint32 I) { 51 void HpackOutputStream::AppendUint32(uint32 I) {
52 // The algorithm below is adapted from the pseudocode in 4.1.1. 52 // The algorithm below is adapted from the pseudocode in 6.1.
53 size_t N = 8 - bit_offset_; 53 size_t N = 8 - bit_offset_;
54 uint8 max_first_byte = static_cast<uint8>((1 << N) - 1); 54 uint8 max_first_byte = static_cast<uint8>((1 << N) - 1);
55 if (I < max_first_byte) { 55 if (I < max_first_byte) {
56 AppendBits(static_cast<uint8>(I), N); 56 AppendBits(static_cast<uint8>(I), N);
57 } else { 57 } else {
58 AppendBits(max_first_byte, N); 58 AppendBits(max_first_byte, N);
59 I -= max_first_byte; 59 I -= max_first_byte;
60 while ((I & ~0x7f) != 0) { 60 while ((I & ~0x7f) != 0) {
61 buffer_.append(1, (I & 0x7f) | 0x80); 61 buffer_.append(1, (I & 0x7f) | 0x80);
62 I >>= 7; 62 I >>= 7;
63 } 63 }
64 AppendBits(static_cast<uint8>(I), 8); 64 AppendBits(static_cast<uint8>(I), 8);
65 } 65 }
66 } 66 }
67 67
68 void HpackOutputStream::TakeString(string* output) { 68 void HpackOutputStream::TakeString(string* output) {
69 // This must hold, since all public functions cause the buffer to 69 // This must hold, since all public functions cause the buffer to
70 // end on a byte boundary. 70 // end on a byte boundary.
71 DCHECK_EQ(bit_offset_, 0u); 71 DCHECK_EQ(bit_offset_, 0u);
72 buffer_.swap(*output); 72 buffer_.swap(*output);
73 buffer_.clear(); 73 buffer_.clear();
74 bit_offset_ = 0; 74 bit_offset_ = 0;
75 } 75 }
76 76
77 } // namespace net 77 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/hpack_encoder_test.cc ('k') | net/spdy/hpack_round_trip_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698