PostGIS  2.2.7dev-r@@SVN_REVISION@@
uint64_t varint_u64_decode ( const uint8_t *  the_start,
const uint8_t *  the_end,
size_t *  size 
)

Definition at line 101 of file varint.c.

References lwerror().

Referenced by bytebuffer_read_uvarint(), do_test_u64_roundtrip(), twkb_parse_state_uvarint(), and varint_s64_decode().

102 {
103  uint64_t nVal = 0;
104  int nShift = 0;
105  uint8_t nByte;
106  const uint8_t *ptr = the_start;
107 
108  /* Check so we don't read beyond the twkb */
109  while( ptr < the_end )
110  {
111  nByte = *ptr;
112  /* Hibit is set, so this isn't the last byte */
113  if (nByte & 0x80)
114  {
115  /* We get here when there is more to read in the input varInt */
116  /* Here we take the least significant 7 bits of the read */
117  /* byte and put it in the most significant place in the result variable. */
118  nVal |= ((uint64_t)(nByte & 0x7f)) << nShift;
119  /* move the "cursor" of the input buffer step (8 bits) */
120  ptr++;
121  /* move the cursor in the resulting variable (7 bits) */
122  nShift += 7;
123  }
124  else
125  {
126  /* move the "cursor" one step */
127  ptr++;
128  /* Move the last read byte to the most significant */
129  /* place in the result and return the whole result */
130  *size = ptr - the_start;
131  return nVal | ((uint64_t)nByte << nShift);
132  }
133  }
134  lwerror("%s: varint extends past end of buffer", __func__);
135  return 0;
136 }
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74

Here is the call graph for this function:

Here is the caller graph for this function: