{-# OPTIONS_GHC -fno-warn-orphans #-} module Data.Binary.Instances.Aeson where import Data.Binary (Binary, Get, get, put) import Data.Binary.Orphans () import Data.Binary.Instances.Scientific () import Data.Binary.Instances.Text () import Data.Binary.Instances.UnorderedContainers () import Data.Binary.Instances.Vector () import qualified Data.Aeson as A instance Binary A.Value where get :: Get Value get = do Int t <- Get Int forall t. Binary t => Get t get :: Get Int case Int t of 0 -> (Object -> Value) -> Get Object -> Get Value forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap Object -> Value A.Object Get Object forall t. Binary t => Get t get 1 -> (Array -> Value) -> Get Array -> Get Value forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap Array -> Value A.Array Get Array forall t. Binary t => Get t get 2 -> (Text -> Value) -> Get Text -> Get Value forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap Text -> Value A.String Get Text forall t. Binary t => Get t get 3 -> (Scientific -> Value) -> Get Scientific -> Get Value forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap Scientific -> Value A.Number Get Scientific forall t. Binary t => Get t get 4 -> (Bool -> Value) -> Get Bool -> Get Value forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap Bool -> Value A.Bool Get Bool forall t. Binary t => Get t get 5 -> Value -> Get Value forall (m :: * -> *) a. Monad m => a -> m a return Value A.Null _ -> String -> Get Value forall (m :: * -> *) a. MonadFail m => String -> m a fail (String -> Get Value) -> String -> Get Value forall a b. (a -> b) -> a -> b $ "Invalid Value tag: " String -> String -> String forall a. [a] -> [a] -> [a] ++ Int -> String forall a. Show a => a -> String show Int t put :: Value -> Put put (A.Object v :: Object v) = Int -> Put forall t. Binary t => t -> Put put (0 :: Int) Put -> Put -> Put forall (m :: * -> *) a b. Monad m => m a -> m b -> m b >> Object -> Put forall t. Binary t => t -> Put put Object v put (A.Array v :: Array v) = Int -> Put forall t. Binary t => t -> Put put (1 :: Int) Put -> Put -> Put forall (m :: * -> *) a b. Monad m => m a -> m b -> m b >> Array -> Put forall t. Binary t => t -> Put put Array v put (A.String v :: Text v) = Int -> Put forall t. Binary t => t -> Put put (2 :: Int) Put -> Put -> Put forall (m :: * -> *) a b. Monad m => m a -> m b -> m b >> Text -> Put forall t. Binary t => t -> Put put Text v put (A.Number v :: Scientific v) = Int -> Put forall t. Binary t => t -> Put put (3 :: Int) Put -> Put -> Put forall (m :: * -> *) a b. Monad m => m a -> m b -> m b >> Scientific -> Put forall t. Binary t => t -> Put put Scientific v put (A.Bool v :: Bool v) = Int -> Put forall t. Binary t => t -> Put put (4 :: Int) Put -> Put -> Put forall (m :: * -> *) a b. Monad m => m a -> m b -> m b >> Bool -> Put forall t. Binary t => t -> Put put Bool v put A.Null = Int -> Put forall t. Binary t => t -> Put put (5 :: Int)