开发者

Sending binary data over IPC from C to Python

I have a C program and a Python program on the same machine. The C program generates some data in nested structures. What form of IPC is the best way to get this data across to the python program?

Serializing in C (especially nested structures) is a real bear, from what I hear, due to lack of serialization libraries. I am not very familiar with shared memory, but I assume the formatting of the C structures may not be very palatable to the python program when it comes to memory alignment and following pointers. The ctype and struct library seems to be for non-nested s开发者_开发百科tructures only. So far, what I am thinking is:

Wrap all the data in the C program into some xml or json format, write it via socket to python program and then let python program interpret the xml/json formatted data. Looks very cumbersome with lots of overheads.

Any better ideas ?


I think you answered your own question. JSON is certainly a good choice. It's also not terribly difficult to do your own serialization in C.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