Skip to content
Snippets Groups Projects
Unverified Commit 5e1f2d6e authored by kongr45gpen's avatar kongr45gpen
Browse files

Remove unneeded templates from the appendString() functions

This reduces the size of the code from 208608 to 208072 bytes, which is
totally negligible
parent 4326bfdb
No related branches found
No related tags found
No related merge requests found
......@@ -159,8 +159,7 @@ public:
*
* @param string The string to insert
*/
template <const size_t SIZE>
void appendString(const String<SIZE>& string);
void appendString(const etl::istring& string);
/**
* Appends a number of bytes to the message
......@@ -175,8 +174,7 @@ public:
*
* @param string The string to insert
*/
template <const size_t SIZE>
void appendFixedString(const String<SIZE>& string);
void appendFixedString(const etl::istring& string);
/**
* Reads the next \p numBits bits from the the message in a big-endian format
......@@ -358,14 +356,7 @@ public:
*
* PTC = 7, PFC = 0
*/
template <const size_t SIZE>
void appendOctetString(const String<SIZE>& string) {
// Make sure that the string is large enough to count
ASSERT_INTERNAL(string.size() <= (std::numeric_limits<uint16_t>::max)(), ErrorHandler::StringTooLarge);
appendUint16(string.size());
appendString(string);
}
void appendOctetString(const etl::istring& string);
/**
* Adds a nested TC or TM Message within the current Message
......@@ -573,25 +564,4 @@ public:
}
};
template <const size_t SIZE>
inline void Message::appendString(const String<SIZE>& string) {
ASSERT_INTERNAL(dataSize + string.size() < ECSS_MAX_MESSAGE_SIZE, ErrorHandler::MessageTooLarge);
// TODO: Do we need to keep this check? How does etl::string handle it?
ASSERT_INTERNAL(string.size() < string.capacity(), ErrorHandler::StringTooLarge);
memcpy(data + dataSize, string.data(), string.size());
dataSize += string.size();
}
template <const size_t SIZE>
inline void Message::appendFixedString(const String<SIZE>& string) {
ASSERT_INTERNAL((dataSize + SIZE) < ECSS_MAX_MESSAGE_SIZE, ErrorHandler::MessageTooLarge);
memcpy(data + dataSize, string.data(), string.size()); // Append the bytes with content
(void) memset(data + dataSize + string.size(), 0, SIZE - string.size()); // The rest of the bytes is set to 0
dataSize += SIZE;
}
#endif // ECSS_SERVICES_PACKET_H
......@@ -166,3 +166,32 @@ void Message::resetRead() {
void Message::appendMessage(const Message& message, uint16_t size) {
appendString(MessageParser::composeECSS(message, size));
}
void Message::appendString(const etl::istring& string) {
ASSERT_INTERNAL(dataSize + string.size() < ECSS_MAX_MESSAGE_SIZE, ErrorHandler::MessageTooLarge);
// TODO: Do we need to keep this check? How does etl::string handle it?
ASSERT_INTERNAL(string.size() < string.capacity(), ErrorHandler::StringTooLarge);
memcpy(data + dataSize, string.data(), string.size());
dataSize += string.size();
}
void Message::appendFixedString(const etl::istring& string) {
ASSERT_INTERNAL((dataSize + string.max_size()) < ECSS_MAX_MESSAGE_SIZE, ErrorHandler::MessageTooLarge);
// Append the bytes with content
memcpy(data + dataSize, string.data(), string.size());
// The rest of the bytes is set to 0
(void) memset(data + dataSize + string.size(), 0, string.max_size() - string.size());
dataSize += string.max_size();
}
void Message::appendOctetString(const etl::istring& string) {
// Make sure that the string is large enough to count
ASSERT_INTERNAL(string.size() <= (std::numeric_limits<uint16_t>::max)(), ErrorHandler::StringTooLarge);
appendUint16(string.size());
appendString(string);
}
......@@ -25,7 +25,7 @@ int main() {
Message packet = Message(0, 0, Message::TC, 1);
packet.appendString<5>("hello");
packet.appendString(String<5>("hello"));
packet.appendBits(15, 0x28a8);
packet.appendBits(1, 1);
packet.appendFloat(5.7);
......
......@@ -156,7 +156,7 @@ TEST_CASE("Requirement 7.3.6 (Real)", "[message][ecss]") {
TEST_CASE("Requirement 7.3.8 (Octet-string)", "[message][ecss]") {
Message message(0, 0, Message::TC, 0);
message.appendString<4>("test");
message.appendString(String<4>("test"));
REQUIRE(message.dataSize == 4);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment