- Moved back to more clean templating method (for now till a fix can be found for the type lookups for issue #7)

This commit is contained in:
Tristan B. Velloza Kildaire 2023-01-09 10:28:56 +02:00
parent c89d6bd8b6
commit 4fc4242c1e
2 changed files with 120 additions and 134 deletions

View File

@ -3,14 +3,6 @@ module libpb.deserialization;
import std.json; import std.json;
import libpb.exceptions : RemoteFieldMissing; import libpb.exceptions : RemoteFieldMissing;
/**
* T
*
* Params:
* RecordType = type of the struct to construct
*/
mixin template T(RecordType)
{
import std.traits : FieldTypeTuple, FieldNameTuple; import std.traits : FieldTypeTuple, FieldNameTuple;
/** /**
@ -23,7 +15,7 @@ mixin template T(RecordType)
* cannot be found within the prpvided JSONValue `jsonIn`. * cannot be found within the prpvided JSONValue `jsonIn`.
* Returns: an instance of RecordType * Returns: an instance of RecordType
*/ */
public RecordType fromJSON(JSONValue jsonIn) public RecordType fromJSON(RecordType)(JSONValue jsonIn)
{ {
RecordType record; RecordType record;
@ -41,9 +33,12 @@ mixin template T(RecordType)
// pragma(msg, structValues[cnt]); // pragma(msg, structValues[cnt]);
} }
debug(dbg)
{
pragma(msg, "Bruh type"); pragma(msg, "Bruh type");
pragma(msg, structTypes[cnt]); pragma(msg, structTypes[cnt]);
// pragma(msg, __traits(identifier, mixin(structTypes[cnt]))); // pragma(msg, __traits(identifier, mixin(structTypes[cnt])));
}
try try
{ {
@ -134,7 +129,6 @@ mixin template T(RecordType)
return record; return record;
} }
}
unittest unittest
{ {
@ -160,8 +154,7 @@ unittest
} }
`); `);
mixin T!(Person); Person person = fromJSON!(Person)(json);
Person person = fromJSON(json);
debug(dbg) debug(dbg)
{ {
@ -199,10 +192,9 @@ unittest
} }
`); `);
mixin T!(Person);
try try
{ {
Person person = fromJSON(json); Person person = fromJSON!(Person)(json);
assert(false); assert(false);
} }
catch(RemoteFieldMissing) catch(RemoteFieldMissing)

View File

@ -158,8 +158,7 @@ public class PocketBase
} }
} }
mixin T!(RecordType); recordsOut ~= fromJSON!(RecordType)(returnedItem);
recordsOut ~= fromJSON(returnedItem);
} }
return recordsOut; return recordsOut;
@ -269,8 +268,7 @@ public class PocketBase
responseJSON["passwordConfirm"] = ""; responseJSON["passwordConfirm"] = "";
} }
mixin T!(RecordType); recordOut = fromJSON!(RecordType)(responseJSON);
recordOut = fromJSON(responseJSON);
return recordOut; return recordOut;
} }
@ -350,9 +348,7 @@ public class PocketBase
recordResponse["email"] = ""; recordResponse["email"] = "";
} }
recordOut = fromJSON!(RecordType)(recordResponse);
mixin T!(RecordType);
recordOut = fromJSON(recordResponse);
// Store the token // Store the token
token = responseJSON["token"].str(); token = responseJSON["token"].str();
@ -451,8 +447,7 @@ public class PocketBase
} }
} }
mixin T!(RecordType); recordOut = fromJSON!(RecordType)(responseJSON);
recordOut = fromJSON(responseJSON);
return recordOut; return recordOut;
} }
@ -557,8 +552,7 @@ public class PocketBase
} }
} }
mixin T!(RecordType); recordOut = fromJSON!(RecordType)(responseJSON);
recordOut = fromJSON(responseJSON);
return recordOut; return recordOut;
} }