{-# OPTIONS_HADDOCK not-home #-}

module FlatBuffers.Internal.Types where

import Data.Word
import FlatBuffers.Internal.Compiler.Display (Display)

-- | Metadata for a struct type.
class IsStruct a where
  structAlignmentOf :: Alignment
  structSizeOf      :: InlineSize

-- | The number of bytes occupied by a piece of data that's stored "inline"
--
-- "inline" here means "stored directly in a table or a vector, and not by reference".
-- E.g.: numeric types, booleans, structs, offsets.
newtype InlineSize = InlineSize { InlineSize -> Word16
unInlineSize :: Word16 }
  deriving newtype (Int -> InlineSize -> ShowS
[InlineSize] -> ShowS
InlineSize -> String
(Int -> InlineSize -> ShowS)
-> (InlineSize -> String)
-> ([InlineSize] -> ShowS)
-> Show InlineSize
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InlineSize -> ShowS
showsPrec :: Int -> InlineSize -> ShowS
$cshow :: InlineSize -> String
show :: InlineSize -> String
$cshowList :: [InlineSize] -> ShowS
showList :: [InlineSize] -> ShowS
Show, InlineSize -> InlineSize -> Bool
(InlineSize -> InlineSize -> Bool)
-> (InlineSize -> InlineSize -> Bool) -> Eq InlineSize
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InlineSize -> InlineSize -> Bool
== :: InlineSize -> InlineSize -> Bool
$c/= :: InlineSize -> InlineSize -> Bool
/= :: InlineSize -> InlineSize -> Bool
Eq, Integer -> InlineSize
InlineSize -> InlineSize
InlineSize -> InlineSize -> InlineSize
(InlineSize -> InlineSize -> InlineSize)
-> (InlineSize -> InlineSize -> InlineSize)
-> (InlineSize -> InlineSize -> InlineSize)
-> (InlineSize -> InlineSize)
-> (InlineSize -> InlineSize)
-> (InlineSize -> InlineSize)
-> (Integer -> InlineSize)
-> Num InlineSize
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
$c+ :: InlineSize -> InlineSize -> InlineSize
+ :: InlineSize -> InlineSize -> InlineSize
$c- :: InlineSize -> InlineSize -> InlineSize
- :: InlineSize -> InlineSize -> InlineSize
$c* :: InlineSize -> InlineSize -> InlineSize
* :: InlineSize -> InlineSize -> InlineSize
$cnegate :: InlineSize -> InlineSize
negate :: InlineSize -> InlineSize
$cabs :: InlineSize -> InlineSize
abs :: InlineSize -> InlineSize
$csignum :: InlineSize -> InlineSize
signum :: InlineSize -> InlineSize
$cfromInteger :: Integer -> InlineSize
fromInteger :: Integer -> InlineSize
Num, Int -> InlineSize
InlineSize -> Int
InlineSize -> [InlineSize]
InlineSize -> InlineSize
InlineSize -> InlineSize -> [InlineSize]
InlineSize -> InlineSize -> InlineSize -> [InlineSize]
(InlineSize -> InlineSize)
-> (InlineSize -> InlineSize)
-> (Int -> InlineSize)
-> (InlineSize -> Int)
-> (InlineSize -> [InlineSize])
-> (InlineSize -> InlineSize -> [InlineSize])
-> (InlineSize -> InlineSize -> [InlineSize])
-> (InlineSize -> InlineSize -> InlineSize -> [InlineSize])
-> Enum InlineSize
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: InlineSize -> InlineSize
succ :: InlineSize -> InlineSize
$cpred :: InlineSize -> InlineSize
pred :: InlineSize -> InlineSize
$ctoEnum :: Int -> InlineSize
toEnum :: Int -> InlineSize
$cfromEnum :: InlineSize -> Int
fromEnum :: InlineSize -> Int
$cenumFrom :: InlineSize -> [InlineSize]
enumFrom :: InlineSize -> [InlineSize]
$cenumFromThen :: InlineSize -> InlineSize -> [InlineSize]
enumFromThen :: InlineSize -> InlineSize -> [InlineSize]
$cenumFromTo :: InlineSize -> InlineSize -> [InlineSize]
enumFromTo :: InlineSize -> InlineSize -> [InlineSize]
$cenumFromThenTo :: InlineSize -> InlineSize -> InlineSize -> [InlineSize]
enumFromThenTo :: InlineSize -> InlineSize -> InlineSize -> [InlineSize]
Enum, Eq InlineSize
Eq InlineSize =>
(InlineSize -> InlineSize -> Ordering)
-> (InlineSize -> InlineSize -> Bool)
-> (InlineSize -> InlineSize -> Bool)
-> (InlineSize -> InlineSize -> Bool)
-> (InlineSize -> InlineSize -> Bool)
-> (InlineSize -> InlineSize -> InlineSize)
-> (InlineSize -> InlineSize -> InlineSize)
-> Ord InlineSize
InlineSize -> InlineSize -> Bool
InlineSize -> InlineSize -> Ordering
InlineSize -> InlineSize -> InlineSize
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: InlineSize -> InlineSize -> Ordering
compare :: InlineSize -> InlineSize -> Ordering
$c< :: InlineSize -> InlineSize -> Bool
< :: InlineSize -> InlineSize -> Bool
$c<= :: InlineSize -> InlineSize -> Bool
<= :: InlineSize -> InlineSize -> Bool
$c> :: InlineSize -> InlineSize -> Bool
> :: InlineSize -> InlineSize -> Bool
$c>= :: InlineSize -> InlineSize -> Bool
>= :: InlineSize -> InlineSize -> Bool
$cmax :: InlineSize -> InlineSize -> InlineSize
max :: InlineSize -> InlineSize -> InlineSize
$cmin :: InlineSize -> InlineSize -> InlineSize
min :: InlineSize -> InlineSize -> InlineSize
Ord, Num InlineSize
Ord InlineSize
(Num InlineSize, Ord InlineSize) =>
(InlineSize -> Rational) -> Real InlineSize
InlineSize -> Rational
forall a. (Num a, Ord a) => (a -> Rational) -> Real a
$ctoRational :: InlineSize -> Rational
toRational :: InlineSize -> Rational
Real, Enum InlineSize
Real InlineSize
(Real InlineSize, Enum InlineSize) =>
(InlineSize -> InlineSize -> InlineSize)
-> (InlineSize -> InlineSize -> InlineSize)
-> (InlineSize -> InlineSize -> InlineSize)
-> (InlineSize -> InlineSize -> InlineSize)
-> (InlineSize -> InlineSize -> (InlineSize, InlineSize))
-> (InlineSize -> InlineSize -> (InlineSize, InlineSize))
-> (InlineSize -> Integer)
-> Integral InlineSize
InlineSize -> Integer
InlineSize -> InlineSize -> (InlineSize, InlineSize)
InlineSize -> InlineSize -> InlineSize
forall a.
(Real a, Enum a) =>
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> (a, a))
-> (a -> a -> (a, a))
-> (a -> Integer)
-> Integral a
$cquot :: InlineSize -> InlineSize -> InlineSize
quot :: InlineSize -> InlineSize -> InlineSize
$crem :: InlineSize -> InlineSize -> InlineSize
rem :: InlineSize -> InlineSize -> InlineSize
$cdiv :: InlineSize -> InlineSize -> InlineSize
div :: InlineSize -> InlineSize -> InlineSize
$cmod :: InlineSize -> InlineSize -> InlineSize
mod :: InlineSize -> InlineSize -> InlineSize
$cquotRem :: InlineSize -> InlineSize -> (InlineSize, InlineSize)
quotRem :: InlineSize -> InlineSize -> (InlineSize, InlineSize)
$cdivMod :: InlineSize -> InlineSize -> (InlineSize, InlineSize)
divMod :: InlineSize -> InlineSize -> (InlineSize, InlineSize)
$ctoInteger :: InlineSize -> Integer
toInteger :: InlineSize -> Integer
Integral, InlineSize
InlineSize -> InlineSize -> Bounded InlineSize
forall a. a -> a -> Bounded a
$cminBound :: InlineSize
minBound :: InlineSize
$cmaxBound :: InlineSize
maxBound :: InlineSize
Bounded)

