Skip to content

Commit 431170f

Browse files
tpwrulestridge
authored andcommitted
inline coding of 0-length messages
Allows the processing of 0-length messages (which is true of some important ones in the DSDL) to be optimized away.
1 parent d7a1990 commit 431170f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

templates/msg.h.em

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,32 @@ static inline uint32_t @(msg_underscored_name)_encode(@(msg_c_type)* msg, uint8_
8181
, bool tao
8282
#endif
8383
) {
84+
@[if msg_max_bitlen == 0]
85+
(void)msg;
86+
(void)buffer;
87+
#if CANARD_ENABLE_TAO_OPTION
88+
(void)tao;
89+
#endif
90+
91+
return 0; // 0-length message encodes to 0 bytes
92+
@[else]
8493
return _@(msg_underscored_name)_encode(msg, buffer
8594
#if CANARD_ENABLE_TAO_OPTION
8695
, tao
8796
#endif
8897
);
98+
@[end if]
8999
}
90100

91101
static inline bool @(msg_underscored_name)_decode(const CanardRxTransfer* transfer, @(msg_c_type)* msg) {
102+
@[if msg_max_bitlen == 0]
103+
(void)msg;
104+
105+
// all transports accurately convey a payload length of 0 bytes so any payload is an error
106+
return transfer->payload_len != 0;
107+
@[else]
92108
return _@(msg_underscored_name)_decode(transfer, msg);
109+
@[end if]
93110
}
94111

95112
#if defined(CANARD_DSDLC_INTERNAL)

0 commit comments

Comments
 (0)