Transform the memory into bytes

        :param memory: Compose memory definition. (1g, 24k)
        :type memory: memory string or integer
        :return: The memory in bytes
        :rtype: int
517249
def ingest_memory(self, memory):
        
        def lshift(num, shift):
            return num << shift

        def k(num, thousands):
            return num * thousands

        # if isinstance(memory, int):
        #     # Memory was specified as an integer, meaning it is in bytes
        memory = str(memory)

        bit_shift = {
            'E': {'func': k, 'shift': 10e17},
            'P': {'func': k, 'shift': 10e14},
            'T': {'func': k, 'shift': 10e11},
            'G': {'func': k, 'shift': 10e8},
            'M': {'func': k, 'shift': 10e5},
            'K': {'func': k, 'shift': 10e2},
            'Ei': {'func': lshift, 'shift': 60},
            'Pi': {'func': lshift, 'shift': 50},
            'Ti': {'func': lshift, 'shift': 40},
            'Gi': {'func': lshift, 'shift': 30},
            'Mi': {'func': lshift, 'shift': 20},
            'Ki': {'func': lshift, 'shift': 10},
        }

        if len(memory) > 2 and memory[-2:] in bit_shift.keys():
            unit = memory[-2:]
            number = int(memory[:-2])
            memory = bit_shift[unit]['func'](number, bit_shift[unit]['shift'])
        elif len(memory) > 1 and memory[-1:] in bit_shift.keys():
            unit = memory[-1]
            number = int(memory[:-1])
            memory = bit_shift[unit]['func'](number, bit_shift[unit]['shift'])
        # Cast to a float to properly consume scientific notation
        return int(float(memory))
200596
def to_bytes(value):
    
    if isinstance(value, text_type):
        return value.encode('utf-8')
    elif isinstance(value, ffi.CData):
        return ffi.string(value)
    elif isinstance(value, binary_type):
        return value
    else:
        raise ValueError('Value must be text, bytes, or char[]')
403948
def any2mb(s):
    """"""
    if is_string(s):
        return int(Memory.from_string(s).to("Mb"))
    else:
        return int(s)
885072
def copy(self):
        
        s = MemoryData(self.address, self.size, self.sort, pointer_addr=self.pointer_addr, max_size=self.max_size)
        s.content = self.content

        return s
185836
def outputdata(self, data):
        
        if not isinstance(data, bytes):
            data = str(data).encode(self.encoding)
        self.output(MemoryStream(data))
956922
def memory_data():
    
    vm = psutil.virtual_memory()
    sw = psutil.swap_memory()

    return {
        'virtual': {
            'total': mark(vm.total, 'bytes'),
            'free': mark(vm.free, 'bytes'),
            'percent': mark(vm.percent, 'percentage')
        },
        'swap': {
            'total': mark(sw.total, 'bytes'),
            'free': mark(sw.free, 'bytes'),
            'percent': mark(sw.percent, 'percentage')
        },
    }
1122412
def bytes(self, *args):
        
        if len(args) == 1 and isinstance(args[0], BTree.Cursor):
            cur = args[0]
        else:
            cur = self.btree.find('eq', self.makekey(*args))

        if cur:
            return cur.getval()
381484
def bytes(self):
        """"""
        addrbyte = b'\x00\x00\x00'
        if self.addr is not None:
            addrbyte = self.addr
        return addrbyte
1193556
def read_memory(self, addr, transfer_size=32, now=True):
        
        result = self.ap.read_memory(addr, transfer_size, now)

        # Read callback returned for async reads.
        def read_memory_cb():
            return self.bp_manager.filter_memory(addr, transfer_size, result())

        if now:
            return self.bp_manager.filter_memory(addr, transfer_size, result)
        else:
            return read_memory_cb
