COVESA / capicxx-someip-tools

Common API C++ SOMEIP tooling
Mozilla Public License 2.0
76 stars 55 forks source link

About Stuct Alignment #39

Closed lxt1997 closed 8 months ago

lxt1997 commented 10 months ago

Hi, I would like to transport a struct through VSOMEIP, and I define a struct like struct test { Int32 a Int8 b Double c } and I assume it will be serilize to 16 bytes since I print the sizeof(test) which equals 16, but through the network packets I captured, I found that this struct was be serilized to 13 bytes, how can I set up its alignment or padding. Thank you

RicardoCarreira commented 8 months ago

According to the SOME/IP Protocol Specification:

So analyzing the struct we have a total of 13 bytes as reported based on the values below, which serializes to a 13 bytes structure without padding on SOME/IP as per the specification.

struct test {
    Int32 a      // 4 bytes
    Int8 b       // 1 byte
    Double c     // 8 bytes
}

This was verified through a modification of example one in capixx-core-tools (E01HelloWorld), sending the struct as the message, and with packet capturing in wireshark as shown in the image below, we can see the length of 21 for the SOME/IP Protocol Message (8 header bytes + 13 message bytes). image

One Solution to this issue could be changing the struct to reflect the wanted alignment (16 bytes), such as:

struct test {
    Int32 a       // 4 bytes
    Int32 b       // 4 bytes
    Double c      // 8 bytes
}

This was tested through a modification of example one (E01HelloWorld), sending the struct as the message, and verified with packet capturing in wireshark as shown in the image below, we can see the length of 24 for the SOME/IP Protocol Message (8 header bytes + 16 message bytes). image

lxt1997 commented 8 months ago

Thanks!