We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 51744d4 commit ea8aa7aCopy full SHA for ea8aa7a
3 files changed
compost_rpc/lib/c/header_template.py
@@ -22,6 +22,21 @@
22
#define COMPOST_EFLAGS -91 ///< Reserved flags set
23
#define COMPOST_ETXN -92 ///< Unexcepted transaction value
24
25
+/// Length of the message header in bytes
26
+#define COMPOST_HEADER_LEN 4
27
+
28
+/**
29
+ * @brief Calculates the length of the entire message in bytes from the first byte of the header
30
+ * @param msg Pointer to the message
31
+ */
32
+#define COMPOST_MSG_LEN(msg) (4 + (4 * (((uint8_t *)msg)[0])))
33
34
35
+ * @brief Calculates the length of the payload in bytes from the first byte of the header
36
37
38
+#define COMPOST_PAYLOAD_LEN(msg) (4 * (((uint8_t *)msg)[0]))
39
40
struct CompostMsg {
41
uint16_t len;
42
uint16_t rpc_id;
examples/pc_to_pc/main.c
@@ -87,20 +87,20 @@ int main(int argc, char *argv[])
87
for (;;) {
88
89
// Read the header (first 4 bytes)
90
- if (read_bytes(connection, rx_buf, HEADER_SIZE) < 1)
+ if (read_bytes(connection, rx_buf, COMPOST_HEADER_LEN) < 1)
91
break;
92
93
// Calculate the size of the payload
94
// (first byte of the header indicates the number of 32-bit words of the payload)
95
- size_t rx_payload_size = 4 * rx_buf[0];
+ size_t rx_payload_size = COMPOST_PAYLOAD_LEN(rx_buf);
96
97
// Read the payload
98
- if (read_bytes(connection, rx_buf + HEADER_SIZE, rx_payload_size) < 1)
+ if (read_bytes(connection, rx_buf + COMPOST_HEADER_LEN, rx_payload_size) < 1)
99
100
101
// Process the request and prepare the response
102
int16_t tx_msg_size =
103
- compost_msg_process(tx_buf, sizeof(tx_buf), rx_buf, HEADER_SIZE + rx_payload_size);
+ compost_msg_process(tx_buf, sizeof(tx_buf), rx_buf, COMPOST_MSG_LEN(rx_buf));
104
105
// If the message size is negative, it indicates an error
106
if (tx_msg_size > 0) {
test/mock/main.c
@@ -92,17 +92,18 @@ int main(int argc, char *argv[])
compost_set_assert_func(compost_assert);
- if (fread(rx_buf, 1, 4, stdin) != 4) {
+ if (fread(rx_buf, 1, COMPOST_HEADER_LEN, stdin) != 4) {
}
- uint16_t data_len8 = rx_buf[0] * 4;
- if (data_len8 > 0) {
- if (fread(rx_buf + 4, 1, data_len8, stdin) != data_len8) {
+ size_t payload_len = COMPOST_PAYLOAD_LEN(rx_buf);
+ if (payload_len > 0) {
+ if (fread(rx_buf + COMPOST_HEADER_LEN, 1, payload_len, stdin) != payload_len) {
- log_msg(" mock <- ", rx_buf, 4 + data_len8);
- int16_t tx_len = compost_msg_process(tx_buf, sizeof(tx_buf), rx_buf, 4 + data_len8);
+ size_t msg_len = COMPOST_MSG_LEN(rx_buf);
+ log_msg(" mock <- ", rx_buf, msg_len);
+ int16_t tx_len = compost_msg_process(tx_buf, sizeof(tx_buf), rx_buf, msg_len);
107
log_msg(" mock -> ", tx_buf, tx_len);
108
109
if (tx_len) {
0 commit comments