Skip to content

Commit 3da8fa5

Browse files
committed
- Updating byte_buffer unittests for the templated version.
1 parent 8bfebae commit 3da8fa5

4 files changed

Lines changed: 199 additions & 135 deletions

File tree

CMakeLists.txt

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,13 @@ target_include_directories(dbps_common_lib PUBLIC
133133
)
134134
target_link_libraries(dbps_common_lib PUBLIC tcb_span)
135135

136-
# Byte buffer processing library
137-
add_library(dbps_byte_buffer_lib STATIC
138-
src/processing/byte_buffer.cpp
139-
)
140-
target_include_directories(dbps_byte_buffer_lib PUBLIC
136+
# Typed buffer processing library (header-only)
137+
add_library(dbps_byte_buffer_lib INTERFACE)
138+
target_include_directories(dbps_byte_buffer_lib INTERFACE
141139
src/processing
142140
src/common
143141
)
144-
target_link_libraries(dbps_byte_buffer_lib PUBLIC tcb_span)
142+
target_link_libraries(dbps_byte_buffer_lib INTERFACE tcb_span)
145143

146144
# Server components library
147145
add_library(dbps_server_lib STATIC
@@ -215,7 +213,7 @@ target_include_directories(dbps_local_lib PUBLIC
215213
)
216214

217215
# Ensure PIC on static libs that are linked into shared libraries
218-
set_target_properties(dbps_common_lib dbps_byte_buffer_lib dbps_server_lib dbps_local_lib
216+
set_target_properties(dbps_common_lib dbps_server_lib dbps_local_lib
219217
PROPERTIES POSITION_INDEPENDENT_CODE ON)
220218

221219
# =============================================================================
@@ -335,13 +333,13 @@ if(BUILD_TESTS)
335333
)
336334
target_include_directories(compression_utils_test PRIVATE src/processing)
337335

338-
# Byte buffer tests
339-
add_executable(byte_buffer_test src/processing/byte_buffer_test.cpp)
340-
target_link_libraries(byte_buffer_test
336+
# Typed buffer tests
337+
add_executable(typed_buffer_test src/processing/typed_buffer_test.cpp)
338+
target_link_libraries(typed_buffer_test
341339
dbps_byte_buffer_lib
342340
gtest_main
343341
)
344-
target_include_directories(byte_buffer_test PRIVATE src/processing src/common)
342+
target_include_directories(typed_buffer_test PRIVATE src/processing src/common)
345343

346344
# Basic encryptor tests
347345
add_executable(basic_encryptor_test src/processing/encryptors/basic_encryptor_test.cpp)
@@ -536,7 +534,7 @@ if(BUILD_TESTS)
536534
parquet_utils_test
537535
bytes_utils_test
538536
compression_utils_test
539-
byte_buffer_test
537+
typed_buffer_test
540538
basic_encryptor_test
541539
auth_utils_test
542540
dbpa_interface_test
@@ -559,7 +557,7 @@ if(BUILD_TESTS)
559557
gtest_discover_tests(parquet_utils_test)
560558
gtest_discover_tests(bytes_utils_test)
561559
gtest_discover_tests(compression_utils_test)
562-
gtest_discover_tests(byte_buffer_test)
560+
gtest_discover_tests(typed_buffer_test)
563561
gtest_discover_tests(basic_encryptor_test)
564562
gtest_discover_tests(auth_utils_test)
565563
gtest_discover_tests(dbpa_interface_test)

src/processing/typed_buffer_codecs.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,61 @@ struct StringVariableSizedCodec {
126126
}
127127
};
128128

129+
struct RawBytesFixedSizedCodec {
130+
using value_type = tcb::span<const uint8_t>;
131+
static constexpr bool is_fixed_sized = true;
132+
133+
explicit RawBytesFixedSizedCodec(size_t element_size_bytes) : element_size_bytes_(element_size_bytes) {
134+
if (element_size_bytes_ == 0) {
135+
throw InvalidInputException("RawBytesFixedSizedCodec requires element_size_bytes > 0");
136+
}
137+
}
138+
139+
static constexpr std::string_view type_name() noexcept {
140+
return "raw bytes (fixed-length)";
141+
}
142+
143+
size_t element_size() const noexcept {
144+
return element_size_bytes_;
145+
}
146+
147+
value_type Decode(tcb::span<const uint8_t> read_span) const noexcept {
148+
return read_span;
149+
}
150+
151+
void Encode(const value_type& value, tcb::span<uint8_t> write_span) const {
152+
if (value.size() != write_span.size()) {
153+
throw InvalidInputException("Encode: value size does not match write_span size");
154+
}
155+
std::memcpy(write_span.data(), value.data(), write_span.size());
156+
}
157+
158+
private:
159+
size_t element_size_bytes_;
160+
};
161+
162+
struct RawBytesVariableSizedCodec {
163+
using value_type = tcb::span<const uint8_t>;
164+
static constexpr bool is_fixed_sized = false;
165+
166+
static constexpr std::string_view type_name() noexcept {
167+
return "raw bytes (variable-length)";
168+
}
169+
170+
size_t element_size() const {
171+
throw InvalidInputException("RawBytesVariableSizedCodec does not have a fixed element size");
172+
}
173+
174+
value_type Decode(tcb::span<const uint8_t> read_span) const noexcept {
175+
return read_span;
176+
}
177+
178+
void Encode(const value_type& value, tcb::span<uint8_t> write_span) const {
179+
if (value.size() != write_span.size()) {
180+
throw InvalidInputException("Encode: value size does not match write_span size");
181+
}
182+
std::memcpy(write_span.data(), value.data(), write_span.size());
183+
}
184+
};
185+
129186
} // namespace dbps::processing

0 commit comments

Comments
 (0)