PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ varint_u64_decode()

uint64_t varint_u64_decode ( const uint8_t the_start,
const uint8_t the_end,
size_t *  size 
)

Definition at line 109 of file varint.c.

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

References lwerror().

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

Here is the call graph for this function:
Here is the caller graph for this function: