Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
stringify.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <concepts>
4#include <cstdint>
5#include <sstream>
6#include <string>
7#include <tuple>
8#include <utility>
9
14
15namespace bb::avm2 {
16
17std::string field_to_string(const FF& ff);
18
19template <typename T>
21std::string to_hex(T value)
22{
23 std::ostringstream stream;
24 auto num_bytes = static_cast<uint64_t>(sizeof(T));
25 auto mask = static_cast<uint64_t>((static_cast<uint128_t>(1) << (num_bytes * 8)) - 1);
26 auto padding = static_cast<int>(num_bytes * 2);
27 stream << std::setfill('0') << std::setw(padding) << std::hex << (value & mask);
28 return stream.str();
29}
30
31template <size_t N> std::string to_string(const std::array<FF, N>& arr)
32{
33 std::ostringstream stream;
34 stream << "{";
35 for (size_t i = 0; i < N; ++i) {
36 stream << field_to_string(arr[i]);
37 if (i < N - 1) {
38 stream << ", ";
39 }
40 }
41 stream << "}";
42 return stream.str();
43}
44
45template <size_t N>
47{
48 std::ostringstream stream;
49 stream << "{";
50 for (size_t i = 0; i < N; ++i) {
51 stream << COLUMN_NAMES[static_cast<size_t>(columns[i])] << ": " << field_to_string(arr[i]);
52 if (i < N - 1) {
53 stream << ", ";
54 }
55 }
56 stream << "}";
57 return stream.str();
58}
59
60template <typename... Ts, size_t N>
62{
63 static_assert(sizeof...(Ts) == N, "Tuple and columns array must have the same size");
64 std::ostringstream stream;
65 stream << "{";
66 [&]<size_t... Is>(std::index_sequence<Is...>) {
67 size_t i = 0;
68 ((stream << (i++ > 0 ? ", " : "") << COLUMN_NAMES[static_cast<size_t>(columns[Is])] << ": "
70 ...);
72 stream << "}";
73 return stream.str();
74}
75
76} // namespace bb::avm2
std::string to_hex(T value)
Definition stringify.hpp:21
std::string to_string(const std::array< FF, N > &arr)
Definition stringify.hpp:31
std::string column_values_to_string(const std::array< FF, N > &arr, const std::array< ColumnAndShifts, N > &columns)
Definition stringify.hpp:46
const std::vector< std::string > & COLUMN_NAMES
Definition columns.hpp:84
std::string field_to_string(const FF &ff)
Definition stringify.cpp:5
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
TUPLET_INLINE constexpr decltype(auto) get(Tup &&tup)
Definition tuplet.hpp:1021
unsigned __int128 uint128_t
Definition serialize.hpp:44