1189698
def mem(data):
    
    
    if type(data) == dict:
        num = sum([data[k].memory_usage(index=True).sum() for k in data])
    else:
        num = data.memory_usage(index=True).sum()
    for x in ['bytes', 'KB', 'MB', 'GB', 'TB']:
        if num < 1024.0:
            return "%3.1f %s" % (num, x)
        num /= 1024.0
    return "%3.1f %s" % (num, 'PB')
1135779
def memory_write(self, offset: int, data: List[Union[int, BitVec]]) -> None:
        
        self.mem_extend(offset, len(data))
        self.memory[offset : offset + len(data)] = data
1172185
def to_bytes(self):
        '''
        
        '''
        # Verify that properties make sense
        self.sanitize()

        # Start with the type
        bitstream = BitArray('uint:4=%d' % self.message_type)

        # Add padding
        bitstream += self._reserved1

        # Add the record count
        bitstream += BitArray('uint:8=%d' % len(self.records))

        # Add the nonce
        bitstream += BitArray(bytes=self.nonce)

        # Add the records
        for record in self.records:
            bitstream += record.to_bitstream()

        return bitstream.bytes
92578
def to_bytes(self):
        '''
        
        '''
        # Verify that the properties make sense
        self.sanitize()

        # Write the version
        bitstream = BitStream('uint:4=%d' % self.version)

        # Write the traffic class
        bitstream += BitStream('uint:8=%d' % self.traffic_class)

        # Write the flow label
        bitstream += BitStream('uint:20=%d' % self.flow_label)

        # Write the payload length
        payload_bytes = bytes(self.payload)
        payload_length = len(payload_bytes)
        bitstream += BitStream('uint:16=%d' % payload_length)

        # Write the next header type
        bitstream += BitStream('uint:8=%d' % self.next_header)

        # Write the hop limit
        bitstream += BitStream('uint:8=%d' % self.hop_limit)

        # Write the source and destination addresses
        bitstream += BitStream('uint:128=%d, '
                               'uint:128=%d' % (int(self.source),
                                                int(self.destination)))

        return bitstream.bytes + payload_bytes
345043
def convert_to_bytes(mem_str):
    
    if str(mem_str)[-1].upper().endswith("G"):
        return int(round(float(mem_str[:-1]) * 1024 * 1024))
    elif str(mem_str)[-1].upper().endswith("M"):
        return int(round(float(mem_str[:-1]) * 1024))
    else:
        return int(round(float(mem_str)))
970640
def convert_to_mb(s):
    """"""
    s = s.upper()
    try:
        if s.endswith('G'):
            return float(s[:-1].strip()) * 1024
        elif s.endswith('T'):
            return float(s[:-1].strip()) * 1024 * 1024
        else:
            return float(s[:-1].strip())
    except (IndexError, ValueError, KeyError, TypeError):
        errmsg = ("Invalid memory format: %s") % s
        raise exception.SDKInternalError(msg=errmsg)
540318
def do_memory(self, arg):
        
        if arg:     # TODO: take min and max addresses
            raise CmdError("too many arguments")
        process = self.get_process_from_prefix()
        try:
            memoryMap       = process.get_memory_map()
            mappedFilenames = process.get_mapped_filenames()
            print('')
            print(CrashDump.dump_memory_map(memoryMap, mappedFilenames))
        except WindowsError:
            msg = "can't get memory information for process (%d)"
            raise CmdError(msg % process.get_pid())
124257
def append(self, data: Union[bytes, bytearray, memoryview]) -> None:
        
        size = len(data)
        if size > self._large_buf_threshold:
            if not isinstance(data, memoryview):
                data = memoryview(data)
            self._buffers.append((True, data))
        elif size > 0:
            if self._buffers:
                is_memview, b = self._buffers[-1]
                new_buf = is_memview or len(b) >= self._large_buf_threshold
            else:
                new_buf = True
            if new_buf:
                self._buffers.append((False, bytearray(data)))
            else:
                b += data  # type: ignore

        self._size += size