Skip to content

Commit

Permalink
Prepare for 0.2.7.1 release.
Browse files Browse the repository at this point in the history
* Added workflows.
* Reformatted code.
* Updated cabal file.
  • Loading branch information
brianjosephmckeon authored Jan 30, 2024
1 parent 135c070 commit 6cad358
Show file tree
Hide file tree
Showing 18 changed files with 951 additions and 642 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: build
on:
pull_request:
branches:
- "*"

jobs:
call-workflow:
uses: byteverse/.github/.github/workflows/build.yaml@main
secrets: inherit
with:
release: false
12 changes: 12 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: release
on:
push:
tags:
- "*"

jobs:
call-workflow:
uses: byteverse/.github/.github/workflows/build.yaml@main
secrets: inherit
with:
release: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode/
dist
dist-*
cabal-dev
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Revision history for json-syntax

## 0.2.7.1 -- 2024-01-29

* Update package metadata.

## 0.2.7.0 -- 2023-10-05

* Add `decodeNewlineDelimited`.
Expand All @@ -19,7 +23,7 @@
* Add `ToValue` instances for `Word`, `Text`, `Value`,
`Scientific`, list (i.e. `[]`), the unit type (i.e. `()`),
* Add `text` and `shortText` for value construction.


## 0.2.4.0 -- 2023-06-27

Expand Down
1 change: 1 addition & 0 deletions Setup.hs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import Distribution.Simple

main = defaultMain
137 changes: 79 additions & 58 deletions bench/Main.hs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}

import Gauge.Main (defaultMain,bgroup,bench,whnf)
import Gauge.Main (bench, bgroup, defaultMain, whnf)

import Metrics1024 (encodedMetrics1024)
import Twitter100 (encodedTwitter100,byteStringTwitter100)
import Url100 (encodedUrl100,byteStringUrl100)
import Twitter100 (byteStringTwitter100, encodedTwitter100)
import Url100 (byteStringUrl100, encodedUrl100)

import qualified Data.Aeson as Aeson
import qualified Data.ByteString.Lazy as LBS
import qualified Data.Bytes as Bytes
import qualified Data.Bytes.Builder as BLDR
import qualified Data.Bytes.Chunks as Chunks
import qualified Data.ByteString.Lazy as LBS
import qualified Json as J
import qualified Json.Smile as Smile
import qualified Data.Aeson as Aeson

