Support Board
Date/Time: Fri, 29 Nov 2024 21:01:03 +0000
Post From: DTC Protocol
[2016-04-01 00:00:20] |
vbmithr - Posts: 204 |
See my code here: https://github.com/vbmithr/ocaml-dtc/blob/master/lib/cstructs.ml This is OCaml (well an OCaml extension to parse C structures), and you can see where fields are padded when I add a field like named like _padding (sometimes there are multiple padding fields). The rules are that types (short, int, long, …) are aligned by a multiple of their size, i.e. for example a short cannot start on byte 5, a long (64 bits) cannot start on byte 6, and so on…, so that if you, say, have a structure like struct MyStruct {
char a; uint64 b; } the size will not be 9, but 16, and equivalent to struct MyStruct {
char a[8]; uint64 b; } That's why I advise you to use the protobuf encoding (and you advised yourself to use JSON). It is tedious to deal with those padding oneself. Date Time Of Last Edit: 2016-04-01 00:01:23
|