-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from haskell-works/use-avro-0.5
Use avro 0.5
- Loading branch information
Showing
10 changed files
with
143 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
packages: . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,26 @@ | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE QuasiQuotes #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
module Message | ||
( TestMessage(..) | ||
, schema'TestMessage | ||
) where | ||
-- | ||
|
||
import Data.Avro | ||
import Data.Avro.Schema | ||
import qualified Data.Avro.Types as AT | ||
import Data.Int | ||
import Data.Text | ||
import Data.Avro | ||
import Data.Avro.Deriving | ||
|
||
data TestMessage = TestMessage Int64 Text Bool Int64 deriving (Show, Eq, Ord) | ||
deriveAvroFromByteString [r| | ||
{ | ||
"type": "record", | ||
"name": "TestMessage", | ||
"namespace": "hw.kafka.avro.test", | ||
"fields": [ | ||
{ "name": "id", "type": "long" }, | ||
{ "name": "name", "type": "string" }, | ||
{ "name": "is_active", "type": "boolean" }, | ||
{ "name": "timestamp", "type": "long" } | ||
] | ||
} | ||
|] | ||
|
||
testMessageSchema = | ||
let fld nm = Field nm [] Nothing Nothing | ||
in Record (TN "TestMessage" ["hw", "kafka", "avro", "test"]) [] Nothing Nothing | ||
[ fld "id" Long Nothing | ||
, fld "name" String Nothing | ||
, fld "is_active" Boolean Nothing | ||
, fld "timestamp" Long Nothing | ||
] | ||
|
||
instance HasAvroSchema TestMessage where | ||
schema = pure testMessageSchema | ||
|
||
instance FromAvro TestMessage where | ||
fromAvro (AT.Record _ r) = | ||
TestMessage <$> r .: "id" | ||
<*> r .: "name" | ||
<*> r .: "is_active" | ||
<*> r .: "timestamp" | ||
fromAvro v = badValue v "TestMessage" | ||
|
||
instance ToAvro TestMessage where | ||
toAvro (TestMessage i s d t) = | ||
record testMessageSchema | ||
[ "id" .= i | ||
, "name" .= s | ||
, "is_active" .= d | ||
, "timestamp" .= t | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.