comparison src/http/v3/ngx_http_v3_parse.c @ 8455:b0e81f49d7c0 quic

HTTP/3: fixed prefixed integer encoding and decoding. Previously bytes were ordered from MSB to LSB, but the right order is the reverse.
author Roman Arutyunyan <arut@nginx.com>
date Thu, 02 Jul 2020 15:15:55 +0300
parents 032cb35ce758
children c9538aef3211
comparison
equal deleted inserted replaced
8454:032cb35ce758 8455:b0e81f49d7c0
89 89
90 ngx_int_t 90 ngx_int_t
91 ngx_http_v3_parse_prefix_int(ngx_connection_t *c, 91 ngx_http_v3_parse_prefix_int(ngx_connection_t *c,
92 ngx_http_v3_parse_prefix_int_t *st, ngx_uint_t prefix, u_char ch) 92 ngx_http_v3_parse_prefix_int_t *st, ngx_uint_t prefix, u_char ch)
93 { 93 {
94 ngx_uint_t mask;
94 enum { 95 enum {
95 sw_start = 0, 96 sw_start = 0,
96 sw_value 97 sw_value
97 }; 98 };
98 99
99 switch (st->state) { 100 switch (st->state) {
100 101
101 case sw_start: 102 case sw_start:
102 103
103 st->mask = (1 << prefix) - 1; 104 mask = (1 << prefix) - 1;
104 st->value = (ch & st->mask); 105 st->value = ch & mask;
105 106
106 if (st->value != st->mask) { 107 if (st->value != mask) {
107 goto done; 108 goto done;
108 } 109 }
109 110
110 st->value = 0; 111 st->shift = 0;
111 st->state = sw_value; 112 st->state = sw_value;
112 break; 113 break;
113 114
114 case sw_value: 115 case sw_value:
115 116
116 st->value = (st->value << 7) + (ch & 0x7f); 117 st->value += (ch & 0x7f) << st->shift;
117 if (ch & 0x80) { 118 if (ch & 0x80) {
118 break; 119 st->shift += 7;
119 } 120 break;
120 121 }
121 st->value += st->mask; 122
122 goto done; 123 goto done;
123 } 124 }
124 125
125 return NGX_AGAIN; 126 return NGX_AGAIN;
126 127