ctypes Structure serialization

Discussion in 'Python' started by rych, Feb 7, 2010.

  1. rych

    rych Guest

    I'm not quite familiar with python serialization but the picle module,
    at least, doesn't seem to be able to serialize a ctypes Structure with
    array-fields. Even if it was, the ASCII file produced is not in a
    human-friendly format.

    Could someone please suggest a method of saving and loading the fields
    in ctypes' Structure derived class to a json or better yet, to
    something like INFO
    http://www.boost.org/doc/libs/1_41_...s.html#boost_propertytree.parsers.info_parser

    For example, I have an object of
    >>> class MyStruct(Structure):

    .... _fields_ = [("a", c_int),
    .... ("b", c_float),
    .... ("point_array", c_float * 4)]

    I'd like the corresponding file to look like

    a 1
    b 1.0
    point array 1.1 1.2 1.3 1.4

    Thanks
     
    rych, Feb 7, 2010
    #1
    1. Advertising

  2. rych

    rych Guest

    OK, an easier question, hopefully.
    How to unpack all fields from ctypes Structure line by line and save
    into the name-value pairs?
     
    rych, Feb 8, 2010
    #2
    1. Advertising

  3. In message <615b1271-a9b0-4558-8e45-
    >, rych wrote:

    > I'm not quite familiar with python serialization but the picle module,
    > at least, doesn't seem to be able to serialize a ctypes Structure with
    > array-fields.


    Remember that a ctypes structure is supposed to represent a lower-language-
    level structure, which is just a block of bytes. Those bytes are the
    serialization.
     
    Lawrence D'Oliveiro, Feb 9, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    8
    Views:
    2,253
    deadsea
    Jan 2, 2005
  2. Replies:
    3
    Views:
    1,035
  3. Henk Punt
    Replies:
    0
    Views:
    398
    Henk Punt
    Jul 23, 2004
  4. Dimitri Ognibene
    Replies:
    4
    Views:
    785
    Dimitri Ognibene
    Sep 2, 2006
  5. Replies:
    0
    Views:
    504
Loading...

Share This Page