Skip to content

Commit

Permalink
add decoder precondition comment
Browse files Browse the repository at this point in the history
  • Loading branch information
kelbon committed Oct 19, 2024
1 parent c03c832 commit 35bd16f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/hpack/decoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ struct header_view {
}
};

// precondition: in != e
void decode_string(In& in, In e, decoded_string& out);

struct decoder {
Expand All @@ -139,10 +140,12 @@ struct decoder {
https://www.rfc-editor.org/rfc/rfc7540#section-8.1.2.5
and protocol error if decoded header name is not lowercase
*/
// precondition: in != e
void decode_header(In& in, In e, header_view& out);

// returns status code
// its always first header of response, so 'in' must point to first byte of headers block
// precondition: in != e
int decode_response_status(In& in, In e);
};

Expand Down
3 changes: 3 additions & 0 deletions src/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ static size_type decode_dynamic_table_size_update(In& in, In e) noexcept {
}

void decode_string(In& in, In e, decoded_string& out) {
assert(in != e);
bool is_huffman = *in & 0b1000'0000;
size_type str_len = decode_integer(in, e, 7);
if (str_len > std::distance(in, e))
Expand All @@ -165,6 +166,7 @@ void decode_string(In& in, In e, decoded_string& out) {
}

void decoder::decode_header(In& in, In e, header_view& out) {
assert(in != e);
if (*in & 0b1000'0000)
return decode_header_fully_indexed(in, e, dyntab, out);
if (*in & 0b0100'0000)
Expand All @@ -183,6 +185,7 @@ void decoder::decode_header(In& in, In e, header_view& out) {
}

int decoder::decode_response_status(In& in, In e) {
assert(in != e);
if (*in & 0b1000'0000) {
// fast path, fully indexed
auto in_before = in;
Expand Down

0 comments on commit 35bd16f

Please sign in to comment.