Skip to content

Commit 4249323

Browse files
committed
Add new text_t based on char, rename prev to data_t.
1 parent cd67ebe commit 4249323

5 files changed

Lines changed: 44 additions & 19 deletions

File tree

include/bitcoin/system/impl/stream/streamers/sha256t_writer.ipp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ namespace system {
3030
// ----------------------------------------------------------------------------
3131

3232
// protected
33-
template <text_t Tag, typename OStream>
33+
template <data_t Tag, typename OStream>
3434
sha256t_writer<Tag, OStream>::sha256t_writer() NOEXCEPT
3535
: base(),
3636
context_(midstate(), one)
3737
{
3838
}
3939

40-
template <text_t Tag, typename OStream>
40+
template <data_t Tag, typename OStream>
4141
sha256t_writer<Tag, OStream>::sha256t_writer(OStream& sink) NOEXCEPT
4242
: base(sink), context_(midstate(), one)
4343
{
4444
}
4545

46-
template <text_t Tag, typename OStream>
46+
template <data_t Tag, typename OStream>
4747
sha256t_writer<Tag, OStream>::~sha256t_writer() NOEXCEPT
4848
{
4949
// Derived virtual destructor called before base destructor.
@@ -53,7 +53,7 @@ sha256t_writer<Tag, OStream>::~sha256t_writer() NOEXCEPT
5353
// protected
5454
// ----------------------------------------------------------------------------
5555

56-
template <text_t Tag, typename OStream>
56+
template <data_t Tag, typename OStream>
5757
void sha256t_writer<Tag, OStream>::do_write_bytes(const uint8_t* data,
5858
size_t size) NOEXCEPT
5959
{
@@ -62,7 +62,7 @@ void sha256t_writer<Tag, OStream>::do_write_bytes(const uint8_t* data,
6262
context_.write(size, data);
6363
}
6464

65-
template <text_t Tag, typename OStream>
65+
template <data_t Tag, typename OStream>
6666
void sha256t_writer<Tag, OStream>::do_flush() NOEXCEPT
6767
{
6868
flusher();
@@ -73,7 +73,7 @@ void sha256t_writer<Tag, OStream>::do_flush() NOEXCEPT
7373
// ----------------------------------------------------------------------------
7474

7575
// static
76-
template <text_t Tag, typename OStream>
76+
template <data_t Tag, typename OStream>
7777
constexpr sha256::state_t sha256t_writer<Tag, OStream>::midstate() NOEXCEPT
7878
{
7979
// Cache midstate of tagged hash part that does not change for a given tag.
@@ -85,7 +85,7 @@ constexpr sha256::state_t sha256t_writer<Tag, OStream>::midstate() NOEXCEPT
8585

8686
// Only hash overflow returns update false, which requires (2^64-8)/8 bytes.
8787
// The stream could invalidate, but writers shouldn't have to check this.
88-
template <text_t Tag, typename OStream>
88+
template <data_t Tag, typename OStream>
8989
void sha256t_writer<Tag, OStream>::flusher() NOEXCEPT
9090
{
9191
hash_digest hash{};

include/bitcoin/system/literals.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ BC_POP_WARNING()
130130
/// Text representations.
131131
/// ---------------------------------------------------------------------------
132132

133-
template <text_t Text>
133+
template <data_t Text>
134134
CONSTEVAL auto operator "" _array() noexcept
135135
{
136136
return Text.data;

include/bitcoin/system/stream/streamers.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,23 +231,23 @@ namespace hash
231231
namespace sha256t
232232
{
233233
/// A hash writer that writes a tagged sha256 hash to a std::ostream.
234-
template <text_t Tag>
234+
template <data_t Tag>
235235
using ostream = sha256t_writer<Tag, std::ostream>;
236236

237237
/// A fast hash writer that writes a tagged sha256 hash to a system::ostream.
238-
template <text_t Tag>
238+
template <data_t Tag>
239239
using fast = sha256t_writer<Tag, system::ostream<>>;
240240

241241
/////// A hash writer that copies a tagged sha256 hash to a data_slab.
242-
////template <text_t Tag>
242+
////template <data_t Tag>
243243
////using copy = make_streamer<copy_sink<data_slab>, tag<Tag, sha256t_writer>::type>;
244244

245245
/////// A hash writer that inserts a tagged sha256 hash into a container.
246-
////template <text_t Tag, typename Container>
246+
////template <data_t Tag, typename Container>
247247
////using push = make_streamer<push_sink<Container>, tag<Tag, sha256t_writer>::type>;
248-
////template <text_t Tag>
248+
////template <data_t Tag>
249249
////using text = push<Tag, std::string>;
250-
////template <text_t Tag>
250+
////template <data_t Tag>
251251
////using data = push<Tag, data_chunk>;
252252
}
253253
}

include/bitcoin/system/stream/streamers/sha256t_writer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace libbitcoin {
2828
namespace system {
2929

3030
/// A tagged hash writer that accepts an ostream.
31-
template <text_t Tag, typename OStream = std::ostream>
31+
template <data_t Tag, typename OStream = std::ostream>
3232
class sha256t_writer
3333
: public byte_writer<OStream>
3434
{

include/bitcoin/system/types.hpp

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,18 +183,18 @@ BC_PUSH_WARNING(NO_DYNAMIC_ARRAY_INDEXING)
183183
BC_PUSH_WARNING(NO_ARRAY_INDEXING)
184184

185185
template <size_t Size>
186-
class text_t
186+
class data_t
187187
{
188188
public:
189-
CONSTEVAL text_t(const char (&string)[Size]) noexcept
190-
: data(to_array(string))
189+
CONSTEVAL data_t(const char (&string)[Size]) noexcept
190+
: data(to_data(string))
191191
{
192192
}
193193

194194
const std::array<uint8_t, Size - 1> data;
195195

196196
private:
197-
static CONSTEVAL auto to_array(const char(&string)[Size]) noexcept
197+
static CONSTEVAL auto to_data(const char(&string)[Size]) noexcept
198198
{
199199
std::array<uint8_t, Size - 1> out{};
200200
for (size_t index{}; index < Size - 1; ++index)
@@ -204,6 +204,31 @@ class text_t
204204
}
205205
};
206206

207+
template <size_t Size>
208+
class text_t
209+
{
210+
public:
211+
CONSTEVAL text_t(const char (&string)[Size]) noexcept
212+
: text(to_text(string))
213+
{
214+
}
215+
216+
const std::array<char, Size - 1> text;
217+
218+
private:
219+
static CONSTEVAL auto to_text(const char(&string)[Size]) noexcept
220+
{
221+
std::array<char, Size - 1> out{};
222+
for (size_t index{}; index < Size - 1; ++index)
223+
out[index] = string[index];
224+
225+
return out;
226+
}
227+
};
228+
229+
template <size_t Size>
230+
data_t(const char(&)[Size]) noexcept -> data_t<Size>;
231+
207232
template <size_t Size>
208233
text_t(const char(&)[Size]) noexcept -> text_t<Size>;
209234

0 commit comments

Comments
 (0)