Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
uint_128_t_adaptor.hpp
Go to the documentation of this file.
1#pragma once
2
3#define MSGPACK_NO_BOOST
4#include <msgpack.hpp>
5
8
9namespace msgpack::adaptor {
10
11template <> struct convert<uint128_t> {
12 msgpack::object const& operator()(msgpack::object const& o, uint128_t& v) const
13 {
14 if (o.type == msgpack::type::POSITIVE_INTEGER) {
15 v = static_cast<uint128_t>(o.via.u64);
16 } else if (o.type == msgpack::type::STR) {
17 // When the bigint is too large to fit in a u64, msgpackr will serialize it as a digits string.
18 // Configured on the TS side with largeBigIntToString: true.
19 uint128_t result = 0;
20 // 2**128 is 39 digits long in base 10.
21 if (o.via.str.size > 39) {
22 throw_or_abort("uint128_t deserialization failed: string too long");
23 }
24
25 for (size_t i = 0; i < o.via.str.size; ++i) {
26 char c = o.via.str.ptr[i];
27 if (c < '0' || c > '9') {
28 throw_or_abort("uint128_t deserialization failed: Non-digit character in input");
29 }
30
31 result = result * 10 + (static_cast<uint128_t>(c - '0'));
32 }
33
34 v = result;
35 } else {
36 throw_or_abort("Invalid type for uint128_t deserialization");
37 }
38 return o;
39 }
40};
41
42} // namespace msgpack::adaptor
constexpr std::array< uint8_t, S > convert(const std::string_view &in)
unsigned __int128 uint128_t
Definition serialize.hpp:44
msgpack::object const & operator()(msgpack::object const &o, uint128_t &v) const
void throw_or_abort(std::string const &err)