15 #include "google/cloud/spanner/bytes.h"
16 #include "google/cloud/internal/base64_transforms.h"
17 #include "google/cloud/status.h"
33 std::ostream& operator<<(std::ostream& os,
Bytes const& bytes) {
35 for (
auto const byte : Base64Decoder(bytes.base64_rep_)) {
38 }
else if (std::isprint(byte)) {
43 std::array<
char,
sizeof(R"(\000)")> buf;
44 auto n = std::snprintf(buf.data(), buf.size(), R"(\%03o)", byte);
45 if (n ==
static_cast<
int>(buf.size() - 1)) {
59 namespace spanner_internal {
61 struct BytesInternals {
64 bytes.base64_rep_ = std::move(rep);
69 return std::move(bytes.base64_rep_);
74 StatusOr<
spanner::
Bytes> BytesFromBase64(std::string input) {
75 auto status =
google::
cloud::internal::ValidateBase64String(input);
76 if (!status
.ok())
return status;
77 return BytesInternals::Create(std::move(input));
82 return BytesInternals::GetRep(std::move(b));