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_
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
24 // An HpackOutputStream handles all the low-level details of encoding
26 class NET_EXPORT_PRIVATE HpackOutputStream
{
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
);
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
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
) {
62 bool AppendStringLiteralForTest(base::StringPiece str
) {
63 return AppendStringLiteral(str
);
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.
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.
96 DISALLOW_COPY_AND_ASSIGN(HpackOutputStream
);
101 #endif // NET_SPDY_HPACK_OUTPUT_STREAM_H_