Skip to content

sgns::base::Blob

More...

#include <blob.hpp>

Inherits from std::array< uint8_t, size_ >

Public Functions

Name
Blob()
constexpr Blob(const std::array< uint8_t, size_ > & l)
constructor enabling initializer list
std::string toString() const
std::string toReadableString() const
std::string toHex() const
std::vector< uint8_t > ToVec() const
size_t size()
outcome::result< Blob< size_ > > fromString(std::string_view data)
outcome::result< Blob< size_ > > fromReadableString(std::string_view data)
outcome::result< Blob< size_ > > fromHex(std::string_view hex)
outcome::result< Blob< size_ > > fromHexWithPrefix(std::string_view hex)
outcome::result< Blob< size_ > > fromSpan(gsl::span< uint8_t > span)

Detailed Description

template <size_t size_>
class sgns::base::Blob;

Base type which represents blob of fixed size.

std::string is convenient to use but it is not safe. We can not specify the fixed length for string.

For std::array it is possible, so we prefer it over std::string.

Public Functions Documentation

function Blob

inline Blob()

Initialize blob value

function Blob

inline explicit constexpr Blob(
    const std::array< uint8_t, size_ > & l
)

constructor enabling initializer list

Parameters:

  • l initializer list

function toString

inline std::string toString() const

Converts current blob to std::string

function toReadableString

inline std::string toReadableString() const

Converts current blob to a readable std::string

function toHex

inline std::string toHex() const

Converts current blob to hex string.

function ToVec

inline std::vector< uint8_t > ToVec() const

function size

static inline size_t size()

In compile-time returns size of current blob.

function fromString

static inline outcome::result< Blob< size_ > > fromString(
    std::string_view data
)

Parameters:

  • data arbitrary string containing

Return: result containing Blob object if string has proper size

Create Blob from arbitrary string, putting its bytes into the blob

function fromReadableString

static inline outcome::result< Blob< size_ > > fromReadableString(
    std::string_view data
)

function fromHex

static inline outcome::result< Blob< size_ > > fromHex(
    std::string_view hex
)

Parameters:

  • hex hex string

Return: result containing Blob object if hex string has proper size and is in hex format

Create Blob from hex string

function fromHexWithPrefix

static inline outcome::result< Blob< size_ > > fromHexWithPrefix(
    std::string_view hex
)

Parameters:

  • hex hex string

Return: result containing Blob object if hex string has proper size and is in hex format

Create Blob from hex string prefixed with 0x

function fromSpan

static inline outcome::result< Blob< size_ > > fromSpan(
    gsl::span< uint8_t > span
)

Parameters:

  • span input byte span

Return: result containing Blob object if span has proper size

Create Blob from span of uint8_t


Updated on 2026-03-04 at 13:10:43 -0800