コード例 #1
0
ファイル: broker.py プロジェクト: SoftwareAG/adapya-entirex
    def __init__(self,
                 send_length=0,
                 receive_length=0,
                 use_api_version=API_VERS7,
                 **kw):

        self.__dict__['errtext_buffer'] = Abuf(80)
        self.__dict__['send_buffer'] = None
        self.__dict__['receive_buffer'] = None
        self.__dict__['trace'] = None
        self.__dict__['use_api_version'] = use_api_version

        Datamap.__init__(self, 'Etbcb', *etbcbfields, **kw)

        self.buffer = Abuf(self.dmlen)
        self.errtext_length = 80
        self.api_type = API_TYPE1
        self.api_version = use_api_version

        if receive_length > 0:
            self.receive_buffer = Abuf(receive_length)
            self.receive_length = receive_length
        if send_length > 0:
            self.send_buffer = Abuf(send_length)
            self.send_length = send_length
コード例 #2
0
    def __init__(self, cis='INFO', broker='', user='', trace=0, rcvsize=32768):
        """ Command and Information service object

            cis = default 'INFO' - full information on all clients/servers/conversations
                  'CMD'          - command services
                  'USER-INFO'    - Information limited to user's own resources
                  'PARTICIPANT-SHUTDOWN'
                  'SECURITY-CMD'

        """
        global cis_version
        self.rcvsize = rcvsize
        self.bb = Broker()
        self.bb.trace = trace & 7
        #bb.trace=1 # dump buffers before Broker calls
        #bb.trace=2 # dump buffers after Broker calls
        # bb.trace=4 # print Broker calls
        # bb.trace=6 # print Broker calls + dump buffers after
        self.bb.broker_id = broker
        self.bb.user_id = user
        self.trace = trace

        # set CIS fixed service names
        self.bb.server_class = 'SAG'
        self.bb.server_name = 'ETBCIS'
        self.bb.service = cis  # type of CIS service (INFO, CMD, ..)

        # set up CIS structures: request and info buffer
        self.cishdr = Cishdr()  # cis header in receive / info buffer

        self.bb.receive_buffer = Abuf(rcvsize)
        self.bb.receive_length = rcvsize

        self.cishdr.buffer = self.bb.receive_buffer

        if cis == 'INFO':
            self.infreq = Infreq()
            self.infreq.buffer = Abuf(self.infreq.dmlen)
            self.infreq.reset()  # reset search fields
            self.infreq.block_length = rcvsize - self.cishdr.dmlen  # size of usable info buffer

            self.bb.send_buffer = self.infreq.buffer
            self.bb.send_length = self.infreq.dmlen

        elif cis in ('CMD', 'PARTICIPANT-SHUTDOWN', 'SECURITY-CMD'):
            self.req = Cisreq()
            self.req.buffer = Abuf(self.req.dmlen)
            self.req.reset(v=cis_version)  # reset optional fields

            self.bb.send_buffer = self.req.buffer
            self.bb.send_length = self.req.dmlen

        else:
            print('Unsupported request', cis)
            print('Terminating')
            exit(1)
コード例 #3
0
def try_multiple():
    print("--- try_multiple() ---")
    global cm
    g = Datamap('mymap', String('foo', 2, occurs=3), Int2('bar'))
    cm = g

    g.buffer = Abuf(8)
    g.buffer.value = b'abKIyz\x11\x00'
    dump(g.buffer)
    dir(g.foo)
    print(g.foo)
    print(g.foo[1])
    for i, v in enumerate(g.foo):
        print(i, v)
    print("list(g.foo) =", list(g.foo))
    print("g.bar=%d" % g.bar)
    g.foo[1] = 'QQQ'
    print(list(g.foo))
    g.foo = ('hh', 'TT', 'ww')
    print(list(g.foo))
    dump(g.buffer)

    try:
        g.foo[3] = 'RRR'
    except StopIteration as e:
        print("Caught StopIteration exception for g.foo[3]='RRR', continue")
        dir(e)
        print(e)
        pass
    return g
