15 #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_BYTES_H 16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_BYTES_H 35 StatusOr<Bytes> BytesFromBase64(std::string input);
36 std::string BytesToBase64(Bytes b);
52 template <
typename InputIt>
53 Bytes(InputIt first, InputIt last) {
54 Encoder encoder(base64_rep_);
55 while (first != last) {
56 encoder.buf_[encoder.len_++] = *first++;
57 if (encoder.len_ == encoder.buf_.size()) encoder.Flush();
59 if (encoder.len_ != 0) encoder.FlushAndPad();
61 template <
typename Container>
62 explicit Bytes(Container
const& c) :
Bytes(std::begin(c), std::end(c)) {}
67 template <
typename Container>
68 Container
get()
const {
69 Decoder decoder(base64_rep_);
70 return Container(decoder.begin(), decoder.end());
76 return a.base64_rep_ == b.base64_rep_;
90 friend StatusOr<Bytes> internal::BytesFromBase64(std::string input);
91 friend std::string internal::BytesToBase64(
Bytes b);
94 explicit Encoder(std::string& rep) : rep_(rep), len_(0) {}
100 std::array<unsigned char, 3> buf_;
113 std::string::const_iterator end)
114 : pos_(begin), end_(end), len_(0) {
124 if (--len_ == 0) Fill();
128 auto const old = *
this;
134 return a.pos_ == b.pos_ && a.len_ == b.len_;
141 std::string::const_iterator pos_;
142 std::string::const_iterator end_;
144 std::array<value_type, 1 + 3> buf_;
147 explicit Decoder(std::string
const& rep) : rep_(rep) {}
148 Iterator begin() {
return Iterator(rep_.begin(), rep_.end()); }
149 Iterator end() {
return Iterator(rep_.end(), rep_.end()); }
151 std::string
const& rep_;
154 std::string base64_rep_;
162 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_BYTES_H
friend bool operator==(Bytes const &a, Bytes const &b)
Bytes(Container const &c)
Container get() const
Conversion to a sequence of octets.
friend bool operator!=(Iterator const &a, Iterator const &b)
std::input_iterator_tag iterator_category
friend bool operator!=(Bytes const &a, Bytes const &b)
Contains all the Cloud Spanner C++ client types and functions.
friend bool operator==(Iterator const &a, Iterator const &b)
A representation of the Spanner BYTES type: variable-length binary data.
#define SPANNER_CLIENT_NS
Bytes(InputIt first, InputIt last)
Construction from a sequence of octets.
Iterator(std::string::const_iterator begin, std::string::const_iterator end)
std::ptrdiff_t difference_type
std::ostream & operator<<(std::ostream &os, Backup const &bn)