Serializes fixed size integer to the buffer
    :param n:
    :param width:
    :return:
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
108789
def parse_width(width, n):
    
    if isinstance(width, int):
        widths = [width] * n

    else:
        assert len(width) == n, "Widths and data do not match"
        widths = width

    return widths
873127
def read(self, n):
    
    while len(self.buf) < n:
      chunk = self.f.recv(4096)
      if not chunk:
        raise EndOfStreamError()
      self.buf += chunk
    res, self.buf = self.buf[:n], self.buf[n:]
    return res
920015
def read(self, n):
        
        out = ctypes.create_string_buffer(n)
        ctypes.windll.kernel32.RtlMoveMemory(out, self.view + self.pos, n)
        self.pos += n
        return out.raw
214976
private static String numToString(int num, int width) {
        String str = Integer.toString(num);
        int len = str.length();
        if (len >= width) {
            return str.substring(len - width, len);
        }
        StringBuilder sb = new StringBuilder(width);
        for (int i = len; i < width; i++) {
            sb.append('0');
        }
        sb.append(str);
        return sb.toString();
    }
467666
def lpad(s, N, char='\0'):
    
    assert isinstance(char, bytes) and len(char) == 1, 'char should be a string with length 1'
    return s.rjust(N, char)
593040
def numpy_buffer(ndarray):
    """"""
    # Credits to: https://github.com/joblib/joblib/blob/04b001861e1dd03a857b7b419c336de64e05714c/joblib/hashing.py

    if isinstance(ndarray, (pd.Series, pd.DataFrame)):
        ndarray = ndarray.values

    if ndarray.flags.c_contiguous:
        obj_c_contiguous = ndarray
    elif ndarray.flags.f_contiguous:
        obj_c_contiguous = ndarray.T
    else:
        obj_c_contiguous = ndarray.flatten()

    obj_c_contiguous = obj_c_contiguous.view(np.uint8)

    if hasattr(np, 'getbuffer'):
        return np.getbuffer(obj_c_contiguous)
    else:
        return memoryview(obj_c_contiguous)
1053631
def add_int(self, n):
        
        self.packet.write(struct.pack('>I', n))
        return self
1265729
def _long_to_bytes(n, length, byteorder):
    
    if byteorder == 'little':
        indexes = range(length)
    else:
        indexes = reversed(range(length))
    return bytearray((n >> i * 8) & 0xff for i in indexes)
110774
def _encode_uvarint(data, n):
    ''' '''
    if n < 0:
        raise ValueError('only support positive integer')
    while True:
        this_byte = n & 0x7f
        n >>= 7
        if n == 0:
            data.append(this_byte)
            break
        data.append(this_byte | 0x80)
375487
def rewrap_long(s, width=COLS):
    
    paras = s.split('\n\n')
    return '\n\n'.join(rewrap(p) for p in paras)
1208895
def serialize_number(x, fmt=SER_BINARY, outlen=None):
    
    ret = b''
    if fmt == SER_BINARY:
        while x:
            x, r = divmod(x, 256)
            ret = six.int2byte(int(r)) + ret
        if outlen is not None:
            assert len(ret) <= outlen
            ret = ret.rjust(outlen, b'\0')
        return ret
    assert fmt == SER_COMPACT
    while x:
        x, r = divmod(x, len(COMPACT_DIGITS))
        ret = COMPACT_DIGITS[r:r + 1] + ret
    if outlen is not None:
        assert len(ret) <= outlen
        ret = ret.rjust(outlen, COMPACT_DIGITS[0:1])
    return ret
1010000
function _bytes (n, fn) {
  assert(!this._parserCallback, 'there is already a "callback" set!');
  assert(isFinite(n) && n > 0, 'can only buffer a finite number of bytes > 0, got "' + n + '"');
  if (!this._parserInit) init(this);
  debug('buffering %o bytes', n);
  this._parserBytesLeft = n;
  this._parserCallback = fn;
  this._parserState = BUFFERING;
}
1350891
def randombytes(size):
    
    buf = ffi.new("unsigned char[]", size)
    lib.randombytes(buf, size)
    return ffi.buffer(buf, size)[:]
232096
def dump_uvarint_b_into(n, buffer, offset=0):
    
    shifted = True
    while shifted:
        shifted = n >> 7
        buffer[offset] = (n & 0x7F) | (0x80 if shifted else 0x00)
        offset += 1
        n = shifted
    return buffer
1002187
async def dump_uvarint(writer, n):
    
    buffer = _UVARINT_BUFFER
    if n == 0:
        buffer[0] = 0
        return await writer.awrite(buffer)

    negative = n < 0
    ll = -n if negative else n

    size = 0
    while ll != 0:
        ll >>= 8
        size += 1

    buffer[0] = size
    await writer.awrite(buffer)

    ll = -n if negative else n

    # TODO: endianity, rev bytes if needed
    for _ in range(size):
        buffer[0] = ll & 0xff
        await writer.awrite(buffer)
        ll >>= 8
192358
def data_from_bn(bn, min_length: nil, required_length: nil)
      raise ArgumentError, "Missing big number" if !bn

      length = BN_num_bytes(bn)
      buf = FFI::MemoryPointer.from_string("\x00"*length)
      BN_bn2bin(bn, buf)
      s = buf.read_string(length)
      s = s.rjust(min_length, "\x00") if min_length
      if required_length && s.bytesize != required_length
        raise BTCError, "Non-matching length of the number: #{s.bytesize} bytes vs required #{required_length}"
      end
      s
    end