forked from typelevel/skunk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'typelevel:main' into multi-query-statement-discarded
- Loading branch information
Showing
22 changed files
with
1,352 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) 2018-2021 by Rob Norris | ||
// This software is licensed under the MIT License (MIT). | ||
// For more information see LICENSE or https://opensource.org/licenses/MIT | ||
|
||
package skunk.postgis | ||
package ewkb | ||
|
||
import scodec.Attempt | ||
import scodec.{Codec => Scodec} | ||
import scodec.bits.BitVector | ||
import scodec.bits.ByteOrdering | ||
|
||
trait EWKBCodecPlatform extends EWKBPrimitives { | ||
def ewkbEncode(ewkb: EWKBType, geometry: Geometry, geoEncoder: Scodec[Geometry])(implicit bo: ByteOrdering): Attempt[BitVector] = { | ||
val encoder = byteOrdering :: ewkbType :: geoEncoder | ||
encoder.encode(bo :: ewkb :: geometry :: shapeless.HNil) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) 2018-2021 by Rob Norris | ||
// This software is licensed under the MIT License (MIT). | ||
// For more information see LICENSE or https://opensource.org/licenses/MIT | ||
|
||
package skunk.postgis | ||
package ewkb | ||
|
||
import scodec.Attempt | ||
import scodec.{Codec => Scodec} | ||
import scodec.bits.BitVector | ||
import scodec.bits.ByteOrdering | ||
|
||
trait EWKBCodecPlatform extends EWKBPrimitives { | ||
def ewkbEncode(ewkb: EWKBType, geometry: Geometry, geoEncoder: Scodec[Geometry])(using bo: ByteOrdering): Attempt[BitVector] = { | ||
val encoder = byteOrdering :: ewkbType :: geoEncoder | ||
encoder.encode((bo, ewkb, geometry)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) 2018-2021 by Rob Norris | ||
// This software is licensed under the MIT License (MIT). | ||
// For more information see LICENSE or https://opensource.org/licenses/MIT | ||
|
||
package skunk | ||
package postgis | ||
package codecs | ||
|
||
import scala.reflect.ClassTag | ||
|
||
import cats.syntax.all._ | ||
import scodec.bits.ByteVector | ||
import skunk.data.Type | ||
|
||
trait PostGISGeometryCodecs { | ||
|
||
val geometry: Codec[Geometry] = Codec.simple[Geometry]( | ||
geometry => ewkb.codecs.geometry.encode(geometry).require.toHex, | ||
str => { | ||
ByteVector.fromHex(str).fold(s"[postgis] Bad EWKB Hex: $str".asLeft[Geometry]) { byteVector => | ||
ewkb.codecs.geometry.decodeValue(byteVector.toBitVector).toEither.leftMap(_.message) | ||
} | ||
}, | ||
Type("geometry") | ||
) | ||
|
||
val point: Codec[Point] = geometryCodec[Point] | ||
val lineString: Codec[LineString] = geometryCodec[LineString] | ||
val polygon: Codec[Polygon] = geometryCodec[Polygon] | ||
val multiPoint: Codec[MultiPoint] = geometryCodec[MultiPoint] | ||
val multiLineString: Codec[MultiLineString] = geometryCodec[MultiLineString] | ||
val multiPolygon: Codec[MultiPolygon] = geometryCodec[MultiPolygon] | ||
val geometryCollection: Codec[GeometryCollection] = geometryCodec[GeometryCollection] | ||
|
||
private def geometryCodec[A >: Null <: Geometry](implicit A: ClassTag[A]): Codec[A] = { | ||
geometry.imap[A](geom => A.runtimeClass.cast(geom).asInstanceOf[A])(o => | ||
o.asInstanceOf[Geometry] | ||
) | ||
} | ||
|
||
} | ||
|
||
object geometry extends PostGISGeometryCodecs | ||
|
||
object all extends PostGISGeometryCodecs |
Oops, something went wrong.