| 50 | } |
| 51 | |
| 52 | void ProtocolBuffer::Reset() { |
| 53 | if (_writeIndex > _contentLength + _bodyStartIndex) { |
| 54 | std::size_t doneIndex = _contentLength + _bodyStartIndex; |
| 55 | std::copy_n(_textProtocol.data() + doneIndex, _writeIndex - doneIndex, _textProtocol.data()); |
| 56 | |
| 57 | _writeIndex -= doneIndex; |
| 58 | if (_writeIndex > _normalCapacity) { |
| 59 | _textProtocol.resize(_writeIndex); |
| 60 | _textProtocol.shrink_to_fit(); |
| 61 | } else { |
| 62 | _textProtocol.resize(_normalCapacity); |
| 63 | _textProtocol.shrink_to_fit(); |
| 64 | } |
| 65 | } else { |
| 66 | _writeIndex = 0; |
| 67 | if (_textProtocol.size() > _normalCapacity) { |
| 68 | _textProtocol.resize(_normalCapacity); |
| 69 | _textProtocol.shrink_to_fit(); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | _contentLength = 0; |
| 74 | _bodyStartIndex = 0; |
| 75 | } |
| 76 | |
| 77 | bool ProtocolBuffer::TryParseHead() { |
| 78 | enum class ParseState { |