コード例 #4
0
def try_MU_1toN_in_PE():
    print("--- try_MU_1toN_in_PE() ---")
    global cm
    g = Datamap(
        'pemap',
        Int2('i1'),
        Uint1('pg_count'),
        Periodic(Datamap('pg', String('pe', 2), Int1('pf')),
                 occurs=lambda: g.pg_count),
        Periodic(
            Datamap(
                'qg',
                String('qe', 2),
                Uint1('mu_count'),
                String('mu', 2, occurs=lambda: -1)  # count 1 byte before field
            ),
            occurs=2),
    )
    print(g.dmlen)
    cm = g

    g.buffer = Abuf(1024)

    if 0:
        print('\noccurs=0')
        g.buffer.value = b'\x01\x00\x01\x00\x02\x00'
        g.prepare()

        dump(g.buffer)
        print(g.pe)

        g.dprint()

        try:
            print(g.pe[0])
        except StopIteration as e:
            dir(e)
            print(e)
            pass

    if 1:
        print('\noccurs=3, muocc=3,1')
        g.buffer.value = b'\x02\x03P1\xffP2\xfeP3\xfdQ1\x03MaMeMiQ2\x01Na'
        g.prepare()

        dump(g.buffer)

        print(g.pg)
        print(g.pg[1])
        for i, v in enumerate(g.pg):
            print(i, v, v.pe, v.pf)
        for i, v in enumerate(g.qg):
            print(i, v, v.qe, len(v.mu))
            for j, w in enumerate(v.mu):
                print('MU', j, w, w.mu)
        g.dprint()

    return g
コード例 #5
0
def try_periodic_1toN():
    print("--- try_periodic_1toN() ---")
    global cm
    g = Datamap(
        'pemap', Int2('i1'), Uint1('pe_count'),
        Periodic(Datamap('pe', String('ps', 2), Int2('pi')),
                 occurs=lambda: g.pe_count),
        Periodic(Datamap('qe', String('qs', 3), Uint1('qi')), occurs=2),
        Int2('i2'))
    print(g.dmlen)
    cm = g

    g.buffer = Abuf(1024)

    print('\noccurs=0')
    g.buffer.value = b'\x11\x00\x00pa1\x01pa2\x02\x22\x00'
    g.prepare()

    dump(g.buffer)
    print(g.pe)
    try:
        print(g.pe[0])
    except StopIteration as e:
        dir(e)
        print(e)
        pass
    try:
        g.pe[1].ps = 'QQQ'
    except StopIteration as e:
        dir(e)
        print(e)
        pass
    for i, v in enumerate(g.pe):
        print(i, v, v.ps, v.pi)
    print(g.i2)
    dump(g.buffer)

    print('\noccurs=3')
    g.buffer.value = b'\x11\x00\x03ab\x01\x00KI\x02\x00yz\x03\x00pa1\x01pa2\x02\x22\x00'
    g.prepare()

    dump(g.buffer)
    print(g.pe)
    print(g.pe[1])
    for i, v in enumerate(g.pe):
        print(i, v, v.ps, v.pi)

    print(g.i2)
    g.pe[1].ps = 'QQQ'
    g.pe[2].pi = 33
    dump(g.buffer)

    g.dprint()

    return g
コード例 #6
0
def try_multiple_1toN():
    print("--- try_multiple_1toN() ---")

    global cm
    g = Datamap('mymap', Uint1('foo_count'),
                String('foo', 2, occurs=lambda: g.foo_count), Int2('bar'))
    cm = g
    g.buffer = Abuf(1024)
    print('occurs=3')
    g.buffer.value = b'\x03abKIyz\x11\x00'
    g.prepare()
    dump(g.buffer)
    dir(g.foo)
    print(g.foo)
    print(g.foo[1])
    for i, v in enumerate(g.foo):
        print(i, v)
    print(list(g.foo))
    print(g.bar)
    g.foo[1] = 'QQQ'
    print(list(g.foo))
    g.foo = ('hh', 'TT', 'ww')
    print(list(g.foo))
    dump(g.buffer)
    try:
        g.foo[3] = 'RRR'
    except StopIteration as e:
        dir(e)
        print(e)
        pass

    print('occurs=0')
    g.buffer.value = b'\x00\x11\x00'
    g.prepare()
    dump(g.buffer)
    dir(g.foo)
    print(g.foo)

    try:
        g.foo[0] = 'RRR'
    except StopIteration as e:
        dir(e)
        print(e)
        pass

    for i, v in enumerate(g.foo):
        print(i, v)
    print(list(g.foo))
    print(g.bar)

    return g
