Encode a signed integer as a zigzag encoded signed integer.
162664
def SignedVarintEncode(value):
  """"""
  result = b""
  if value < 0:
    value += (1 << 64)

  bits = value & 0x7f
  value >>= 7
  while value:
    result += HIGH_CHR_MAP[bits]
    bits = value & 0x7f
    value >>= 7
  result += CHR_MAP[bits]

  return result
1050995
function (signed, bytes, size) {
        if (signed) {
            switch(bytes) {
                case 1:
                return new Int8Array(size);
                case 2:
                return new Int16Array(size);
                case 4:
                return new Int32Array(size);
                default:
                throw new RangeError("Invalid newArray parameter element_bytes:" + bytes);
            }
        } else {
            switch(bytes) {
                case 1:
                return new Uint8Array(size);
                case 2:
                return new Uint16Array(size);
                case 4:
                return new Uint32Array(size);
                default:
                throw new RangeError("Invalid newArray parameter element_bytes:" + bytes);
            }
        }
    }
969797
def encode_setid(uint128):
    """"""
    hi, lo = divmod(uint128, 2**64)
    return b32encode(struct.pack('<QQ', lo, hi))[:-6].lower()
545067
def dump_uint_b_into(n, width, buffer, offset=0):
    
    for idx in range(width):
        buffer[idx + offset] = n & 0xff
        n >>= 8
    return buffer
377979
def _SignedVarintSize(value):
  """"""
  if value < 0: return 10
  if value <= 0x7f: return 1
  if value <= 0x3fff: return 2
  if value <= 0x1fffff: return 3
  if value <= 0xfffffff: return 4
  if value <= 0x7ffffffff: return 5
  if value <= 0x3ffffffffff: return 6
  if value <= 0x1ffffffffffff: return 7
  if value <= 0xffffffffffffff: return 8
  if value <= 0x7fffffffffffffff: return 9
  return 10
411646
def encode_uleb128(value)
      raise ArgumentError, "Signed integers are not supported" if value < 0
      return "\x00" if value == 0
      bytes = []
      while value != 0
        byte = value & 0b01111111 # 0x7f
        value >>= 7
        if value != 0
          byte |= 0b10000000 # 0x80
        end
        bytes << byte
      end
      return BTC::Data.data_from_bytes(bytes)
    end
117833
def append_sint32(self, value):
        
        zigzag_value = wire_format.zig_zag_encode(value)
        self._stream.append_var_uint32(zigzag_value)
1339958
def decint(n, signed=False):  # pylint: disable=invalid-name,too-many-branches
    

    if isinstance(n, str):
        n = utils.to_string(n)

    if n is True:
        return 1

    if n is False:
        return 0

    if n is None:
        return 0

    if is_numeric(n):
        if signed:
            if not -TT255 <= n <= TT255 - 1:
                raise EncodingError('Number out of range: %r' % n)
        else:
            if not 0 <= n <= TT256 - 1:
                raise EncodingError('Number out of range: %r' % n)

        return n

    if is_string(n):
        if len(n) > 32:
            raise EncodingError('String too long: %r' % n)

        if len(n) == 40:
            int_bigendian = decode_hex(n)
        else:
            int_bigendian = n  # pylint: disable=redefined-variable-type

        result = big_endian_to_int(int_bigendian)
        if signed:
            if result >= TT255:
                result -= TT256

            if not -TT255 <= result <= TT255 - 1:
                raise EncodingError('Number out of range: %r' % n)
        else:
            if not 0 <= result <= TT256 - 1:
                raise EncodingError('Number out of range: %r' % n)

        return result

    raise EncodingError('Cannot decode integer: %r' % n)
1061789
def encode(self, uuid, pad_length=None):
        
        if pad_length is None:
            pad_length = self._length
        return int_to_string(uuid.int, self._alphabet, padding=pad_length)
741715
def write_uint64(self, value, little_endian=True):
        
        if little_endian:
            endian = "<"
        else:
            endian = ">"
        return self.pack('%sQ' % endian, value)
274132
def encode(precision, with_z):
    """"""
    logger = logging.getLogger('geobuf')
    stdin = click.get_text_stream('stdin')
    sink = click.get_binary_stream('stdout')
    try:
        data = json.load(stdin)
        pbf = geobuf.encode(
            data,
            precision if precision >= 0 else 6,
            3 if with_z else 2)
        sink.write(pbf)
        sys.exit(0)
    except Exception:
        logger.exception("Failed. Exception caught")
        sys.exit(1)
552905
def int_subtype(i, bits, signed) :
        ""
        if not isinstance(i, int) :
            raise TypeError("value is not int: %s" % repr(i))
        #end if
        if signed :
            lo = - 1 << bits - 1
            hi = (1 << bits - 1) - 1
        else :
            lo = 0
            hi = (1 << bits) - 1
        #end if
        if i < lo or i > hi :
            raise ValueError \
              (
                "%d not in range of %s %d-bit value" % (i, ("unsigned", "signed")[signed], bits)
              )
        #end if
        return \
            i
915235
def encode(cls, value):
        
        try:
            coerced = int(value)
            if coerced + 0 == value:
                return repr(coerced)

        except (TypeError, ValueError):
            pass

        raise InvalidValue('not an int')
911173
def signed_int_to_unsigned_hex(signed_int: int) -> str:
    
    hex_string = hex(struct.unpack('Q', struct.pack('q', signed_int))[0])[2:]
    if hex_string.endswith('L'):
        return hex_string[:-1]
    return hex_string
1146170
def intToBin(i):
    
    # divide in two parts (bytes)
    i1 = i % 256
    i2 = int(i / 256)
    # make string (little endian)
    return i.to_bytes(2, byteorder='little')
1096961
def append_sint64(self, value):
        
        zigzag_value = wire_format.zig_zag_encode(value)
        self._stream.append_var_uint64(zigzag_value)
737311
def encodeSemiOctets(number):
    
    if len(number) % 2 == 1:
        number = number + 'F' # append the "end" indicator
    octets = [int(number[i+1] + number[i], 16) for i in xrange(0, len(number), 2)]
    return bytearray(octets)