hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
byteutils.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_BYTEUTILS_H
7 #define IROHA_BYTEUTILS_H
8 
9 #include <algorithm>
10 #include <string>
11 #include <vector>
12 
13 #include <boost/optional.hpp>
14 
15 #include "common/bind.hpp"
16 #include "common/blob.hpp"
17 #include "common/hexutils.hpp"
18 
19 namespace iroha {
25  inline std::vector<uint8_t> stringToBytes(const std::string &source) {
26  return std::vector<uint8_t>(source.begin(), source.end());
27  }
28 
34  inline std::string bytesToString(const std::vector<uint8_t> &source) {
35  return std::string(source.begin(), source.end());
36  }
37 
44  template <size_t size>
45  boost::optional<blob_t<size>> stringToBlob(const std::string &string) {
46  if (size != string.size()) {
47  return boost::none;
48  }
49  blob_t<size> array;
50  std::copy(string.begin(), string.end(), array.begin());
51  return array;
52  }
53 
60  template <size_t size>
61  boost::optional<blob_t<size>> hexstringToArray(const std::string &string) {
62  return hexstringToBytestring(string) | stringToBlob<size>;
63  }
64 
65 } // namespace iroha
66 
67 #endif // IROHA_BYTEUTILS_H
string(REPLACE".""/"CMAKE_SWIG_OUTDIR ${SWIG_JAVA_PKG}) else() set(CMAKE_SWIG_FLAGS"") endif() myswig_add_library(irohajava LANGUAGE java SOURCES bindings.i) unset(CMAKE_SWIG_FLAGS) swig_link_libraries(irohajava $
Definition: CMakeLists.txt:54
std::vector< uint8_t > stringToBytes(const std::string &source)
Definition: byteutils.hpp:25
boost::optional< blob_t< size > > hexstringToArray(const std::string &string)
Definition: byteutils.hpp:61
Definition: block_query.hpp:16
boost::optional< std::string > hexstringToBytestring(const std::string &str)
Definition: hexutils.hpp:37
boost::optional< blob_t< size > > stringToBlob(const std::string &string)
Definition: byteutils.hpp:45
Definition: blob.hpp:49
const std::string end
Definition: logger.cpp:9
std::string bytesToString(const std::vector< uint8_t > &source)
Definition: byteutils.hpp:34