コード例 #7
0
def try_string(ebcdic=0,encoding=''):
    global cm

    p = Datamap( 'Test strings encoding=%s, ebcdic=%d' % (encoding,ebcdic),
        String( 'str8', 8),
        String( 'str4', 4),
        String( 'str10', 10),
        encoding=encoding,ebcdic=ebcdic
        )

    cm=p

    sz=p.getsize()  # return size of datamap

    print()
    print( '=== Datamap=%s, size=%d ===\n' % (p.dmname, sz))
    print( '    encoding = %s' % (p.encoding))
    print( '    ebcdic   = %d' % (p.ebcdic))

    p.buffer = Abuf(sz)

    # set field values
    p.str8 = b'abcd56'       # string
    p.str4 = b'a1'           # string
    p.str10 = u'a+צה�'       # string

    print( '-- print some numbers --')
    print( p.str8)
    print( p.str4)
    print( p.str10)

    print( '--- Dumping datamap structure ---')
    dump(p.buffer)

    print( '---Printing datamap structure with dprint() ---\n')
    p.dprint()  # print datamap

    print( '---Printing datamap structure with lprint() ---\n')
    p.lprint(header=1)  # print datamap header
    p.lprint()          # print datamap

    return p
コード例 #8
0
def try_periodic():
    print("--- try_periodic() ---")
    global cm
    g = Datamap('mymap', Int2('i1'),
                Periodic(Datamap('pe', String('ps', 2), Int2('pi')), occurs=3),
                Int2('i2'))
    cm = g
    print(g.dmlen)
    g.buffer = Abuf(g.dmlen)
    g.buffer.value = b'\x11\x00ab\x01\x00KI\x02\x00yz\x03\x00\x22\x00'
    dump(g.buffer)
    dir(g.pe)
    print(g.pe)
    print(g.pe[1])
    for i, v in enumerate(g.pe):
        print(i, v, v.ps, v.pi)
    print(g.i2)
    g.pe[1].ps = 'QQQ'
    g.pe[2].pi = 33
    dump(g.buffer)
    return g
コード例 #9
0
    def iread(self,
              itype,
              uid='',
              puid='',
              token='',
              server_class='',
              server='',
              service='',
              conv_id='',
              uowid='',
              uowstatus=0,
              userstatus='',
              recvuid='',
              recvtoken='',
              recvclass='',
              recvserver='',
              recvservice='',
              topic='',
              publicationid='',
              conv_type=0,
              subscriptiontype=0):
        """ generator returning info objects from class
        Example: read and print information on all services of REPTOR server_class
        >> cis=Cis(broker='da3f:3800',user='******')
        >> for iob in cis.iread(CIO_SERVICE,server_class='REPTOR'):
        >>     iob.dprint()
        >>

        """
        global cis_version

        if cis_version > 8:
            from adapya.entirex.etbcinf import Info_conversation, \
                Info_client, Info_server, Info_psf, Info_service, Info_UOW_statistics
        else:
            from adapya.entirex.etbcinf8 import Info_conversation, \
                Info_client, Info_server, Info_psf, Info_service, Info_UOW_statistics

        ii = Broker()  # establish unique conversation for read sequence
        # copy properties from own Cis object
        ii.trace = self.bb.trace
        ii.broker_id = self.bb.broker_id
        ii.user_id = self.bb.user_id

        # set CIS fixed service names
        ii.server_class = 'SAG'
        ii.server_name = 'ETBCIS'
        ii.service = 'INFO'  # Full information on all clients/servers/conversations

        cishdr = Cishdr()  # cis header in receive / info buffer

        infreq = Infreq()
        infreq.buffer = Abuf(infreq.dmlen)
        infreq.block_length = self.rcvsize - cishdr.dmlen  # size of usable info buffer
        infreq.version = cis_version  # interface level 8
        # init alpha selection fields from call parameters
        infreq.uid = uid
        infreq.puid = puid
        infreq.token = token
        infreq.server_class = server_class
        infreq.server = server
        infreq.service = service
        infreq.conv_id = conv_id
        infreq.uowid = uowid
        infreq.userstatus = userstatus
        infreq.recvuid = recvuid
        infreq.recvtoken = recvtoken
        infreq.recvserver = recvserver
        infreq.recvservice = recvservice
        infreq.recvclass = recvclass
        infreq.topic = topic
        infreq.publicationid = publicationid
        infreq.subscriptiontype = subscriptiontype
        infreq.conv_type = conv_type

        ii.receive_buffer = Abuf(self.rcvsize)
        ii.receive_length = self.rcvsize

        cishdr.buffer = ii.receive_buffer

        ii.send_buffer = infreq.buffer
        ii.send_length = infreq.dmlen

        infos = {
            CIO_CLIENT: Info_client,
            CIO_SERVER: Info_server,
            CIO_CONVERSATION: Info_conversation,
            CIO_PSF: Info_psf,
            CIO_SERVICE: Info_service,
            CIO_UOW_STATISTICS: Info_UOW_statistics
        }

        Infoclass = infos.get(itype, None)

        if Infoclass:
            infreq.object_type = itype  # set object type in request
            info = Infoclass()
        else:
            raise 'Invalid CIS object for ireader() type %s' % cio_str(itype)

        try:
            ii.conv_id = 'NEW'
            ii.wait = 'YES'  # 0s -> 00200031
            ii.send()

            if self.trace & 8:
                print('after first call')
                infreq.dprint()
                cishdr.dprint()

            if self.cishdr.error_code == 4:  # 4 nothing found
                ec = self.cishdr.etb_error_code
                et = self.cishdr.etb_error_text
                if not ec == '00000000':
                    print(
                        'Broker Information Service ETB Error %d: %s\nNo objects returned'
                        % (ec, et))
            elif self.cishdr.error_code > 0:  # print any other error
                ec = self.cishdr.error_code
                raise CISError(
                    'Broker Information Service Error %d: %s' %
                    (ec, bis_error(ec)), self)

            if cishdr.totobj == 0:
                raise StopIteration

            remaining = cishdr.totobj

            while 1:
                offset = cishdr.dmlen  # first info after cishdr

                for i in range(cishdr.curobj):
                    # print('returning %d. object in current' % (i)
                    # info.dprint()
                    info.buffer = Abuf(info.dmlen)
                    info.buffer.value = ii.receive_buffer[offset:offset +
                                                          info.dmlen]

                    yield info
                    offset += info.dmlen  # next offset in receive buffer

                remaining -= cishdr.curobj

                if remaining > 0:
                    ii.receive()
                    if self.trace & 8:
                        print('after next call')
                        infreq.dprint()
                        cishdr.dprint()
                else:
                    raise StopIteration

        except:
            raise  # return with StopIteration or any other error
        finally:
            if cishdr.totobj > 0:
                ii.endConversation()
