Bitcoin Core 32.1.0
P2P Digital Currency
Loading...
Searching...
No Matches
base_blob< BITS > Class Template Reference

Template base class for fixed-sized opaque blobs. More...

#include <uint256.h>

Public Member Functions

constexpr base_blob ()
constexpr base_blob (uint8_t v)
constexpr base_blob (std::span< const unsigned char > vch)
consteval base_blob (std::string_view hex_str)
constexpr bool IsNull () const
constexpr void SetNull ()
constexpr bool operator== (const base_blob &) const =default
constexpr std::strong_ordering operator<=> (const base_blob &other) const =default
 Lexicographic ordering.
constexpr const unsigned char * data () const
constexpr unsigned char * data ()
constexpr unsigned char * begin ()
constexpr unsigned char * end ()
constexpr const unsigned char * begin () const
constexpr const unsigned char * end () const
constexpr uint64_t GetUint64 (int pos) const
template<typename Stream>
void Serialize (Stream &s) const
template<typename Stream>
void Unserialize (Stream &s)
Hex representation

The hex representation used by GetHex(), ToString(), and FromHex() is unusual, since it shows bytes of the base_blob in reverse order.

For example, a 4-byte blob {0x12, 0x34, 0x56, 0x78} is represented as "78563412" instead of the more typical "12345678" representation that would be shown in a hex editor or used by typical byte-array / hex conversion functions like python's bytes.hex() and bytes.fromhex().

The nice thing about the reverse-byte representation, even though it is unusual, is that if a blob contains an arithmetic number in little endian format (with least significant bytes first, and most significant bytes last), the GetHex() output will match the way the number would normally be written in base-16 (with most significant digits first and least significant digits last).

This means, for example, that ArithToUint256(num).GetHex() can be used to display an arith_uint256 num value as a number, because ArithToUint256() converts the number to a blob in little-endian format, so the arith_uint256 class doesn't need to have its own number parsing and formatting functions.

std::string GetHex () const
std::string ToString () const

Static Public Member Functions

static constexpr unsigned int size ()

Protected Attributes

std::array< uint8_t, WIDTH > m_data

Static Protected Attributes

static constexpr int WIDTH = BITS / 8

Detailed Description

template<unsigned int BITS>
class base_blob< BITS >

Template base class for fixed-sized opaque blobs.

Definition at line 27 of file uint256.h.

Constructor & Destructor Documentation

◆ base_blob() [1/4]

template<unsigned int BITS>
base_blob< BITS >::base_blob ( )
inlineconstexpr

Definition at line 37 of file uint256.h.

Here is the caller graph for this function:

◆ base_blob() [2/4]

template<unsigned int BITS>
base_blob< BITS >::base_blob ( uint8_t v)
inlineexplicitconstexpr

Definition at line 40 of file uint256.h.

◆ base_blob() [3/4]

template<unsigned int BITS>
base_blob< BITS >::base_blob ( std::span< const unsigned char > vch)
inlineexplicitconstexpr

Definition at line 42 of file uint256.h.

Here is the call graph for this function:

◆ base_blob() [4/4]

template<unsigned int BITS>
base_blob< BITS >::base_blob ( std::string_view hex_str)
explicitconsteval

Definition at line 125 of file uint256.h.

Here is the call graph for this function:

Member Function Documentation

◆ begin() [1/2]

template<unsigned int BITS>
unsigned char * base_blob< BITS >::begin ( )
inlineconstexpr

Definition at line 101 of file uint256.h.

◆ begin() [2/2]

template<unsigned int BITS>
const unsigned char * base_blob< BITS >::begin ( ) const
inlineconstexpr

Definition at line 104 of file uint256.h.

◆ data() [1/2]

template<unsigned int BITS>
unsigned char * base_blob< BITS >::data ( )
inlineconstexpr

Definition at line 99 of file uint256.h.

◆ data() [2/2]

template<unsigned int BITS>
const unsigned char * base_blob< BITS >::data ( ) const
inlineconstexpr

Definition at line 98 of file uint256.h.

Here is the caller graph for this function:

◆ end() [1/2]

template<unsigned int BITS>
unsigned char * base_blob< BITS >::end ( )
inlineconstexpr

Definition at line 102 of file uint256.h.

Here is the caller graph for this function:

◆ end() [2/2]

template<unsigned int BITS>
const unsigned char * base_blob< BITS >::end ( ) const
inlineconstexpr

Definition at line 105 of file uint256.h.

◆ GetHex()

template<unsigned int BITS>
template std::string base_blob< BITS >::GetHex ( ) const

Definition at line 11 of file uint256.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetUint64()

template<unsigned int BITS>
uint64_t base_blob< BITS >::GetUint64 ( int pos) const
inlineconstexpr

Definition at line 109 of file uint256.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsNull()

template<unsigned int BITS>
bool base_blob< BITS >::IsNull ( ) const
inlineconstexpr

Definition at line 50 of file uint256.h.

Here is the caller graph for this function:

◆ operator<=>()

template<unsigned int BITS>
std::strong_ordering base_blob< BITS >::operator<=> ( const base_blob< BITS > & other) const
constexprdefault

Lexicographic ordering.

Note
Does NOT match the ordering on the corresponding base_uint::CompareTo, which starts comparing from the end.
Here is the call graph for this function:

◆ operator==()

template<unsigned int BITS>
bool base_blob< BITS >::operator== ( const base_blob< BITS > & ) const
constexprdefault
Here is the call graph for this function:

◆ Serialize()

template<unsigned int BITS>
template<typename Stream>
void base_blob< BITS >::Serialize ( Stream & s) const
inline

Definition at line 112 of file uint256.h.

Here is the caller graph for this function:

◆ SetNull()

template<unsigned int BITS>
void base_blob< BITS >::SetNull ( )
inlineconstexpr

Definition at line 57 of file uint256.h.

Here is the caller graph for this function:

◆ size()

template<unsigned int BITS>
constexpr unsigned int base_blob< BITS >::size ( )
inlinestaticconstexpr

Definition at line 107 of file uint256.h.

Here is the caller graph for this function:

◆ ToString()

template<unsigned int BITS>
template std::string base_blob< BITS >::ToString ( ) const

Definition at line 21 of file uint256.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Unserialize()

template<unsigned int BITS>
template<typename Stream>
void base_blob< BITS >::Unserialize ( Stream & s)
inline

Definition at line 118 of file uint256.h.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_data

template<unsigned int BITS>
std::array<uint8_t, WIDTH> base_blob< BITS >::m_data
protected

Definition at line 32 of file uint256.h.

◆ WIDTH

template<unsigned int BITS>
int base_blob< BITS >::WIDTH = BITS / 8
staticconstexprprotected

Definition at line 30 of file uint256.h.


The documentation for this class was generated from the following files: