-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Avro serialization support for Haskell
--
-- Avro serialization and deserialization support for Haskell
@package avro
@version 0.3.4.2
module Data.Avro.Decode.Lazy.LazyValue
data LazyValue f
Null :: LazyValue f
Boolean :: Bool -> LazyValue f
Int :: Int32 -> LazyValue f
Long :: Int64 -> LazyValue f
Float :: Float -> LazyValue f
Double :: Double -> LazyValue f
Bytes :: ByteString -> LazyValue f
String :: Text -> LazyValue f
-- | Dynamically enforced monomorphic type.
Array :: (Vector (LazyValue f)) -> LazyValue f
-- | Dynamically enforced monomorphic type
Map :: (HashMap Text (LazyValue f)) -> LazyValue f
Record :: f -> (HashMap Text (LazyValue f)) -> LazyValue f
-- | Set of union options, schema for selected option, and the actual
-- value.
Union :: (NonEmpty f) -> f -> (LazyValue f) -> LazyValue f
Fixed :: f -> ByteString -> LazyValue f
-- | An enum is a set of the possible symbols (the schema) and the selected
-- symbol
Enum :: f -> Int -> Text -> LazyValue f
Error :: !String -> LazyValue f
instance GHC.Show.Show f => GHC.Show.Show (Data.Avro.Decode.Lazy.LazyValue.LazyValue f)
instance GHC.Classes.Eq f => GHC.Classes.Eq (Data.Avro.Decode.Lazy.LazyValue.LazyValue f)
module Data.Avro.Types.Value
data Value f
Null :: Value f
Boolean :: !Bool -> Value f
Int :: {-# UNPACK #-} !Int32 -> Value f
Long :: {-# UNPACK #-} !Int64 -> Value f
Float :: {-# UNPACK #-} !Float -> Value f
Double :: {-# UNPACK #-} !Double -> Value f
Bytes :: {-# UNPACK #-} !ByteString -> Value f
String :: {-# UNPACK #-} !Text -> Value f
-- | Dynamically enforced monomorphic type.
Array :: (Vector (Value f)) -> Value f
-- | Dynamically enforced monomorphic type
Map :: (HashMap Text (Value f)) -> Value f
Record :: f -> (HashMap Text (Value f)) -> Value f
-- | Set of union options, schema for selected option, and the actual
-- value.
Union :: (NonEmpty f) -> f -> (Value f) -> Value f
Fixed :: f -> {-# UNPACK #-} !ByteString -> Value f
-- | An enum is a set of the possible symbols (the schema) and the selected
-- symbol
Enum :: f -> {-# UNPACK #-} !Int -> Text -> Value f
instance GHC.Show.Show f => GHC.Show.Show (Data.Avro.Types.Value.Value f)
instance GHC.Classes.Eq f => GHC.Classes.Eq (Data.Avro.Types.Value.Value f)
module Data.Avro.Types
-- | Avro Schemas, represented here as values of type Schema,
-- describe the serialization and de-serialization of values.
--
-- In Avro schemas are compose-able such that encoding data under a
-- schema and decoding with a variant, such as newer or older version of
-- the original schema, can be accomplished by using the
-- Deconflict module.
module Data.Avro.Schema
-- | An Avro schema is either * A "JSON object in the form
-- `{"type":"typeName" ...` * A "JSON string, naming a defined type"
-- (basic type wo free variablesnames) * A "JSON array,
-- representing a union"
--
-- N.B. It is possible to create a Haskell value (of Schema type) that is
-- not a valid Avro schema by violating one of the above or one of the
-- conditions called out in validateSchema.
type Schema = Type
-- | Avro types are considered either primitive (string, int, etc) or
-- complex/declared (structures, unions etc).
data Type
Null :: Type
Boolean :: Type
Int :: Type
Long :: Type
Float :: Type
Double :: Type
Bytes :: Type
String :: Type
Array :: Type -> Type
[item] :: Type -> Type
Map :: Type -> Type
[values] :: Type -> Type
NamedType :: TypeName -> Type
Record :: TypeName -> Maybe Text -> [TypeName] -> Maybe Text -> Maybe Order -> [Field] -> Type
[name] :: Type -> TypeName
[namespace] :: Type -> Maybe Text
[aliases] :: Type -> [TypeName]
[doc] :: Type -> Maybe Text
[order] :: Type -> Maybe Order
[fields] :: Type -> [Field]
Enum :: TypeName -> Maybe Text -> [TypeName] -> Maybe Text -> [Text] -> Int64 -> Maybe Text -> Type
[name] :: Type -> TypeName
[namespace] :: Type -> Maybe Text
[aliases] :: Type -> [TypeName]
[doc] :: Type -> Maybe Text
[symbols] :: Type -> [Text]
[symbolLookup] :: Type -> Int64 -> Maybe Text
Union :: NonEmpty Type -> Int64 -> Maybe Type -> Type
[options] :: Type -> NonEmpty Type
[unionLookup] :: Type -> Int64 -> Maybe Type
Fixed :: TypeName -> Maybe Text -> [TypeName] -> Int -> Type
[name] :: Type -> TypeName
[namespace] :: Type -> Maybe Text
[aliases] :: Type -> [TypeName]
[size] :: Type -> Int
data Field
Field :: Text -> [Text] -> Maybe Text -> Maybe Order -> Type -> Maybe (Value Type) -> Field
[fldName] :: Field -> Text
[fldAliases] :: Field -> [Text]
[fldDoc] :: Field -> Maybe Text
[fldOrder] :: Field -> Maybe Order
[fldType] :: Field -> Type
[fldDefault] :: Field -> Maybe (Value Type)
data Order
Ascending :: Order
Descending :: Order
Ignore :: Order
newtype TypeName
TN :: Text -> TypeName
[unTN] :: TypeName -> Text
-- | mkEnum name aliases namespace docs syms Constructs an
-- Enum schema using the enumeration type's name, aliases (if
-- any), namespace, documentation, and list of symbols that inhabit the
-- enumeration.
mkEnum :: TypeName -> [TypeName] -> Maybe Text -> Maybe Text -> [Text] -> Type
-- | mkUnion subTypes Defines a union of the provided subTypes.
-- N.B. it is invalid Avro to include another union or to have more than
-- one of the same type as a direct member of the union. No check is done
-- for this condition!
mkUnion :: NonEmpty Type -> Type
-- | Placeholder NO-OP function!
--
-- Validates a schema to ensure:
--
--
-- - All types are defined
-- - Unions do not directly contain other unions
-- - Unions are not ambiguous (may not contain more than one schema
-- with the same type except for named types of record, fixed and
-- enum)
-- - Default values for unions can be cast as the type indicated by the
-- first structure.
-- - Default values can be cast/de-serialize correctly.
-- - Named types are resolvable
--
validateSchema :: Schema -> Parser ()
-- | Get the name of the type. In the case of unions, get the name of the
-- first value in the union schema.
typeName :: Type -> Text
-- | buildTypeEnvironment schema builds a function mapping type
-- names to the types declared in the traversed schema. Notice this
-- function does not currently handle namespaces in a correct manner,
-- possibly allowing for bad environment lookups when used on complex
-- schemas.
buildTypeEnvironment :: Applicative m => (TypeName -> m Type) -> Type -> TypeName -> m Type
data Result a
Success :: a -> Result a
Error :: String -> Result a
resultToEither :: Result b -> Either String b
-- | Checks that two schemas match. This is like equality of schemas,
-- except NamedTypes match against other types with the same
-- name.
--
-- This extends recursively: two records match if they have the same
-- name, the same number of fields and the fields all match.
matches :: Type -> Type -> Bool
-- | Parses a string literal into a bytestring in the format expected for
-- bytes and fixed values. Will fail if every character does not have a
-- codepoint between 0 and 255.
parseBytes :: Text -> Result ByteString
-- | Turn a ByteString into a Text that matches the format
-- Avro expects from bytes and fixed literals in JSON. Each byte is
-- mapped to a single Unicode codepoint between 0 and 255.
serializeBytes :: ByteString -> Text
-- | Parse JSON-encoded avro data.
parseAvroJSON :: (Type -> Value -> Result (Value Type)) -> (Text -> Maybe Type) -> Type -> Value -> Result (Value Type)
instance GHC.Show.Show a => GHC.Show.Show (Data.Avro.Schema.Result a)
instance GHC.Classes.Ord a => GHC.Classes.Ord (Data.Avro.Schema.Result a)
instance GHC.Classes.Eq a => GHC.Classes.Eq (Data.Avro.Schema.Result a)
instance GHC.Show.Show Data.Avro.Schema.Field
instance GHC.Classes.Eq Data.Avro.Schema.Field
instance GHC.Show.Show Data.Avro.Schema.Type
instance GHC.Show.Show Data.Avro.Schema.Order
instance GHC.Classes.Ord Data.Avro.Schema.Order
instance GHC.Classes.Eq Data.Avro.Schema.Order
instance GHC.Classes.Ord Data.Avro.Schema.TypeName
instance GHC.Classes.Eq Data.Avro.Schema.TypeName
instance Data.Aeson.Types.FromJSON.FromJSON Data.Avro.Schema.Field
instance GHC.Base.Monad Data.Avro.Schema.Result
instance GHC.Base.Functor Data.Avro.Schema.Result
instance Control.Monad.Fail.MonadFail Data.Avro.Schema.Result
instance Control.Monad.Error.Class.MonadError GHC.Base.String Data.Avro.Schema.Result
instance GHC.Base.Applicative Data.Avro.Schema.Result
instance GHC.Base.Alternative Data.Avro.Schema.Result
instance GHC.Base.MonadPlus Data.Avro.Schema.Result
instance GHC.Base.Semigroup (Data.Avro.Schema.Result a)
instance GHC.Base.Monoid (Data.Avro.Schema.Result a)
instance Data.Foldable.Foldable Data.Avro.Schema.Result
instance Data.Traversable.Traversable Data.Avro.Schema.Result
instance GHC.Classes.Eq Data.Avro.Schema.Type
instance Data.Aeson.Types.FromJSON.FromJSON Data.Avro.Schema.Type
instance Data.Aeson.Types.ToJSON.ToJSON Data.Avro.Schema.Type
instance Data.Aeson.Types.ToJSON.ToJSON Data.Avro.Schema.Field
instance Data.Aeson.Types.ToJSON.ToJSON (Data.Avro.Types.Value.Value Data.Avro.Schema.Type)
instance Data.Aeson.Types.ToJSON.ToJSON Data.Avro.Schema.Order
instance Data.Aeson.Types.FromJSON.FromJSON Data.Avro.Schema.Order
instance GHC.Show.Show Data.Avro.Schema.TypeName
instance GHC.Base.Semigroup Data.Avro.Schema.TypeName
instance GHC.Base.Monoid Data.Avro.Schema.TypeName
instance Data.String.IsString Data.Avro.Schema.TypeName
instance Data.Hashable.Class.Hashable Data.Avro.Schema.TypeName
instance Data.Aeson.Types.ToJSON.ToJSON Data.Avro.Schema.TypeName
instance Data.Aeson.Types.FromJSON.FromJSON Data.Avro.Schema.TypeName
module Data.Avro.Deriving.NormSchema
-- | Extracts all the records from the schema (flattens the schema) Named
-- types get resolved when needed to include at least one "inlined"
-- schema in each record and to make each record self-contained. Note:
-- Namespaces are not really supported in this version. All the
-- namespaces (including inlined into full names) will be ignored during
-- names resolution.
extractDerivables :: Schema -> [Schema]
getTypes :: Type -> [(TypeName, Type)]
normSchema :: Schema -> State (Map TypeName Schema) Schema
module Data.Avro.HasAvroSchema
class HasAvroSchema a
schema :: HasAvroSchema a => Tagged a Type
schemaOf :: (HasAvroSchema a) => a -> Type
wrapTag :: (Type -> Type) -> Tagged a Type -> Tagged b Type
instance Data.Avro.HasAvroSchema.HasAvroSchema GHC.Word.Word8
instance Data.Avro.HasAvroSchema.HasAvroSchema GHC.Word.Word16
instance Data.Avro.HasAvroSchema.HasAvroSchema GHC.Word.Word32
instance Data.Avro.HasAvroSchema.HasAvroSchema GHC.Word.Word64
instance Data.Avro.HasAvroSchema.HasAvroSchema GHC.Types.Bool
instance Data.Avro.HasAvroSchema.HasAvroSchema ()
instance Data.Avro.HasAvroSchema.HasAvroSchema GHC.Types.Int
instance Data.Avro.HasAvroSchema.HasAvroSchema GHC.Int.Int8
instance Data.Avro.HasAvroSchema.HasAvroSchema GHC.Int.Int16
instance Data.Avro.HasAvroSchema.HasAvroSchema GHC.Int.Int32
instance Data.Avro.HasAvroSchema.HasAvroSchema GHC.Int.Int64
instance Data.Avro.HasAvroSchema.HasAvroSchema GHC.Types.Double
instance Data.Avro.HasAvroSchema.HasAvroSchema GHC.Types.Float
instance Data.Avro.HasAvroSchema.HasAvroSchema Data.Text.Internal.Text
instance Data.Avro.HasAvroSchema.HasAvroSchema Data.Text.Internal.Lazy.Text
instance Data.Avro.HasAvroSchema.HasAvroSchema Data.ByteString.Internal.ByteString
instance Data.Avro.HasAvroSchema.HasAvroSchema Data.ByteString.Lazy.Internal.ByteString
instance (Data.Avro.HasAvroSchema.HasAvroSchema a, Data.Avro.HasAvroSchema.HasAvroSchema b) => Data.Avro.HasAvroSchema.HasAvroSchema (Data.Either.Either a b)
instance Data.Avro.HasAvroSchema.HasAvroSchema a => Data.Avro.HasAvroSchema.HasAvroSchema (Data.Map.Internal.Map Data.Text.Internal.Text a)
instance Data.Avro.HasAvroSchema.HasAvroSchema a => Data.Avro.HasAvroSchema.HasAvroSchema (Data.HashMap.Base.HashMap Data.Text.Internal.Text a)
instance Data.Avro.HasAvroSchema.HasAvroSchema a => Data.Avro.HasAvroSchema.HasAvroSchema (Data.Map.Internal.Map Data.Text.Internal.Lazy.Text a)
instance Data.Avro.HasAvroSchema.HasAvroSchema a => Data.Avro.HasAvroSchema.HasAvroSchema (Data.HashMap.Base.HashMap Data.Text.Internal.Lazy.Text a)
instance Data.Avro.HasAvroSchema.HasAvroSchema a => Data.Avro.HasAvroSchema.HasAvroSchema (Data.Map.Internal.Map GHC.Base.String a)
instance Data.Avro.HasAvroSchema.HasAvroSchema a => Data.Avro.HasAvroSchema.HasAvroSchema (Data.HashMap.Base.HashMap GHC.Base.String a)
instance Data.Avro.HasAvroSchema.HasAvroSchema a => Data.Avro.HasAvroSchema.HasAvroSchema (GHC.Base.Maybe a)
instance Data.Avro.HasAvroSchema.HasAvroSchema a => Data.Avro.HasAvroSchema.HasAvroSchema [a]
instance (Data.Avro.HasAvroSchema.HasAvroSchema a, GHC.Arr.Ix i) => Data.Avro.HasAvroSchema.HasAvroSchema (GHC.Arr.Array i a)
instance Data.Avro.HasAvroSchema.HasAvroSchema a => Data.Avro.HasAvroSchema.HasAvroSchema (Data.Vector.Vector a)
instance Data.Avro.HasAvroSchema.HasAvroSchema a => Data.Avro.HasAvroSchema.HasAvroSchema (Data.Vector.Unboxed.Base.Vector a)
instance Data.Avro.HasAvroSchema.HasAvroSchema a => Data.Avro.HasAvroSchema.HasAvroSchema (Data.Set.Internal.Set a)
module Data.Avro.ToAvro
class HasAvroSchema a => ToAvro a
toAvro :: ToAvro a => a -> Value Type
(.=) :: ToAvro a => Text -> a -> (Text, Value Type)
instance Data.Avro.ToAvro.ToAvro GHC.Types.Bool
instance Data.Avro.ToAvro.ToAvro ()
instance Data.Avro.ToAvro.ToAvro GHC.Types.Int
instance Data.Avro.ToAvro.ToAvro GHC.Int.Int32
instance Data.Avro.ToAvro.ToAvro GHC.Int.Int64
instance Data.Avro.ToAvro.ToAvro GHC.Types.Double
instance Data.Avro.ToAvro.ToAvro GHC.Types.Float
instance Data.Avro.ToAvro.ToAvro Data.Text.Internal.Text
instance Data.Avro.ToAvro.ToAvro Data.Text.Internal.Lazy.Text
instance Data.Avro.ToAvro.ToAvro Data.ByteString.Internal.ByteString
instance Data.Avro.ToAvro.ToAvro Data.ByteString.Lazy.Internal.ByteString
instance (Data.Avro.ToAvro.ToAvro a, Data.Avro.ToAvro.ToAvro b) => Data.Avro.ToAvro.ToAvro (Data.Either.Either a b)
instance Data.Avro.ToAvro.ToAvro a => Data.Avro.ToAvro.ToAvro (Data.Map.Internal.Map Data.Text.Internal.Text a)
instance Data.Avro.ToAvro.ToAvro a => Data.Avro.ToAvro.ToAvro (Data.HashMap.Base.HashMap Data.Text.Internal.Text a)
instance Data.Avro.ToAvro.ToAvro a => Data.Avro.ToAvro.ToAvro (Data.Map.Internal.Map Data.Text.Internal.Lazy.Text a)
instance Data.Avro.ToAvro.ToAvro a => Data.Avro.ToAvro.ToAvro (Data.HashMap.Base.HashMap Data.Text.Internal.Lazy.Text a)
instance Data.Avro.ToAvro.ToAvro a => Data.Avro.ToAvro.ToAvro (Data.Map.Internal.Map GHC.Base.String a)
instance Data.Avro.ToAvro.ToAvro a => Data.Avro.ToAvro.ToAvro (Data.HashMap.Base.HashMap GHC.Base.String a)
instance Data.Avro.ToAvro.ToAvro a => Data.Avro.ToAvro.ToAvro (GHC.Base.Maybe a)
instance Data.Avro.ToAvro.ToAvro a => Data.Avro.ToAvro.ToAvro [a]
module Data.Avro.Deconflict
-- | deconflict writer reader val will convert a value that was
-- encoded/decoded with the writer's schema into the form specified by
-- the reader's schema.
deconflict :: Schema -> Schema -> Value Type -> Either String (Value Type)
module Data.Avro.Decode.Lazy.Convert
toStrictValue :: LazyValue f -> Either String (Value f)
fromStrictValue :: Value f -> LazyValue f
module Data.Avro.Decode.Lazy.Deconflict
-- | deconflict writer reader val will convert a value that was
-- encoded/decoded with the writer's schema into the form specified by
-- the reader's schema.
deconflict :: Schema -> Schema -> LazyValue Type -> LazyValue Type
module Data.Avro.Zag
class Zag a where {
type family Zagged a;
}
zag :: Zag a => a -> Zagged a
instance Data.Avro.Zag.Zag GHC.Word.Word8
instance Data.Avro.Zag.Zag GHC.Word.Word16
instance Data.Avro.Zag.Zag GHC.Word.Word32
instance Data.Avro.Zag.Zag GHC.Word.Word64
instance Data.Avro.Zag.Zag GHC.Types.Word
module Data.Avro.DecodeRaw
class DecodeRaw a
decodeRaw :: DecodeRaw a => Get a
instance Data.Avro.DecodeRaw.DecodeRaw GHC.Types.Word
instance Data.Avro.DecodeRaw.DecodeRaw GHC.Word.Word8
instance Data.Avro.DecodeRaw.DecodeRaw GHC.Word.Word16
instance Data.Avro.DecodeRaw.DecodeRaw GHC.Word.Word32
instance Data.Avro.DecodeRaw.DecodeRaw GHC.Word.Word64
instance Data.Avro.DecodeRaw.DecodeRaw GHC.Types.Int
instance Data.Avro.DecodeRaw.DecodeRaw GHC.Int.Int8
instance Data.Avro.DecodeRaw.DecodeRaw GHC.Int.Int16
instance Data.Avro.DecodeRaw.DecodeRaw GHC.Int.Int32
instance Data.Avro.DecodeRaw.DecodeRaw GHC.Int.Int64
module Data.Avro.Decode.Get
class GetAvro a
getAvro :: GetAvro a => Get a
data ContainerHeader
ContainerHeader :: !ByteString -> ByteString -> Get ByteString -> !Schema -> ContainerHeader
[syncBytes] :: ContainerHeader -> !ByteString
[decompress] :: ContainerHeader -> ByteString -> Get ByteString
[containedSchema] :: ContainerHeader -> !Schema
nrSyncBytes :: Integral sb => sb
getCodec :: Monad m => Maybe ByteString -> m (ByteString -> m ByteString)
getBoolean :: Get Bool
-- | Get a 32-bit int (zigzag encoded, max of 5 bytes)
getInt :: Get Int32
-- | Get a 64 bit int (zigzag encoded, max of 10 bytes)
getLong :: Get Int64
-- | Get an zigzag encoded integral value consuming bytes till the msb is
-- 0.
getZigZag :: (Bits i, Integral i, DecodeRaw i) => Get i
getBytes :: Get ByteString
getString :: Get Text
getFloat :: Get Float
getDouble :: Get Double
getArray :: GetAvro ty => Get [ty]
getMap :: GetAvro ty => Get (Map Text ty)
sFromIntegral :: forall a b m. (Monad m, Bounded a, Bounded b, Integral a, Integral b) => a -> m b
instance Data.Avro.Decode.Get.GetAvro Data.Avro.Decode.Get.ContainerHeader
instance Data.Avro.Decode.Get.GetAvro ty => Data.Avro.Decode.Get.GetAvro (Data.Map.Internal.Map Data.Text.Internal.Text ty)
instance Data.Avro.Decode.Get.GetAvro GHC.Types.Bool
instance Data.Avro.Decode.Get.GetAvro GHC.Int.Int32
instance Data.Avro.Decode.Get.GetAvro GHC.Int.Int64
instance Data.Avro.Decode.Get.GetAvro Data.ByteString.Lazy.Internal.ByteString
instance Data.Avro.Decode.Get.GetAvro Data.ByteString.Internal.ByteString
instance Data.Avro.Decode.Get.GetAvro Data.Text.Internal.Text
instance Data.Avro.Decode.Get.GetAvro GHC.Types.Float
instance Data.Avro.Decode.Get.GetAvro GHC.Types.Double
instance Data.Avro.Decode.Get.GetAvro GHC.Base.String
instance Data.Avro.Decode.Get.GetAvro a => Data.Avro.Decode.Get.GetAvro [a]
instance Data.Avro.Decode.Get.GetAvro a => Data.Avro.Decode.Get.GetAvro (GHC.Base.Maybe a)
instance Data.Avro.Decode.Get.GetAvro a => Data.Avro.Decode.Get.GetAvro (GHC.Arr.Array GHC.Types.Int a)
instance Data.Avro.Decode.Get.GetAvro a => Data.Avro.Decode.Get.GetAvro (Data.Vector.Vector a)
instance (Data.Avro.Decode.Get.GetAvro a, GHC.Classes.Ord a) => Data.Avro.Decode.Get.GetAvro (Data.Set.Internal.Set a)
module Data.Avro.Decode
-- | Decode bytes into a Value as described by Schema.
decodeAvro :: Schema -> ByteString -> Either String (Value Type)
decodeContainer :: ByteString -> Either String (Schema, [[Value Type]])
decodeContainerWith :: (Schema -> Get a) -> ByteString -> Either String (Schema, [[a]])
getAvroOf :: Schema -> Get (Value Type)
class GetAvro a
getAvro :: GetAvro a => Get a
module Data.Avro.Zig
class Zig a where {
type family Zigged a;
}
zig :: Zig a => a -> Zigged a
instance Data.Avro.Zig.Zig GHC.Int.Int8
instance Data.Avro.Zig.Zig GHC.Int.Int16
instance Data.Avro.Zig.Zig GHC.Int.Int32
instance Data.Avro.Zig.Zig GHC.Int.Int64
instance Data.Avro.Zig.Zig GHC.Types.Int
module Data.Avro.EncodeRaw
class EncodeRaw a
encodeRaw :: EncodeRaw a => a -> Builder
instance Data.Avro.EncodeRaw.EncodeRaw GHC.Types.Word
instance Data.Avro.EncodeRaw.EncodeRaw GHC.Word.Word8
instance Data.Avro.EncodeRaw.EncodeRaw GHC.Word.Word16
instance Data.Avro.EncodeRaw.EncodeRaw GHC.Word.Word32
instance Data.Avro.EncodeRaw.EncodeRaw GHC.Word.Word64
instance Data.Avro.EncodeRaw.EncodeRaw GHC.Types.Int
instance Data.Avro.EncodeRaw.EncodeRaw GHC.Int.Int8
instance Data.Avro.EncodeRaw.EncodeRaw GHC.Int.Int16
instance Data.Avro.EncodeRaw.EncodeRaw GHC.Int.Int32
instance Data.Avro.EncodeRaw.EncodeRaw GHC.Int.Int64
module Data.Avro.Encode
getSchema :: forall a. EncodeAvro a => a -> Schema
encodeAvro :: EncodeAvro a => a -> ByteString
-- | Encode chunks of objects into a container, using 16 random bytes for
-- the synchronization markers.
encodeContainer :: EncodeAvro a => Schema -> [[a]] -> IO ByteString
-- | Encode chunks of objects into a container, using the provided
-- ByteString as the synchronization markers.
encodeContainerWithSync :: EncodeAvro a => Schema -> ByteString -> [[a]] -> ByteString
class EncodeAvro a
avro :: EncodeAvro a => a -> AvroM
class Zag a where {
type family Zagged a;
}
zag :: Zag a => a -> Zagged a
putAvro :: EncodeAvro a => a -> Builder
instance Data.Avro.Encode.EncodeAvro GHC.Types.Int
instance Data.Avro.Encode.EncodeAvro GHC.Int.Int8
instance Data.Avro.Encode.EncodeAvro GHC.Int.Int16
instance Data.Avro.Encode.EncodeAvro GHC.Int.Int32
instance Data.Avro.Encode.EncodeAvro GHC.Int.Int64
instance Data.Avro.Encode.EncodeAvro GHC.Word.Word8
instance Data.Avro.Encode.EncodeAvro GHC.Word.Word16
instance Data.Avro.Encode.EncodeAvro GHC.Word.Word32
instance Data.Avro.Encode.EncodeAvro GHC.Word.Word64
instance Data.Avro.Encode.EncodeAvro Data.Text.Internal.Text
instance Data.Avro.Encode.EncodeAvro Data.Text.Internal.Lazy.Text
instance Data.Avro.Encode.EncodeAvro Data.ByteString.Lazy.Internal.ByteString
instance Data.Avro.Encode.EncodeAvro Data.ByteString.Internal.ByteString
instance Data.Avro.Encode.EncodeAvro GHC.Base.String
instance Data.Avro.Encode.EncodeAvro GHC.Types.Double
instance Data.Avro.Encode.EncodeAvro GHC.Types.Float
instance Data.Avro.Encode.EncodeAvro a => Data.Avro.Encode.EncodeAvro [a]
instance (GHC.Arr.Ix i, Data.Avro.Encode.EncodeAvro a) => Data.Avro.Encode.EncodeAvro (GHC.Arr.Array i a)
instance Data.Avro.Encode.EncodeAvro a => Data.Avro.Encode.EncodeAvro (Data.Vector.Vector a)
instance (Data.Vector.Unboxed.Base.Unbox a, Data.Avro.Encode.EncodeAvro a) => Data.Avro.Encode.EncodeAvro (Data.Vector.Unboxed.Base.Vector a)
instance Data.Avro.Encode.EncodeAvro a => Data.Avro.Encode.EncodeAvro (Data.Set.Internal.Set a)
instance Data.Avro.Encode.EncodeAvro a => Data.Avro.Encode.EncodeAvro (Data.HashMap.Base.HashMap Data.Text.Internal.Text a)
instance Data.Avro.Encode.EncodeAvro a => Data.Avro.Encode.EncodeAvro (GHC.Base.Maybe a)
instance Data.Avro.Encode.EncodeAvro ()
instance Data.Avro.Encode.EncodeAvro GHC.Types.Bool
instance Data.Avro.Encode.EncodeAvro (Data.Avro.Types.Value.Value Data.Avro.Schema.Type)
module Data.Avro.FromAvro
class HasAvroSchema a => FromAvro a
fromAvro :: FromAvro a => Value Type -> Result a
(.:) :: FromAvro a => HashMap Text (Value Type) -> Text -> Result a
badValue :: Value Type -> String -> Result a
instance (Data.Avro.FromAvro.FromAvro a, Data.Avro.FromAvro.FromAvro b) => Data.Avro.FromAvro.FromAvro (Data.Either.Either a b)
instance Data.Avro.FromAvro.FromAvro GHC.Types.Bool
instance Data.Avro.FromAvro.FromAvro Data.ByteString.Internal.ByteString
instance Data.Avro.FromAvro.FromAvro Data.ByteString.Lazy.Internal.ByteString
instance Data.Avro.FromAvro.FromAvro GHC.Types.Int
instance Data.Avro.FromAvro.FromAvro GHC.Int.Int32
instance Data.Avro.FromAvro.FromAvro GHC.Int.Int64
instance Data.Avro.FromAvro.FromAvro GHC.Types.Double
instance Data.Avro.FromAvro.FromAvro GHC.Types.Float
instance Data.Avro.FromAvro.FromAvro a => Data.Avro.FromAvro.FromAvro (GHC.Base.Maybe a)
instance Data.Avro.FromAvro.FromAvro a => Data.Avro.FromAvro.FromAvro [a]
instance Data.Avro.FromAvro.FromAvro Data.Text.Internal.Text
instance Data.Avro.FromAvro.FromAvro Data.Text.Internal.Lazy.Text
instance Data.Avro.FromAvro.FromAvro a => Data.Avro.FromAvro.FromAvro (Data.Map.Internal.Map Data.Text.Internal.Text a)
instance Data.Avro.FromAvro.FromAvro a => Data.Avro.FromAvro.FromAvro (Data.HashMap.Base.HashMap Data.Text.Internal.Text a)
module Data.Avro.Decode.Lazy
-- | Decode bytes into a Value as described by Schema.
decodeAvro :: Schema -> ByteString -> LazyValue Type
-- | Decodes the container as a lazy list of values of the requested type.
--
-- The schema for the requested type will be de-conflicted with the
-- schema embedded with the container.
--
-- Errors are reported as a part of the list and the list will stop at
-- first error. This means that the consumer will get all the "good"
-- content from the container until the error is detected, then this
-- error and then the list is finished.
decodeContainer :: forall a. FromAvro a => ByteString -> [Either String a]
-- | Decodes the container as a lazy list of values of the requested type.
--
-- The schema for the requested type will be de-conflicted with the
-- schema embedded with the container.
--
-- The content of the container is returned as a list of "blocks" of
-- values inside this container, so the notion of blocks in the container
-- is preserved. Since decoding is lazy it should be safe to concat these
-- values into one lazy list.
--
-- The "outer" error represents the error in opening the container itself
-- (including problems like reading schemas embedded into the container.)
--
-- The "inner" errors represent problems in decoding individual values.
--
-- Note that this function will not stop decoding at the first occurance
-- of the "inner" error, and will continue attempting decoding values, so
-- it is possible to get Right after Left. It is up to the
-- user to decide whether it is correct or not to continue after errors
-- (most likely it will not be correct).
--
-- decodeContainer function makes a choice to stop after the first
-- error.
decodeContainer' :: forall a. FromAvro a => ByteString -> Either String [[Either String a]]
-- | Same as decodeContainer but uses provided schema as a reader
-- schema for the container instead of the schema obtained from the type
-- of a.
--
-- It is up to the user to make sure that the provided schema is
-- compatible with a and with the container's writer schema.
decodeContainerWithSchema :: FromAvro a => Schema -> ByteString -> [Either String a]
-- | Same as decodeContainer' but uses provided schema as a reader
-- schema for the container instead of the schema obtained from the type
-- of a.
--
-- It is up to the user to make sure that the provided schema is
-- compatible with a and with the container's writer schema.
decodeContainerWithSchema' :: FromAvro a => Schema -> ByteString -> Either String [[Either String a]]
-- | Decodes the container into a list of blocks of raw Avro values.
--
-- The content of the container is returned as a list of "blocks" of
-- values inside this container, so the notion of blocks in the container
-- is preserved. Since decoding is lazy it should be safe to concat these
-- values into one lazy list.
--
-- Each LazyValue can be an Error and this function
-- doesn't make any attempts of dealing with them leaving it up to the
-- user.
--
-- The "outer" error represents the error in opening the container itself
-- (including problems like reading schemas embedded into the container.)
getContainerValues :: ByteString -> Either String (Schema, [[LazyValue Type]])
getContainerValuesWith :: (Schema -> ByteString -> (ByteString, LazyValue Type)) -> ByteString -> Either String (Schema, [[LazyValue Type]])
getAvroOf :: Schema -> ByteString -> (ByteString, LazyValue Type)
class GetAvro a
getAvro :: GetAvro a => Get a
-- | Avro encoding and decoding routines.
--
-- This library provides a high level interface for encoding (and
-- decoding) Haskell values in Apache's Avro serialization format. The
-- goal is to match Aeson's API whenever reasonable, meaning user
-- experience with one effectively translate to the other.
--
-- Avro RPC is not currently supported.
--
--
-- - *Library Structure**
--
--
-- The library structure includes: * This module, Avro, providing
-- a high-level interface via classes of FromAvro and
-- ToAvro for decoding and encoding values. * Type define
-- the types of Avro data, providing a common (intermediate)
-- representation for any data that is encoded or decoded by Data.Avro. *
-- Encode and Decode: More efficient conversion capable of
-- avoiding the intermediate representation. Also, the implementation of
-- the en/decoding of the intermediate representation. *
-- Deconflict: translate decoded data from an encoder schema to
-- the (potentially different) decoder's schema. * Schema: Defines
-- the type for Avro schema's and its JSON encoding/decoding.
--
-- Example decoding:
--
-- Let's say you have an ADT and related schema:
--
--
-- {--}
-- import qualified Data.Avro.Types as Ty
-- import Data.Avro.Schema
-- import Data.Avro
-- import Data.List.NonEmpty (NonEmpty(..))
--
-- data MyEnum = A | B | C | D deriving (Eq,Ord,Show,Enum,Generic)
-- data MyStruct = MyStruct (Either MyEnum String) Int
--
-- meSchema :: Schema
-- meSchema = Schema $ mkEnum MyEnum [] Nothing Nothing [A,B,C,D]
--
-- msSchema :: Schema
-- msSchema =
-- Struct MyStruct Nothing [] Nothing Nothing
-- [ fld "enumOrString" eOrS (Just $ String "The Default")
-- , fld "int" Int (Just (Ty.Int 1))
-- ]
-- where
-- fld nm ty def = Field nm [] Nothing Nothing ty def
-- eOrS = mkUnion (meSchema :| [String])
--
-- instance ToAvro MyEnum where
-- toAvro = toAvroEnum
-- instance ToAvro MyStruct where
-- toAvro (MyStruct ab i) =
-- record [ "enumOrString" .= ab
-- , "int" .= i
-- ]
--
-- main = do
-- let val = MyStruct (Right Hello) 1
-- print (fromAvro (toAvro val) == Success val)
--
module Data.Avro
class HasAvroSchema a => FromAvro a
fromAvro :: FromAvro a => Value Type -> Result a
class HasAvroSchema a => ToAvro a
toAvro :: ToAvro a => a -> Value Type
class HasAvroSchema a
schema :: HasAvroSchema a => Tagged a Type
type Avro a = (FromAvro a, ToAvro a)
(.:) :: FromAvro a => HashMap Text (Value Type) -> Text -> Result a
(.=) :: ToAvro a => Text -> a -> (Text, Value Type)
record :: Foldable f => Type -> f (Text, Value Type) -> Value Type
fixed :: Type -> ByteString -> Value Type
data Result a
Success :: a -> Result a
Error :: String -> Result a
badValue :: Value Type -> String -> Result a
-- | Decode a lazy bytestring using a Schema for the return type.
decode :: forall a. FromAvro a => ByteString -> Result a
-- | Decode a lazy bytestring with a provided schema
decodeWithSchema :: FromAvro a => Schema -> ByteString -> Result a
-- | Decode a container and de-conflict the writer schema with a reader
-- schema for a return type. Like in decodeContainerWithSchema
-- exceptions are thrown instead of a Result type to allow this
-- function to be read lazy (to be done in some later version).
decodeContainer :: forall a. FromAvro a => ByteString -> [[a]]
-- | Decode a container and de-conflict the writer schema with a given
-- reader-schema. Exceptions are thrown instead of a Result type
-- to allow this function to be read lazy (to be done in some later
-- version).
decodeContainerWithSchema :: FromAvro a => Schema -> ByteString -> [[a]]
-- | Like decodeContainer but returns the avro-encoded bytes for
-- each object in the container instead of the Haskell type.
--
-- This is particularly useful when slicing up containers into one or
-- more smaller files. By extracting the original bytestring it is
-- possible to avoid re-encoding data.
decodeContainerBytes :: ByteString -> [[ByteString]]
-- | Encodes a value to a lazy ByteString
encode :: ToAvro a => a -> ByteString
-- | Encode chunks of objects into a container, using 16 random bytes for
-- the synchronization markers.
encodeContainer :: forall a. ToAvro a => [[a]] -> IO ByteString
-- | Encode chunks of objects into a container, using the provided
-- ByteString as the synchronization markers
encodeContainerWithSync :: forall a. ToAvro a => (Word64, Word64, Word64, Word64) -> [[a]] -> ByteString
schemaOf :: (HasAvroSchema a) => a -> Type
-- | Avro supports a JSON representation of Avro objects alongside the Avro
-- binary format. An Avro schema can be used to generate and validate
-- JSON representations of Avro objects.
--
-- The JSON format is the same format as used for default values in
-- schemas except unions are encoded differently. Non-union values are
-- encoded as follows:
--
-- TODO: table
--
-- (Table from the Avro 1.8.2 specification:
-- https://avro.apache.org/docs/1.8.2/spec.html#schema_record)
--
-- Bytes and fixed are encoded as JSON strings where each byte is
-- translated into the corresponding Unicode codepoint between 0–255,
-- which includes non-printable characters. Note that this encoding
-- happens at the Unicode code-point level, meaning it is independent of
-- text encoding. (JSON is, by definition, encoded in UTF8.)
--
-- Unions are encoded as an object with a single field that specifies the
-- "branch" of the union. If the branch is a primitive type like
-- "string", the name of the primitive type is used:
--
--
-- { "string" : "foo" }
--
--
-- For named types (record, enum and fixed), the name of the type is
-- used:
--
--
-- { MyRecord : { ... } }
--
module Data.Avro.JSON
decodeAvroJSON :: Schema -> Value -> Result (Value Schema)
-- | Convert a Value into a type that has an Avro schema. The schema
-- is used to validate the JSON and will return an Error if the
-- JSON object is not encoded correctly or does not match the schema.
fromJSON :: forall a. (FromAvro a) => Value -> Result a
-- | Parse a ByteString as JSON and convert it to a type with an
-- Avro schema. Will return Error if the input is not valid JSON
-- or the JSON does not convert with the specified schema.
parseJSON :: forall a. (FromAvro a) => ByteString -> Result a
-- | Convert an object with an Avro schema to JSON using that schema.
--
-- We always need the schema to encode to JSON because
-- representing unions requires using the names of named types.
toJSON :: forall a. (ToAvro a) => a -> Value
module Data.Avro.EitherN
data Either3 a b c
E3_1 :: a -> Either3 a b c
E3_2 :: b -> Either3 a b c
E3_3 :: c -> Either3 a b c
data Either4 a b c d
E4_1 :: a -> Either4 a b c d
E4_2 :: b -> Either4 a b c d
E4_3 :: c -> Either4 a b c d
E4_4 :: d -> Either4 a b c d
data Either5 a b c d e
E5_1 :: a -> Either5 a b c d e
E5_2 :: b -> Either5 a b c d e
E5_3 :: c -> Either5 a b c d e
E5_4 :: d -> Either5 a b c d e
E5_5 :: e -> Either5 a b c d e
instance GHC.Generics.Generic (Data.Avro.EitherN.Either5 a b c d e)
instance (GHC.Show.Show a, GHC.Show.Show b, GHC.Show.Show c, GHC.Show.Show d, GHC.Show.Show e) => GHC.Show.Show (Data.Avro.EitherN.Either5 a b c d e)
instance (GHC.Classes.Ord a, GHC.Classes.Ord b, GHC.Classes.Ord c, GHC.Classes.Ord d, GHC.Classes.Ord e) => GHC.Classes.Ord (Data.Avro.EitherN.Either5 a b c d e)
instance (GHC.Classes.Eq a, GHC.Classes.Eq b, GHC.Classes.Eq c, GHC.Classes.Eq d, GHC.Classes.Eq e) => GHC.Classes.Eq (Data.Avro.EitherN.Either5 a b c d e)
instance GHC.Generics.Generic (Data.Avro.EitherN.Either4 a b c d)
instance (GHC.Show.Show a, GHC.Show.Show b, GHC.Show.Show c, GHC.Show.Show d) => GHC.Show.Show (Data.Avro.EitherN.Either4 a b c d)
instance (GHC.Classes.Ord a, GHC.Classes.Ord b, GHC.Classes.Ord c, GHC.Classes.Ord d) => GHC.Classes.Ord (Data.Avro.EitherN.Either4 a b c d)
instance (GHC.Classes.Eq a, GHC.Classes.Eq b, GHC.Classes.Eq c, GHC.Classes.Eq d) => GHC.Classes.Eq (Data.Avro.EitherN.Either4 a b c d)
instance GHC.Generics.Generic (Data.Avro.EitherN.Either3 a b c)
instance (GHC.Show.Show a, GHC.Show.Show b, GHC.Show.Show c) => GHC.Show.Show (Data.Avro.EitherN.Either3 a b c)
instance (GHC.Classes.Ord a, GHC.Classes.Ord b, GHC.Classes.Ord c) => GHC.Classes.Ord (Data.Avro.EitherN.Either3 a b c)
instance (GHC.Classes.Eq a, GHC.Classes.Eq b, GHC.Classes.Eq c) => GHC.Classes.Eq (Data.Avro.EitherN.Either3 a b c)
instance (Data.Avro.HasAvroSchema.HasAvroSchema a, Data.Avro.HasAvroSchema.HasAvroSchema b, Data.Avro.HasAvroSchema.HasAvroSchema c, Data.Avro.HasAvroSchema.HasAvroSchema d, Data.Avro.HasAvroSchema.HasAvroSchema e) => Data.Avro.HasAvroSchema.HasAvroSchema (Data.Avro.EitherN.Either5 a b c d e)
instance (Data.Avro.FromAvro.FromAvro a, Data.Avro.FromAvro.FromAvro b, Data.Avro.FromAvro.FromAvro c, Data.Avro.FromAvro.FromAvro d, Data.Avro.FromAvro.FromAvro e) => Data.Avro.FromAvro.FromAvro (Data.Avro.EitherN.Either5 a b c d e)
instance (Data.Avro.ToAvro.ToAvro a, Data.Avro.ToAvro.ToAvro b, Data.Avro.ToAvro.ToAvro c, Data.Avro.ToAvro.ToAvro d, Data.Avro.ToAvro.ToAvro e) => Data.Avro.ToAvro.ToAvro (Data.Avro.EitherN.Either5 a b c d e)
instance (Data.Avro.HasAvroSchema.HasAvroSchema a, Data.Avro.HasAvroSchema.HasAvroSchema b, Data.Avro.HasAvroSchema.HasAvroSchema c, Data.Avro.HasAvroSchema.HasAvroSchema d) => Data.Avro.HasAvroSchema.HasAvroSchema (Data.Avro.EitherN.Either4 a b c d)
instance (Data.Avro.FromAvro.FromAvro a, Data.Avro.FromAvro.FromAvro b, Data.Avro.FromAvro.FromAvro c, Data.Avro.FromAvro.FromAvro d) => Data.Avro.FromAvro.FromAvro (Data.Avro.EitherN.Either4 a b c d)
instance (Data.Avro.ToAvro.ToAvro a, Data.Avro.ToAvro.ToAvro b, Data.Avro.ToAvro.ToAvro c, Data.Avro.ToAvro.ToAvro d) => Data.Avro.ToAvro.ToAvro (Data.Avro.EitherN.Either4 a b c d)
instance (Data.Avro.HasAvroSchema.HasAvroSchema a, Data.Avro.HasAvroSchema.HasAvroSchema b, Data.Avro.HasAvroSchema.HasAvroSchema c) => Data.Avro.HasAvroSchema.HasAvroSchema (Data.Avro.EitherN.Either3 a b c)
instance (Data.Avro.FromAvro.FromAvro a, Data.Avro.FromAvro.FromAvro b, Data.Avro.FromAvro.FromAvro c) => Data.Avro.FromAvro.FromAvro (Data.Avro.EitherN.Either3 a b c)
instance (Data.Avro.ToAvro.ToAvro a, Data.Avro.ToAvro.ToAvro b, Data.Avro.ToAvro.ToAvro c) => Data.Avro.ToAvro.ToAvro (Data.Avro.EitherN.Either3 a b c)
module Data.Avro.Deriving
-- | Derives Avro from a given schema file. Generates data types, FromAvro
-- and ToAvro instances.
data DeriveOptions
DeriveOptions :: TypeName -> Field -> Text -> TypeName -> Field -> (FieldStrictness, FieldUnpackedness) -> DeriveOptions
-- | How to build field names for generated data types
[fieldNameBuilder] :: DeriveOptions -> TypeName -> Field -> Text
-- | Determines field representation of generated data types
[fieldRepresentation] :: DeriveOptions -> TypeName -> Field -> (FieldStrictness, FieldUnpackedness)
-- | Describes the strictness of a field for a derived data type. The field
-- will be derived as if it were written with a !.
data FieldStrictness
StrictField :: FieldStrictness
LazyField :: FieldStrictness
-- | Describes the representation of a field for a derived data type. The
-- field will be derived as if it were written with an {--}
-- pragma.
data FieldUnpackedness
UnpackedField :: FieldUnpackedness
NonUnpackedField :: FieldUnpackedness
-- | Default deriving options
--
--
-- defaultDeriveOptions = DeriveOptions
-- { fieldNameBuilder = mkPrefixedFieldName
-- , fieldStrictness = mkLazyField
-- }
--
defaultDeriveOptions :: DeriveOptions
-- | Generates a field name that is prefixed with the type name.
--
-- For example, if the schema defines type Person that has a
-- field firstName, then the generated Haskell type will be like
--
--
-- Person { personFirstName :: Text }
--
mkPrefixedFieldName :: TypeName -> Field -> Text
-- | Generates a field name that matches the field name in schema
-- (sanitised for Haskell, so first letter is lower cased)
--
-- For example, if the schema defines type Person that has a
-- field firstName, then the generated Haskell type will be like
--
--
-- Person { firstName :: Text }
--
--
-- You may want to enable DuplicateRecordFields if you want to use
-- this method.
mkAsIsFieldName :: TypeName -> Field -> Text
-- | Marks any field as non-strict in the generated data types.
mkLazyField :: TypeName -> Field -> (FieldStrictness, FieldUnpackedness)
-- | Make a field strict and unpacked if it has a primitive representation.
-- Primitive types are types which GHC has either a static or an unlifted
-- representation: `()`, Boolean, Int32, Int64,
-- Float, Double.
mkStrictPrimitiveField :: TypeName -> Field -> (FieldStrictness, FieldUnpackedness)
-- | Generates the value of type Schema that it can later be used
-- with deriveAvro' or deriveAvroWithOptions'.
--
--
-- mySchema :: Schema
-- mySchema = $(makeSchema "schemas/my-schema.avsc")
--
makeSchema :: FilePath -> Q Exp
-- | Generates Haskell classes and FromAvro and ToAvro
-- instances given the Avro schema file
deriveAvroWithOptions :: DeriveOptions -> FilePath -> Q [Dec]
-- | Generates Haskell classes and FromAvro and ToAvro
-- instances given the Avro schema
deriveAvroWithOptions' :: DeriveOptions -> Schema -> Q [Dec]
-- | Derives "read only" Avro from a given schema file. Generates data
-- types and FromAvro.
deriveFromAvroWithOptions :: DeriveOptions -> FilePath -> Q [Dec]
-- | Same as deriveAvroWithOptions but uses
-- defaultDeriveOptions
--
--
-- deriveAvro' = deriveAvroWithOptions' defaultDeriveOptions
--
deriveAvro :: FilePath -> Q [Dec]
-- | Same as deriveAvroWithOptions' but uses
-- defaultDeriveOptions
--
--
-- deriveAvro' = deriveAvroWithOptions' defaultDeriveOptions
--
deriveAvro' :: Schema -> Q [Dec]
-- | Derives "read only" Avro from a given schema file. Generates data
-- types and FromAvro.
deriveFromAvro :: FilePath -> Q [Dec]
instance GHC.Generics.Generic Data.Avro.Deriving.DeriveOptions
instance GHC.Generics.Generic Data.Avro.Deriving.FieldUnpackedness
instance GHC.Generics.Generic Data.Avro.Deriving.FieldStrictness