コード例 #10
0
    def iget(self,
             itype,
             uid='',
             puid='',
             server_class='',
             server='',
             service='',
             token='',
             conv_id=''):
        """ function to get one info object
        Example: get and print general BROKER information
        >> with Cis(broker='da3f:3800',user='******') as cis:
        >>     ibr = cis.iget(CIO_BROKER)
        >>     ibr.dprint()
        >>

        """
        global cis_version

        if cis_version > 8:
            from adapya.entirex.etbcinf import Info_broker, Info_UOW_statistics
        else:
            from adapya.entirex.etbcinf8 import Info_broker, Info_UOW_statistics

        # info objects returning only one item - suitable for iget()
        infos = {
            CIO_BROKER: Info_broker,
            CIO_UOW_STATISTICS: Info_UOW_statistics
        }  # currently limited

        Infoclass = infos.get(itype, None)

        if Infoclass:
            self.infreq.object_type = itype  # set object type in request
            info = Infoclass()
        else:
            raise CISError(
                'Invalid CIS object for ireader() type %s' % cio_str(itype),
                self)

        self.infreq.update(
            version=9 if itype == CIO_UOW_STATISTICS else cis_version,
            server_class=server_class,  # selection
            server=server,  # selection
            service=service,  # selection
            uid=uid,  # selection
            puid=puid,  # selection
            token=token,  # selection
            conv_id=conv_id,  # selection
        )

        try:
            self.bb.conv_id = 'NEW'
            self.bb.wait = 'YES'  # 0s -> 00200031
            self.bb.send()

            if self.trace & 8:
                print('after first call')
                self.infreq.dprint()
                self.cishdr.dprint()

            if self.cishdr.error_code == 4:
                info = None
            elif self.cishdr.error_code > 0:
                ec = self.cishdr.error_code
                raise CISError(
                    'Broker Information Service Error %d: %s' %
                    (ec, bis_error(ec)), self)
            else:  # self.cishdr.error_code == 0
                if self.cishdr.totobj != 1:
                    raise CISError('Nothing returned from Broker CIS', self)

                offset = self.cishdr.dmlen  # first info after cishdr

                info.buffer = Abuf(info.dmlen)
                info.buffer.value = self.bb.receive_buffer[offset:offset +
                                                           info.dmlen]

            self.bb.endConversation()
            return info

        except:
            raise  # return any error
