flatbuffers-0.2.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

fromMonoFoldable Source #

Arguments

:: (MonoFoldable mono, Element mono ~ a) 
=> Int32

n: the number of elements in xs

-> mono

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: fromMonoFoldable asks for the collection's length to be passed in as an argument rather than use olength because:

  1. olength 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 olength inside fromMonoFoldable can inhibit some fusions which would otherwise be possible.

Since: 0.2.0.0

Instances
WriteVectorElement Bool Source # 
Instance details

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector Bool :: Type Source #

Methods

fromMonoFoldable :: (MonoFoldable mono, Element mono ~ Bool) => Int32 -> mono -> WriteVector Bool Source #

WriteVectorElement Double Source # 
Instance details

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector Double :: Type Source #

Methods

fromMonoFoldable :: (MonoFoldable mono, Element mono ~ Double) => Int32 -> mono -> WriteVector Double Source #

WriteVectorElement Float Source # 
Instance details

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector Float :: Type Source #

Methods

fromMonoFoldable :: (MonoFoldable mono, Element mono ~ Float) => Int32 -> mono -> WriteVector Float Source #

WriteVectorElement Int8 Source # 
Instance details

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector Int8 :: Type Source #

Methods

fromMonoFoldable :: (MonoFoldable mono, Element mono ~ Int8) => Int32 -> mono -> WriteVector Int8 Source #

WriteVectorElement Int16 Source # 
Instance details

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector Int16 :: Type Source #

Methods

fromMonoFoldable :: (MonoFoldable mono, Element mono ~ Int16) => Int32 -> mono -> WriteVector Int16 Source #

WriteVectorElement Int32 Source # 
Instance details

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector Int32 :: Type Source #

Methods

fromMonoFoldable :: (MonoFoldable mono, Element mono ~ Int32) => Int32 -> mono -> WriteVector Int32 Source #

WriteVectorElement Int64 Source # 
Instance details

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector Int64 :: Type Source #

Methods

fromMonoFoldable :: (MonoFoldable mono, Element mono ~ Int64) => Int32 -> mono -> WriteVector Int64 Source #

WriteVectorElement Word8 Source # 
Instance details

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector Word8 :: Type Source #

Methods

fromMonoFoldable :: (MonoFoldable mono, Element mono ~ Word8) => Int32 -> mono -> WriteVector Word8 Source #

WriteVectorElement Word16 Source # 
Instance details

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector Word16 :: Type Source #

Methods

fromMonoFoldable :: (MonoFoldable mono, Element mono ~ Word16) => Int32 -> mono -> WriteVector Word16 Source #

WriteVectorElement Word32 Source # 
Instance details

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector Word32 :: Type Source #

Methods

fromMonoFoldable :: (MonoFoldable mono, Element mono ~ Word32) => Int32 -> mono -> WriteVector Word32 Source #

WriteVectorElement Word64 Source # 
Instance details

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector Word64 :: Type Source #

Methods

fromMonoFoldable :: (MonoFoldable mono, Element mono ~ Word64) => Int32 -> mono -> WriteVector Word64 Source #

WriteVectorElement Text Source # 
Instance details

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector Text :: Type Source #

Methods

fromMonoFoldable :: (MonoFoldable mono, Element mono ~ Text) => Int32 -> mono -> WriteVector Text Source #

WriteVectorElement (WriteUnion a) Source # 
Instance details

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector (WriteUnion a) :: Type Source #

Methods

fromMonoFoldable :: (MonoFoldable mono, Element mono ~ WriteUnion a) => Int32 -> mono -> WriteVector (WriteUnion a) Source #

WriteVectorElement (WriteTable a) Source # 
Instance details

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector (WriteTable a) :: Type Source #

Methods

fromMonoFoldable :: (MonoFoldable mono, Element mono ~ WriteTable a) => Int32 -> mono -> WriteVector (WriteTable a) Source #

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

Defined in FlatBuffers.Internal.Write

Associated Types

data WriteVector (WriteStruct a) :: Type Source #

fromMonoFoldable' :: (WriteVectorElement a, MonoFoldable mono, Element mono ~ a) => mono -> WriteVector a Source #

Convenience function, equivalent to:

fromMonoFoldable' xs = fromMonoFoldable (fromIntegral (olength xs)) xs

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

Since: 0.2.0.0

fromFoldable :: (WriteVectorElement a, Foldable f) => Int32 -> f a -> WriteVector a Source #

fromMonoFoldable for types that implement Foldable but not MonoFoldable.

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

fromMonoFoldable' for types that implement Foldable but not MonoFoldable.

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

fromMonoFoldable 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

fromByteString :: ByteString -> WriteVector Word8 Source #

Efficiently creates a vector from a ByteString. Large ByteStrings are inserted directly, but small ones are copied to ensure that the generated chunks are large on average.

Since: 0.2.0.0

fromLazyByteString :: ByteString -> WriteVector Word8 Source #

Efficiently creates a vector from a lazy ByteString. Large chunks of the ByteString are inserted directly, but small ones are copied to ensure that the generated chunks are large on average.

Since: 0.2.0.0

Reading a vector

class VectorElement a where Source #

Associated Types

data Vector a Source #

A vector that is being read from a flatbuffer.

Methods

length :: Vector a -> Int32 Source #

Returns the size of the vector.

O(1).

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).

O(c), where c is the number of chunks in the underlying ByteString.

toList :: Vector a -> Either ReadError [a] Source #

Converts the vector to a list.

O(n).

take :: Int32 -> Vector a -> Vector a Source #

take n xs returns the prefix of xs of length n, or xs itself if n > length xs.

O(1).

Since: 0.2.0.0

drop :: Int32 -> Vector a -> Vector a Source #

drop n xs returns the suffix of xs after the first n elements, or [] if n > length xs.

O(c), where c is the number of chunks in the underlying ByteString.

Since: 0.2.0.0

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 #

IsStruct a => 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 #

index :: VectorElement a => 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.

O(c), where c is the number of chunks in the underlying ByteString.

toByteString :: Vector Word8 -> ByteString Source #

Convert the vector to a lazy ByteString.

O(c), where c is the number of chunks in the underlying ByteString.

Since: 0.2.0.0