PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ _varint_u64_encode_buf()

static size_t _varint_u64_encode_buf ( uint64_t  val,
uint8_t *  buf 
)
static

Definition at line 26 of file varint.c.

References lwerror().

Referenced by varint_s32_encode_buf(), varint_s64_encode_buf(), varint_u32_encode_buf(), and varint_u64_encode_buf().

27 {
28  uint8_t grp;
29  uint64_t q = val;
30  uint8_t *ptr = buf;
31  while (1)
32  {
33  /* We put the 7 least significant bits in grp */
34  grp = 0x7f & q;
35  /* We rightshift our input value 7 bits */
36  /* which means that the 7 next least significant bits */
37  /* becomes the 7 least significant */
38  q = q >> 7;
39  /* Check if, after our rightshifting, we still have */
40  /* anything to read in our input value. */
41  if ( q > 0 )
42  {
43  /* In the next line quite a lot is happening. */
44  /* Since there is more to read in our input value */
45  /* we signal that by setting the most siginicant bit */
46  /* in our byte to 1. */
47  /* Then we put that byte in our buffer and move the pointer */
48  /* forward one step */
49  *ptr = 0x80 | grp;
50  ptr++;
51  }
52  else
53  {
54  /* The same as above, but since there is nothing more */
55  /* to read in our input value we leave the most significant bit unset */
56  *ptr = grp;
57  ptr++;
58  return ptr - buf;
59  }
60  }
61  /* This cannot happen */
62  lwerror("%s: Got out of infinite loop. Consciousness achieved.", __func__);
63  return (size_t)0;
64 }
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: