Skip to content

Commit 8c04d40

Browse files
Encode with SMILE
Documented at https://github.com/FasterXML/smile-format-specification Co-authored-by: Eric Demko <edemko@layer3com.com>
1 parent 418d802 commit 8c04d40

68 files changed

Lines changed: 534 additions & 76 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bench/Main.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@ import qualified Data.Bytes.Builder as BLDR
1212
import qualified Data.Bytes.Chunks as Chunks
1313
import qualified Data.ByteString.Lazy as LBS
1414
import qualified Json as J
15+
import qualified Json.Smile as Smile
1516
import qualified Data.Aeson as Aeson
1617

1718
main :: IO ()
1819
main = do
1920
valueTwitter100 <- case J.decode (Bytes.fromByteArray encodedTwitter100) of
2021
Left _ -> fail "json-syntax failed to decode twitter-100"
2122
Right v -> pure v
23+
valueUrl100 <- case J.decode (Bytes.fromByteArray encodedUrl100) of
24+
Left _ -> fail "json-syntax failed to decode url-100"
25+
Right v -> pure v
2226
aesonValueTwitter100 <- case Aeson.decodeStrict' byteStringTwitter100 of
2327
Nothing -> fail "aeson failed to decode twitter-100"
2428
Just (v :: Aeson.Value) -> pure v
@@ -32,13 +36,22 @@ main = do
3236
, bench "encode" $ whnf
3337
(\v -> Chunks.length (BLDR.run 128 (J.encode v)))
3438
valueTwitter100
39+
, bench "encode-smile-simple" $ whnf
40+
(\v -> Chunks.length (BLDR.run 128 (Smile.encode v)))
41+
valueTwitter100
3542
]
3643
]
3744
, bgroup "url"
3845
[ bgroup "100"
3946
[ bench "decode" $ whnf
4047
(\b -> J.decode (Bytes.fromByteArray b))
4148
encodedUrl100
49+
, bench "encode" $ whnf
50+
(\v -> Chunks.length (BLDR.run 128 (J.encode v)))
51+
valueUrl100
52+
, bench "encode-smile-simple" $ whnf
53+
(\v -> Chunks.length (BLDR.run 128 (Smile.encode v)))
54+
valueUrl100
4255
]
4356
]
4457
]

cabal.project

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
packages: .
2+
3+
source-repository-package
4+
type: git
5+
location: https://github.com/byteverse/bytesmith
6+
tag: ac29b91728cea68b5107e69133fd78f0d68f76e0
7+
8+
source-repository-package
9+
type: git
10+
location: https://github.com/byteverse/bytebuild
11+
tag: 4f03a98100237863bb4a9ac75d4de6723a8e0961

common/Twitter100.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ byteStringTwitter100 :: ByteString
2525
byteStringTwitter100 = encodeUtf8
2626
[text|
2727
{
28-
"completed_in": 1.195569,
28+
"completed_in": 1.000000,
2929
"max_id": 30121530767708160,
3030
"max_id_str": "30121530767708160",
3131
"next_page": "?page=2&max_id=30121530767708160&rpp=100&q=haskell",

json-syntax.cabal

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,25 @@ build-type: Simple
2626
extra-source-files: CHANGELOG.md
2727

2828
library
29-
exposed-modules: Json
29+
exposed-modules:
30+
Json
31+
Json.Smile
3032
build-depends:
3133
, array-builder >=0.1 && <0.2
3234
, array-chunks >=0.1.3 && <0.2
3335
, base >=4.12 && <5
34-
, bytebuild >=0.3.8 && <0.4
36+
, bytebuild >=0.3.9 && <0.4
3537
, byteslice >=0.1.3 && <0.3
3638
, bytesmith >=0.3.2 && <0.4
3739
, bytestring >=0.10.8 && <0.11
40+
, integer-gmp >=1.0 && <1.1
41+
, natural-arithmetic >=0.1.2 && <0.2
42+
, contiguous >=0.6 && <0.7
3843
, primitive >=0.7 && <0.8
3944
, run-st >=0.1.1 && <0.2
4045
, scientific-notation >=0.1.2 && <0.2
4146
, text-short >=0.1.3 && <0.2
47+
, zigzag >=0.0.1
4248
hs-source-dirs: src
4349
default-language: Haskell2010
4450
ghc-options: -Wall -O2
@@ -53,7 +59,7 @@ test-suite test
5359
ghc-options: -Wall -O2
5460
build-depends:
5561
, QuickCheck >=2.14.2
56-
, aeson
62+
, aeson <2.0
5763
, array-chunks
5864
, base >=4.12.0.0 && <5
5965
, bytebuild
@@ -66,6 +72,7 @@ test-suite test
6672
, scientific-notation >=0.1.1
6773
, tasty >=1.2.3 && <1.3
6874
, tasty-hunit >=0.10.0.2 && <0.11
75+
, tasty-golden >=2.0 && <2.4
6976
, tasty-quickcheck >=0.10.1.2 && <0.11
7077
, text >=1.2
7178
, text-short

0 commit comments

Comments
 (0)