Bitcoin Core  28.1.0
P2P Digital Currency
Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
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 (Span< const unsigned char > vch)
 
consteval base_blob (std::string_view hex_str)
 
constexpr bool IsNull () const
 
constexpr void SetNull ()
 
constexpr int Compare (const base_blob &other) const
 Lexicographic ordering. More...
 
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 reverse-byte hex representation is a convenient way to view the blob as a number, because it is consistent with the way the base_uint class converts blobs to numbers.

Note
base_uint treats the blob as an array of bytes with the numerically least significant byte first and the most significant byte last. Because numbers are typically written with the most significant digit first and the least significant digit last, the reverse hex display of the blob corresponds to the same numeric value that base_uint interprets from the blob.
std::string GetHex () const
 
void SetHexDeprecated (std::string_view str)
 Unlike FromHex this accepts any invalid input, thus it is fragile and deprecated! More...
 
std::string ToString () const
 

Static Public Member Functions

static constexpr unsigned int size ()
 

Protected Attributes

std::array< uint8_t, WIDTHm_data
 

Static Protected Attributes

static constexpr int WIDTH = BITS / 8
 

Friends

constexpr bool operator== (const base_blob &a, const base_blob &b)
 
constexpr bool operator!= (const base_blob &a, const base_blob &b)
 
constexpr bool operator< (const base_blob &a, const base_blob &b)
 

Detailed Description

template<unsigned int BITS>
class base_blob< BITS >

Template base class for fixed-sized opaque blobs.

Definition at line 23 of file uint256.h.

Constructor & Destructor Documentation

◆ base_blob() [1/4]

template<unsigned int BITS>
constexpr base_blob< BITS >::base_blob ( )
inline

Definition at line 33 of file uint256.h.

◆ base_blob() [2/4]

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

Definition at line 36 of file uint256.h.

◆ base_blob() [3/4]

template<unsigned int BITS>
constexpr base_blob< BITS >::base_blob ( Span< const unsigned char >  vch)
inlineexplicit

Definition at line 38 of file uint256.h.

◆ base_blob() [4/4]

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

Definition at line 126 of file uint256.h.

Member Function Documentation

◆ begin() [1/2]

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

Definition at line 102 of file uint256.h.

◆ begin() [2/2]

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

Definition at line 105 of file uint256.h.

◆ Compare()

template<unsigned int BITS>
constexpr int base_blob< BITS >::Compare ( const base_blob< BITS > &  other) const
inline

Lexicographic ordering.

Note
Does NOT match the ordering on the corresponding base_uint::CompareTo, which starts comparing from the end.

Definition at line 62 of file uint256.h.

Here is the caller graph for this function:

◆ data() [1/2]

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

Definition at line 99 of file uint256.h.

Here is the caller graph for this function:

◆ data() [2/2]

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

Definition at line 100 of file uint256.h.

◆ end() [1/2]

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

Definition at line 103 of file uint256.h.

Here is the caller graph for this function:

◆ end() [2/2]

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

Definition at line 106 of file uint256.h.

◆ GetHex()

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

Definition at line 11 of file uint256.cpp.

Here is the caller graph for this function:

◆ GetUint64()

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

Definition at line 110 of file uint256.h.

Here is the caller graph for this function:

◆ IsNull()

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

Definition at line 46 of file uint256.h.

Here is the caller graph for this function:

◆ Serialize()

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

Definition at line 113 of file uint256.h.

Here is the caller graph for this function:

◆ SetHexDeprecated()

template<unsigned int BITS>
void base_blob< BITS >::SetHexDeprecated ( std::string_view  str)

Unlike FromHex this accepts any invalid input, thus it is fragile and deprecated!

  • Hex numbers that don't specify enough bytes to fill the internal array will be treated as setting the beginning of it, which corresponds to the least significant bytes when converted to base_uint.
  • Hex numbers specifying too many bytes will have the numerically most significant bytes (the beginning of the string) narrowed away.
  • An odd count of hex digits will result in the high bits of the leftmost byte being zero. "0x123" => {0x23, 0x1, 0x0, ..., 0x0}

Definition at line 21 of file uint256.cpp.

Here is the caller graph for this function:

◆ SetNull()

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

Definition at line 53 of file uint256.h.

Here is the caller graph for this function:

◆ size()

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

Definition at line 108 of file uint256.h.

Here is the caller graph for this function:

◆ ToString()

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

Definition at line 47 of file uint256.cpp.

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 119 of file uint256.h.

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator!=

template<unsigned int BITS>
constexpr bool operator!= ( const base_blob< BITS > &  a,
const base_blob< BITS > &  b 
)
friend

Definition at line 65 of file uint256.h.

◆ operator<

template<unsigned int BITS>
constexpr bool operator< ( const base_blob< BITS > &  a,
const base_blob< BITS > &  b 
)
friend

Definition at line 66 of file uint256.h.

◆ operator==

template<unsigned int BITS>
constexpr bool operator== ( const base_blob< BITS > &  a,
const base_blob< BITS > &  b 
)
friend

Definition at line 64 of file uint256.h.

Member Data Documentation

◆ m_data

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

Definition at line 27 of file uint256.h.

◆ WIDTH

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

Definition at line 26 of file uint256.h.


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