MCPcopy Create free account
hub / github.com/apache/brpc / ParseH2Settings

Function ParseH2Settings

src/brpc/policy/http2_rpc_protocol.cpp:163–211  ·  view source on GitHub ↗

Parse from n bytes from the iterator. Returns true on success.

Source from the content-addressed store, hash-verified

161// Parse from n bytes from the iterator.
162// Returns true on success.
163bool ParseH2Settings(H2Settings* out, butil::IOBufBytesIterator& it, size_t n) {
164 const uint32_t npairs = n / 6;
165 if (npairs * 6 != n) {
166 LOG(ERROR) << "Invalid payload_size=" << n;
167 return false;
168 }
169 for (uint32_t i = 0; i < npairs; ++i) {
170 uint16_t id = LoadUint16(it);
171 uint32_t value = LoadUint32(it);
172 switch (static_cast<H2SettingsIdentifier>(id)) {
173 case H2_SETTINGS_HEADER_TABLE_SIZE:
174 out->header_table_size = value;
175 break;
176 case H2_SETTINGS_ENABLE_PUSH:
177 if (value > 1) {
178 LOG(ERROR) << "Invalid value=" << value << " for ENABLE_PUSH";
179 return false;
180 }
181 out->enable_push = value;
182 break;
183 case H2_SETTINGS_MAX_CONCURRENT_STREAMS:
184 out->max_concurrent_streams = value;
185 break;
186 case H2_SETTINGS_STREAM_WINDOW_SIZE:
187 if (value > H2Settings::MAX_WINDOW_SIZE) {
188 LOG(ERROR) << "Invalid stream_window_size=" << value;
189 return false;
190 }
191 out->stream_window_size = value;
192 break;
193 case H2_SETTINGS_MAX_FRAME_SIZE:
194 if (value > H2Settings::MAX_OF_MAX_FRAME_SIZE ||
195 value < H2Settings::DEFAULT_MAX_FRAME_SIZE) {
196 LOG(ERROR) << "Invalid max_frame_size=" << value;
197 return false;
198 }
199 out->max_frame_size = value;
200 break;
201 case H2_SETTINGS_MAX_HEADER_LIST_SIZE:
202 out->max_header_list_size = value;
203 break;
204 default:
205 // An endpoint that receives a SETTINGS frame with any unknown or
206 // unsupported identifier MUST ignore that setting (section 6.5.2)
207 break;
208 }
209 }
210 return true;
211}
212
213// Maximum value that may be returned by SerializeH2Settings
214static const size_t H2_SETTINGS_MAX_BYTE_SIZE = 36;

Callers 1

OnSettingsMethod · 0.85

Calls 2

LoadUint16Function · 0.85
LoadUint32Function · 0.85

Tested by

no test coverage detected