@@ -40,8 +40,8 @@ namespace util {
4040 * @parma outputSizePtr A pointer to a single integer that is set to the number of bytes used in the output memory.
4141 */
4242template <typename int_t = uint64_t >
43- void encodeVarint (int_t value, uint8_t * output, uint8_t * outputSizePtr) {
44- uint8_t outputSize = 0 ;
43+ void encodeVarint (int_t value, uint8_t * output, size_t * outputSizePtr) {
44+ size_t outputSize = 0 ;
4545 // While more than 7 bits of data are left, occupy the last output byte
4646 // and set the next byte flag
4747 while (value > 127 ) {
@@ -63,8 +63,8 @@ void encodeVarint(int_t value, uint8_t* output, uint8_t* outputSizePtr) {
6363 * @parma outputSizePtr A pointer to a single integer that is set to the number of bytes used in the output memory.
6464 */
6565template <typename int_t = uint64_t >
66- void encodeVarshort (int_t value, uint16_t * output, uint8_t * outputSizePtr) {
67- uint8_t outputSize = 0 ;
66+ void encodeVarshort (int_t value, uint16_t * output, size_t * outputSizePtr) {
67+ size_t outputSize = 0 ;
6868 // While more than 15 bits of data are left, occupy the last output byte
6969 // and set the next byte flag
7070 while (value > 32767 ) {
@@ -115,16 +115,19 @@ size_t getVarshortLength(int_t value){
115115 * @param output the buffer to write to
116116 */
117117template <typename int_t = uint64_t , typename buffer_t >
118- void encodeVarint (int_t value, buffer_t & output) {
118+ void encodeVarint (int_t value, buffer_t & output, size_t * written_bytes ) {
119119 // While more than 7 bits of data are left, occupy the last output byte
120120 // and set the next byte flag
121+ size_t length = 0 ;
121122 while (value > 127 ) {
122123 // |128: Set the next byte flag
123124 output.push_back (((uint8_t ) (value & 127 )) | 128 );
124125 // Remove the seven bits we just wrote
125126 value >>= 7 ;
127+ ++length;
126128 }
127129 output.push_back (((uint8_t ) value) & 127 );
130+ *written_bytes = ++length;
128131}
129132
130133/* *
@@ -178,7 +181,7 @@ inline size_t skipVarint(const char* input) {
178181
179182inline std::string decodeVarintString (const char * input){
180183 uint64_t length = 0 ;
181- uint8_t i = 0 ;
184+ size_t i = 0 ;
182185
183186 for (;; i++) {
184187 length |= (input[i] & 127 ) << (7 * i);
@@ -192,6 +195,24 @@ inline std::string decodeVarintString(const char* input){
192195 return std::string (input + i + 1 , length);
193196}
194197
198+ inline const char * decodeVarintString (const char * input, size_t * length_ptr) {
199+ size_t length = 0 ;
200+ size_t i = 0 ;
201+
202+ for (;; i++) {
203+ length |= (input[i] & 127 ) << (7 * i);
204+
205+ // If the next-byte flag is set
206+ if (!(input[i] & 128 )) {
207+ break ;
208+ }
209+ }
210+
211+ *length_ptr = length;
212+ return input + i + 1 ;
213+
214+ }
215+
195216
196217} /* namespace util */
197218} /* namespace dictionary */
0 commit comments