| 93 | } |
| 94 | |
| 95 | static unsigned int decodeVByte(const unsigned char*& data) |
| 96 | { |
| 97 | unsigned char lead = *data++; |
| 98 | |
| 99 | // fast path: single byte |
| 100 | if (lead < 128) |
| 101 | return lead; |
| 102 | |
| 103 | // slow path: up to 4 extra bytes |
| 104 | // note that this loop always terminates, which is important for malformed data |
| 105 | unsigned int result = lead & 127; |
| 106 | unsigned int shift = 7; |
| 107 | |
| 108 | for (int i = 0; i < 4; ++i) |
| 109 | { |
| 110 | unsigned char group = *data++; |
| 111 | result |= unsigned(group & 127) << shift; |
| 112 | shift += 7; |
| 113 | |
| 114 | if (group < 128) |
| 115 | break; |
| 116 | } |
| 117 | |
| 118 | return result; |
| 119 | } |
| 120 | |
| 121 | static void encodeIndex(unsigned char*& data, unsigned int index, unsigned int last) |
| 122 | { |
no outgoing calls
no test coverage detected