| 694 | } |
| 695 | |
| 696 | void HPacker::Encode(butil::IOBufAppender* out, const Header& header, |
| 697 | const HPackOptions& options) { |
| 698 | if (options.index_policy != HPACK_NEVER_INDEX_HEADER) { |
| 699 | const int index = FindHeaderFromIndexTable(header); |
| 700 | if (index > 0) { |
| 701 | // This header is already in the index table |
| 702 | return EncodeInteger(out, 0x80, 7, index); |
| 703 | } |
| 704 | } // The header can't be indexed or the header wasn't in the index table |
| 705 | |
| 706 | const int name_index = FindNameFromIndexTable(header.name); |
| 707 | if (options.index_policy == HPACK_INDEX_HEADER) { |
| 708 | // TODO: Add Options that indexes name independently |
| 709 | _encode_table->AddHeader(header); |
| 710 | } |
| 711 | switch (options.index_policy) { |
| 712 | case HPACK_INDEX_HEADER: |
| 713 | EncodeInteger(out, 0x40, 6, name_index); |
| 714 | break; |
| 715 | case HPACK_NOT_INDEX_HEADER: |
| 716 | EncodeInteger(out, 0x00, 4, name_index); |
| 717 | break; |
| 718 | case HPACK_NEVER_INDEX_HEADER: |
| 719 | EncodeInteger(out, 0x10, 4, name_index); |
| 720 | break; |
| 721 | } |
| 722 | if (name_index == 0) { |
| 723 | EncodeString<true>(out, header.name, options.encode_name); |
| 724 | } |
| 725 | EncodeString<false>(out, header.value, options.encode_value); |
| 726 | } |
| 727 | |
| 728 | inline const HPacker::Header* HPacker::HeaderAt(int index) const { |
| 729 | return (index >= _decode_table->start_index()) |
no test coverage detected