Unpacking a C struct with Pythons struct module -


i sending struct in binary format c python script.

my c struct:

struct example {     float val1;     float val2;     float val3; } 

how send it:

struct example *ex; ex->val1 = 5.3f; ex->val2 = 12.5f; ex->val3 = 15.5f;  write(fd, &ex, sizeof(struct example)); 

how recieve:

buf = sock.recv(12) buf = struct.unpack('f f f', buf) print buf 

but when print out on python side random garbage. i'm pretty sure there wrong struct definition in python i'm not sure what.

this line wrong:

write(fd, &ex, sizeof(struct example)); 

it should be:

write(fd, ex, sizeof(struct example)); 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -