parameters: (val)
return_statement: return int_to_bytes(hdr, HDR_LEN, 'big') + int_to_bytes(rval, sz, 'big')
docstring: Encodes an arbitrarily-sized integer to bytes in a way that preserves
      ordering - ``bigint_encode(a) < bigint_encode(b)`` iff ``a < b``.
  
      The exact encoding is as follows:
  
      - first 4 bytes of the encoded value is a big endian number called the
        header.  It represents the number's size (in bytes) and sign.  Positive
        numbers have ``0x80000000 + size`` as the header, while negative numbers
        are have ``0x80000000 - size``.
      - the rest of the encoding represents the number itself, encoded as big
        endian of ``size`` bytes.  If the number is positive, it is stored
        directly.  If it is negative, its absolute value is stored with all bits
        inverted.
      - the number is always stored with the smallest size that will fit it -
        in particular, 0 is stored with a header of 0x80000000 and no payload.
docstring_summary: Encodes an arbitrarily-sized integer to bytes in a way that preserves
      ordering - ``bigint_encode(a) < bigint_encode(b)`` iff ``a < b``.
docstring_tokens: Encodes an arbitrarily - sized integer to bytes in a way that preserves ordering - bigint_encode ( a ) < bigint_encode ( b ) iff a < b .
function: def bigint_encode(val):
      """
      Encodes an arbitrarily-sized integer to bytes in a way that preserves
      ordering - ``bigint_encode(a) < bigint_encode(b)`` iff ``a < b``.
  
      The exact encoding is as follows:
  
      - first 4 bytes of the encoded value is a big endian number called the
        header.  It represents the number's size (in bytes) and sign.  Positive
        numbers have ``0x80000000 + size`` as the header, while negative numbers
        are have ``0x80000000 - size``.
      - the rest of the encoding represents the number itself, encoded as big
        endian of ``size`` bytes.  If the number is positive, it is stored
        directly.  If it is negative, its absolute value is stored with all bits
        inverted.
      - the number is always stored with the smallest size that will fit it -
        in particular, 0 is stored with a header of 0x80000000 and no payload.
      """
      val = operator.index(val)
      sz = (val.bit_length() + 7) // 8
      if val < 0:
          hdr = HDR_BIAS - sz
          rval = -val ^ ((1 << (sz * 8)) - 1)
      else:
          hdr = HDR_BIAS + sz
          rval = val
      return int_to_bytes(hdr, HDR_LEN, 'big') + int_to_bytes(rval, sz, 'big')
function_tokens: def bigint_encode ( val ) : val = operator . index ( val ) sz = ( val . bit_length ( ) + 7 ) // 8 if val < 0 : hdr = HDR_BIAS - sz rval = - val ^ ( ( 1 << ( sz * 8 ) ) - 1 ) else : hdr = HDR_BIAS + sz rval = val return int_to_bytes ( hdr , HDR_LEN , 'big' ) + int_to_bytes ( rval , sz , 'big' )