X-Git-Url: http://www.average.org/gitweb/?p=pdns-pipe-nmc.git;a=blobdiff_plain;f=Data%2FJsonRpc.hs;h=64d184c72809f778a092cd82cd2ee14df075fadd;hp=b1879bccef89f57638ad44a122ad2d93f1c892c1;hb=fd964990cb0ff04f9789dcff2aef520bd093c704;hpb=dc93b41b2b38777c077e7327fe019e9a10acc8b9 diff --git a/Data/JsonRpc.hs b/Data/JsonRpc.hs index b1879bc..64d184c 100644 --- a/Data/JsonRpc.hs +++ b/Data/JsonRpc.hs @@ -1,16 +1,35 @@ -module JsonRpc ( JsonRpcRequest(..) - , JsonRpcNotification(..) - , JsonRpcResponse(..) +{-# LANGUAGE OverloadedStrings #-} + +module JsonRpc ( JsonRpcRequestV1 + , JsonRpcRequestV2 + , JsonRpcNotification + , JsonRpcResponse ) where -import Data.ByteString (ByteString) +import Data.ByteString.Lazy (ByteString) import Control.Applicative ((<$>), (<*>), empty) import Data.Aeson -data JsonRpcRequest = JsonRpcRequest { jrpcReqMethod :: ByteString - , jrpcReqParams :: [ByteString] - , jrpcReqId :: ByteString - } deriving (Show) +data JsonRpcRequestV1 = JsonRpcRequestV1 { jrpcReqMethod1 :: ByteString + , jrpcReqParams1 :: [ByteString] + , jrpcReqId1 :: ByteString + } deriving (Show) +instance ToJSON JsonRpcRequestV1 where + toJSON (JsonRpcRequestV1 method params id) = + object [ "method" .= method + , "params" .= params + , "id" .= id ] + +data JsonRpcRequestV2 = JsonRpcRequestV2 { jrpcReqMethod2 :: ByteString + , jrpcReqParams2 :: [ByteString] + , jrpcReqId2 :: ByteString + } deriving (Show) +instance ToJSON JsonRpcRequestV2 where + toJSON (JsonRpcRequestV2 jrpcReqMethod2 jrpcReqParams2 jrpcReqId2) = + object [ "jsonrpc" .= toJSON ("2.0" :: ByteString) + , "method" .= jrpcReqMethod2 + , "params" .= jrpcReqParams2 + , "id" .= jrpcReqId2 ] data JsonRpcNotification = JsonRpcNotification { jrpcNtfMethod :: ByteString , jrpcNtfParams :: [ByteString] @@ -25,5 +44,3 @@ data JsonRpcResponse = JsonRpcResponse { jrpcRspResult :: Maybe Value , jrpcRspError :: JsonRpcError , jrpcRspId :: ByteString } deriving (Show) - -