Commit 4ee89e62 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

nghttp2_hd: Refactor a bit

parent ee65dea8
...@@ -436,51 +436,41 @@ static size_t count_encoded_length(size_t n, size_t prefix) ...@@ -436,51 +436,41 @@ static size_t count_encoded_length(size_t n, size_t prefix)
{ {
size_t k = (1 << prefix) - 1; size_t k = (1 << prefix) - 1;
size_t len = 0; size_t len = 0;
if(n >= k) {
n -= k; if(n < k) {
++len;
} else {
return 1; return 1;
} }
do {
++len; n -= k;
if(n >= 128) { ++len;
n >>= 7;
} else { for(; n >= 128; n >>= 7, ++len);
break;
} return len + 1;
} while(n);
return len;
} }
static size_t encode_length(uint8_t *buf, size_t n, size_t prefix) static size_t encode_length(uint8_t *buf, size_t n, size_t prefix)
{ {
size_t k = (1 << prefix) - 1; size_t k = (1 << prefix) - 1;
size_t len = 0; uint8_t *begin = buf;
*buf &= ~k; *buf &= ~k;
if(n < k) { if(n < k) {
*buf++ |= n; *buf |= n;
return 1; return 1;
} }
*buf++ |= k; *buf++ |= k;
n -= k; n -= k;
++len;
do { for(; n >= 128; n >>= 7) {
++len; *buf++ = (1 << 7) | (n & 0x7f);
if(n >= 128) { }
*buf++ = (1 << 7) | (n & 0x7f);
n >>= 7; *buf++ = (uint8_t)n;
} else {
*buf++ = (uint8_t)n; return (size_t)(buf - begin);
break;
}
} while(n);
return len;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment