-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
95 lines (77 loc) · 2.26 KB
/
test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
This file is part of cpp-base64.
Copyright (C) 2020-2021 ReimuNotMoe <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the MIT License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <vector>
#include <iostream>
#include "cpp-base64X.hpp"
using namespace YukiWorkshop;
int main() {
// Example 1
// Encode
std::string brand = "YukiWorkshop";
std::string out1;
Base64X::Encoder<std::string> e1;
e1 >> out1;
e1 << brand << " " << "Rocks!" << nullptr;
std::cout << out1 << "\n";
// Decode
std::string dout1;
Base64X::Decoder<std::string> d1;
d1 >> dout1;
d1 << out1;
std::cout << dout1 << "\n";
// Example 2
// Encode
std::string buf = "Austin!";
std::vector<uint8_t> v(buf.begin(), buf.end());
std::string words[4] = { "Hey ", "guys, ", "this is "};
std::string out2;
Base64X::Encoder<std::string> e2;
for (auto &word : words) {
out2 += e2.encode(word);
}
out2 += e2.encode(v);
out2 += e2.finalize();
std::cout << out2 << "\n";
// Decode
Base64X::Decoder<std::string> d2;
for (auto &it : out2) {
std::string c;
c.push_back(it);
std::cout << d2.decode(c);
}
std::cout << "\n";
// Example 3
// Encode
std::string buf0 = "roses are red";
std::vector<uint8_t> buf1(buf0.begin(), buf0.end());
auto out3 = Base64X::encode(buf1).as<std::string>();
std::cout << out3 << "\n";
auto out4 = Base64X::encode("violets are blue").as<std::vector<uint8_t>>();
fwrite(out4.data(), 1, out4.size(), stdout);
fputc('\n', stdout);
// Decode
auto dout3 = Base64X::decode(out3).as<std::string>();
std::cout << dout3 << "\n";
auto dout4 = Base64X::decode(out4).as<std::vector<uint8_t>>();
fwrite(dout4.data(), 1, dout4.size(), stdout);
fputc('\n', stdout);
// Example 4
// Encode
std::vector<double> buf2 = {3.14159265357, 42.42, 233.233, 666.666};
auto out5 = Base64X::encode(buf2).as<std::vector<uint8_t>>();
fwrite(out5.data(), 1, out5.size(), stdout);
fputc('\n', stdout);
// Decode
auto dout5 = Base64X::decode(out5).as_vector<double>();
for (auto &it : dout5) {
std::cout << it << " ";
}
std::cout << "\n";
}