| 386 | |
| 387 | template<typename Stream, VarIntMode Mode, typename I> |
| 388 | I ReadVarInt(Stream& is) |
| 389 | { |
| 390 | CheckVarIntMode<Mode, I>(); |
| 391 | I n = 0; |
| 392 | while(true) { |
| 393 | unsigned char chData = ser_readdata8(is); |
| 394 | if (n > (std::numeric_limits<I>::max() >> 7)) { |
| 395 | throw std::ios_base::failure("ReadVarInt(): size too large"); |
| 396 | } |
| 397 | n = (n << 7) | (chData & 0x7F); |
| 398 | if (chData & 0x80) { |
| 399 | if (n == std::numeric_limits<I>::max()) { |
| 400 | throw std::ios_base::failure("ReadVarInt(): size too large"); |
| 401 | } |
| 402 | n++; |
| 403 | } else { |
| 404 | return n; |
| 405 | } |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | /** Simple wrapper class to serialize objects using a formatter; used by Using(). */ |
| 410 | template<typename Formatter, typename T> |
nothing calls this directly
no test coverage detected