module Data.RTCM3.Aeson where
import BasicPrelude
import Data.Aeson
import Data.ByteString.Base64 as Base64
import Data.Text.Encoding
import Data.Text.Encoding.Error
import Data.Word.Word24
instance ToJSON ByteString where
toJSON = toJSON . decodeUtf8With ignore . Base64.encode
instance FromJSON ByteString where
parseJSON = withText "ByteString" (pure . Base64.decodeLenient . encodeUtf8)
instance ToJSON Word24 where
toJSON = Number . fromIntegral
instance FromJSON Word24 where
parseJSON = withScientific "Word24" (pure . truncate)