Skip to content

Commit

Permalink
Fixes #9 - unable to pack into spans
Browse files Browse the repository at this point in the history
with span-lite this currently breaks on MSVC (but not gcc). Waiting to see response to bug report in span-lite
  • Loading branch information
CrustyAuklet committed Sep 27, 2021
1 parent b12b022 commit 1f3ef3b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def validate(self):

def requirements(self):
if not tools.valid_min_cppstd(self, "20"):
self.requires("span-lite/0.7.0")
self.requires("span-lite/0.10.1")

def build_requirements(self):
if tools.get_env("CONAN_RUN_TESTS", True) or self.develop:
Expand Down
14 changes: 7 additions & 7 deletions include/bitpacker/bitstruct.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,8 @@ namespace bitpacker {

/// helper function to pack types into the given buffer
template<typename Fmt, size_type N, size_type... Items, typename... Args>
constexpr void pack(std::array<byte_type, N>& output, const size_type start_bit, std::index_sequence<Items...> /*unused*/, Args&&... args) {
constexpr void pack(span<byte_type, N> output, const size_type start_bit, std::index_sequence<Items...> /*unused*/, Args&&... args) {
static_assert(calcbytes(Fmt{}) <= N, "bitpacker::pack : format larger than given array, not even counting the offset!");
static_assert(sizeof...(args) == sizeof...(Items), "pack expected items for packing != sizeof...(args) passed");
constexpr auto byte_order = impl::get_byte_order(Fmt{});
static_assert(byte_order == impl::Endian::big, "Unpacking little endian byte order not supported yet...");
Expand Down Expand Up @@ -501,21 +502,20 @@ namespace bitpacker {
template<typename Fmt, typename... Args>
constexpr auto pack(Fmt /*unused*/, Args&&... args) {
std::array<byte_type, calcbytes(Fmt{})> output{};
impl::pack<Fmt>(output, 0, std::make_index_sequence<impl::count_non_padding(Fmt{})>(), std::forward<Args>(args)...);
impl::pack<Fmt>(span(output), 0, std::make_index_sequence<impl::count_non_padding(Fmt{})>(), std::forward<Args>(args)...);
return output;
}

/**
* Pack Args... into data, starting at given bit offset offset, according to given format string fmt.
* @param fmt [IN] format string created with macro `BP_STRING()`
* @param data [IN/OUT] reference to existing std::array of bytes to pack into
* @param data [IN/OUT] reference to a fixed size span of bytes to pack into
* @param offset [IN] bit index to start unpacking from
* @param args... [IN] list of arguments to pack into the format string
*/
template<typename Fmt, size_type N, typename... Args>
constexpr void pack_into(Fmt /*unused*/, std::array<byte_type, N>& data, const size_type offset, Args&&... args) {
static_assert(calcbytes(Fmt{}) <= N, "bitpacker::pack_into : format larger than given array, not even counting the offset!");
impl::pack<Fmt>(data, offset, std::make_index_sequence<impl::count_non_padding(Fmt{})>(), std::forward<Args>(args)...);
template<typename Fmt, typename Output, typename... Args>
constexpr void pack_into(Fmt /*unused*/, Output& data, const size_type offset, Args&&... args) {
impl::pack<Fmt>(span(data), offset, std::make_index_sequence<impl::count_non_padding(Fmt{})>(), std::forward<Args>(args)...);
}

} // namespace bitpacker
Expand Down
1 change: 1 addition & 0 deletions tests/python_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#define CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER
#include "test_common.hpp"
#include "bitpacker/bitstruct.hpp"

template < typename T >
std::string escapeString(const T &val)
Expand Down

0 comments on commit 1f3ef3b

Please sign in to comment.