Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- type ReadError = String
- newtype TableIndex = TableIndex {}
- newtype VOffset = VOffset {}
- newtype OffsetFromRoot = OffsetFromRoot Int32
- data Table a = Table {
- vtable :: !Position
- tablePos :: !PositionInfo
- newtype Struct a = Struct {}
- data Union a
- = Union !a
- | UnionNone
- | UnionUnknown !Word8
- type Position = ByteString
- data PositionInfo = PositionInfo {}
- class HasPosition a where
- getPosition :: a -> Position
- move :: Integral i => a -> i -> a
- decode :: ByteString -> Either ReadError (Table a)
- checkFileIdentifier :: forall a. HasFileIdentifier a => ByteString -> Bool
- checkFileIdentifier' :: FileIdentifier -> ByteString -> Bool
- moveToElem :: HasPosition pos => pos -> Int32 -> Int32 -> pos
- checkIndexBounds :: Int32 -> Int32 -> Int32
- inlineVectorToList :: HasPosition pos => Get a -> pos -> Either ReadError [a]
- class VectorElement a where
- readStructField :: (Position -> a) -> VOffset -> Struct s -> a
- readTableFieldOpt :: (PositionInfo -> Either ReadError a) -> TableIndex -> Table t -> Either ReadError (Maybe a)
- readTableFieldReq :: (PositionInfo -> Either ReadError a) -> TableIndex -> String -> Table t -> Either ReadError a
- readTableFieldWithDef :: (PositionInfo -> Either ReadError a) -> TableIndex -> a -> Table t -> Either ReadError a
- readTableFieldUnion :: (Positive Word8 -> PositionInfo -> Either ReadError (Union a)) -> TableIndex -> Table t -> Either ReadError (Union a)
- readTableFieldUnionVectorOpt :: (Positive Word8 -> PositionInfo -> Either ReadError (Union a)) -> TableIndex -> Table t -> Either ReadError (Maybe (Vector (Union a)))
- readTableFieldUnionVectorReq :: (Positive Word8 -> PositionInfo -> Either ReadError (Union a)) -> TableIndex -> String -> Table t -> Either ReadError (Vector (Union a))
- readInt8 :: HasPosition a => a -> Either ReadError Int8
- readInt16 :: HasPosition a => a -> Either ReadError Int16
- readInt32 :: HasPosition a => a -> Either ReadError Int32
- readInt64 :: HasPosition a => a -> Either ReadError Int64
- readWord8 :: HasPosition a => a -> Either ReadError Word8
- readWord16 :: HasPosition a => a -> Either ReadError Word16
- readWord32 :: HasPosition a => a -> Either ReadError Word32
- readWord64 :: HasPosition a => a -> Either ReadError Word64
- readFloat :: HasPosition a => a -> Either ReadError Float
- readDouble :: HasPosition a => a -> Either ReadError Double
- readBool :: HasPosition a => a -> Either ReadError Bool
- word8ToBool :: Word8 -> Bool
- readPrimVector :: (Position -> Vector a) -> PositionInfo -> Either ReadError (Vector a)
- readTableVector :: PositionInfo -> Either ReadError (Vector (Table a))
- readStructVector :: forall a. IsStruct a => PositionInfo -> Either ReadError (Vector (Struct a))
- readUnionVector :: (Positive Word8 -> PositionInfo -> Either ReadError (Union a)) -> PositionInfo -> PositionInfo -> Either ReadError (Vector (Union a))
- readText :: HasPosition a => a -> Either ReadError Text
- readText' :: Get (Either ReadError Text)
- readTable :: PositionInfo -> Either ReadError (Table t)
- readTable' :: PositionInfo -> Either ReadError (Table t)
- readStruct :: HasPosition a => a -> Struct s
- tableIndexToVOffset :: Table t -> TableIndex -> Either ReadError (Maybe VOffset)
- readUOffsetAndSkip :: HasPosition pos => pos -> Either ReadError pos
- runGet :: Get a -> ByteString -> Either ReadError a
- missingField :: String -> Either ReadError a
- byteStringSafeIndex :: ByteString -> Int32 -> Either ReadError Word8
Documentation
newtype TableIndex Source #
Instances
Num TableIndex Source # | |
Defined in FlatBuffers.Internal.Read (+) :: TableIndex -> TableIndex -> TableIndex # (-) :: TableIndex -> TableIndex -> TableIndex # (*) :: TableIndex -> TableIndex -> TableIndex # negate :: TableIndex -> TableIndex # abs :: TableIndex -> TableIndex # signum :: TableIndex -> TableIndex # fromInteger :: Integer -> TableIndex # | |
Show TableIndex Source # | |
Defined in FlatBuffers.Internal.Read showsPrec :: Int -> TableIndex -> ShowS # show :: TableIndex -> String # showList :: [TableIndex] -> ShowS # |
Instances
Enum VOffset Source # | |
Eq VOffset Source # | |
Integral VOffset Source # | |
Defined in FlatBuffers.Internal.Read | |
Num VOffset Source # | |
Ord VOffset Source # | |
Real VOffset Source # | |
Defined in FlatBuffers.Internal.Read toRational :: VOffset -> Rational # | |
Show VOffset Source # | |
newtype OffsetFromRoot Source #
Instances
A table that is being read from a flatbuffer.
Table | |
|
Instances
VectorElement (Table a) Source # | |
Defined in FlatBuffers.Internal.Read | |
HasPosition (Vector (Table a)) Source # | |
newtype Vector (Table a) Source # | |
Defined in FlatBuffers.Internal.Read |
A struct that is being read from a flatbuffer.
Instances
VectorElement (Struct a) Source # | |
Defined in FlatBuffers.Internal.Read | |
data Vector (Struct a) Source # | |
Defined in FlatBuffers.Internal.Read |
A union that is being read from a flatbuffer.
Instances
VectorElement (Union a) Source # | |
Defined in FlatBuffers.Internal.Read | |
data Vector (Union a) Source # | |
Defined in FlatBuffers.Internal.Read data Vector (Union a) = VectorUnion {
|
type Position = ByteString Source #
data PositionInfo Source #
Current position in the buffer
PositionInfo | |
|
Instances
HasPosition PositionInfo Source # | |
Defined in FlatBuffers.Internal.Read getPosition :: PositionInfo -> Position Source # move :: Integral i => PositionInfo -> i -> PositionInfo Source # |
class HasPosition a where Source #
Instances
HasPosition ByteString Source # | |
Defined in FlatBuffers.Internal.Read getPosition :: ByteString -> Position Source # move :: Integral i => ByteString -> i -> ByteString Source # | |
HasPosition PositionInfo Source # | |
Defined in FlatBuffers.Internal.Read getPosition :: PositionInfo -> Position Source # move :: Integral i => PositionInfo -> i -> PositionInfo Source # | |
HasPosition (Vector Bool) Source # | |
HasPosition (Vector Double) Source # | |
HasPosition (Vector Float) Source # | |
HasPosition (Vector Int8) Source # | |
HasPosition (Vector Int16) Source # | |
HasPosition (Vector Int32) Source # | |
HasPosition (Vector Int64) Source # | |
HasPosition (Vector Word8) Source # | |
HasPosition (Vector Word16) Source # | |
HasPosition (Vector Word32) Source # | |
HasPosition (Vector Word64) Source # | |
HasPosition (Vector (Table a)) Source # | |
decode :: ByteString -> Either ReadError (Table a) Source #
Deserializes a flatbuffer from a lazy ByteString
.
checkFileIdentifier :: forall a. HasFileIdentifier a => ByteString -> Bool Source #
Checks if a buffer contains the file identifier for a root table a
, to see if it's
safe to decode it to a Table
.
It should be used in conjunction with -XTypeApplications
.
{-# LANGUAGE TypeApplications #-} if checkFileIdentifier @Monster bs then decode @Monster bs else return someMonster
checkFileIdentifier' :: FileIdentifier -> ByteString -> Bool Source #
moveToElem :: HasPosition pos => pos -> Int32 -> Int32 -> pos Source #
inlineVectorToList :: HasPosition pos => Get a -> pos -> Either ReadError [a] Source #
class VectorElement a where Source #
length :: Vector a -> Either ReadError Int32 Source #
Returns the size of the vector.
index :: Vector a -> Int32 -> Either ReadError a Source #
Returns the item at the given index.
If the given index is negative or too large, an error
is thrown.
unsafeIndex :: Vector a -> Int32 -> Either ReadError a Source #
Returns the item at the given index without performing the bounds check.
Given an invalid index, unsafeIndex
will likely read garbage data or return a ReadError
.
In the case of Vector Word8
, using a negative index carries the same risks as unsafeIndex
(i.e. reading from outside the buffer's boundaries).
toList :: Vector a -> Either ReadError [a] Source #
Converts the vector to a list.
Instances
readTableFieldOpt :: (PositionInfo -> Either ReadError a) -> TableIndex -> Table t -> Either ReadError (Maybe a) Source #
readTableFieldReq :: (PositionInfo -> Either ReadError a) -> TableIndex -> String -> Table t -> Either ReadError a Source #
readTableFieldWithDef :: (PositionInfo -> Either ReadError a) -> TableIndex -> a -> Table t -> Either ReadError a Source #
readTableFieldUnion :: (Positive Word8 -> PositionInfo -> Either ReadError (Union a)) -> TableIndex -> Table t -> Either ReadError (Union a) Source #
readTableFieldUnionVectorOpt :: (Positive Word8 -> PositionInfo -> Either ReadError (Union a)) -> TableIndex -> Table t -> Either ReadError (Maybe (Vector (Union a))) Source #
readTableFieldUnionVectorReq :: (Positive Word8 -> PositionInfo -> Either ReadError (Union a)) -> TableIndex -> String -> Table t -> Either ReadError (Vector (Union a)) Source #
readWord16 :: HasPosition a => a -> Either ReadError Word16 Source #
readWord32 :: HasPosition a => a -> Either ReadError Word32 Source #
readWord64 :: HasPosition a => a -> Either ReadError Word64 Source #
readDouble :: HasPosition a => a -> Either ReadError Double Source #
word8ToBool :: Word8 -> Bool Source #
readPrimVector :: (Position -> Vector a) -> PositionInfo -> Either ReadError (Vector a) Source #
readTableVector :: PositionInfo -> Either ReadError (Vector (Table a)) Source #
readStructVector :: forall a. IsStruct a => PositionInfo -> Either ReadError (Vector (Struct a)) Source #
readUnionVector :: (Positive Word8 -> PositionInfo -> Either ReadError (Union a)) -> PositionInfo -> PositionInfo -> Either ReadError (Vector (Union a)) Source #
readText :: HasPosition a => a -> Either ReadError Text Source #
Follow a pointer to the position of a string and read it.
readTable :: PositionInfo -> Either ReadError (Table t) Source #
Follow a pointer to the position of a table and read it.
readTable' :: PositionInfo -> Either ReadError (Table t) Source #
Read a table from the current buffer position.
readStruct :: HasPosition a => a -> Struct s Source #
tableIndexToVOffset :: Table t -> TableIndex -> Either ReadError (Maybe VOffset) Source #
readUOffsetAndSkip :: HasPosition pos => pos -> Either ReadError pos Source #
byteStringSafeIndex :: ByteString -> Int32 -> Either ReadError Word8 Source #
Safer version of index
that doesn't throw when index is too large.
Assumes i > 0
.