Skip to content

Commit

Permalink
geometric module moved to checkValue
Browse files Browse the repository at this point in the history
  • Loading branch information
denizzzka committed Dec 28, 2021
1 parent 7be0c97 commit afc1d2b
Showing 1 changed file with 7 additions and 33 deletions.
40 changes: 7 additions & 33 deletions src/dpq2/conv/geometric.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module dpq2.conv.geometric;

import dpq2.oids: OidType;
import dpq2.value: ConvExceptionType, throwTypeComplaint, Value, ValueConvException, ValueFormat;
import dpq2.conv.to_d_types: checkValue;
import std.bitmanip: bigEndianToNative, nativeToBigEndian;
import std.traits;
import std.typecons : Nullable;
Expand Down Expand Up @@ -272,16 +273,9 @@ private alias ET = ConvExceptionType;
Vec2Ddouble binaryValueAs(Vec2Ddouble)(in Value v)
if(isValidPointType!Vec2Ddouble)
{
if(!(v.oidType == OidType.Point))
throwTypeComplaint(v.oidType, "Point", __FILE__, __LINE__);
v.checkValue(OidType.Point, 16, "Point");

auto data = v.data;

if(!(data.length == 16))
throw new AE(ET.SIZE_MISMATCH,
"Value length isn't equal to Postgres Point size", __FILE__, __LINE__);

return pointFromBytes!Vec2Ddouble(data[0..16]);
return pointFromBytes!Vec2Ddouble(v.data[0..16]);
}

private Vec2Ddouble pointFromBytes(Vec2Ddouble)(in ubyte[16] data) pure
Expand All @@ -293,25 +287,15 @@ if(isValidPointType!Vec2Ddouble)
T binaryValueAs(T)(in Value v)
if (is(T == Line))
{
if(!(v.oidType == OidType.Line))
throwTypeComplaint(v.oidType, "Line", __FILE__, __LINE__);

if(!(v.data.length == 24))
throw new AE(ET.SIZE_MISMATCH,
"Value length isn't equal to Postgres Line size", __FILE__, __LINE__);
v.checkValue(OidType.Line, 24, "Line");

return Line((v.data[0..8].bigEndianToNative!double), v.data[8..16].bigEndianToNative!double, v.data[16..24].bigEndianToNative!double);
}

LineSegment binaryValueAs(LineSegment)(in Value v)
if(isValidLineSegmentType!LineSegment)
{
if(!(v.oidType == OidType.LineSegment))
throwTypeComplaint(v.oidType, "LineSegment", __FILE__, __LINE__);

if(!(v.data.length == 32))
throw new AE(ET.SIZE_MISMATCH,
"Value length isn't equal to Postgres LineSegment size", __FILE__, __LINE__);
v.checkValue(OidType.LineSegment, 32, "LineSegment");

alias Point = ReturnType!(LineSegment.start);

Expand All @@ -324,12 +308,7 @@ if(isValidLineSegmentType!LineSegment)
Box binaryValueAs(Box)(in Value v)
if(isValidBoxType!Box)
{
if(!(v.oidType == OidType.Box))
throwTypeComplaint(v.oidType, "Box", __FILE__, __LINE__);

if(!(v.data.length == 32))
throw new AE(ET.SIZE_MISMATCH,
"Value length isn't equal to Postgres Box size", __FILE__, __LINE__);
v.checkValue(OidType.Box, 32, "Box");

alias Point = typeof(Box.min);

Expand Down Expand Up @@ -404,12 +383,7 @@ if(isValidPolygon!Polygon)
T binaryValueAs(T)(in Value v)
if(isInstanceOf!(Circle, T))
{
if(!(v.oidType == OidType.Circle))
throwTypeComplaint(v.oidType, "Circle", __FILE__, __LINE__);

if(!(v.data.length == 24))
throw new AE(ET.SIZE_MISMATCH,
"Value length isn't equal to Postgres Circle size", __FILE__, __LINE__);
v.checkValue(OidType.Circle, 24, "Circle");

alias Point = typeof(T.center);

Expand Down

0 comments on commit afc1d2b

Please sign in to comment.