module Data.Hermes
(
decodeEither
, Decoder(runDecoder)
, HermesEnv
, atKey
, atKeyOptional
, atKeyStrict
, atPointer
, bool
, char
, double
, int
, scientific
, string
, text
, list
, nullable
, objectAsKeyValues
, day
, month
, quarter
, timeOfDay
, timeZone
, localTime
, utcTime
, zonedTime
, HermesException(..)
, DocumentError(..)
, isNull
, withArray
, withBool
, withDocumentValue
, withDouble
, withInt
, withObject
, withString
, withText
, withRawByteString
, Array
, ArrayIter
, Document
, InputBuffer
, Object
, Parser
, Value
) where
import Control.Exception (try)
import Control.Monad.Trans.Reader (ReaderT(..), runReaderT)
import Data.ByteString (ByteString)
import qualified System.IO.Unsafe as Unsafe
import Data.Hermes.Decoder
import Data.Hermes.Decoder.Internal
( Decoder(..)
, DocumentError(..)
, HermesEnv
, HermesException(..)
, withHermesEnv
)
import Data.Hermes.SIMDJSON.Types
import Data.Hermes.SIMDJSON.Wrapper (withInputBuffer)
decodeEither :: (Value -> Decoder a) -> ByteString -> Either HermesException a
decodeEither :: forall a.
(Value -> Decoder a) -> ByteString -> Either HermesException a
decodeEither Value -> Decoder a
d ByteString
bs =
forall a. IO a -> a
Unsafe.unsafePerformIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e a. Exception e => IO a -> IO (Either e a)
try forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. (HermesEnv -> IO a) -> IO a
withHermesEnv forall a b. (a -> b) -> a -> b
$ \HermesEnv
hEnv ->
forall a. ByteString -> (InputBuffer -> IO a) -> IO a
withInputBuffer ByteString
bs forall a b. (a -> b) -> a -> b
$ \InputBuffer
input ->
forall a b c. (a -> b -> c) -> b -> a -> c
flip forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT HermesEnv
hEnv forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Decoder a -> ReaderT HermesEnv IO a
runDecoder forall a b. (a -> b) -> a -> b
$ forall a. (Value -> Decoder a) -> InputBuffer -> Decoder a
withDocumentValue Value -> Decoder a
d InputBuffer
input