-- | The memory alignment (in bytes) for a piece of data in a flatbuffer.
-- E.g., `Data.Int.Int32` are always aligned to 4 bytes.
-- This number should always be a power of 2 in the range [1, 16].
newtype Alignment = Alignment { Alignment -> Word8
unAlignment :: Word8 }
  deriving newtype (Int -> Alignment -> ShowS
[Alignment] -> ShowS
Alignment -> String
(Int -> Alignment -> ShowS)
-> (Alignment -> String)
-> ([Alignment] -> ShowS)
-> Show Alignment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Alignment -> ShowS
showsPrec :: Int -> Alignment -> ShowS
$cshow :: Alignment -> String
show :: Alignment -> String
$cshowList :: [Alignment] -> ShowS
showList :: [Alignment] -> ShowS
Show, Alignment -> Alignment -> Bool
(Alignment -> Alignment -> Bool)
-> (Alignment -> Alignment -> Bool) -> Eq Alignment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Alignment -> Alignment -> Bool
== :: Alignment -> Alignment -> Bool
$c/= :: Alignment -> Alignment -> Bool
/= :: Alignment -> Alignment -> Bool
Eq, Integer -> Alignment
Alignment -> Alignment
Alignment -> Alignment -> Alignment
(Alignment -> Alignment -> Alignment)
-> (Alignment -> Alignment -> Alignment)
-> (Alignment -> Alignment -> Alignment)
-> (Alignment -> Alignment)
-> (Alignment -> Alignment)
-> (Alignment -> Alignment)
-> (Integer -> Alignment)
-> Num Alignment
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
$c+ :: Alignment -> Alignment -> Alignment
+ :: Alignment -> Alignment -> Alignment
$c- :: Alignment -> Alignment -> Alignment
- :: Alignment -> Alignment -> Alignment
$c* :: Alignment -> Alignment -> Alignment
* :: Alignment -> Alignment -> Alignment
$cnegate :: Alignment -> Alignment
negate :: Alignment -> Alignment
$cabs :: Alignment -> Alignment
abs :: Alignment -> Alignment
$csignum :: Alignment -> Alignment
signum :: Alignment -> Alignment
$cfromInteger :: Integer -> Alignment
fromInteger :: Integer -> Alignment
Num, Int -> Alignment
Alignment -> Int
Alignment -> [Alignment]
Alignment -> Alignment
Alignment -> Alignment -> [Alignment]
Alignment -> Alignment -> Alignment -> [Alignment]
(Alignment -> Alignment)
-> (Alignment -> Alignment)
-> (Int -> Alignment)
-> (Alignment -> Int)
-> (Alignment -> [Alignment])
-> (Alignment -> Alignment -> [Alignment])
-> (Alignment -> Alignment -> [Alignment])
-> (Alignment -> Alignment -> Alignment -> [Alignment])
-> Enum Alignment
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: Alignment -> Alignment
succ :: Alignment -> Alignment
$cpred :: Alignment -> Alignment
pred :: Alignment -> Alignment
$ctoEnum :: Int -> Alignment
toEnum :: Int -> Alignment
$cfromEnum :: Alignment -> Int
fromEnum :: Alignment -> Int
$cenumFrom :: Alignment -> [Alignment]
enumFrom :: Alignment -> [Alignment]
$cenumFromThen :: Alignment -> Alignment -> [Alignment]
enumFromThen :: Alignment -> Alignment -> [Alignment]
$cenumFromTo :: Alignment -> Alignment -> [Alignment]
enumFromTo :: Alignment -> Alignment -> [Alignment]
$cenumFromThenTo :: Alignment -> Alignment -> Alignment -> [Alignment]
enumFromThenTo :: Alignment -> Alignment -> Alignment -> [Alignment]
Enum, Eq Alignment
Eq Alignment =>
(Alignment -> Alignment -> Ordering)
-> (Alignment -> Alignment -> Bool)
-> (Alignment -> Alignment -> Bool)
-> (Alignment -> Alignment -> Bool)
-> (Alignment -> Alignment -> Bool)
-> (Alignment -> Alignment -> Alignment)
-> (Alignment -> Alignment -> Alignment)
-> Ord Alignment
Alignment -> Alignment -> Bool
Alignment -> Alignment -> Ordering
Alignment -> Alignment -> Alignment
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Alignment -> Alignment -> Ordering
compare :: Alignment -> Alignment -> Ordering
$c< :: Alignment -> Alignment -> Bool
< :: Alignment -> Alignment -> Bool
$c<= :: Alignment -> Alignment -> Bool
<= :: Alignment -> Alignment -> Bool
$c> :: Alignment -> Alignment -> Bool
> :: Alignment -> Alignment -> Bool
$c>= :: Alignment -> Alignment -> Bool
>= :: Alignment -> Alignment -> Bool
$cmax :: Alignment -> Alignment -> Alignment
max :: Alignment -> Alignment -> Alignment
$cmin :: Alignment -> Alignment -> Alignment
min :: Alignment -> Alignment -> Alignment
Ord, Num Alignment
Ord Alignment
(Num Alignment, Ord Alignment) =>
(Alignment -> Rational) -> Real Alignment
Alignment -> Rational
forall a. (Num a, Ord a) => (a -> Rational) -> Real a
$ctoRational :: Alignment -> Rational
toRational :: Alignment -> Rational
Real, Enum Alignment
Real Alignment
(Real Alignment, Enum Alignment) =>
(Alignment -> Alignment -> Alignment)
-> (Alignment -> Alignment -> Alignment)
-> (Alignment -> Alignment -> Alignment)
-> (Alignment -> Alignment -> Alignment)
-> (Alignment -> Alignment -> (Alignment, Alignment))
-> (Alignment -> Alignment -> (Alignment, Alignment))
-> (Alignment -> Integer)
-> Integral Alignment
Alignment -> Integer
Alignment -> Alignment -> (Alignment, Alignment)
Alignment -> Alignment -> Alignment
forall a.
(Real a, Enum a) =>
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> (a, a))
-> (a -> a -> (a, a))
-> (a -> Integer)
-> Integral a
$cquot :: Alignment -> Alignment -> Alignment
quot :: Alignment -> Alignment -> Alignment
$crem :: Alignment -> Alignment -> Alignment
rem :: Alignment -> Alignment -> Alignment
$cdiv :: Alignment -> Alignment -> Alignment
div :: Alignment -> Alignment -> Alignment
$cmod :: Alignment -> Alignment -> Alignment
mod :: Alignment -> Alignment -> Alignment
$cquotRem :: Alignment -> Alignment -> (Alignment, Alignment)
quotRem :: Alignment -> Alignment -> (Alignment, Alignment)
$cdivMod :: Alignment -> Alignment -> (Alignment, Alignment)
divMod :: Alignment -> Alignment -> (Alignment, Alignment)
$ctoInteger :: Alignment -> Integer
toInteger :: Alignment -> Integer
Integral, Alignment
Alignment -> Alignment -> Bounded Alignment
forall a. a -> a -> Bounded a
$cminBound :: Alignment
minBound :: Alignment
$cmaxBound :: Alignment
maxBound :: Alignment
Bounded, Alignment -> String
(Alignment -> String) -> Display Alignment
forall a. (a -> String) -> Display a
$cdisplay :: Alignment -> String
display :: Alignment -> String
Display)