Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #40470

How to Nest Structs?

Newsgroups comp.lang.python
Date 2013-03-04 10:22 -0800
Message-ID <d0536361-5359-47bd-8d7f-9ae1ef72c195@googlegroups.com> (permalink)
Subject How to Nest Structs?
From Ari King <ari.brandeis.king@gmail.com>

Show all headers | View raw


Hi,

I'm trying to nest the "info_header", "info_body", and "info_trailer" structs (see below) into a "data_packet" struct. Does anyone know how I can/should accomplish this? Thanks.

batch_header_format = struct.Struct('!c2h')
info_header_format = struct.Struct('!2hl')
mkt_status_format = struct.Struct('!c')
info_trailer_format = struct.Struct('!hc')

mkt_session_codes = [b'PO',b'PC',b'CO',b'CC',b'CK',b'CL']
mkt_type = [b'N',b'S',b'O',b'A',b'C',b'G']

batch_header = batch_header_format.pack(b'1',1,1024)

total_size = info_header_format.size + mkt_status_format.size + info_trailer_format.size

# Combine following into data struct.
info_header = info_header_format.pack(int(binascii.hexlify(mkt_session_codes[random.randint(0,5)])), total_size, 124)
info_body = mkt_status_format.pack(mkt_type[random.randint(0,5)])
info_trailer = info_trailer_format.pack(0, b'\r')

-Ari

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

How to Nest Structs? Ari King <ari.brandeis.king@gmail.com> - 2013-03-04 10:22 -0800
  Re: How to Nest Structs? web@cjhanks.name - 2013-03-04 14:29 -0800

csiph-web