QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // Copyright (c) 2018 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. |
| 4 | |
| 5 | #include "net/third_party/quiche/src/quic/core/qpack/qpack_encoder_stream_sender.h" |
| 6 | |
| 7 | #include <cstddef> |
| 8 | #include <limits> |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 9 | #include <string> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10 | |
| 11 | #include "net/third_party/quiche/src/quic/core/qpack/qpack_constants.h" |
| 12 | #include "net/third_party/quiche/src/quic/platform/api/quic_logging.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13 | |
| 14 | namespace quic { |
| 15 | |
| 16 | QpackEncoderStreamSender::QpackEncoderStreamSender(Delegate* delegate) |
| 17 | : delegate_(delegate) { |
| 18 | DCHECK(delegate_); |
| 19 | } |
| 20 | |
| 21 | void QpackEncoderStreamSender::SendInsertWithNameReference( |
| 22 | bool is_static, |
| 23 | uint64_t name_index, |
| 24 | QuicStringPiece value) { |
| 25 | instruction_encoder_.set_s_bit(is_static); |
| 26 | instruction_encoder_.set_varint(name_index); |
| 27 | instruction_encoder_.set_value(value); |
| 28 | |
| 29 | instruction_encoder_.Encode(InsertWithNameReferenceInstruction()); |
| 30 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 31 | std::string output; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 32 | |
| 33 | instruction_encoder_.Next(std::numeric_limits<size_t>::max(), &output); |
| 34 | DCHECK(!instruction_encoder_.HasNext()); |
| 35 | |
| 36 | delegate_->WriteEncoderStreamData(output); |
| 37 | } |
| 38 | |
| 39 | void QpackEncoderStreamSender::SendInsertWithoutNameReference( |
| 40 | QuicStringPiece name, |
| 41 | QuicStringPiece value) { |
| 42 | instruction_encoder_.set_name(name); |
| 43 | instruction_encoder_.set_value(value); |
| 44 | |
| 45 | instruction_encoder_.Encode(InsertWithoutNameReferenceInstruction()); |
| 46 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 47 | std::string output; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 48 | |
| 49 | instruction_encoder_.Next(std::numeric_limits<size_t>::max(), &output); |
| 50 | DCHECK(!instruction_encoder_.HasNext()); |
| 51 | |
| 52 | delegate_->WriteEncoderStreamData(output); |
| 53 | } |
| 54 | |
| 55 | void QpackEncoderStreamSender::SendDuplicate(uint64_t index) { |
| 56 | instruction_encoder_.set_varint(index); |
| 57 | |
| 58 | instruction_encoder_.Encode(DuplicateInstruction()); |
| 59 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 60 | std::string output; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 61 | |
| 62 | instruction_encoder_.Next(std::numeric_limits<size_t>::max(), &output); |
| 63 | DCHECK(!instruction_encoder_.HasNext()); |
| 64 | |
| 65 | delegate_->WriteEncoderStreamData(output); |
| 66 | } |
| 67 | |
| 68 | void QpackEncoderStreamSender::SendSetDynamicTableCapacity(uint64_t capacity) { |
| 69 | instruction_encoder_.set_varint(capacity); |
| 70 | |
| 71 | instruction_encoder_.Encode(SetDynamicTableCapacityInstruction()); |
| 72 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 73 | std::string output; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 74 | |
| 75 | instruction_encoder_.Next(std::numeric_limits<size_t>::max(), &output); |
| 76 | DCHECK(!instruction_encoder_.HasNext()); |
| 77 | |
| 78 | delegate_->WriteEncoderStreamData(output); |
| 79 | } |
| 80 | |
| 81 | } // namespace quic |