module Database.Bolty.Value.Type
( Bolt(..)
, asNull, asBool, asInt, asFloat, asBytes, asText
, asList, asDict, asNode, asRelationship, asPath
, Node(..)
, Relationship(..)
, UnboundRelationship(..)
, Path(..)
, Date(..)
, Time(..)
, LocalTime(..)
, DateTime(..)
, DateTimeZoneId(..)
, LocalDateTime(..)
, Duration(..)
, Point2D(..)
, Point3D(..)
) where
import Data.Int (Int64)
import Data.Kind (Type)
import GHC.Generics (Generic)
import qualified Data.ByteString as BS
import qualified Data.HashMap.Lazy as H
import qualified Data.Text as T
import qualified Data.Vector as V
import Data.PackStream.Ps
import Data.PackStream.Result (Result(..))
import Data.PackStream.Integer (PSInteger)
import Database.Bolty.Value.Helpers (sigNode, sigRel, sigURel, sigPath
, sigDate, sigTime, sigLocalTime, sigDateTime
, sigDateTimeZoneId, sigLocalDateTime, sigDuration
, sigPoint2D, sigPoint3D)
import Numeric (showHex)
type Bolt :: Type
data Bolt
= BoltNull
| BoltBoolean !Bool
| BoltInteger !PSInteger
| BoltFloat !Double
| BoltBytes !BS.ByteString
| BoltString !T.Text
| BoltList !(V.Vector Bolt)
| BoltDictionary !(H.HashMap T.Text Bolt)
| BoltNode Node
| BoltRelationship Relationship
| BoltUnboundRelationship UnboundRelationship
| BoltPath Path
| BoltDate Date
| BoltTime Time
| BoltLocalTime LocalTime
| BoltDateTime DateTime
| BoltDateTimeZoneId DateTimeZoneId
| BoltLocalDateTime LocalDateTime
| BoltDuration Duration
| BoltPoint2D Point2D
| BoltPoint3D Point3D
deriving stock (Int -> Bolt -> ShowS
[Bolt] -> ShowS
Bolt -> String
(Int -> Bolt -> ShowS)
-> (Bolt -> String) -> ([Bolt] -> ShowS) -> Show Bolt
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Bolt -> ShowS
showsPrec :: Int -> Bolt -> ShowS
$cshow :: Bolt -> String
show :: Bolt -> String
$cshowList :: [Bolt] -> ShowS
showList :: [Bolt] -> ShowS
Show, Bolt -> Bolt -> Bool
(Bolt -> Bolt -> Bool) -> (Bolt -> Bolt -> Bool) -> Eq Bolt
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Bolt -> Bolt -> Bool
== :: Bolt -> Bolt -> Bool
$c/= :: Bolt -> Bolt -> Bool
/= :: Bolt -> Bolt -> Bool
Eq, (forall x. Bolt -> Rep Bolt x)
-> (forall x. Rep Bolt x -> Bolt) -> Generic Bolt
forall x. Rep Bolt x -> Bolt
forall x. Bolt -> Rep Bolt x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Bolt -> Rep Bolt x
from :: forall x. Bolt -> Rep Bolt x
$cto :: forall x. Rep Bolt x -> Bolt
to :: forall x. Rep Bolt x -> Bolt
Generic)
instance PackStream Bolt where
toPs :: Bolt -> Ps
toPs Bolt
BoltNull = Ps
PsNull
toPs (BoltBoolean Bool
b) = Bool -> Ps
PsBoolean Bool
b
toPs (BoltInteger PSInteger
n) = PSInteger -> Ps
PsInteger PSInteger
n
toPs (BoltFloat Double
d) = Double -> Ps
PsFloat Double
d
toPs (BoltBytes ByteString
b) = ByteString -> Ps
PsBytes ByteString
b
toPs (BoltString Text
t) = Text -> Ps
PsString Text
t
toPs (BoltList Vector Bolt
v) = Vector Ps -> Ps
PsList ((Bolt -> Ps) -> Vector Bolt -> Vector Ps
forall a b. (a -> b) -> Vector a -> Vector b
V.map Bolt -> Ps
forall a. PackStream a => a -> Ps
toPs Vector Bolt
v)
toPs (BoltDictionary HashMap Text Bolt
m) = HashMap Text Ps -> Ps
PsDictionary ((Bolt -> Ps) -> HashMap Text Bolt -> HashMap Text Ps
forall v1 v2 k. (v1 -> v2) -> HashMap k v1 -> HashMap k v2
H.map Bolt -> Ps
forall a. PackStream a => a -> Ps
toPs HashMap Text Bolt
m)
toPs (BoltNode Node
n) = Node -> Ps
forall a. PackStream a => a -> Ps
toPs Node
n
toPs (BoltRelationship Relationship
r) = Relationship -> Ps
forall a. PackStream a => a -> Ps
toPs Relationship
r
toPs (BoltUnboundRelationship UnboundRelationship
r) = UnboundRelationship -> Ps
forall a. PackStream a => a -> Ps
toPs UnboundRelationship
r
toPs (BoltPath Path
p) = Path -> Ps
forall a. PackStream a => a -> Ps
toPs Path
p
toPs (BoltDate Date
d) = Date -> Ps
forall a. PackStream a => a -> Ps
toPs Date
d
toPs (BoltTime Time
t) = Time -> Ps
forall a. PackStream a => a -> Ps
toPs Time
t
toPs (BoltLocalTime LocalTime
t) = LocalTime -> Ps
forall a. PackStream a => a -> Ps
toPs LocalTime
t
toPs (BoltDateTime DateTime
dt) = DateTime -> Ps
forall a. PackStream a => a -> Ps
toPs DateTime
dt
toPs (BoltDateTimeZoneId DateTimeZoneId
dt) = DateTimeZoneId -> Ps
forall a. PackStream a => a -> Ps
toPs DateTimeZoneId
dt
toPs (BoltLocalDateTime LocalDateTime
dt) = LocalDateTime -> Ps
forall a. PackStream a => a -> Ps
toPs LocalDateTime
dt
toPs (BoltDuration Duration
d) = Duration -> Ps
forall a. PackStream a => a -> Ps
toPs Duration
d
toPs (BoltPoint2D Point2D
p) = Point2D -> Ps
forall a. PackStream a => a -> Ps
toPs Point2D
p
toPs (BoltPoint3D Point3D
p) = Point3D -> Ps
forall a. PackStream a => a -> Ps
toPs Point3D
p
fromPs :: Ps -> Result Bolt
fromPs Ps
PsNull = Bolt -> Result Bolt
forall a. a -> Result a
Success Bolt
BoltNull
fromPs (PsBoolean Bool
b) = Bolt -> Result Bolt
forall a. a -> Result a
Success (Bool -> Bolt
BoltBoolean Bool
b)
fromPs (PsInteger PSInteger
n) = Bolt -> Result Bolt
forall a. a -> Result a
Success (PSInteger -> Bolt
BoltInteger PSInteger
n)
fromPs (PsFloat Double
d) = Bolt -> Result Bolt
forall a. a -> Result a
Success (Double -> Bolt
BoltFloat Double
d)
fromPs (PsBytes ByteString
b) = Bolt -> Result Bolt
forall a. a -> Result a
Success (ByteString -> Bolt
BoltBytes ByteString
b)
fromPs (PsString Text
t) = Bolt -> Result Bolt
forall a. a -> Result a
Success (Text -> Bolt
BoltString Text
t)
fromPs (PsList Vector Ps
v) = Vector Bolt -> Bolt
BoltList (Vector Bolt -> Bolt) -> Result (Vector Bolt) -> Result Bolt
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Ps -> Result Bolt) -> Vector Ps -> Result (Vector Bolt)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Vector a -> f (Vector b)
traverse Ps -> Result Bolt
forall a. PackStream a => Ps -> Result a
fromPs Vector Ps
v
fromPs (PsDictionary HashMap Text Ps
m) = HashMap Text Bolt -> Bolt
BoltDictionary (HashMap Text Bolt -> Bolt)
-> Result (HashMap Text Bolt) -> Result Bolt
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Ps -> Result Bolt)
-> HashMap Text Ps -> Result (HashMap Text Bolt)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> HashMap Text a -> f (HashMap Text b)
traverse Ps -> Result Bolt
forall a. PackStream a => Ps -> Result a
fromPs HashMap Text Ps
m
fromPs ps :: Ps
ps@(PsStructure Tag
t Vector Ps
_) = case Tag
t of
Tag
_ | Tag
t Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Tag
sigNode -> Node -> Bolt
BoltNode (Node -> Bolt) -> Result Node -> Result Bolt
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ps -> Result Node
forall a. PackStream a => Ps -> Result a
fromPs Ps
ps
| Tag
t Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Tag
sigRel -> Relationship -> Bolt
BoltRelationship (Relationship -> Bolt) -> Result Relationship -> Result Bolt
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ps -> Result Relationship
forall a. PackStream a => Ps -> Result a
fromPs Ps
ps
| Tag
t Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Tag
sigURel -> UnboundRelationship -> Bolt
BoltUnboundRelationship (UnboundRelationship -> Bolt)
-> Result UnboundRelationship -> Result Bolt
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ps -> Result UnboundRelationship
forall a. PackStream a => Ps -> Result a
fromPs Ps
ps
| Tag
t Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Tag
sigPath -> Path -> Bolt
BoltPath (Path -> Bolt) -> Result Path -> Result Bolt
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ps -> Result Path
forall a. PackStream a => Ps -> Result a
fromPs Ps
ps
| Tag
t Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Tag
sigDate -> Date -> Bolt
BoltDate (Date -> Bolt) -> Result Date -> Result Bolt
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ps -> Result Date
forall a. PackStream a => Ps -> Result a
fromPs Ps
ps
| Tag
t Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Tag
sigTime -> Time -> Bolt
BoltTime (Time -> Bolt) -> Result Time -> Result Bolt
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ps -> Result Time
forall a. PackStream a => Ps -> Result a
fromPs Ps
ps
| Tag
t Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Tag
sigLocalTime -> LocalTime -> Bolt
BoltLocalTime (LocalTime -> Bolt) -> Result LocalTime -> Result Bolt
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ps -> Result LocalTime
forall a. PackStream a => Ps -> Result a
fromPs Ps
ps
| Tag
t Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Tag
sigDateTime -> DateTime -> Bolt
BoltDateTime (DateTime -> Bolt) -> Result DateTime -> Result Bolt
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ps -> Result DateTime
forall a. PackStream a => Ps -> Result a
fromPs Ps
ps
| Tag
t Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Tag
sigDateTimeZoneId -> DateTimeZoneId -> Bolt
BoltDateTimeZoneId (DateTimeZoneId -> Bolt) -> Result DateTimeZoneId -> Result Bolt
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ps -> Result DateTimeZoneId
forall a. PackStream a => Ps -> Result a
fromPs Ps
ps
| Tag
t Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Tag
sigLocalDateTime -> LocalDateTime -> Bolt
BoltLocalDateTime (LocalDateTime -> Bolt) -> Result LocalDateTime -> Result Bolt
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ps -> Result LocalDateTime
forall a. PackStream a => Ps -> Result a
fromPs Ps
ps
| Tag
t Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Tag
sigDuration -> Duration -> Bolt
BoltDuration (Duration -> Bolt) -> Result Duration -> Result Bolt
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ps -> Result Duration
forall a. PackStream a => Ps -> Result a
fromPs Ps
ps
| Tag
t Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Tag
sigPoint2D -> Point2D -> Bolt
BoltPoint2D (Point2D -> Bolt) -> Result Point2D -> Result Bolt
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ps -> Result Point2D
forall a. PackStream a => Ps -> Result a
fromPs Ps
ps
| Tag
t Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Tag
sigPoint3D -> Point3D -> Bolt
BoltPoint3D (Point3D -> Bolt) -> Result Point3D -> Result Bolt
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ps -> Result Point3D
forall a. PackStream a => Ps -> Result a
fromPs Ps
ps
| Bool
otherwise -> Text -> Result Bolt
forall a. Text -> Result a
Error (Text -> Result Bolt) -> Text -> Result Bolt
forall a b. (a -> b) -> a -> b
$ Text
"unknown structure tag: 0x" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (Tag -> ShowS
forall a. Integral a => a -> ShowS
showHex Tag
t String
"")
type Node :: Type
data Node = Node
{ Node -> Int64
id :: !Int64
, Node -> Vector Text
labels :: !(V.Vector T.Text)
, Node -> HashMap Text Ps
properties :: !(H.HashMap T.Text Ps)
, Node -> Text
element_id :: !T.Text
}
deriving stock (Int -> Node -> ShowS
[Node] -> ShowS
Node -> String
(Int -> Node -> ShowS)
-> (Node -> String) -> ([Node] -> ShowS) -> Show Node
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Node -> ShowS
showsPrec :: Int -> Node -> ShowS
$cshow :: Node -> String
show :: Node -> String
$cshowList :: [Node] -> ShowS
showList :: [Node] -> ShowS
Show, Node -> Node -> Bool
(Node -> Node -> Bool) -> (Node -> Node -> Bool) -> Eq Node
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Node -> Node -> Bool
== :: Node -> Node -> Bool
$c/= :: Node -> Node -> Bool
/= :: Node -> Node -> Bool
Eq, (forall x. Node -> Rep Node x)
-> (forall x. Rep Node x -> Node) -> Generic Node
forall x. Rep Node x -> Node
forall x. Node -> Rep Node x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Node -> Rep Node x
from :: forall x. Node -> Rep Node x
$cto :: forall x. Rep Node x -> Node
to :: forall x. Rep Node x -> Node
Generic)
instance PackStream Node where
toPs :: Node -> Ps
toPs Node{Int64
id :: Node -> Int64
id :: Int64
id, Vector Text
labels :: Node -> Vector Text
labels :: Vector Text
labels, HashMap Text Ps
properties :: Node -> HashMap Text Ps
properties :: HashMap Text Ps
properties, Text
element_id :: Node -> Text
element_id :: Text
element_id} =
Tag -> Vector Ps -> Ps
PsStructure Tag
sigNode (Vector Ps -> Ps) -> Vector Ps -> Ps
forall a b. (a -> b) -> a -> b
$ [Ps] -> Vector Ps
forall a. [a] -> Vector a
V.fromList [Int64 -> Ps
forall a. PackStream a => a -> Ps
toPs Int64
id, Vector Text -> Ps
forall a. PackStream a => a -> Ps
toPs Vector Text
labels, HashMap Text Ps -> Ps
forall a. PackStream a => a -> Ps
toPs HashMap Text Ps
properties, Text -> Ps
forall a. PackStream a => a -> Ps
toPs Text
element_id]
fromPs :: Ps -> Result Node
fromPs (PsStructure Tag
t Vector Ps
fs) | Tag
t Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Tag
sigNode, Vector Ps -> Int
forall a. Vector a -> Int
V.length Vector Ps
fs Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
4 =
Int64 -> Vector Text -> HashMap Text Ps -> Text -> Node
Node (Int64 -> Vector Text -> HashMap Text Ps -> Text -> Node)
-> Result Int64
-> Result (Vector Text -> HashMap Text Ps -> Text -> Node)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ps -> Result Int64
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
0) Result (Vector Text -> HashMap Text Ps -> Text -> Node)
-> Result (Vector Text) -> Result (HashMap Text Ps -> Text -> Node)
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result (Vector Text)
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
1) Result (HashMap Text Ps -> Text -> Node)
-> Result (HashMap Text Ps) -> Result (Text -> Node)
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result (HashMap Text Ps)
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
2) Result (Text -> Node) -> Result Text -> Result Node
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result Text
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
3)
fromPs (PsStructure Tag
t Vector Ps
fs) | Tag
t Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Tag
sigNode, Vector Ps -> Int
forall a. Vector a -> Int
V.length Vector Ps
fs Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
3 =
Int64 -> Vector Text -> HashMap Text Ps -> Text -> Node
Node (Int64 -> Vector Text -> HashMap Text Ps -> Text -> Node)
-> Result Int64
-> Result (Vector Text -> HashMap Text Ps -> Text -> Node)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ps -> Result Int64
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
0) Result (Vector Text -> HashMap Text Ps -> Text -> Node)
-> Result (Vector Text) -> Result (HashMap Text Ps -> Text -> Node)
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result (Vector Text)
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
1) Result (HashMap Text Ps -> Text -> Node)
-> Result (HashMap Text Ps) -> Result (Text -> Node)
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result (HashMap Text Ps)
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
2) Result (Text -> Node) -> Result Text -> Result Node
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Text -> Result Text
forall a. a -> Result a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
""
fromPs Ps
other = Text -> Ps -> Result Node
forall a. Text -> Ps -> Result a
typeMismatch Text
"Node" Ps
other
type Relationship :: Type
data Relationship = Relationship
{ Relationship -> Int64
id :: !Int64
, Relationship -> Int64
startNodeId :: !Int64
, Relationship -> Int64
endNodeId :: !Int64
, Relationship -> Text
type_ :: !T.Text
, Relationship -> HashMap Text Ps
properties :: !(H.HashMap T.Text Ps)
, Relationship -> Text
element_id :: !T.Text
, Relationship -> Text
start_node_element_id :: !T.Text
, Relationship -> Text
end_node_element_id :: !T.Text
}
deriving stock (Int -> Relationship -> ShowS
[Relationship] -> ShowS
Relationship -> String
(Int -> Relationship -> ShowS)
-> (Relationship -> String)
-> ([Relationship] -> ShowS)
-> Show Relationship
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Relationship -> ShowS
showsPrec :: Int -> Relationship -> ShowS
$cshow :: Relationship -> String
show :: Relationship -> String
$cshowList :: [Relationship] -> ShowS
showList :: [Relationship] -> ShowS
Show, Relationship -> Relationship -> Bool
(Relationship -> Relationship -> Bool)
-> (Relationship -> Relationship -> Bool) -> Eq Relationship
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Relationship -> Relationship -> Bool
== :: Relationship -> Relationship -> Bool
$c/= :: Relationship -> Relationship -> Bool
/= :: Relationship -> Relationship -> Bool
Eq, (forall x. Relationship -> Rep Relationship x)
-> (forall x. Rep Relationship x -> Relationship)
-> Generic Relationship
forall x. Rep Relationship x -> Relationship
forall x. Relationship -> Rep Relationship x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Relationship -> Rep Relationship x
from :: forall x. Relationship -> Rep Relationship x
$cto :: forall x. Rep Relationship x -> Relationship
to :: forall x. Rep Relationship x -> Relationship
Generic)
instance PackStream Relationship where
toPs :: Relationship -> Ps
toPs Relationship{Int64
id :: Relationship -> Int64
id :: Int64
id, Int64
startNodeId :: Relationship -> Int64
startNodeId :: Int64
startNodeId, Int64
endNodeId :: Relationship -> Int64
endNodeId :: Int64
endNodeId, Text
type_ :: Relationship -> Text
type_ :: Text
type_, HashMap Text Ps
properties :: Relationship -> HashMap Text Ps
properties :: HashMap Text Ps
properties, Text
element_id :: Relationship -> Text
element_id :: Text
element_id, Text
start_node_element_id :: Relationship -> Text
start_node_element_id :: Text
start_node_element_id, Text
end_node_element_id :: Relationship -> Text
end_node_element_id :: Text
end_node_element_id} =
Tag -> Vector Ps -> Ps
PsStructure Tag
sigRel (Vector Ps -> Ps) -> Vector Ps -> Ps
forall a b. (a -> b) -> a -> b
$ [Ps] -> Vector Ps
forall a. [a] -> Vector a
V.fromList
[Int64 -> Ps
forall a. PackStream a => a -> Ps
toPs Int64
id, Int64 -> Ps
forall a. PackStream a => a -> Ps
toPs Int64
startNodeId, Int64 -> Ps
forall a. PackStream a => a -> Ps
toPs Int64
endNodeId, Text -> Ps
forall a. PackStream a => a -> Ps
toPs Text
type_, HashMap Text Ps -> Ps
forall a. PackStream a => a -> Ps
toPs HashMap Text Ps
properties
, Text -> Ps
forall a. PackStream a => a -> Ps
toPs Text
element_id, Text -> Ps
forall a. PackStream a => a -> Ps
toPs Text
start_node_element_id, Text -> Ps
forall a. PackStream a => a -> Ps
toPs Text
end_node_element_id]
fromPs :: Ps -> Result Relationship
fromPs (PsStructure Tag
t Vector Ps
fs) | Tag
t Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Tag
sigRel, Vector Ps -> Int
forall a. Vector a -> Int
V.length Vector Ps
fs Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
8 =
Int64
-> Int64
-> Int64
-> Text
-> HashMap Text Ps
-> Text
-> Text
-> Text
-> Relationship
Relationship (Int64
-> Int64
-> Int64
-> Text
-> HashMap Text Ps
-> Text
-> Text
-> Text
-> Relationship)
-> Result Int64
-> Result
(Int64
-> Int64
-> Text
-> HashMap Text Ps
-> Text
-> Text
-> Text
-> Relationship)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ps -> Result Int64
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
0) Result
(Int64
-> Int64
-> Text
-> HashMap Text Ps
-> Text
-> Text
-> Text
-> Relationship)
-> Result Int64
-> Result
(Int64
-> Text -> HashMap Text Ps -> Text -> Text -> Text -> Relationship)
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result Int64
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
1) Result
(Int64
-> Text -> HashMap Text Ps -> Text -> Text -> Text -> Relationship)
-> Result Int64
-> Result
(Text -> HashMap Text Ps -> Text -> Text -> Text -> Relationship)
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result Int64
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
2)
Result
(Text -> HashMap Text Ps -> Text -> Text -> Text -> Relationship)
-> Result Text
-> Result (HashMap Text Ps -> Text -> Text -> Text -> Relationship)
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result Text
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
3) Result (HashMap Text Ps -> Text -> Text -> Text -> Relationship)
-> Result (HashMap Text Ps)
-> Result (Text -> Text -> Text -> Relationship)
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result (HashMap Text Ps)
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
4) Result (Text -> Text -> Text -> Relationship)
-> Result Text -> Result (Text -> Text -> Relationship)
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result Text
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
5)
Result (Text -> Text -> Relationship)
-> Result Text -> Result (Text -> Relationship)
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result Text
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
6) Result (Text -> Relationship) -> Result Text -> Result Relationship
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result Text
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
7)
fromPs (PsStructure Tag
t Vector Ps
fs) | Tag
t Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Tag
sigRel, Vector Ps -> Int
forall a. Vector a -> Int
V.length Vector Ps
fs Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
5 =
Int64
-> Int64
-> Int64
-> Text
-> HashMap Text Ps
-> Text
-> Text
-> Text
-> Relationship
Relationship (Int64
-> Int64
-> Int64
-> Text
-> HashMap Text Ps
-> Text
-> Text
-> Text
-> Relationship)
-> Result Int64
-> Result
(Int64
-> Int64
-> Text
-> HashMap Text Ps
-> Text
-> Text
-> Text
-> Relationship)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ps -> Result Int64
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
0) Result
(Int64
-> Int64
-> Text
-> HashMap Text Ps
-> Text
-> Text
-> Text
-> Relationship)
-> Result Int64
-> Result
(Int64
-> Text -> HashMap Text Ps -> Text -> Text -> Text -> Relationship)
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result Int64
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
1) Result
(Int64
-> Text -> HashMap Text Ps -> Text -> Text -> Text -> Relationship)
-> Result Int64
-> Result
(Text -> HashMap Text Ps -> Text -> Text -> Text -> Relationship)
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result Int64
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
2)
Result
(Text -> HashMap Text Ps -> Text -> Text -> Text -> Relationship)
-> Result Text
-> Result (HashMap Text Ps -> Text -> Text -> Text -> Relationship)
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result Text
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
3) Result (HashMap Text Ps -> Text -> Text -> Text -> Relationship)
-> Result (HashMap Text Ps)
-> Result (Text -> Text -> Text -> Relationship)
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result (HashMap Text Ps)
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
4) Result (Text -> Text -> Text -> Relationship)
-> Result Text -> Result (Text -> Text -> Relationship)
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Text -> Result Text
forall a. a -> Result a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
"" Result (Text -> Text -> Relationship)
-> Result Text -> Result (Text -> Relationship)
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Text -> Result Text
forall a. a -> Result a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
"" Result (Text -> Relationship) -> Result Text -> Result Relationship
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Text -> Result Text
forall a. a -> Result a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
""
fromPs Ps
other = Text -> Ps -> Result Relationship
forall a. Text -> Ps -> Result a
typeMismatch Text
"Relationship" Ps
other
type UnboundRelationship :: Type
data UnboundRelationship = UnboundRelationship
{ UnboundRelationship -> Int64
id :: !Int64
, UnboundRelationship -> Text
type_ :: !T.Text
, UnboundRelationship -> HashMap Text Ps
properties :: !(H.HashMap T.Text Ps)
, UnboundRelationship -> Text
element_id :: !T.Text
}
deriving stock (Int -> UnboundRelationship -> ShowS
[UnboundRelationship] -> ShowS
UnboundRelationship -> String
(Int -> UnboundRelationship -> ShowS)
-> (UnboundRelationship -> String)
-> ([UnboundRelationship] -> ShowS)
-> Show UnboundRelationship
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UnboundRelationship -> ShowS
showsPrec :: Int -> UnboundRelationship -> ShowS
$cshow :: UnboundRelationship -> String
show :: UnboundRelationship -> String
$cshowList :: [UnboundRelationship] -> ShowS
showList :: [UnboundRelationship] -> ShowS
Show, UnboundRelationship -> UnboundRelationship -> Bool
(UnboundRelationship -> UnboundRelationship -> Bool)
-> (UnboundRelationship -> UnboundRelationship -> Bool)
-> Eq UnboundRelationship
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UnboundRelationship -> UnboundRelationship -> Bool
== :: UnboundRelationship -> UnboundRelationship -> Bool
$c/= :: UnboundRelationship -> UnboundRelationship -> Bool
/= :: UnboundRelationship -> UnboundRelationship -> Bool
Eq, (forall x. UnboundRelationship -> Rep UnboundRelationship x)
-> (forall x. Rep UnboundRelationship x -> UnboundRelationship)
-> Generic UnboundRelationship
forall x. Rep UnboundRelationship x -> UnboundRelationship
forall x. UnboundRelationship -> Rep UnboundRelationship x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. UnboundRelationship -> Rep UnboundRelationship x
from :: forall x. UnboundRelationship -> Rep UnboundRelationship x
$cto :: forall x. Rep UnboundRelationship x -> UnboundRelationship
to :: forall x. Rep UnboundRelationship x -> UnboundRelationship
Generic)
instance PackStream UnboundRelationship where
toPs :: UnboundRelationship -> Ps
toPs UnboundRelationship{Int64
id :: UnboundRelationship -> Int64
id :: Int64
id, Text
type_ :: UnboundRelationship -> Text
type_ :: Text
type_, HashMap Text Ps
properties :: UnboundRelationship -> HashMap Text Ps
properties :: HashMap Text Ps
properties, Text
element_id :: UnboundRelationship -> Text
element_id :: Text
element_id} =
Tag -> Vector Ps -> Ps
PsStructure Tag
sigURel (Vector Ps -> Ps) -> Vector Ps -> Ps
forall a b. (a -> b) -> a -> b
$ [Ps] -> Vector Ps
forall a. [a] -> Vector a
V.fromList [Int64 -> Ps
forall a. PackStream a => a -> Ps
toPs Int64
id, Text -> Ps
forall a. PackStream a => a -> Ps
toPs Text
type_, HashMap Text Ps -> Ps
forall a. PackStream a => a -> Ps
toPs HashMap Text Ps
properties, Text -> Ps
forall a. PackStream a => a -> Ps
toPs Text
element_id]
fromPs :: Ps -> Result UnboundRelationship
fromPs (PsStructure Tag
t Vector Ps
fs) | Tag
t Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Tag
sigURel, Vector Ps -> Int
forall a. Vector a -> Int
V.length Vector Ps
fs Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
4 =
Int64 -> Text -> HashMap Text Ps -> Text -> UnboundRelationship
UnboundRelationship (Int64 -> Text -> HashMap Text Ps -> Text -> UnboundRelationship)
-> Result Int64
-> Result (Text -> HashMap Text Ps -> Text -> UnboundRelationship)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ps -> Result Int64
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
0) Result (Text -> HashMap Text Ps -> Text -> UnboundRelationship)
-> Result Text
-> Result (HashMap Text Ps -> Text -> UnboundRelationship)
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result Text
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
1) Result (HashMap Text Ps -> Text -> UnboundRelationship)
-> Result (HashMap Text Ps) -> Result (Text -> UnboundRelationship)
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result (HashMap Text Ps)
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
2) Result (Text -> UnboundRelationship)
-> Result Text -> Result UnboundRelationship
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result Text
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
3)
fromPs (PsStructure Tag
t Vector Ps
fs) | Tag
t Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Tag
sigURel, Vector Ps -> Int
forall a. Vector a -> Int
V.length Vector Ps
fs Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
3 =
Int64 -> Text -> HashMap Text Ps -> Text -> UnboundRelationship
UnboundRelationship (Int64 -> Text -> HashMap Text Ps -> Text -> UnboundRelationship)
-> Result Int64
-> Result (Text -> HashMap Text Ps -> Text -> UnboundRelationship)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ps -> Result Int64
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
0) Result (Text -> HashMap Text Ps -> Text -> UnboundRelationship)
-> Result Text
-> Result (HashMap Text Ps -> Text -> UnboundRelationship)
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result Text
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
1) Result (HashMap Text Ps -> Text -> UnboundRelationship)
-> Result (HashMap Text Ps) -> Result (Text -> UnboundRelationship)
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result (HashMap Text Ps)
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
2) Result (Text -> UnboundRelationship)
-> Result Text -> Result UnboundRelationship
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Text -> Result Text
forall a. a -> Result a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
""
fromPs Ps
other = Text -> Ps -> Result UnboundRelationship
forall a. Text -> Ps -> Result a
typeMismatch Text
"UnboundRelationship" Ps
other
type Path :: Type
data Path = Path
{ Path -> Vector Node
nodes :: !(V.Vector Node)
, Path -> Vector UnboundRelationship
rels :: !(V.Vector UnboundRelationship)
, Path -> Vector Int64
indices :: !(V.Vector Int64)
}
deriving stock (Int -> Path -> ShowS
[Path] -> ShowS
Path -> String
(Int -> Path -> ShowS)
-> (Path -> String) -> ([Path] -> ShowS) -> Show Path
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Path -> ShowS
showsPrec :: Int -> Path -> ShowS
$cshow :: Path -> String
show :: Path -> String
$cshowList :: [Path] -> ShowS
showList :: [Path] -> ShowS
Show, Path -> Path -> Bool
(Path -> Path -> Bool) -> (Path -> Path -> Bool) -> Eq Path
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Path -> Path -> Bool
== :: Path -> Path -> Bool
$c/= :: Path -> Path -> Bool
/= :: Path -> Path -> Bool
Eq, (forall x. Path -> Rep Path x)
-> (forall x. Rep Path x -> Path) -> Generic Path
forall x. Rep Path x -> Path
forall x. Path -> Rep Path x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Path -> Rep Path x
from :: forall x. Path -> Rep Path x
$cto :: forall x. Rep Path x -> Path
to :: forall x. Rep Path x -> Path
Generic)
instance PackStream Path where
toPs :: Path -> Ps
toPs Path{Vector Node
nodes :: Path -> Vector Node
nodes :: Vector Node
nodes, Vector UnboundRelationship
rels :: Path -> Vector UnboundRelationship
rels :: Vector UnboundRelationship
rels, Vector Int64
indices :: Path -> Vector Int64
indices :: Vector Int64
indices} =
Tag -> Vector Ps -> Ps
PsStructure Tag
sigPath (Vector Ps -> Ps) -> Vector Ps -> Ps
forall a b. (a -> b) -> a -> b
$ [Ps] -> Vector Ps
forall a. [a] -> Vector a
V.fromList [Vector Node -> Ps
forall a. PackStream a => a -> Ps
toPs Vector Node
nodes, Vector UnboundRelationship -> Ps
forall a. PackStream a => a -> Ps
toPs Vector UnboundRelationship
rels, Vector Int64 -> Ps
forall a. PackStream a => a -> Ps
toPs Vector Int64
indices]
fromPs :: Ps -> Result Path
fromPs (PsStructure Tag
t Vector Ps
fs) | Tag
t Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Tag
sigPath, Vector Ps -> Int
forall a. Vector a -> Int
V.length Vector Ps
fs Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
3 =
Vector Node -> Vector UnboundRelationship -> Vector Int64 -> Path
Path (Vector Node -> Vector UnboundRelationship -> Vector Int64 -> Path)
-> Result (Vector Node)
-> Result (Vector UnboundRelationship -> Vector Int64 -> Path)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ps -> Result (Vector Node)
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
0) Result (Vector UnboundRelationship -> Vector Int64 -> Path)
-> Result (Vector UnboundRelationship)
-> Result (Vector Int64 -> Path)
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result (Vector UnboundRelationship)
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
1) Result (Vector Int64 -> Path)
-> Result (Vector Int64) -> Result Path
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result (Vector Int64)
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
2)
fromPs Ps
other = Text -> Ps -> Result Path
forall a. Text -> Ps -> Result a
typeMismatch Text
"Path" Ps
other
type Date :: Type
data Date = Date
{ Date -> Int64
days :: !Int64
}
deriving stock (Int -> Date -> ShowS
[Date] -> ShowS
Date -> String
(Int -> Date -> ShowS)
-> (Date -> String) -> ([Date] -> ShowS) -> Show Date
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Date -> ShowS
showsPrec :: Int -> Date -> ShowS
$cshow :: Date -> String
show :: Date -> String
$cshowList :: [Date] -> ShowS
showList :: [Date] -> ShowS
Show, Date -> Date -> Bool
(Date -> Date -> Bool) -> (Date -> Date -> Bool) -> Eq Date
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Date -> Date -> Bool
== :: Date -> Date -> Bool
$c/= :: Date -> Date -> Bool
/= :: Date -> Date -> Bool
Eq, (forall x. Date -> Rep Date x)
-> (forall x. Rep Date x -> Date) -> Generic Date
forall x. Rep Date x -> Date
forall x. Date -> Rep Date x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Date -> Rep Date x
from :: forall x. Date -> Rep Date x
$cto :: forall x. Rep Date x -> Date
to :: forall x. Rep Date x -> Date
Generic)
instance PackStream Date where
toPs :: Date -> Ps
toPs Date{Int64
days :: Date -> Int64
days :: Int64
days} =
Tag -> Vector Ps -> Ps
PsStructure Tag
sigDate (Vector Ps -> Ps) -> Vector Ps -> Ps
forall a b. (a -> b) -> a -> b
$ Ps -> Vector Ps
forall a. a -> Vector a
V.singleton (Int64 -> Ps
forall a. PackStream a => a -> Ps
toPs Int64
days)
fromPs :: Ps -> Result Date
fromPs (PsStructure Tag
t Vector Ps
fs) | Tag
t Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Tag
sigDate, Vector Ps -> Int
forall a. Vector a -> Int
V.length Vector Ps
fs Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1 =
Int64 -> Date
Date (Int64 -> Date) -> Result Int64 -> Result Date
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ps -> Result Int64
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
0)
fromPs Ps
other = Text -> Ps -> Result Date
forall a. Text -> Ps -> Result a
typeMismatch Text
"Date" Ps
other
type Time :: Type
data Time = Time
{ Time -> Int64
nanoseconds :: !Int64
, Time -> Int64
tz_offset_seconds :: !Int64
}
deriving stock (Int -> Time -> ShowS
[Time] -> ShowS
Time -> String
(Int -> Time -> ShowS)
-> (Time -> String) -> ([Time] -> ShowS) -> Show Time
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Time -> ShowS
showsPrec :: Int -> Time -> ShowS
$cshow :: Time -> String
show :: Time -> String
$cshowList :: [Time] -> ShowS
showList :: [Time] -> ShowS
Show, Time -> Time -> Bool
(Time -> Time -> Bool) -> (Time -> Time -> Bool) -> Eq Time
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Time -> Time -> Bool
== :: Time -> Time -> Bool
$c/= :: Time -> Time -> Bool
/= :: Time -> Time -> Bool
Eq, (forall x. Time -> Rep Time x)
-> (forall x. Rep Time x -> Time) -> Generic Time
forall x. Rep Time x -> Time
forall x. Time -> Rep Time x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Time -> Rep Time x
from :: forall x. Time -> Rep Time x
$cto :: forall x. Rep Time x -> Time
to :: forall x. Rep Time x -> Time
Generic)
instance PackStream Time where
toPs :: Time -> Ps
toPs Time{Int64
nanoseconds :: Time -> Int64
nanoseconds :: Int64
nanoseconds, Int64
tz_offset_seconds :: Time -> Int64
tz_offset_seconds :: Int64
tz_offset_seconds} =
Tag -> Vector Ps -> Ps
PsStructure Tag
sigTime (Vector Ps -> Ps) -> Vector Ps -> Ps
forall a b. (a -> b) -> a -> b
$ [Ps] -> Vector Ps
forall a. [a] -> Vector a
V.fromList [Int64 -> Ps
forall a. PackStream a => a -> Ps
toPs Int64
nanoseconds, Int64 -> Ps
forall a. PackStream a => a -> Ps
toPs Int64
tz_offset_seconds]
fromPs :: Ps -> Result Time
fromPs (PsStructure Tag
t Vector Ps
fs) | Tag
t Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Tag
sigTime, Vector Ps -> Int
forall a. Vector a -> Int
V.length Vector Ps
fs Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
2 =
Int64 -> Int64 -> Time
Time (Int64 -> Int64 -> Time) -> Result Int64 -> Result (Int64 -> Time)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ps -> Result Int64
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
0) Result (Int64 -> Time) -> Result Int64 -> Result Time
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result Int64
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
1)
fromPs Ps
other = Text -> Ps -> Result Time
forall a. Text -> Ps -> Result a
typeMismatch Text
"Time" Ps
other
type LocalTime :: Type
data LocalTime = LocalTime
{ LocalTime -> Int64
nanoseconds :: !Int64
}
deriving stock (Int -> LocalTime -> ShowS
[LocalTime] -> ShowS
LocalTime -> String
(Int -> LocalTime -> ShowS)
-> (LocalTime -> String)
-> ([LocalTime] -> ShowS)
-> Show LocalTime
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LocalTime -> ShowS
showsPrec :: Int -> LocalTime -> ShowS
$cshow :: LocalTime -> String
show :: LocalTime -> String
$cshowList :: [LocalTime] -> ShowS
showList :: [LocalTime] -> ShowS
Show, LocalTime -> LocalTime -> Bool
(LocalTime -> LocalTime -> Bool)
-> (LocalTime -> LocalTime -> Bool) -> Eq LocalTime
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LocalTime -> LocalTime -> Bool
== :: LocalTime -> LocalTime -> Bool
$c/= :: LocalTime -> LocalTime -> Bool
/= :: LocalTime -> LocalTime -> Bool
Eq, (forall x. LocalTime -> Rep LocalTime x)
-> (forall x. Rep LocalTime x -> LocalTime) -> Generic LocalTime
forall x. Rep LocalTime x -> LocalTime
forall x. LocalTime -> Rep LocalTime x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. LocalTime -> Rep LocalTime x
from :: forall x. LocalTime -> Rep LocalTime x
$cto :: forall x. Rep LocalTime x -> LocalTime
to :: forall x. Rep LocalTime x -> LocalTime
Generic)
instance PackStream LocalTime where
toPs :: LocalTime -> Ps
toPs LocalTime{Int64
nanoseconds :: LocalTime -> Int64
nanoseconds :: Int64
nanoseconds} =
Tag -> Vector Ps -> Ps
PsStructure Tag
sigLocalTime (Vector Ps -> Ps) -> Vector Ps -> Ps
forall a b. (a -> b) -> a -> b
$ Ps -> Vector Ps
forall a. a -> Vector a
V.singleton (Int64 -> Ps
forall a. PackStream a => a -> Ps
toPs Int64
nanoseconds)
fromPs :: Ps -> Result LocalTime
fromPs (PsStructure Tag
t Vector Ps
fs) | Tag
t Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Tag
sigLocalTime, Vector Ps -> Int
forall a. Vector a -> Int
V.length Vector Ps
fs Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1 =
Int64 -> LocalTime
LocalTime (Int64 -> LocalTime) -> Result Int64 -> Result LocalTime
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ps -> Result Int64
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
0)
fromPs Ps
other = Text -> Ps -> Result LocalTime
forall a. Text -> Ps -> Result a
typeMismatch Text
"LocalTime" Ps
other
type DateTime :: Type
data DateTime = DateTime
{ DateTime -> Int64
seconds :: !Int64
, DateTime -> Int64
nanoseconds :: !Int64
, DateTime -> Int64
tz_offset_seconds :: !Int64
}
deriving stock (Int -> DateTime -> ShowS
[DateTime] -> ShowS
DateTime -> String
(Int -> DateTime -> ShowS)
-> (DateTime -> String) -> ([DateTime] -> ShowS) -> Show DateTime
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DateTime -> ShowS
showsPrec :: Int -> DateTime -> ShowS
$cshow :: DateTime -> String
show :: DateTime -> String
$cshowList :: [DateTime] -> ShowS
showList :: [DateTime] -> ShowS
Show, DateTime -> DateTime -> Bool
(DateTime -> DateTime -> Bool)
-> (DateTime -> DateTime -> Bool) -> Eq DateTime
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DateTime -> DateTime -> Bool
== :: DateTime -> DateTime -> Bool
$c/= :: DateTime -> DateTime -> Bool
/= :: DateTime -> DateTime -> Bool
Eq, (forall x. DateTime -> Rep DateTime x)
-> (forall x. Rep DateTime x -> DateTime) -> Generic DateTime
forall x. Rep DateTime x -> DateTime
forall x. DateTime -> Rep DateTime x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. DateTime -> Rep DateTime x
from :: forall x. DateTime -> Rep DateTime x
$cto :: forall x. Rep DateTime x -> DateTime
to :: forall x. Rep DateTime x -> DateTime
Generic)
instance PackStream DateTime where
toPs :: DateTime -> Ps
toPs DateTime{Int64
seconds :: DateTime -> Int64
seconds :: Int64
seconds, Int64
nanoseconds :: DateTime -> Int64
nanoseconds :: Int64
nanoseconds, Int64
tz_offset_seconds :: DateTime -> Int64
tz_offset_seconds :: Int64
tz_offset_seconds} =
Tag -> Vector Ps -> Ps
PsStructure Tag
sigDateTime (Vector Ps -> Ps) -> Vector Ps -> Ps
forall a b. (a -> b) -> a -> b
$ [Ps] -> Vector Ps
forall a. [a] -> Vector a
V.fromList [Int64 -> Ps
forall a. PackStream a => a -> Ps
toPs Int64
seconds, Int64 -> Ps
forall a. PackStream a => a -> Ps
toPs Int64
nanoseconds, Int64 -> Ps
forall a. PackStream a => a -> Ps
toPs Int64
tz_offset_seconds]
fromPs :: Ps -> Result DateTime
fromPs (PsStructure Tag
t Vector Ps
fs) | Tag
t Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Tag
sigDateTime, Vector Ps -> Int
forall a. Vector a -> Int
V.length Vector Ps
fs Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
3 =
Int64 -> Int64 -> Int64 -> DateTime
DateTime (Int64 -> Int64 -> Int64 -> DateTime)
-> Result Int64 -> Result (Int64 -> Int64 -> DateTime)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ps -> Result Int64
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
0) Result (Int64 -> Int64 -> DateTime)
-> Result Int64 -> Result (Int64 -> DateTime)
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result Int64
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
1) Result (Int64 -> DateTime) -> Result Int64 -> Result DateTime
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result Int64
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
2)
fromPs Ps
other = Text -> Ps -> Result DateTime
forall a. Text -> Ps -> Result a
typeMismatch Text
"DateTime" Ps
other
type DateTimeZoneId :: Type
data DateTimeZoneId = DateTimeZoneId
{ DateTimeZoneId -> Int64
seconds :: !Int64
, DateTimeZoneId -> Int64
nanoseconds :: !Int64
, DateTimeZoneId -> Text
tz_id :: !T.Text
}
deriving stock (Int -> DateTimeZoneId -> ShowS
[DateTimeZoneId] -> ShowS
DateTimeZoneId -> String
(Int -> DateTimeZoneId -> ShowS)
-> (DateTimeZoneId -> String)
-> ([DateTimeZoneId] -> ShowS)
-> Show DateTimeZoneId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DateTimeZoneId -> ShowS
showsPrec :: Int -> DateTimeZoneId -> ShowS
$cshow :: DateTimeZoneId -> String
show :: DateTimeZoneId -> String
$cshowList :: [DateTimeZoneId] -> ShowS
showList :: [DateTimeZoneId] -> ShowS
Show, DateTimeZoneId -> DateTimeZoneId -> Bool
(DateTimeZoneId -> DateTimeZoneId -> Bool)
-> (DateTimeZoneId -> DateTimeZoneId -> Bool) -> Eq DateTimeZoneId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DateTimeZoneId -> DateTimeZoneId -> Bool
== :: DateTimeZoneId -> DateTimeZoneId -> Bool
$c/= :: DateTimeZoneId -> DateTimeZoneId -> Bool
/= :: DateTimeZoneId -> DateTimeZoneId -> Bool
Eq, (forall x. DateTimeZoneId -> Rep DateTimeZoneId x)
-> (forall x. Rep DateTimeZoneId x -> DateTimeZoneId)
-> Generic DateTimeZoneId
forall x. Rep DateTimeZoneId x -> DateTimeZoneId
forall x. DateTimeZoneId -> Rep DateTimeZoneId x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. DateTimeZoneId -> Rep DateTimeZoneId x
from :: forall x. DateTimeZoneId -> Rep DateTimeZoneId x
$cto :: forall x. Rep DateTimeZoneId x -> DateTimeZoneId
to :: forall x. Rep DateTimeZoneId x -> DateTimeZoneId
Generic)
instance PackStream DateTimeZoneId where
toPs :: DateTimeZoneId -> Ps
toPs DateTimeZoneId{Int64
seconds :: DateTimeZoneId -> Int64
seconds :: Int64
seconds, Int64
nanoseconds :: DateTimeZoneId -> Int64
nanoseconds :: Int64
nanoseconds, Text
tz_id :: DateTimeZoneId -> Text
tz_id :: Text
tz_id} =
Tag -> Vector Ps -> Ps
PsStructure Tag
sigDateTimeZoneId (Vector Ps -> Ps) -> Vector Ps -> Ps
forall a b. (a -> b) -> a -> b
$ [Ps] -> Vector Ps
forall a. [a] -> Vector a
V.fromList [Int64 -> Ps
forall a. PackStream a => a -> Ps
toPs Int64
seconds, Int64 -> Ps
forall a. PackStream a => a -> Ps
toPs Int64
nanoseconds, Text -> Ps
forall a. PackStream a => a -> Ps
toPs Text
tz_id]
fromPs :: Ps -> Result DateTimeZoneId
fromPs (PsStructure Tag
t Vector Ps
fs) | Tag
t Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Tag
sigDateTimeZoneId, Vector Ps -> Int
forall a. Vector a -> Int
V.length Vector Ps
fs Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
3 =
Int64 -> Int64 -> Text -> DateTimeZoneId
DateTimeZoneId (Int64 -> Int64 -> Text -> DateTimeZoneId)
-> Result Int64 -> Result (Int64 -> Text -> DateTimeZoneId)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ps -> Result Int64
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
0) Result (Int64 -> Text -> DateTimeZoneId)
-> Result Int64 -> Result (Text -> DateTimeZoneId)
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result Int64
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
1) Result (Text -> DateTimeZoneId)
-> Result Text -> Result DateTimeZoneId
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result Text
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
2)
fromPs Ps
other = Text -> Ps -> Result DateTimeZoneId
forall a. Text -> Ps -> Result a
typeMismatch Text
"DateTimeZoneId" Ps
other
type LocalDateTime :: Type
data LocalDateTime = LocalDateTime
{ LocalDateTime -> Int64
seconds :: !Int64
, LocalDateTime -> Int64
nanoseconds :: !Int64
}
deriving stock (Int -> LocalDateTime -> ShowS
[LocalDateTime] -> ShowS
LocalDateTime -> String
(Int -> LocalDateTime -> ShowS)
-> (LocalDateTime -> String)
-> ([LocalDateTime] -> ShowS)
-> Show LocalDateTime
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LocalDateTime -> ShowS
showsPrec :: Int -> LocalDateTime -> ShowS
$cshow :: LocalDateTime -> String
show :: LocalDateTime -> String
$cshowList :: [LocalDateTime] -> ShowS
showList :: [LocalDateTime] -> ShowS
Show, LocalDateTime -> LocalDateTime -> Bool
(LocalDateTime -> LocalDateTime -> Bool)
-> (LocalDateTime -> LocalDateTime -> Bool) -> Eq LocalDateTime
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LocalDateTime -> LocalDateTime -> Bool
== :: LocalDateTime -> LocalDateTime -> Bool
$c/= :: LocalDateTime -> LocalDateTime -> Bool
/= :: LocalDateTime -> LocalDateTime -> Bool
Eq, (forall x. LocalDateTime -> Rep LocalDateTime x)
-> (forall x. Rep LocalDateTime x -> LocalDateTime)
-> Generic LocalDateTime
forall x. Rep LocalDateTime x -> LocalDateTime
forall x. LocalDateTime -> Rep LocalDateTime x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. LocalDateTime -> Rep LocalDateTime x
from :: forall x. LocalDateTime -> Rep LocalDateTime x
$cto :: forall x. Rep LocalDateTime x -> LocalDateTime
to :: forall x. Rep LocalDateTime x -> LocalDateTime
Generic)
instance PackStream LocalDateTime where
toPs :: LocalDateTime -> Ps
toPs LocalDateTime{Int64
seconds :: LocalDateTime -> Int64
seconds :: Int64
seconds, Int64
nanoseconds :: LocalDateTime -> Int64
nanoseconds :: Int64
nanoseconds} =
Tag -> Vector Ps -> Ps
PsStructure Tag
sigLocalDateTime (Vector Ps -> Ps) -> Vector Ps -> Ps
forall a b. (a -> b) -> a -> b
$ [Ps] -> Vector Ps
forall a. [a] -> Vector a
V.fromList [Int64 -> Ps
forall a. PackStream a => a -> Ps
toPs Int64
seconds, Int64 -> Ps
forall a. PackStream a => a -> Ps
toPs Int64
nanoseconds]
fromPs :: Ps -> Result LocalDateTime
fromPs (PsStructure Tag
t Vector Ps
fs) | Tag
t Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Tag
sigLocalDateTime, Vector Ps -> Int
forall a. Vector a -> Int
V.length Vector Ps
fs Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
2 =
Int64 -> Int64 -> LocalDateTime
LocalDateTime (Int64 -> Int64 -> LocalDateTime)
-> Result Int64 -> Result (Int64 -> LocalDateTime)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ps -> Result Int64
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
0) Result (Int64 -> LocalDateTime)
-> Result Int64 -> Result LocalDateTime
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result Int64
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
1)
fromPs Ps
other = Text -> Ps -> Result LocalDateTime
forall a. Text -> Ps -> Result a
typeMismatch Text
"LocalDateTime" Ps
other
type Duration :: Type
data Duration = Duration
{ Duration -> Int64
months :: !Int64
, Duration -> Int64
days :: !Int64
, Duration -> Int64
seconds :: !Int64
, Duration -> Int64
nanoseconds :: !Int64
}
deriving stock (Int -> Duration -> ShowS
[Duration] -> ShowS
Duration -> String
(Int -> Duration -> ShowS)
-> (Duration -> String) -> ([Duration] -> ShowS) -> Show Duration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Duration -> ShowS
showsPrec :: Int -> Duration -> ShowS
$cshow :: Duration -> String
show :: Duration -> String
$cshowList :: [Duration] -> ShowS
showList :: [Duration] -> ShowS
Show, Duration -> Duration -> Bool
(Duration -> Duration -> Bool)
-> (Duration -> Duration -> Bool) -> Eq Duration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Duration -> Duration -> Bool
== :: Duration -> Duration -> Bool
$c/= :: Duration -> Duration -> Bool
/= :: Duration -> Duration -> Bool
Eq, (forall x. Duration -> Rep Duration x)
-> (forall x. Rep Duration x -> Duration) -> Generic Duration
forall x. Rep Duration x -> Duration
forall x. Duration -> Rep Duration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Duration -> Rep Duration x
from :: forall x. Duration -> Rep Duration x
$cto :: forall x. Rep Duration x -> Duration
to :: forall x. Rep Duration x -> Duration
Generic)
instance PackStream Duration where
toPs :: Duration -> Ps
toPs Duration{Int64
months :: Duration -> Int64
months :: Int64
months, Int64
days :: Duration -> Int64
days :: Int64
days, Int64
seconds :: Duration -> Int64
seconds :: Int64
seconds, Int64
nanoseconds :: Duration -> Int64
nanoseconds :: Int64
nanoseconds} =
Tag -> Vector Ps -> Ps
PsStructure Tag
sigDuration (Vector Ps -> Ps) -> Vector Ps -> Ps
forall a b. (a -> b) -> a -> b
$ [Ps] -> Vector Ps
forall a. [a] -> Vector a
V.fromList [Int64 -> Ps
forall a. PackStream a => a -> Ps
toPs Int64
months, Int64 -> Ps
forall a. PackStream a => a -> Ps
toPs Int64
days, Int64 -> Ps
forall a. PackStream a => a -> Ps
toPs Int64
seconds, Int64 -> Ps
forall a. PackStream a => a -> Ps
toPs Int64
nanoseconds]
fromPs :: Ps -> Result Duration
fromPs (PsStructure Tag
t Vector Ps
fs) | Tag
t Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Tag
sigDuration, Vector Ps -> Int
forall a. Vector a -> Int
V.length Vector Ps
fs Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
4 =
Int64 -> Int64 -> Int64 -> Int64 -> Duration
Duration (Int64 -> Int64 -> Int64 -> Int64 -> Duration)
-> Result Int64 -> Result (Int64 -> Int64 -> Int64 -> Duration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ps -> Result Int64
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
0) Result (Int64 -> Int64 -> Int64 -> Duration)
-> Result Int64 -> Result (Int64 -> Int64 -> Duration)
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result Int64
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
1) Result (Int64 -> Int64 -> Duration)
-> Result Int64 -> Result (Int64 -> Duration)
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result Int64
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
2) Result (Int64 -> Duration) -> Result Int64 -> Result Duration
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result Int64
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
3)
fromPs Ps
other = Text -> Ps -> Result Duration
forall a. Text -> Ps -> Result a
typeMismatch Text
"Duration" Ps
other
type Point2D :: Type
data Point2D = Point2D
{ Point2D -> Int64
srid :: !Int64
, Point2D -> Double
x :: !Double
, Point2D -> Double
y :: !Double
}
deriving stock (Int -> Point2D -> ShowS
[Point2D] -> ShowS
Point2D -> String
(Int -> Point2D -> ShowS)
-> (Point2D -> String) -> ([Point2D] -> ShowS) -> Show Point2D
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Point2D -> ShowS
showsPrec :: Int -> Point2D -> ShowS
$cshow :: Point2D -> String
show :: Point2D -> String
$cshowList :: [Point2D] -> ShowS
showList :: [Point2D] -> ShowS
Show, Point2D -> Point2D -> Bool
(Point2D -> Point2D -> Bool)
-> (Point2D -> Point2D -> Bool) -> Eq Point2D
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Point2D -> Point2D -> Bool
== :: Point2D -> Point2D -> Bool
$c/= :: Point2D -> Point2D -> Bool
/= :: Point2D -> Point2D -> Bool
Eq, (forall x. Point2D -> Rep Point2D x)
-> (forall x. Rep Point2D x -> Point2D) -> Generic Point2D
forall x. Rep Point2D x -> Point2D
forall x. Point2D -> Rep Point2D x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Point2D -> Rep Point2D x
from :: forall x. Point2D -> Rep Point2D x
$cto :: forall x. Rep Point2D x -> Point2D
to :: forall x. Rep Point2D x -> Point2D
Generic)
instance PackStream Point2D where
toPs :: Point2D -> Ps
toPs Point2D{Int64
srid :: Point2D -> Int64
srid :: Int64
srid, Double
x :: Point2D -> Double
x :: Double
x, Double
y :: Point2D -> Double
y :: Double
y} =
Tag -> Vector Ps -> Ps
PsStructure Tag
sigPoint2D (Vector Ps -> Ps) -> Vector Ps -> Ps
forall a b. (a -> b) -> a -> b
$ [Ps] -> Vector Ps
forall a. [a] -> Vector a
V.fromList [Int64 -> Ps
forall a. PackStream a => a -> Ps
toPs Int64
srid, Double -> Ps
forall a. PackStream a => a -> Ps
toPs Double
x, Double -> Ps
forall a. PackStream a => a -> Ps
toPs Double
y]
fromPs :: Ps -> Result Point2D
fromPs (PsStructure Tag
t Vector Ps
fs) | Tag
t Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Tag
sigPoint2D, Vector Ps -> Int
forall a. Vector a -> Int
V.length Vector Ps
fs Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
3 =
Int64 -> Double -> Double -> Point2D
Point2D (Int64 -> Double -> Double -> Point2D)
-> Result Int64 -> Result (Double -> Double -> Point2D)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ps -> Result Int64
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
0) Result (Double -> Double -> Point2D)
-> Result Double -> Result (Double -> Point2D)
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result Double
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
1) Result (Double -> Point2D) -> Result Double -> Result Point2D
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result Double
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
2)
fromPs Ps
other = Text -> Ps -> Result Point2D
forall a. Text -> Ps -> Result a
typeMismatch Text
"Point2D" Ps
other
type Point3D :: Type
data Point3D = Point3D
{ Point3D -> Int64
srid :: !Int64
, Point3D -> Double
x :: !Double
, Point3D -> Double
y :: !Double
, Point3D -> Double
z :: !Double
}
deriving stock (Int -> Point3D -> ShowS
[Point3D] -> ShowS
Point3D -> String
(Int -> Point3D -> ShowS)
-> (Point3D -> String) -> ([Point3D] -> ShowS) -> Show Point3D
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Point3D -> ShowS
showsPrec :: Int -> Point3D -> ShowS
$cshow :: Point3D -> String
show :: Point3D -> String
$cshowList :: [Point3D] -> ShowS
showList :: [Point3D] -> ShowS
Show, Point3D -> Point3D -> Bool
(Point3D -> Point3D -> Bool)
-> (Point3D -> Point3D -> Bool) -> Eq Point3D
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Point3D -> Point3D -> Bool
== :: Point3D -> Point3D -> Bool
$c/= :: Point3D -> Point3D -> Bool
/= :: Point3D -> Point3D -> Bool
Eq, (forall x. Point3D -> Rep Point3D x)
-> (forall x. Rep Point3D x -> Point3D) -> Generic Point3D
forall x. Rep Point3D x -> Point3D
forall x. Point3D -> Rep Point3D x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Point3D -> Rep Point3D x
from :: forall x. Point3D -> Rep Point3D x
$cto :: forall x. Rep Point3D x -> Point3D
to :: forall x. Rep Point3D x -> Point3D
Generic)
instance PackStream Point3D where
toPs :: Point3D -> Ps
toPs Point3D{Int64
srid :: Point3D -> Int64
srid :: Int64
srid, Double
x :: Point3D -> Double
x :: Double
x, Double
y :: Point3D -> Double
y :: Double
y, Double
z :: Point3D -> Double
z :: Double
z} =
Tag -> Vector Ps -> Ps
PsStructure Tag
sigPoint3D (Vector Ps -> Ps) -> Vector Ps -> Ps
forall a b. (a -> b) -> a -> b
$ [Ps] -> Vector Ps
forall a. [a] -> Vector a
V.fromList [Int64 -> Ps
forall a. PackStream a => a -> Ps
toPs Int64
srid, Double -> Ps
forall a. PackStream a => a -> Ps
toPs Double
x, Double -> Ps
forall a. PackStream a => a -> Ps
toPs Double
y, Double -> Ps
forall a. PackStream a => a -> Ps
toPs Double
z]
fromPs :: Ps -> Result Point3D
fromPs (PsStructure Tag
t Vector Ps
fs) | Tag
t Tag -> Tag -> Bool
forall a. Eq a => a -> a -> Bool
== Tag
sigPoint3D, Vector Ps -> Int
forall a. Vector a -> Int
V.length Vector Ps
fs Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
4 =
Int64 -> Double -> Double -> Double -> Point3D
Point3D (Int64 -> Double -> Double -> Double -> Point3D)
-> Result Int64 -> Result (Double -> Double -> Double -> Point3D)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ps -> Result Int64
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
0) Result (Double -> Double -> Double -> Point3D)
-> Result Double -> Result (Double -> Double -> Point3D)
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result Double
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
1) Result (Double -> Double -> Point3D)
-> Result Double -> Result (Double -> Point3D)
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result Double
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
2) Result (Double -> Point3D) -> Result Double -> Result Point3D
forall a b. Result (a -> b) -> Result a -> Result b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ps -> Result Double
forall a. PackStream a => Ps -> Result a
fromPs (Vector Ps
fs Vector Ps -> Int -> Ps
forall a. Vector a -> Int -> a
V.! Int
3)
fromPs Ps
other = Text -> Ps -> Result Point3D
forall a. Text -> Ps -> Result a
typeMismatch Text
"Point3D" Ps
other
asNull :: Bolt -> Maybe ()
asNull :: Bolt -> Maybe ()
asNull Bolt
BoltNull = () -> Maybe ()
forall a. a -> Maybe a
Just ()
asNull Bolt
_ = Maybe ()
forall a. Maybe a
Nothing
asBool :: Bolt -> Maybe Bool
asBool :: Bolt -> Maybe Bool
asBool (BoltBoolean Bool
b) = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
b
asBool Bolt
_ = Maybe Bool
forall a. Maybe a
Nothing
asInt :: Bolt -> Maybe PSInteger
asInt :: Bolt -> Maybe PSInteger
asInt (BoltInteger PSInteger
i) = PSInteger -> Maybe PSInteger
forall a. a -> Maybe a
Just PSInteger
i
asInt Bolt
_ = Maybe PSInteger
forall a. Maybe a
Nothing
asFloat :: Bolt -> Maybe Double
asFloat :: Bolt -> Maybe Double
asFloat (BoltFloat Double
d) = Double -> Maybe Double
forall a. a -> Maybe a
Just Double
d
asFloat Bolt
_ = Maybe Double
forall a. Maybe a
Nothing
asBytes :: Bolt -> Maybe BS.ByteString
asBytes :: Bolt -> Maybe ByteString
asBytes (BoltBytes ByteString
b) = ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
b
asBytes Bolt
_ = Maybe ByteString
forall a. Maybe a
Nothing
asText :: Bolt -> Maybe T.Text
asText :: Bolt -> Maybe Text
asText (BoltString Text
t) = Text -> Maybe Text
forall a. a -> Maybe a
Just Text
t
asText Bolt
_ = Maybe Text
forall a. Maybe a
Nothing
asList :: Bolt -> Maybe (V.Vector Bolt)
asList :: Bolt -> Maybe (Vector Bolt)
asList (BoltList Vector Bolt
v) = Vector Bolt -> Maybe (Vector Bolt)
forall a. a -> Maybe a
Just Vector Bolt
v
asList Bolt
_ = Maybe (Vector Bolt)
forall a. Maybe a
Nothing
asDict :: Bolt -> Maybe (H.HashMap T.Text Bolt)
asDict :: Bolt -> Maybe (HashMap Text Bolt)
asDict (BoltDictionary HashMap Text Bolt
m) = HashMap Text Bolt -> Maybe (HashMap Text Bolt)
forall a. a -> Maybe a
Just HashMap Text Bolt
m
asDict Bolt
_ = Maybe (HashMap Text Bolt)
forall a. Maybe a
Nothing
asNode :: Bolt -> Maybe Node
asNode :: Bolt -> Maybe Node
asNode (BoltNode Node
n) = Node -> Maybe Node
forall a. a -> Maybe a
Just Node
n
asNode Bolt
_ = Maybe Node
forall a. Maybe a
Nothing
asRelationship :: Bolt -> Maybe Relationship
asRelationship :: Bolt -> Maybe Relationship
asRelationship (BoltRelationship Relationship
r) = Relationship -> Maybe Relationship
forall a. a -> Maybe a
Just Relationship
r
asRelationship Bolt
_ = Maybe Relationship
forall a. Maybe a
Nothing
asPath :: Bolt -> Maybe Path
asPath :: Bolt -> Maybe Path
asPath (BoltPath Path
p) = Path -> Maybe Path
forall a. a -> Maybe a
Just Path
p
asPath Bolt
_ = Maybe Path
forall a. Maybe a
Nothing