Cast: Skip receiver log messages with time delta that can't be encoded.
[chromium-blink-merge.git] / net / spdy / hpack_output_stream.h
blob67c7739ecdddd4069661f48826046cd613a56857
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
3 // found in the LICENSE file.
5 #ifndef NET_SPDY_HPACK_OUTPUT_STREAM_H_
6 #define NET_SPDY_HPACK_OUTPUT_STREAM_H_
8 #include <map>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "base/macros.h"
13 #include "base/strings/string_piece.h"
14 #include "net/base/net_export.h"
15 #include "net/spdy/hpack_constants.h" // For HpackPrefix.
16 #include "net/spdy/hpack_encoding_context.h"
18 // All section references below are to
19 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-05
20 // .
22 namespace net {
24 // An HpackOutputStream handles all the low-level details of encoding
25 // header fields.
26 class NET_EXPORT_PRIVATE HpackOutputStream {
27 public:
28 // |max_string_literal_size| is the largest that any one string
29 // |literal (header name or header value) can be.
30 explicit HpackOutputStream(uint32 max_string_literal_size);
31 ~HpackOutputStream();
33 // Corresponds to 4.2.
34 void AppendIndexedHeader(uint32 index_or_zero);
36 // Corresponds to 4.3.1 (second form). Returns whether or not the
37 // append was successful; if the append was unsuccessful, no other
38 // member function may be called.
39 bool AppendLiteralHeaderNoIndexingWithName(base::StringPiece name,
40 base::StringPiece value);
42 // Moves the internal buffer to the given string and clears all
43 // internal state.
44 void TakeString(std::string* output);
46 // Appends the lower |bit_size| bits of |bits| to the internal buffer.
48 // |bit_size| must be > 0 and <= 8. |bits| must not have any bits
49 // set other than the lower |bit_size| bits.
50 void AppendBits(uint8 bits, size_t bit_size);
52 // Accessors for testing.
54 void AppendBitsForTest(uint8 bits, size_t size) {
55 AppendBits(bits, size);
58 void AppendUint32ForTest(uint32 I) {
59 AppendUint32(I);
62 bool AppendStringLiteralForTest(base::StringPiece str) {
63 return AppendStringLiteral(str);
66 private:
67 // Simply forwards to AppendBits(prefix.bits, prefix.bit-size).
68 void AppendPrefix(HpackPrefix prefix);
70 // Appends the given integer using the representation described in
71 // 4.1.1. If the internal buffer ends on a byte boundary, the prefix
72 // length N is taken to be 8; otherwise, it is taken to be the
73 // number of bits to the next byte boundary.
75 // It is guaranteed that the internal buffer will end on a byte
76 // boundary after this function is called.
77 void AppendUint32(uint32 I);
79 // Appends the given string using the representation described in
80 // 4.1.2. The internal buffer must end on a byte boundary, and it is
81 // guaranteed that the internal buffer will end on a byte boundary
82 // after this function is called. Returns whether or not the append
83 // was successful; if the append was unsuccessful, no other member
84 // function may be called.
85 bool AppendStringLiteral(base::StringPiece str);
87 const uint32 max_string_literal_size_;
89 // The internal bit buffer.
90 std::string buffer_;
92 // If 0, the buffer ends on a byte boundary. If non-zero, the buffer
93 // ends on the most significant nth bit. Guaranteed to be < 8.
94 size_t bit_offset_;
96 DISALLOW_COPY_AND_ASSIGN(HpackOutputStream);
99 } // namespace net
101 #endif // NET_SPDY_HPACK_OUTPUT_STREAM_H_