Converting a C struct into Python to be sent through a socket -
i'm updating old, large piece of software written in c sends struct through socket server. updated software written in python, means need send same information in same byte layout c struct in python. i'm aware of python package struct, , use it. problem is, struct absolutely huge. give idea, here's snipet:
// struct wish send typedef struct { struct st_command_header header; union { char buffer[32]; struct set_360_camera_message camera_msg; struct u_olcd_msg olcd_msg; }; } struct_to_be_set stc; // supporting structs struct st_command_header { union u_all_types len; union u_all_types cmd; union u_all_types cmd_counter; union u_all_types items; } __attribute__((packed)); struct u_olcd_msg { // on 100 lines of fields fill } // other structs necessary
as understand it, struct python package requires manually pack struct, difficult given size of struct , number of union statements. ideally, i'd way utilize existing code generating struct in c somehow transferring on bytes python code socket. there way this? have looked ctypes , swig, didn't see easy way byte representation c code.
Comments
Post a Comment