Viewing the byte representation of a struct

23 views
Skip to first unread message

Lawrence Moore

unread,
Jul 9, 2015, 12:35:16 PM7/9/15
to pytho...@googlegroups.com
Hi,

I'd like some way to view the underlying byte representation of a struct (I'd like to send the struct through a socket), but I can't seem to find a way to do that.  Any suggestions? 

Thanks. 

Armin Rigo

unread,
Jul 9, 2015, 12:47:55 PM7/9/15
to pytho...@googlegroups.com
Hi Lawrence,
If p is a cdata object of type 'struct foo *', then you can cast it to
a 'char *' (like you would do in C). But even better is
'ffi.buffer(p)', which returns a Python buffer. You can pass it
directly to socket.send() for example, or use 'ffi.buffer(p)[:]' to
get the data as a raw string.


A bientôt,

Armin.

Lawrence Moore

unread,
Jul 9, 2015, 12:49:20 PM7/9/15
to pytho...@googlegroups.com, ar...@tunes.org
thanks so much!
Reply all
Reply to author
Forward
0 new messages