Вопрос

I'm writing a program which will communicate with another program and, obviously, should use same protocol for it.

What I need is something like protobuf, but not protobuf, because it won't let me describe packets format exactly as I want. For example, it inserts field numbers in its packets. Pickle won't do either because of the same reasons.

I wrote my own thing using struct but it is ugly and I not fully understand how is it working. I need something where I can describe different fields like short, integer, their endianness, complex fields, which consists of primitive fields or another complex fields, arrays of primitive fields, array of complex fields.

Could you recommend something like this? Or I doomed to stick to my own solution?

Это было полезно?

Решение

I've had to write Python code for dealing with binary formats before, and struct is no fun to work with. The construct module is much nicer. It allows you to both consume and generate complex binary formats using a simple declarative syntax.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top