Skip to content

Commit 7123e82

Browse files
committed
Use static alloc heatshrink encoder
They don't mix well if compiled both into one static library.
1 parent 8113f52 commit 7123e82

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

ext/heatshrink/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ add_library(heatshrink STATIC
99
${heatshrink_SOURCE_DIR}/src/heatshrink_encoder.c
1010
)
1111

12+
target_compile_definitions(heatshrink PUBLIC
13+
HEATSHRINK_DYNAMIC_ALLOC=0
14+
HEATSHRINK_STATIC_WINDOW_BITS=9
15+
HEATSHRINK_STATIC_LOOKAHEAD_BITS=5
16+
)
17+
1218
target_include_directories(heatshrink
1319
PUBLIC
1420
${heatshrink_SOURCE_DIR}/include

libxbot-service-interface/src/HeatshrinkEncode.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,25 @@ extern "C" {
55
}
66

77
std::vector<uint8_t> HeatshrinkEncode(uint8_t *data, const size_t size) {
8-
heatshrink_encoder *encoder = heatshrink_encoder_alloc(8, 4);
8+
heatshrink_encoder encoder;
99
std::vector<uint8_t> out;
1010
uint8_t buf[128];
1111
size_t processed = 0, processed_now, polled_now;
1212
HSE_poll_res poll_res;
1313

14+
heatshrink_encoder_reset(&encoder);
1415
while (processed < size) {
15-
heatshrink_encoder_sink(encoder, &data[processed], size - processed, &processed_now);
16+
heatshrink_encoder_sink(&encoder, &data[processed], size - processed, &processed_now);
1617
processed += processed_now;
1718

1819
do {
19-
poll_res = heatshrink_encoder_poll(encoder, buf, sizeof(buf), &polled_now);
20+
poll_res = heatshrink_encoder_poll(&encoder, buf, sizeof(buf), &polled_now);
2021
out.insert(out.end(), buf, buf + polled_now);
2122
} while (poll_res == HSER_POLL_MORE);
2223
}
2324

24-
while (heatshrink_encoder_finish(encoder) == HSER_FINISH_MORE) {
25-
heatshrink_encoder_poll(encoder, buf, sizeof(buf), &polled_now);
25+
while (heatshrink_encoder_finish(&encoder) == HSER_FINISH_MORE) {
26+
heatshrink_encoder_poll(&encoder, buf, sizeof(buf), &polled_now);
2627
out.insert(out.end(), buf, buf + polled_now);
2728
}
2829

libxbot-service/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ add_library(xbot-service STATIC
1818
src/DataSource.cpp
1919
)
2020
target_compile_options(xbot-service PRIVATE -Wall -Wextra -Werror -Wno-volatile)
21-
target_compile_definitions(heatshrink PUBLIC HEATSHRINK_DYNAMIC_ALLOC=0)
2221

2322
if (NOT DEFINED XBOT_CUSTOM_PORT_PATH)
2423
SET(XBOT_CUSTOM_PORT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/src/portable/linux)

0 commit comments

Comments
 (0)