mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpiutil] Base64: Add unsigned span/vector variants (#3702)
This commit is contained in:
@@ -132,6 +132,20 @@ std::string_view Base64Decode(std::string_view encoded, size_t* num_read,
|
||||
return os.str();
|
||||
}
|
||||
|
||||
size_t Base64Decode(std::string_view encoded, std::vector<uint8_t>* plain) {
|
||||
plain->resize(0);
|
||||
raw_uvector_ostream os(*plain);
|
||||
return Base64Decode(os, encoded);
|
||||
}
|
||||
|
||||
span<uint8_t> Base64Decode(std::string_view encoded, size_t* num_read,
|
||||
SmallVectorImpl<uint8_t>& buf) {
|
||||
buf.clear();
|
||||
raw_usvector_ostream os(buf);
|
||||
*num_read = Base64Decode(os, encoded);
|
||||
return os.array();
|
||||
}
|
||||
|
||||
static const char basis_64[] =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
@@ -179,4 +193,24 @@ std::string_view Base64Encode(std::string_view plain,
|
||||
return os.str();
|
||||
}
|
||||
|
||||
void Base64Encode(raw_ostream& os, span<const uint8_t> plain) {
|
||||
Base64Encode(os, std::string_view{reinterpret_cast<const char*>(plain.data()),
|
||||
plain.size()});
|
||||
}
|
||||
|
||||
void Base64Encode(span<const uint8_t> plain, std::string* encoded) {
|
||||
encoded->resize(0);
|
||||
raw_string_ostream os(*encoded);
|
||||
Base64Encode(os, plain);
|
||||
os.flush();
|
||||
}
|
||||
|
||||
std::string_view Base64Encode(span<const uint8_t> plain,
|
||||
SmallVectorImpl<char>& buf) {
|
||||
buf.clear();
|
||||
raw_svector_ostream os(buf);
|
||||
Base64Encode(os, plain);
|
||||
return os.str();
|
||||
}
|
||||
|
||||
} // namespace wpi
|
||||
|
||||
Reference in New Issue
Block a user