Loading [MathJax]/extensions/tex2jax.js
LSST Applications g0fba68d861+05a5e06e50,g1fd858c14a+904f1f4196,g2c84ff76c0+247cd845a2,g2c9e612ef2+f5117f1d55,g35bb328faa+fcb1d3bbc8,g4af146b050+123c2f4d45,g4d2262a081+a9e7a6e053,g4e0f332c67+c58e4b632d,g53246c7159+fcb1d3bbc8,g5a012ec0e7+ac98094cfc,g60b5630c4e+f5117f1d55,g67b6fd64d1+dd0349c22b,g78460c75b0+2f9a1b4bcd,g786e29fd12+cf7ec2a62a,g7b71ed6315+fcb1d3bbc8,g87b7deb4dc+2a1aa4536a,g8852436030+d21aad2af4,g89139ef638+dd0349c22b,g8d6b6b353c+f5117f1d55,g9125e01d80+fcb1d3bbc8,g989de1cb63+dd0349c22b,g9f33ca652e+0a580a37dd,g9f7030ddb1+ae84e0d5a5,ga2b97cdc51+f5117f1d55,gabe3b4be73+1e0a283bba,gb1101e3267+1d994e7598,gb58c049af0+f03b321e39,gb89ab40317+dd0349c22b,gcca6a94b71+4ed007ada1,gcf25f946ba+d21aad2af4,gd315a588df+9d9c5ccff1,gd6cbbdb0b4+75aa4b1db4,gd9a9a58781+fcb1d3bbc8,gde0f65d7ad+6fce216140,ge278dab8ac+c61fbefdff,ge410e46f29+dd0349c22b,ge82c20c137+e12a08b75a,gf67bdafdda+dd0349c22b,v28.0.2.rc1
LSST Data Management Base Package
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
lsst::afw::formatters Namespace Reference

Functions

ndarray::Array< std::uint8_t, 1, 1 > stringToBytes (std::string const &str)
 Encode a std::string as a vector of uint8.
 
std::string bytesToString (ndarray::Array< std::uint8_t const, 1, 1 > const &bytes)
 Decode a std::string from a vector of uint8 returned by stringToBytes.
 

Function Documentation

◆ bytesToString()

std::string lsst::afw::formatters::bytesToString ( ndarray::Array< std::uint8_t const, 1, 1 > const & bytes)

Decode a std::string from a vector of uint8 returned by stringToBytes.

Definition at line 54 of file Utils.cc.

54 {
55 auto nchars = bytes.size() * sizeof(std::uint8_t) / sizeof(char);
56 char const* charCArr = reinterpret_cast<char const*>(bytes.getData());
57 return std::string(charCArr, nchars);
58}

◆ stringToBytes()

ndarray::Array< std::uint8_t, 1, 1 > lsst::afw::formatters::stringToBytes ( std::string const & str)

Encode a std::string as a vector of uint8.

Definition at line 43 of file Utils.cc.

43 {
44 auto nbytes = str.size() * sizeof(char) / sizeof(std::uint8_t);
45 std::uint8_t const* byteCArr = reinterpret_cast<std::uint8_t const*>(str.data());
46 auto shape = ndarray::makeVector(nbytes);
47 auto strides = ndarray::makeVector(1);
48 // Make an Array that shares memory with `str` (and does not free that memory when destroyed),
49 // then return a copy; this is simpler than manually copying the data into a newly allocated array
50 ndarray::Array<std::uint8_t const, 1, 1> localArray = ndarray::external(byteCArr, shape, strides);
51 return ndarray::copy(localArray);
52}