15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file. 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#ifndef NET_SPDY_HPACK_OUTPUT_STREAM_H_ 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define NET_SPDY_HPACK_OUTPUT_STREAM_H_ 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <map> 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <string> 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/basictypes.h" 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/macros.h" 135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/strings/string_piece.h" 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "net/base/net_export.h" 155c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "net/spdy/hpack_constants.h" 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// All section references below are to 18116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-08 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace net { 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// An HpackOutputStream handles all the low-level details of encoding 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// header fields. 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class NET_EXPORT_PRIVATE HpackOutputStream { 255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public: 265c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu explicit HpackOutputStream(); 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ~HpackOutputStream(); 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 29a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Appends the lower |bit_size| bits of |bits| to the internal buffer. 30a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // 31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // |bit_size| must be > 0 and <= 8. |bits| must not have any bits 32a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // set other than the lower |bit_size| bits. 33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) void AppendBits(uint8 bits, size_t bit_size); 34a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Simply forwards to AppendBits(prefix.bits, prefix.bit-size). 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void AppendPrefix(HpackPrefix prefix); 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 385c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Directly appends |buffer|. 395c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu void AppendBytes(base::StringPiece buffer); 405c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Appends the given integer using the representation described in 42116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // 6.1. If the internal buffer ends on a byte boundary, the prefix 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // length N is taken to be 8; otherwise, it is taken to be the 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // number of bits to the next byte boundary. 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // It is guaranteed that the internal buffer will end on a byte 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // boundary after this function is called. 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void AppendUint32(uint32 I); 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 505c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Swaps the interal buffer with |output|. 515c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu void TakeString(std::string* output); 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 535c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu private: 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // The internal bit buffer. 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string buffer_; 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // If 0, the buffer ends on a byte boundary. If non-zero, the buffer 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // ends on the most significant nth bit. Guaranteed to be < 8. 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) size_t bit_offset_; 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(HpackOutputStream); 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}; 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace net 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif // NET_SPDY_HPACK_OUTPUT_STREAM_H_ 67