Skip to content

Commit 73352dc

Browse files
committed
fix MP of uint128 (doublecheck)
1 parent b70997e commit 73352dc

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

barretenberg/cpp/src/barretenberg/serialize/msgpack.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,11 @@ inline constexpr std::string camel_case(std::string_view name)
150150
} // namespace msgpack_detail
151151

152152
// Same as MSGPACK_FIELDS but expecting the serialized names to be in camelCase.
153+
// NOTE: We create an intermediate variable because `pack_fn` requires lvalues, and since `camel_case` returns a
154+
// std::string things get weird.
153155
#define MSGPACK_CAMEL_CASE_FIELDS(...) \
154156
void msgpack(auto pack_fn) \
155157
{ \
156-
pack_fn(NVPFG(::msgpack_detail::camel_case, , __VA_ARGS__)); \
158+
auto args = std::make_tuple(NVPFG(::msgpack_detail::camel_case, , __VA_ARGS__)); \
159+
std::apply(pack_fn, args); \
157160
}

barretenberg/cpp/src/barretenberg/serialize/msgpack_impl/uint_128_t_adaptor.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77

88
namespace msgpack::adaptor {
99

10+
// Pack function for uint128_t
11+
template <> struct pack<uint128_t> {
12+
template <typename Stream> msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, uint128_t const& v) const
13+
{
14+
// Use the bin format for 16 bytes of data
15+
o.pack_bin(16);
16+
o.pack_bin_body(reinterpret_cast<const char*>(&v), 16);
17+
return o;
18+
}
19+
};
20+
1021
template <> struct convert<uint128_t> {
1122
msgpack::object const& operator()(msgpack::object const& o, uint128_t& v) const
1223
{

barretenberg/cpp/src/barretenberg/vm2/common/aztec_types.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "barretenberg/common/streams.hpp" // Derives operator<< from MSGPACK_FIELDS.
88
#include "barretenberg/serialize/msgpack.hpp"
9+
#include "barretenberg/serialize/msgpack_impl/uint_128_t_adaptor.hpp"
910
#include "barretenberg/vm2/common/aztec_constants.hpp"
1011
#include "barretenberg/vm2/common/field.hpp"
1112
#include "msgpack/adaptor/define_decl.hpp"

0 commit comments

Comments
 (0)