Skip to content

Conversation

@Baryonics
Copy link

No description provided.

@YanzhaoW
Copy link
Owner

Hi,

Please wait for pr #31 to finish before you start writing on this pull request.

@YanzhaoW
Copy link
Owner

YanzhaoW commented Nov 28, 2025

Ok, #31 is merged. You could start to implement the class (make sure you have updated your local master branch).

First change EXPECT_FALSE to EXPECT_TRUE here:

EXPECT_FALSE(res.has_value());
auto struct_data = deserializer_converter.run(serializer_converter);
EXPECT_FALSE(struct_data.has_value());

Then, implement the convert function here to make sure the test succeeds.

auto StructSerializer::convert([[maybe_unused]] const StructData* input, [[maybe_unused]] std::vector<char>& output)
-> std::expected<std::size_t, std::string_view>
{
// NOTE: DO NOT do any memory allocation here. If heap data is needed, please initialize it in the constructor.
output.clear();
return std::unexpected{ "not implemented" };
}

To do the testing, go to the build/bin folder and run

./unit_test_srs_backend

@Baryonics Baryonics force-pushed the implement_struct_serializer branch from a6009c8 to cfb12f3 Compare December 1, 2025 16:10
Copy link
Owner

@YanzhaoW YanzhaoW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Here are some suggestions/comments for now:

}

template<typename T>
constexpr auto bin_to_gray(T bin_val)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use binary_to_gray to be more consistent with gray_to_binary.

@Baryonics Baryonics force-pushed the implement_struct_serializer branch from 0feb102 to faac71a Compare December 16, 2025 14:49
Copy link
Owner

@YanzhaoW YanzhaoW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Here are some further suggestions:

Comment on lines +97 to +98
auto output = std::vector<char>{};
output.resize(sizeof(std::uint64_t) / common::BYTE_BIT_LENGTH);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, this is not a good decision to create a new vector in a loop. When a new vector is created, you have the memory allocation (in heap), which is very slow and should be avoided.

What you could do is to create some buffer vector and initialize it only once in the constructor. In the loop, before you write something into it, reset all its members to be zero. Your compact_to_vector should take an non-const ref as its output:

void compact (const T& compact_data, std::vector<char>& output);

Comment on lines +97 to +98
auto output = std::vector<char>{};
output.resize(sizeof(std::uint64_t) / common::BYTE_BIT_LENGTH);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You sure output.resize(sizeof(std::uint64_t) / common::BYTE_BIT_LENGTH); is correct? sizeof(std::uint64_t) / common::BYTE_BIT_LENGTH always results in 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants