10Duke Enterprise C++ SDK
Loading...
Searching...
No Matches
BinaryView.h
1#ifndef TENDUKE_CORE_BINARYVIEW_H
2#define TENDUKE_CORE_BINARYVIEW_H
3
4#include "./DataSpan.h"
5
6#include <cstring>
7#include <string>
8
9namespace tenduke { namespace utl {
10
40{
41public:
48 const unsigned char *data,
49 const std::size_t size
50 ) : data_(data)
51 , size_(size)
52 {
53 }
54
58 const unsigned char * data() const override
59 {
60 return data_;
61 }
62
66 std::size_t size_bytes() const override
67 {
68 return size_;
69 }
70
71private:
72 const unsigned char *data_;
73 std::size_t size_;
74};
75
81{
82 return {nullptr, 0};
83}
84
92 const unsigned char* data,
93 const std::size_t size
94) {
95 return {data, size};
96}
97
103template <std::size_t N>
104inline BinaryView make_view(unsigned char (&arr)[N])
105{
106 return BinaryView(arr, N);
107}
108
114inline BinaryView make_view(const char *value)
115{
116 return {
117 reinterpret_cast<const unsigned char*>(value),
118 std::strlen((const char*)value)
119 };
120}
121
127inline BinaryView make_view(const std::string &value)
128{
129 return {
130 reinterpret_cast<const unsigned char*>(value.data()),
131 value.size()
132 };
133}
134
135}}
136
137#endif //TENDUKE_CORE_BINARYVIEW_H
A read-only view of binary data.
Definition BinaryView.h:40
BinaryView(const unsigned char *data, const std::size_t size)
Constructs a new instance.
Definition BinaryView.h:47
const unsigned char * data() const override
Returns a pointer to the beginning of the underlying sequence.This provides a read-only view of the d...
Definition BinaryView.h:58
std::size_t size_bytes() const override
Returns the size of the span in bytes.size of the span in bytes
Definition BinaryView.h:66
A span of binary data.
Definition DataSpan.h:16
Utilities.
Definition Base64Decoder.h:10
BinaryView empty_view()
Creates an empty tenduke::utl::BinaryView.
Definition BinaryView.h:80
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
Root for classes, functions and globals of 10Duke C++ Client.
Definition APIRequest.h:4