7from .adapter_frontendclass
import MemoryBlock, DataReaderWriter, DataReaderWriterException, DataReaderWriterInitException
18 print(
"Adapter Exercise")
23 memoryBlockSize = dataReaderWriter.MemoryBlockByteSize
28 for index
in range(0, dataSize):
29 writeData.append(index + 1)
31 readData = dataReaderWriter.Read(0, memoryBlockSize)
32 dataDump = dataReaderWriter.BufferToString(readData, memoryBlockSize, 2)
33 print(
" Initial memory block contents:")
37 dataDump = dataReaderWriter.BufferToString(writeData, len(writeData), 2)
38 print(
" Data to be written to memory block:")
41 print(
" Writing data to byte offset {}...".format(byteOffset))
43 dataReaderWriter.Write(byteOffset, writeData, len(writeData))
45 print(
" Reading back the memory block...")
47 readData = dataReaderWriter.Read(0, memoryBlockSize)
51 dataDump = dataReaderWriter.BufferToString(readData, memoryBlockSize, 2)
52 print(
" Current memory block contents:")
54 except DataReaderWriterInitException
as ex:
55 print(
"Error with startup or shutdown! {0}".format(ex))
56 except DataReaderWriterException
as ex:
57 print(
"Error with reading or writing! {0}".format(ex))
Represents a data reader/writer to a caller.
def Adapter_Exercise()
Example of using the Adapter Pattern.