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
12
13namespace bb::avm2 {
14
15std::string field_to_string(const FF& ff);
16
17template <typename T>
19std::string to_hex(T value)
20{
21 std::ostringstream stream;
22 auto num_bytes = static_cast<uint64_t>(sizeof(T));
23 auto mask = static_cast<uint64_t>((static_cast<uint128_t>(1) << (num_bytes * 8)) - 1);
24 auto padding = static_cast<int>(num_bytes * 2);
25 stream << std::setfill('0') << std::setw(padding) << std::hex << (value & mask);
26 return stream.str();
27}
28
29template <size_t N> std::string to_string(const std::array<FF, N>& arr)
30{
31 std::ostringstream stream;
32 stream << "{";
33 for (size_t i = 0; i < N; ++i) {
34 stream << field_to_string(arr[i]);
35 if (i < N - 1) {
36 stream << ", ";
37 }
38 }
39 stream << "}";
40 return stream.str();
41}
42
43template <size_t N>
45{
46 std::ostringstream stream;
47 stream << "{";
48 for (size_t i = 0; i < N; ++i) {
49 stream << COLUMN_NAMES[static_cast<size_t>(columns[i])] << ": " << field_to_string(arr[i]);
50 if (i < N - 1) {
51 stream << ", ";
52 }
53 }
54 stream << "}";
55 return stream.str();
56}
57
58} // namespace bb::avm2
std::string to_hex(T value)
Definition stringify.hpp:19
std::string to_string(const std::array< FF, N > &arr)
Definition stringify.hpp:29
std::string column_values_to_string(const std::array< FF, N > &arr, const std::array< ColumnAndShifts, N > &columns)
Definition stringify.hpp:44
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
unsigned __int128 uint128_t
Definition serialize.hpp:44