[Python] How to transfer this part of code from C to Python using dataclass

Discussão em 'Python' iniciado por Stack, Março 14, 2025.

  1. Stack

    Stack Membro Participativo

    I have this part of code:

    MAX_NUMBER_OF_ITEMS = 9

    typedef struct {
    uint64_t status;
    uint8_t serial_number_of_items [MAX_NUMBER_OF_ITEMS];
    uint8_t version;
    }Items_Info_t;


    How can I convert the following C code to Python, specifically the part:

    uint8_t number_of_items [MAX_NUMBER_OF_ITEMS]


    I try to do this way:

    class Sensor Info:

    status: int
    serial_number_of_items: List[int]
    version: int


    Also, how can I perform serialization using struct.pack after that?

    Continue reading...

Compartilhe esta Página