コード例 #11
0
ファイル: test_conv.py プロジェクト: SoftwareAG/adapya-base
b'\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f',
b'\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f',
b'\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f',
b'\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f',
b'\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f',
b'\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f',
b'\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f',
b'\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f',
b'\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf',
b'\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf',
b'\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf',
b'\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf',
b'\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef',
b'\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff')

tbuf=Abuf(256);
ebuf=Abuf(256);
abuf=Abuf(256);

for t in tt:
    tbuf.write(t)

ebuf[0:256]=tbuf[0:256]

conv.asc2ebc(ebuf,0,len(ebuf))

abuf[0:256]=ebuf[0:256]
conv.ebc2asc(abuf,0,len(abuf))

print( 'tbuf has characters from 0 to 255')
dump.dump(tbuf,header='tbuf')
コード例 #12
0
excl4 = Datamap(
    'EXCL4',
    # 4 Byte Excluded length Record
    Uint4('rlen'),  # Record length
)

# used for writing
wrdw = Datamap(
    'RDW',
    # RDW Record descriptor word
    Uint2('rlen'),  # Record length
    Uint1('seg'),  # Segment control
    Uint1('seg2'),  # Segment control 2 (unused)
    byteOrder=NETWORKBO,
    buffer=Abuf(4),
)

isnp = Datamap(
    'ISN_prefix',
    Uint4('isn'),  # Segment descriptor
    byteOrder=NETWORKBO,
    buffer=Abuf(4))


