April 2020
Intermediate to advanced
412 pages
9h 58m
English
When you run the binary, you will see the following output:

In this simple program, we're simulating communication with an external device. Since we don't have a real device, the SendDataToDevice function just prints the size of the data it is supposed to send to the target device.
Suppose the device can operate on chunks of data of a variable size. Each chunk of data is prepended by its size and encoded as a 32-bit unsigned integer. This can be described as follows:
| Size | Payload |
| 0-4 bytes | 5 - N bytes, where N is Size |
In our code, we declare size as uint32_t:
uint32_t size = sizeof(buffer);
This means that it will ...