Skip to content

Commit 1651677

Browse files
committed
fix: Fix long-stl error with test
1 parent c8f5809 commit 1651677

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

example/efp_logger_example.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,11 @@ int main() {
2929
// ! Every 20 ~ 30 char will take one buffer space.
3030
fatal("This is a fatal message with a std::string: {}", std::string("fatal error"));
3131

32+
const auto lorem_ipsum = std::string("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
33+
info("This is a info message with a long string: {}", lorem_ipsum);
34+
const auto a_1000 = std::string(1000, 'a');
35+
info("This is a info message with a 1000 char string: {}", a_1000);
36+
info("Does it support Korean? {}", "한글도 되나요?");
37+
3238
return 0;
3339
}

include/efp/logger.hpp

+14-12
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ namespace efp {
8787
};
8888

8989
constexpr uint8_t stl_string_data_capacity = sizeof(FormatedMessage);
90-
constexpr uint8_t stl_string_head_capacity = stl_string_data_capacity - 1;
90+
constexpr uint8_t stl_string_head_capacity = stl_string_data_capacity - sizeof(size_t);
9191

9292
// Data structure for std::string preventing each char takes size of full Enum;
9393
struct StlStringHead {
94-
uint8_t length;
94+
size_t length;
9595
char chars[stl_string_head_capacity];
9696
};
9797

@@ -145,26 +145,28 @@ namespace efp {
145145

146146
// todo Need pointer casting specialization
147147
inline Unit enqueue_arg(const std::string& a) {
148-
const uint8_t str_length = a.length();
148+
const auto str_length = a.length();
149149

150150
StlStringHead head{};
151-
uint8_t chars_in_head = str_length < stl_string_head_capacity
152-
? str_length
153-
: stl_string_head_capacity;
151+
const auto chars_in_head = str_length < stl_string_head_capacity
152+
? str_length
153+
: stl_string_head_capacity;
154+
154155
_memcpy(head.chars, a.data(), chars_in_head);
155-
head.length = static_cast<uint8_t>(chars_in_head);
156+
157+
head.length = str_length;
156158

157159
_write_buffer->push_back(head);
158160

159161
if (str_length > stl_string_head_capacity) {
160162
int remaining_length = str_length - chars_in_head;
161-
uint8_t offset = chars_in_head;
163+
size_t offset = chars_in_head;
162164

163165
while (remaining_length > 0) {
164166
StlStringData data{};
165-
uint8_t length_to_push = remaining_length < stl_string_data_capacity
166-
? remaining_length
167-
: stl_string_data_capacity;
167+
size_t length_to_push = remaining_length < stl_string_data_capacity
168+
? remaining_length
169+
: stl_string_data_capacity;
168170

169171
_memcpy(data.chars, a.data() + offset, length_to_push);
170172

@@ -234,7 +236,7 @@ namespace efp {
234236
: stl_string_head_capacity);
235237

236238
// Extracting the remaining parts of the string if necessary
237-
int remaining_length = arg.length - stl_string_head_capacity;
239+
size_t remaining_length = arg.length - stl_string_head_capacity;
238240
while (remaining_length > 0) {
239241
_read_buffer->pop_front().match(
240242
[&](const StlStringData& d) {

0 commit comments

Comments
 (0)