flatbuffers-0.1.0.0: Haskell implementation of the FlatBuffers protocol.

Safe HaskellNone
LanguageHaskell2010

FlatBuffers.Vector

Contents

Description

This module is intended to be imported qualified to avoid name clashes with Prelude. E.g.:

import           FlatBuffers.Vector (Vector, WriteVector)
import qualified FlatBuffers.Vector as Vector
Synopsis

Creating a vector

class WriteVectorElement a where Source #

Associated Types

data WriteVector a Source #

A vector to be written to a flatbuffer.

Methods

fromFoldable Source #

Arguments

:: Foldable f 
=> Int32

n: the number of elements in xs

-> f a

xs: a collection

-> WriteVector a 

Constructs a flatbuffers vector.

If n is larger than the length of xs, this will result in a malformed buffer. If n is smaller than the length of xs, all elements of xs will still be written to the buffer, but the client will only be able to read the first n elements.

Note: fromFoldable asks for the collection's length to be passed in as an argument rather than use Foldable.length because:

  1. Foldable.length is often O(n), and in some use cases there may be a better way to know the collection's length ahead of time.
  2. Calling Foldable.length inside fromFoldable can inhibit some fusions which would otherwise be possible.
Instances
WriteVectorElement Bool Source # 
Instance details

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector Bool :: Type Source #

WriteVectorElement Double Source # 
Instance details

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector Double :: Type Source #

WriteVectorElement Float Source # 
Instance details

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector Float :: Type Source #

WriteVectorElement Int8 Source # 
Instance details

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector Int8 :: Type Source #

WriteVectorElement Int16 Source # 
Instance details

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector Int16 :: Type Source #

WriteVectorElement Int32 Source # 
Instance details

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector Int32 :: Type Source #

WriteVectorElement Int64 Source # 
Instance details

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector Int64 :: Type Source #

WriteVectorElement Word8 Source # 
Instance details

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector Word8 :: Type Source #

WriteVectorElement Word16 Source # 
Instance details

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector Word16 :: Type Source #

WriteVectorElement Word32 Source # 
Instance details

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector Word32 :: Type Source #

WriteVectorElement Word64 Source # 
Instance details

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector Word64 :: Type Source #

WriteVectorElement Text Source # 
Instance details

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector Text :: Type Source #

WriteVectorElement (WriteUnion a) Source # 
Instance details

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector (WriteUnion a) :: Type Source #

WriteVectorElement (WriteTable a) Source # 
Instance details

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector (WriteTable a) :: Type Source #

IsStruct a => WriteVectorElement (WriteStruct a) Source # 
Instance details

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector (WriteStruct a) :: Type Source #

fromFoldable' :: WriteVectorElement a => Foldable f => f a -> WriteVector a Source #

Convenience function, equivalent to:

fromFoldable' xs = fromFoldable (fromIntegral (Foldable.length xs)) xs

In some cases it may be slower than using fromFoldable directly.

fromList :: WriteVectorElement a => Int32 -> [a] -> WriteVector a Source #

fromFoldable specialized to list

fromList' :: WriteVectorElement a => [a] -> WriteVector a Source #

fromFoldable' specialized to list

singleton :: WriteVectorElement a => a -> WriteVector a Source #

Creates a flatbuffers vector with a single element

empty :: WriteVectorElement a => WriteVector a Source #

Creates an empty flatbuffers vector

Reading a vector

class VectorElement a where Source #

Minimal complete definition

length, unsafeIndex, toList

Associated Types

data Vector a Source #

A vector that is being read from a flatbuffer.

Methods

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
VectorElement Bool Source # 
Instance details

Defined in FlatBuffers.Internal.Read

Associated Types

data Vector Bool :: Type Source #

VectorElement Double Source # 
Instance details

Defined in FlatBuffers.Internal.Read

Associated Types

data Vector Double :: Type Source #

VectorElement Float Source # 
Instance details

Defined in FlatBuffers.Internal.Read

Associated Types

data Vector Float :: Type Source #

VectorElement Int8 Source # 
Instance details

Defined in FlatBuffers.Internal.Read

Associated Types

data Vector Int8 :: Type Source #

VectorElement Int16 Source # 
Instance details

Defined in FlatBuffers.Internal.Read

Associated Types

data Vector Int16 :: Type Source #

VectorElement Int32 Source # 
Instance details

Defined in FlatBuffers.Internal.Read

Associated Types

data Vector Int32 :: Type Source #

VectorElement Int64 Source # 
Instance details

Defined in FlatBuffers.Internal.Read

Associated Types

data Vector Int64 :: Type Source #

VectorElement Word8 Source # 
Instance details

Defined in FlatBuffers.Internal.Read

Associated Types

data Vector Word8 :: Type Source #

VectorElement Word16 Source # 
Instance details

Defined in FlatBuffers.Internal.Read

Associated Types

data Vector Word16 :: Type Source #

VectorElement Word32 Source # 
Instance details

Defined in FlatBuffers.Internal.Read

Associated Types

data Vector Word32 :: Type Source #

VectorElement Word64 Source # 
Instance details

Defined in FlatBuffers.Internal.Read

Associated Types

data Vector Word64 :: Type Source #

VectorElement Text Source # 
Instance details

Defined in FlatBuffers.Internal.Read

Associated Types

data Vector Text :: Type Source #

VectorElement (Union a) Source # 
Instance details

Defined in FlatBuffers.Internal.Read

Associated Types

data Vector (Union a) :: Type Source #

VectorElement (Struct a) Source # 
Instance details

Defined in FlatBuffers.Internal.Read

Associated Types

data Vector (Struct a) :: Type Source #

VectorElement (Table a) Source # 
Instance details

Defined in FlatBuffers.Internal.Read

Associated Types

data Vector (Table a) :: Type Source #