Skip to content

Commit

Permalink
Adds encodeStrict
Browse files Browse the repository at this point in the history
Adds an `encodeStrict` helper to `Fleece.Aeson` that returns a strict
`ByteString`
  • Loading branch information
onslaughtq committed Mar 25, 2024
1 parent f78fc83 commit 9ff6be9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion json-fleece-aeson/json-fleece-aeson.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cabal-version: 1.12
-- see: https://github.com/sol/hpack

name: json-fleece-aeson
version: 0.3.4.0
version: 0.3.5.0
description: Please see the README on GitHub at <https://github.com/githubuser/json-fleece-aeson#readme>
homepage: https://github.com/flipstone/json-fleece#readme
bug-reports: https://github.com/flipstone/json-fleece/issues
Expand Down
2 changes: 1 addition & 1 deletion json-fleece-aeson/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: json-fleece-aeson
version: 0.3.4.0
version: 0.3.5.0
github: "flipstone/json-fleece/json-fleece-aeson"
license: BSD3
author: "Author name here"
Expand Down
6 changes: 6 additions & 0 deletions json-fleece-aeson/src/Fleece/Aeson/Encoder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
module Fleece.Aeson.Encoder
( Encoder (..)
, encode
, encodeStrict
) where

import qualified Data.Aeson as Aeson
import qualified Data.Aeson.Encoding as AesonEncoding
import qualified Data.Aeson.Key as AesonKey
import qualified Data.Aeson.Types as AesonTypes
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as LBS
import Data.Coerce (coerce)
import qualified Data.Map.Strict as Map
Expand All @@ -34,6 +36,10 @@ encode :: Encoder a -> a -> LBS.ByteString
encode (Encoder _name toEncoding) =
AesonEncoding.encodingToLazyByteString . toEncoding

encodeStrict :: Encoder a -> a -> BS.ByteString
encodeStrict (Encoder _name toEncoding) =
LBS.toStrict . AesonEncoding.encodingToLazyByteString . toEncoding

instance FC.Fleece Encoder where
newtype Object Encoder object _constructor
= Object (object -> Aeson.Series)
Expand Down

0 comments on commit 9ff6be9

Please sign in to comment.