46 lines
930 B
D
46 lines
930 B
D
module models.response;
|
|
|
|
import std.base64 : Base64;
|
|
import std.csv : csvReader;
|
|
import std.array : array;
|
|
import std.algorithm : map;
|
|
import std.string : splitLines;
|
|
import std.array : split, join;
|
|
import std.typecons : Nullable;
|
|
|
|
class Response
|
|
{
|
|
string resultCode;
|
|
string buildVersion;
|
|
Nullable!string serverTime;
|
|
Nullable!string version_;
|
|
}
|
|
|
|
struct Base64CSV
|
|
{
|
|
string[][] records;
|
|
|
|
alias records this;
|
|
|
|
@safe //I guess
|
|
string toRepresentation() const
|
|
{
|
|
auto csvString = records.map!(r => r.join(",")).array.join("\n").idup ~ "\n";
|
|
|
|
return Base64.encode(cast(const(ubyte[])) csvString);
|
|
}
|
|
|
|
@safe //I guess
|
|
static Base64CSV fromRepresentation(string input)
|
|
{
|
|
auto inputString = cast(string) Base64.decode(input).idup;
|
|
|
|
auto records = inputString.splitLines.map!(line => line.split(',')).array;
|
|
auto base64csv = Base64CSV(records);
|
|
|
|
assert(base64csv.toRepresentation == input);
|
|
|
|
return base64csv;
|
|
}
|
|
}
|