Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/rfl/capnproto/Writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ class RFL_API Writer {
std::is_same<std::remove_cvref_t<T>, bool>()) {
_parent->val_.set(_parent->ix_++, _var);

} else if constexpr (std::is_unsigned<std::remove_cvref_t<T>>()) {
_parent->val_.set(_parent->ix_++, static_cast<std::uint64_t>(_var));

} else if constexpr (std::is_integral<std::remove_cvref_t<T>>()) {
_parent->val_.set(_parent->ix_++, static_cast<std::int64_t>(_var));
Comment thread
lixin-wei marked this conversation as resolved.

Expand Down Expand Up @@ -211,6 +214,10 @@ class RFL_API Writer {
std::is_same<std::remove_cvref_t<T>, bool>()) {
_parent->val_.set(to_kj_string_ptr(_name), _var);

} else if constexpr (std::is_unsigned<std::remove_cvref_t<T>>()) {
_parent->val_.set(to_kj_string_ptr(_name),
static_cast<std::uint64_t>(_var));

} else if constexpr (std::is_integral<std::remove_cvref_t<T>>()) {
_parent->val_.set(to_kj_string_ptr(_name),
static_cast<std::int64_t>(_var));
Expand Down Expand Up @@ -242,6 +249,9 @@ class RFL_API Writer {
std::is_same<std::remove_cvref_t<T>, bool>()) {
_parent->val_.set(field, _var);

} else if constexpr (std::is_unsigned<std::remove_cvref_t<T>>()) {
_parent->val_.set(field, static_cast<std::uint64_t>(_var));

} else if constexpr (std::is_integral<std::remove_cvref_t<T>>()) {
_parent->val_.set(field, static_cast<std::int64_t>(_var));

Expand Down
34 changes: 34 additions & 0 deletions tests/capnproto/test_uint64.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <rfl.hpp>
#include <cstdint>
#include <climits>
#include <string>

#include "write_and_read.hpp"

namespace test_uint64 {

struct UnsignedStruct {
uint64_t x = UINT64_MAX;
uint32_t y = UINT32_MAX;
uint16_t z = UINT16_MAX;
uint8_t w = UINT8_MAX;
};

TEST(capnproto, test_uint64) {
const auto s = UnsignedStruct{};
write_and_read(s);
}

TEST(capnproto, test_uint64_specific_values) {
const auto s = UnsignedStruct{
.x = 0, .y = 0, .z = 0, .w = 0};
write_and_read(s);
}

TEST(capnproto, test_uint64_max_values) {
const auto s = UnsignedStruct{
.x = UINT64_MAX, .y = UINT32_MAX, .z = UINT16_MAX, .w = UINT8_MAX};
write_and_read(s);
}
Comment thread
lixin-wei marked this conversation as resolved.

} // namespace test_uint64
Loading