PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ _varint_u64_encode_buf()

static size_t _varint_u64_encode_buf ( uint64_t  val,
uint8_t buf 
)
static

Definition at line 34 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().

35 {
36  uint8_t grp;
37  uint64_t q = val;
38  uint8_t *ptr = buf;
39  while (1)
40  {
41  /* We put the 7 least significant bits in grp */
42  grp = 0x7f & q;
43  /* We rightshift our input value 7 bits */
44  /* which means that the 7 next least significant bits */
45  /* becomes the 7 least significant */
46  q = q >> 7;
47  /* Check if, after our rightshifting, we still have */
48  /* anything to read in our input value. */
49  if ( q > 0 )
50  {
51  /* In the next line quite a lot is happening. */
52  /* Since there is more to read in our input value */
53  /* we signal that by setting the most siginicant bit */
54  /* in our byte to 1. */
55  /* Then we put that byte in our buffer and move the pointer */
56  /* forward one step */
57  *ptr = 0x80 | grp;
58  ptr++;
59  }
60  else
61  {
62  /* The same as above, but since there is nothing more */
63  /* to read in our input value we leave the most significant bit unset */
64  *ptr = grp;
65  ptr++;
66  return ptr - buf;
67  }
68  }
69  /* This cannot happen */
70  lwerror("%s: Got out of infinite loop. Consciousness achieved.", __func__);
71  return (size_t)0;
72 }
unsigned char uint8_t
Definition: uthash.h:79
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
Here is the call graph for this function:
Here is the caller graph for this function: