blob: 3fb3b33f35ed969c3051d62f044f79498af2fcc9 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// 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>
vasilvv872e7a32019-03-12 16:42:44 -07009#include <string>
QUICHE teama6ef0a62019-03-07 20:34:33 -050010
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 teama6ef0a62019-03-07 20:34:33 -050013
14namespace quic {
15
16QpackEncoderStreamSender::QpackEncoderStreamSender(Delegate* delegate)
17 : delegate_(delegate) {
18 DCHECK(delegate_);
19}
20
21void 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
vasilvvc48c8712019-03-11 13:38:16 -070031 std::string output;
QUICHE teama6ef0a62019-03-07 20:34:33 -050032
33 instruction_encoder_.Next(std::numeric_limits<size_t>::max(), &output);
34 DCHECK(!instruction_encoder_.HasNext());
35
36 delegate_->WriteEncoderStreamData(output);
37}
38
39void 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
vasilvvc48c8712019-03-11 13:38:16 -070047 std::string output;
QUICHE teama6ef0a62019-03-07 20:34:33 -050048
49 instruction_encoder_.Next(std::numeric_limits<size_t>::max(), &output);
50 DCHECK(!instruction_encoder_.HasNext());
51
52 delegate_->WriteEncoderStreamData(output);
53}
54
55void QpackEncoderStreamSender::SendDuplicate(uint64_t index) {
56 instruction_encoder_.set_varint(index);
57
58 instruction_encoder_.Encode(DuplicateInstruction());
59
vasilvvc48c8712019-03-11 13:38:16 -070060 std::string output;
QUICHE teama6ef0a62019-03-07 20:34:33 -050061
62 instruction_encoder_.Next(std::numeric_limits<size_t>::max(), &output);
63 DCHECK(!instruction_encoder_.HasNext());
64
65 delegate_->WriteEncoderStreamData(output);
66}
67
68void QpackEncoderStreamSender::SendSetDynamicTableCapacity(uint64_t capacity) {
69 instruction_encoder_.set_varint(capacity);
70
71 instruction_encoder_.Encode(SetDynamicTableCapacityInstruction());
72
vasilvvc48c8712019-03-11 13:38:16 -070073 std::string output;
QUICHE teama6ef0a62019-03-07 20:34:33 -050074
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