| 215 | } |
| 216 | |
| 217 | size_t LoadHeader(const char* buf, size_t len) { |
| 218 | size_t useBytes = Min<size_t>(RequireBytesForComplete_, len); |
| 219 | Header_.Append(buf, useBytes); |
| 220 | RequireBytesForComplete_ -= useBytes; |
| 221 | if (RequireBytesForComplete_) { |
| 222 | //continue load header |
| 223 | Loader_ = &TTcp2Message::LoadHeader; |
| 224 | return useBytes; |
| 225 | } |
| 226 | |
| 227 | const TBaseHeader& hdr = *reinterpret_cast<const TBaseHeader*>(Header_.Data()); |
| 228 | |
| 229 | if (hdr.Type == TBaseHeader::Request) { |
| 230 | if (Header_.Size() < sizeof(TRequestHeader)) { |
| 231 | throw yexception() << TStringBuf("invalid request header size"); |
| 232 | } |
| 233 | InitContentLoading(RequestHeader().ContentLength); |
| 234 | } else if (hdr.Type == TBaseHeader::Response) { |
| 235 | if (Header_.Size() < sizeof(TResponseHeader)) { |
| 236 | throw yexception() << TStringBuf("invalid response header size"); |
| 237 | } |
| 238 | InitContentLoading(ResponseHeader().ContentLength); |
| 239 | } else if (hdr.Type == TBaseHeader::Cancel) { |
| 240 | if (Header_.Size() < sizeof(TCancelHeader)) { |
| 241 | throw yexception() << TStringBuf("invalid cancel header size"); |
| 242 | } |
| 243 | return useBytes; |
| 244 | } else { |
| 245 | throw yexception() << TStringBuf("unsupported request type: ") << static_cast<unsigned>(hdr.Type); |
| 246 | } |
| 247 | return useBytes + (this->*Loader_)(buf + useBytes, len - useBytes); |
| 248 | } |
| 249 | |
| 250 | void InitContentLoading(size_t contentLength) { |
| 251 | RequireBytesForComplete_ = contentLength; |
nothing calls this directly
no test coverage detected