10Duke Enterprise C++ SDK
Loading...
Searching...
No Matches
tenduke::utl::BinaryView Class Reference

#include <BinaryView.h>

Detailed Description

A read-only view of binary data.

This class represents a read-only view of binary data, providing access to the data and its size.

The class can wrap various sources of binary data, including raw pointers, fixed-size arrays, and strings.

As a "view" it does not manage the contained data.

You can use factory functions to create instances of BinaryView from various sources, for example:

#include "utl/BinaryView.h"
// Remember that BinaryView does not take ownership of the data: The view is valid only for the lifetime
// of the source data
const auto spanFromConstCharPtr = ::tenduke::utl::make_view("data from const char *");
const auto spanFromStdString = ::tenduke::utl::make_view(std::string("data from std::string");
unsigned char byteBuffer[] = {0x00, 0x01, 0x03};
const auto spanFromByteBuffer = ::tenduke::utl::make_view(byteBuffer);
unsigned char * bytePointer;
std::size_t size;
const auto spanFromBytePtr = ::tenduke::utl::make_view(bytePointer, size);
BinaryView make_view(const unsigned char *data, const std::size_t size)
A helper function to create a tenduke::utl::BinaryView from a const pointer.
Definition BinaryView.h:91
Inheritance diagram for tenduke::utl::BinaryView:
tenduke::utl::DataSpan

Public Member Functions

 BinaryView (const unsigned char *data, const std::size_t size)
 Constructs a new instance.
const unsigned char * data () const override
 Returns a pointer to the beginning of the underlying sequence.This provides a read-only view of the data.
std::size_t size_bytes () const override
 Returns the size of the span in bytes.
Returns
size of the span in bytes

Constructor & Destructor Documentation

◆ BinaryView()

tenduke::utl::BinaryView::BinaryView ( const unsigned char * data,
const std::size_t size )
inline

Constructs a new instance.

Parameters
datathe binary data
sizethe size of the binary data in bytes

Member Function Documentation

◆ data()

const unsigned char * tenduke::utl::BinaryView::data ( ) const
inlineoverridevirtual

Returns a pointer to the beginning of the underlying sequence.This provides a read-only view of the data.

Implements tenduke::utl::DataSpan.

◆ size_bytes()

std::size_t tenduke::utl::BinaryView::size_bytes ( ) const
inlineoverridevirtual

Returns the size of the span in bytes.

Returns
size of the span in bytes

Implements tenduke::utl::DataSpan.


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