main :: IO ()
main = do
Expand All @@ -31,58 +30,80 @@ main = do
Nothing -> fail "aeson failed to decode twitter-100"
Just (v :: Aeson.Value) -> pure v
defaultMain
[ bgroup "json"
[ bgroup "twitter"
[ bgroup "100"
[ bench "decode" $ whnf
(\b -> J.decode (Bytes.fromByteArray b))
encodedTwitter100
, bench "encode" $ whnf
(\v -> Chunks.length (BLDR.run 128 (J.encode v)))
valueTwitter100
, bench "encode-smile" $ whnf
(\v -> Chunks.length (BLDR.run 128 (Smile.encode v)))
valueTwitter100
]
]
, bgroup "url"
[ bgroup "100"
[ bench "decode" $ whnf
(\b -> J.decode (Bytes.fromByteArray b))
encodedUrl100
, bench "encode" $ whnf
(\v -> Chunks.length (BLDR.run 128 (J.encode v)))
valueUrl100
, bench "encode-smile" $ whnf
(\v -> Chunks.length (BLDR.run 128 (Smile.encode v)))
valueUrl100
]
]
, bgroup "metrics"
[ bgroup "1024"
[ bench "encode" $ whnf
(\v -> Chunks.length (BLDR.run 128 (J.encode v)))
valueMetrics1024
, bench "encode-smile" $ whnf
(\v -> Chunks.length (BLDR.run 128 (Smile.encode v)))
valueMetrics1024
]
]
]
, bgroup "aeson"
[ bgroup "twitter"
[ bgroup "100"
[ bench "decode"
(whnf (Aeson.decodeStrict' @Aeson.Value) byteStringTwitter100)
, bench "encode" $ whnf
(\v -> LBS.length (Aeson.encode v))
aesonValueTwitter100
]
[ bgroup
"json"
[ bgroup
"twitter"
[ bgroup
"100"
[ bench "decode" $
whnf
(\b -> J.decode (Bytes.fromByteArray b))
encodedTwitter100
, bench "encode" $
whnf
(\v -> Chunks.length (BLDR.run 128 (J.encode v)))
valueTwitter100
, bench "encode-smile" $
whnf
(\v -> Chunks.length (BLDR.run 128 (Smile.encode v)))
valueTwitter100
]
]
, bgroup
"url"
[ bgroup
"100"
[ bench "decode" $
whnf
(\b -> J.decode (Bytes.fromByteArray b))
encodedUrl100
, bench "encode" $
whnf
(\v -> Chunks.length (BLDR.run 128 (J.encode v)))
valueUrl100
, bench "encode-smile" $
whnf
(\v -> Chunks.length (BLDR.run 128 (Smile.encode v)))
valueUrl100
]
]
, bgroup
"metrics"
[ bgroup
"1024"
[ bench "encode" $
whnf
(\v -> Chunks.length (BLDR.run 128 (J.encode v)))
valueMetrics1024
, bench "encode-smile" $
whnf
(\v -> Chunks.length (BLDR.run 128 (Smile.encode v)))
valueMetrics1024
]
]
]
, bgroup "url"
[ bgroup "100"
[ bench "decode" (whnf (Aeson.decodeStrict' @Aeson.Value) byteStringUrl100)
]
, bgroup
"aeson"
[ bgroup
"twitter"
[ bgroup
"100"
[ bench
"decode"
(whnf (Aeson.decodeStrict' @Aeson.Value) byteStringTwitter100)
, bench "encode" $
whnf
(\v -> LBS.length (Aeson.encode v))
aesonValueTwitter100
]
]
, bgroup
"url"
[ bgroup
"100"
[ bench "decode" (whnf (Aeson.decodeStrict' @Aeson.Value) byteStringUrl100)
]
]
]
]
]
12 changes: 7 additions & 5 deletions common/Metrics1024.hs
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}

module Metrics1024
( encodedMetrics1024
, byteStringMetrics1024
) where

import Data.ByteString (ByteString)
import Data.ByteString.Short (ShortByteString,toShort)
import Data.ByteString.Short (ShortByteString, toShort)
import Data.Primitive (ByteArray)
import Data.Text.Encoding (encodeUtf8)
import NeatInterpolation (text)

import qualified Data.Primitive as PM
import qualified Data.ByteString.Short.Internal as BSS
import qualified Data.Primitive as PM

shortByteStringToByteArray :: ShortByteString -> ByteArray
shortByteStringToByteArray :: ShortByteString -> ByteArray
shortByteStringToByteArray (BSS.SBS x) = PM.ByteArray x

encodedMetrics1024 :: ByteArray
encodedMetrics1024 =
shortByteStringToByteArray (toShort byteStringMetrics1024)

byteStringMetrics1024 :: ByteString
byteStringMetrics1024 = encodeUtf8
[text|
byteStringMetrics1024 =
encodeUtf8
[text|
[ {"@id":"1E7nJ7Ki1ei1mSOuy","@service":"npm","@historical":false,"@timestamp":"2022-02-01T15:10:00Z","@row":"1","organization.acronym":"nyc","agent.type":"freight","host.address":"192.0.2.43","host.ip":"192.0.2.43","host.model":"unknown","host.model_oid":"1.3.6.1.4.1.14988.1","host.vendor":"mikrotik","component.cpu.utilization":0,"component.name":"","host.hostname":"NYC-S75-APT4215"}
, {"@id":"1E7nJ7SponsUYpH9l","@service":"npm","@historical":false,"@timestamp":"2022-02-01T15:10:00Z","@row":"2","organization.acronym":"nyc","agent.type":"freight","host.address":"192.0.2.43","host.ip":"192.0.2.43","host.model":"unknown","host.model_oid":"1.3.6.1.4.1.14988.1","host.vendor":"mikrotik","component.cpu.utilization":0,"component.name":"","host.hostname":"NYC-S75-APT4215"}
, {"@id":"1E7nJ7VyTvxK5KDVi","@service":"npm","@historical":false,"@timestamp":"2022-02-01T15:10:00Z","@row":"3","organization.acronym":"nyc","agent.type":"freight","host.address":"192.0.2.43","host.ip":"192.0.2.43","host.model":"unknown","host.model_oid":"1.3.6.1.4.1.14988.1","host.vendor":"mikrotik","component.cpu.utilization":0,"component.name":"","host.hostname":"NYC-S75-APT4215"}
Expand Down
18 changes: 10 additions & 8 deletions common/Person.hs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}

module Person
( encodedPerson
, encodedFlattenedPerson
) where

import Data.ByteString (ByteString)
import Data.ByteString.Short (ShortByteString,toShort)
import Data.ByteString.Short (ShortByteString, toShort)
import Data.Primitive (ByteArray)
import Data.Text.Encoding (encodeUtf8)
import NeatInterpolation (text)

import qualified Data.Primitive as PM
import qualified Data.ByteString.Short.Internal as BSS
import qualified Data.Primitive as PM

shortByteStringToByteArray :: ShortByteString -> ByteArray
shortByteStringToByteArray :: ShortByteString -> ByteArray
shortByteStringToByteArray (BSS.SBS x) = PM.ByteArray x

encodedPerson :: ByteArray
Expand All @@ -26,8 +27,9 @@ encodedFlattenedPerson =
shortByteStringToByteArray (toShort byteStringFlattenedPerson)

byteStringPerson :: ByteString
byteStringPerson = encodeUtf8
[text|
byteStringPerson =
encodeUtf8
[text|
{ "name": "bilbo"
, "occupation":
{ "name": "burglar"
Expand All @@ -39,13 +41,13 @@ byteStringPerson = encodeUtf8
|]

byteStringFlattenedPerson :: ByteString
byteStringFlattenedPerson = encodeUtf8
[text|
byteStringFlattenedPerson =
encodeUtf8
[text|
{ "name": "bilbo"
, "occupation.name": "burglar"
, "occupation.start": "2022-05-30"
, "height": 124
, "favorites": ["adventures","lunch"]
}
|]

13 changes: 7 additions & 6 deletions common/Twitter100.hs
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}

module Twitter100
( encodedTwitter100
, byteStringTwitter100
) where

import Data.ByteString (ByteString)
import Data.ByteString.Short (ShortByteString,toShort)
import Data.ByteString.Short (ShortByteString, toShort)
import Data.Primitive (ByteArray)
import Data.Text.Encoding (encodeUtf8)
import NeatInterpolation (text)

import qualified Data.Primitive as PM
import qualified Data.ByteString.Short.Internal as BSS
import qualified Data.Primitive as PM

shortByteStringToByteArray :: ShortByteString -> ByteArray
shortByteStringToByteArray :: ShortByteString -> ByteArray
shortByteStringToByteArray (BSS.SBS x) = PM.ByteArray x

encodedTwitter100 :: ByteArray
encodedTwitter100 =
shortByteStringToByteArray (toShort byteStringTwitter100)

byteStringTwitter100 :: ByteString
byteStringTwitter100 = encodeUtf8
[text|
byteStringTwitter100 =
encodeUtf8
[text|
{
"completed_in": 1.000000,
"max_id": 30121530767708160,
Expand Down Expand Up @@ -1864,4 +1866,3 @@ byteStringTwitter100 = encodeUtf8
"since_id_str": "0"
}
|]

14 changes: 7 additions & 7 deletions common/Url100.hs
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}

module Url100
( encodedUrl100
, byteStringUrl100
) where

import Data.ByteString (ByteString)
import Data.ByteString.Short (ShortByteString,toShort)
import Data.ByteString.Short (ShortByteString, toShort)
import Data.Primitive (ByteArray)
import Data.Text.Encoding (encodeUtf8)
import NeatInterpolation (text)

import qualified Data.Primitive as PM
import qualified Data.ByteString.Short.Internal as BSS
import qualified Data.Primitive as PM

shortByteStringToByteArray :: ShortByteString -> ByteArray
shortByteStringToByteArray :: ShortByteString -> ByteArray
shortByteStringToByteArray (BSS.SBS x) = PM.ByteArray x

encodedUrl100 :: ByteArray
encodedUrl100 =
shortByteStringToByteArray (toShort byteStringUrl100)

byteStringUrl100 :: ByteString
byteStringUrl100 = encodeUtf8
[text|
byteStringUrl100 =
encodeUtf8
[text|
[ "https://balance.example.com/aunt.htm"
, "http://anger.example.com/"
, "https://www.example.edu/basket/branch#boat"
Expand Down Expand Up @@ -126,5 +128,3 @@ byteStringUrl100 = encodeUtf8
, "http://attack.example.org/"
]
|]


Loading

0 comments on commit 6cad358

Please sign in to comment.