tlx
bitdump.hpp
Go to the documentation of this file.
1/*******************************************************************************
2 * tlx/string/bitdump.hpp
3 *
4 * Part of tlx - http://panthema.net/tlx
5 *
6 * Copyright (C) 2019 Timo Bingmann <tb@panthema.net>
7 *
8 * All rights reserved. Published under the Boost Software License, Version 1.0
9 ******************************************************************************/
10
11#ifndef TLX_STRING_BITDUMP_HEADER
12#define TLX_STRING_BITDUMP_HEADER
13
14#include <cstdint>
15#include <string>
16
17namespace tlx {
18
19//! \addtogroup tlx_string
20//! \{
21//! \name Bitdump Methods
22//! \{
23
24/******************************************************************************/
25// Bitdump Methods
26
27/*!
28 * Dump a (binary) string of 8-bit bytes as a sequence of '0' and '1'
29 * characters, with the most significant bits (msb) first. Each 8-bit byte is
30 * represented with a block of '0'/'1's separated by spaces.
31 *
32 * \param data binary data to output as bits
33 * \param size length of binary data
34 * \return string of binary digits
35 */
36std::string bitdump_8_msb(const void* const data, size_t size);
37
38/*!
39 * Dump a (binary) string of 8-bit bytes as a sequence of '0' and '1'
40 * characters, with the most significant bits (msb) first. Each 8-bit byte is
41 * represented with a block of '0'/'1's separated by spaces.
42 *
43 * \param str binary data to output as bits
44 * \return string of binary digits
45 */
46std::string bitdump_8_msb(const std::string& str);
47
48/*!
49 * Dump a (binary) item of 8-bit bytes as a sequence of '0' and '1' characters,
50 * with the most significant bits (msb) first. Each 8-bit byte is represented
51 * with a block of '0'/'1's separated by spaces.
52 *
53 * \param t binary data to output as bits
54 * \return string of binary digits
55 */
56template <typename Type>
57std::string bitdump_8_msb_type(const Type& t) {
58 return bitdump_8_msb(&t, sizeof(t));
59}
60
61/*----------------------------------------------------------------------------*/
62
63//! deprecated method: unclear naming and documentation.
64std::string bitdump_le8(const void* const data, size_t size);
65
66//! deprecated method: unclear naming and documentation.
67std::string bitdump_le8(const std::string& str);
68
69//! deprecated method: unclear naming and documentation.
70template <typename Type>
71std::string bitdump_le8_type(const Type& t) {
72 return bitdump_8_msb_type(t);
73}
74
75/*----------------------------------------------------------------------------*/
76
77/*!
78 * Dump a (binary) string of 8-bit bytes as a sequence of '0' and '1'
79 * characters, with the least significant bits (lsb) first. Each 8-bit byte is
80 * represented with a block of '0'/'1's separated by spaces.
81 *
82 * \param data binary data to output as bits
83 * \param size length of binary data
84 * \return string of binary digits
85 */
86std::string bitdump_8_lsb(const void* const data, size_t size);
87
88/*!
89 * Dump a (binary) string of 8-bit bytes as a sequence of '0' and '1'
90 * characters, with the least significant bits (lsb) first. Each 8-bit byte is
91 * represented with a block of '0'/'1's separated by spaces.
92 *
93 * \param str binary data to output as bits
94 * \return string of binary digits
95 */
96std::string bitdump_8_lsb(const std::string& str);
97
98/*!
99 * Dump a (binary) item of 8-bit bytes as a sequence of '0' and '1' characters,
100 * with the least significant bits (lsb) first. Each 8-bit byte is represented
101 * with a block of '0'/'1's separated by spaces.
102 *
103 * \param t binary data to output as bits
104 * \return string of binary digits
105 */
106template <typename Type>
107std::string bitdump_8_lsb_type(const Type& t) {
108 return bitdump_8_lsb(&t, sizeof(t));
109}
110
111/*----------------------------------------------------------------------------*/
112
113//! deprecated method: unclear naming and documentation.
114std::string bitdump_be8(const void* const data, size_t size);
115
116//! deprecated method: unclear naming and documentation.
117std::string bitdump_be8(const std::string& str);
118
119//! deprecated method: unclear naming and documentation.
120template <typename Type>
121std::string bitdump_be8_type(const Type& t) {
122 return bitdump_8_lsb_type(t);
123}
124
125/*----------------------------------------------------------------------------*/
126
127//! \}
128//! \}
129
130} // namespace tlx
131
132#endif // !TLX_STRING_BITDUMP_HEADER
133
134/******************************************************************************/
std::string bitdump_le8(const void *const data, size_t size)
deprecated method: unclear naming and documentation.
Definition: bitdump.cpp:48
std::string bitdump_be8_type(const Type &t)
deprecated method: unclear naming and documentation.
Definition: bitdump.hpp:121
std::string bitdump_8_lsb(const void *const data, size_t size)
Dump a (binary) string of 8-bit bytes as a sequence of '0' and '1' characters, with the least signifi...
Definition: bitdump.cpp:59
std::string bitdump_8_msb_type(const Type &t)
Dump a (binary) item of 8-bit bytes as a sequence of '0' and '1' characters, with the most significan...
Definition: bitdump.hpp:57
std::string bitdump_8_lsb_type(const Type &t)
Dump a (binary) item of 8-bit bytes as a sequence of '0' and '1' characters, with the least significa...
Definition: bitdump.hpp:107
std::string bitdump_le8_type(const Type &t)
deprecated method: unclear naming and documentation.
Definition: bitdump.hpp:71
std::string bitdump_be8(const void *const data, size_t size)
deprecated method: unclear naming and documentation.
Definition: bitdump.cpp:89
std::string bitdump_8_msb(const void *const data, size_t size)
Dump a (binary) string of 8-bit bytes as a sequence of '0' and '1' characters, with the most signific...
Definition: bitdump.cpp:18