def readrec(f,
            recform='',
            dumphdr='',
            numrec=0,
            skiprec=0,
            ecodec='cp037',
コード例 #13
0
def try_all_formats():
    global cm

    p = Datamap(
        'test_all_formats p',
        String('str8', 8),
        Unicode('uni4', 4),  # unicode 4 chars = 8 bytes
        Utf8('utf8', 8),
        Bytes('byt4', 4),
        Char('cha1'),
        Int1('int1'),
        Uint1('uin1'),
        Int2('int2'),
        Uint2('uin2'),
        Int4('int4'),
        Uint4('uin4', opt=T_STCK),  # Uint4 STCK display as time
        Int8('int8'),
        Uint8('uin8', opt=T_STCK),  # Uint8 STCK display as timestamp
        Float('flo4'),
        Double('dou8'),
        Packed('pac4', 4),
        Unpacked('unp1', 1),
        Unpacked('unp8', 8),
        Unpacked('datetime', 14, dt='DATETIME'),  # Python datetime object
        Unpacked('timestamp', 20, dt='TIMESTAMP'),  # Python datetime object
        Unpacked('date', 8, dt='DATE'),  # Python date object
        Unpacked('time', 6, dt='TIME'),  # Python time object
        Packed('natdate', 4, dt='NATDATE'),  # Python date object
        Packed('nattime', 7, dt='NATTIME'),  # Python datetime object
        Uint4('unixtime', dt='UNIXTIME'),  # Python datetime object
        Int8('xtimestamp', dt='XTIMESTAMP'),  # Python datetime object
    )

    cm = p

    sz = p.getsize()  # return size of datamap
    dtnow = datetime.now()

    print()
    print('--- Datamap=%s, size=%d ---\n' % (p.dmname, sz))

    print('    datetime now: %s' % dtnow)

    p.buffer = Abuf(sz)

    # set field values
    p.str8 = 'Maßkrüge'  # string
    p.uni4 = 'ßöäü'  # unicode
    p.utf8 = 'äßö'  # utf8
    p.byt4 = b'\xC1\xC4\xC1\x4B'  # non-ASCII bytes are displayed in HEX
    p.cha1 = '©'  # copyright character
    # p.cha1='c'
    p.int1 = -128
    p.uin1 = 255

    p.int2 = -32768
    p.uin2 = 65535

    p.int4 = -0x80000000
    p.uin4 = 0xaee3efa4  # 1.1.1997

    p.int8 = -0x8000000000000000
    p.uin8 = 0xb1962f9305180000  # 1.1.1999

    p.flo4 = 2.0
    p.dou8 = 0.5

    p.pac4 = -1234567
    p.unp1 = 1
    p.unp8 = -12345678

    p.datetime = dtnow
    p.date = dtnow.date()
    p.time = dtnow.time()
    p.nattime = dtnow
    p.natdate = dtnow.date()
    p.timestamp = dtnow

    p.unixtime = dtnow
    p.xtimestamp = dtnow

    print('-- print some numbers --')
    print('pac8', p.pac4)
    print('unp1', p.unp1)
    assert p.unp1 == 1
    print('unp8', p.unp8)
    assert p.unp8 == -12345678
    print('datetime', p.datetime)  # datetime() str() method

    print('--- Dumping datamap structure ---')
    dump(p.buffer)

    print('---Printing datamap structure with dprint() ---\n')
    p.dprint()  # print datamap

    print('---Printing datamap structure with lprint() ---\n')
    p.lprint(header=1)  # print datamap header
    p.lprint()  # print datamap
    p.lprint()  # print datamap

    try:
        print('--- Assigning to undefined field xx ---')
        p.xx = 123
    except DatamapError as e:
        print('\t', e.value)
        dump(e.dmap.buffer)

    return p
コード例 #14
0
def try_var_formats():
    print("--- try_var_formats() ---")
    global cm

    p = Datamap(
        'test_var_formats',
        String('sv1', 0, opt=T_VAR1),
        String('sv2', 0, opt=T_VAR2),
        String('sv4', 0, opt=T_VAR4),
        Unicode('uv1', 0, opt=T_VAR1),  # unicode 4 chars = 8 bytes
        Utf8('tv1', 0, opt=T_VAR1),
        # Bytes(  'bv1', 0, opt=T_VAR1),
    )

    p0 = Datamap(
        'test_var_formats0',
        Uint1('iv1'),
        Uint2('iv2'),
        Uint4('iv4'),
        Uint1('ui1'),
        Uint1('ti1'),
        # Uint1(  'bi1'),
    )

    p1 = Datamap(
        'test_var_formats1',
        Uint1('iv1'),
        String('sv1', 3),
        Uint2('iv2'),
        String('sv2', 2),
        Uint4('iv4'),
        String('sv4', 4),
        Uint1('ui1'),
        Unicode('uv1', 4),  # unicode 4 chars = 8 bytes
        Uint1('ti1'),
        Utf8('tv1', 8),
        # Uint1(  'bi1'),
        # Bytes(  'bv1', 4),
    )

    p2 = Datamap(
        'test_var_formats2',
        Uint1('iv1'),
        String('sv1', 254),
        Uint2('iv2'),
        String('sv2', 256),
        Uint4('iv4'),
        String('sv4', 64000),
        Uint1('ui1'),
        Unicode('uv1', 126),  # unicode 4 chars = 8 bytes
        Uint1('ti1'),
        Utf8('tv1', 8),
        # Uint1(  'bi1'),
        # Bytes(  'bv1', 4),
    )

    cm = (p, p0, p1, p2)

    p0.buffer = Abuf(p0.getsize())
    p1.buffer = Abuf(p1.getsize())
    p2.buffer = Abuf(p2.getsize())

    p0.iv1 = 1
    p0.iv2 = 2
    p0.iv4 = 4
    p0.ui1 = 1
    p0.ti1 = 1

    p1.iv1 = 4
    p1.iv2 = 4
    p1.iv4 = 8
    p1.ui1 = 9
    p1.ti1 = 9
    p1.sv1 = 'abc'
    p1.sv2 = 'DE'
    p1.sv4 = 'fghi'
    p1.uv1 = 'JKLM'
    p1.tv1 = 'nopqrstu'

    p2.iv1 = 255
    p2.iv2 = 258
    p2.iv4 = 64004
    p2.ui1 = 253
    p2.ti1 = 9
    p2.sv1 = 'A' * 254
    p2.sv2 = 'b' * 256
    p2.sv4 = 'C' * 64000
    p2.uv1 = 'd' * 126
    p2.tv1 = 'E' * 8

    p.buffer = p0.buffer
    dump(p.buffer)
    p.dprint()

    p.buffer = p1.buffer
    dump(p.buffer)
    p.prepare()
    p.dprint()

    p.buffer = p2.buffer
    dump(p.buffer)
    p.prepare()
    p.dprint()
    print(p.items())

    return p, p0, p1, p2