Skip to content

Commit

Permalink
Removing not-so-'smart' de/serialisation of base64 bytes streams
Browse files Browse the repository at this point in the history
Fixes #47
  • Loading branch information
brendanhay committed Feb 11, 2017
1 parent a9c9744 commit 634e075
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 56 deletions.
3 changes: 1 addition & 2 deletions core/gogol-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ library
ghc-options: -Wall

exposed-modules:
Network.Google.Data.Base64
Network.Google.Data.Bytes
, Network.Google.Data.JSON
, Network.Google.Data.Numeric
, Network.Google.Data.Time
Expand All @@ -59,7 +59,6 @@ library
, http-media >= 0.6
, http-types >= 0.8.6
, lens >= 4.4
, memory >= 0.8
, resourcet >= 1.1
, scientific >= 0.3
, servant >= 0.4.4
Expand Down
53 changes: 0 additions & 53 deletions core/src/Network/Google/Data/Base64.hs

This file was deleted.

49 changes: 49 additions & 0 deletions core/src/Network/Google/Data/Bytes.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

-- |
-- Module : Network.Google.Data.Bytes
-- Copyright : (c) 2013-2016 Brendan Hay
-- License : Mozilla Public License, v. 2.0.
-- Maintainer : Brendan Hay <[email protected]>
-- Stability : provisional
-- Portability : non-portable (GHC extensions)
--
module Network.Google.Data.Bytes
( Bytes (..)
, _Bytes
) where

import Control.Lens (Iso', iso)
import Data.Aeson (FromJSON (..), ToJSON (..))
import Data.ByteString (ByteString)
import Data.Data (Data, Typeable)
import Data.Hashable
import qualified Data.Text.Encoding as Text
import GHC.Generics (Generic)
import Network.Google.Data.JSON (parseJSONText, toJSONText)
import Web.HttpApiData (FromHttpApiData (..),
ToHttpApiData (..))
-- | Binary data.
--
-- This data is passed to/from the serialisation routines as-is, and any
-- particular encoding or decoding (say, base64) is left up to the caller.
newtype Bytes = Bytes { unBytes :: ByteString }
deriving (Eq, Show, Read, Ord, Data, Typeable, Generic)

instance Hashable Bytes

_Bytes :: Iso' Bytes ByteString
_Bytes = iso unBytes Bytes

instance ToHttpApiData Bytes where
toQueryParam = Text.decodeUtf8 . unBytes
toHeader = unBytes

instance FromHttpApiData Bytes where
parseQueryParam = pure . Bytes . Text.encodeUtf8
parseHeader = pure . Bytes

instance FromJSON Bytes where parseJSON = parseJSONText "Bytes"
instance ToJSON Bytes where toJSON = toJSONText
2 changes: 1 addition & 1 deletion core/src/Network/Google/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import Servant.API as Export hiding (Headers, getResponse)
import Servant.Utils.Links as Export hiding (Link)
import Web.HttpApiData as Export (FromHttpApiData (..), ToHttpApiData (..))

import Network.Google.Data.Base64 as Export
import Network.Google.Data.Bytes as Export
import Network.Google.Data.JSON as Export
import Network.Google.Data.Numeric as Export
import Network.Google.Data.Time as Export
Expand Down

0 comments on commit 634e075

Please sign in to comment.