Safe Haskell | None |
---|---|
Language | Haskell2010 |
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
- class WriteVectorElement a where
- data WriteVector a
- fromMonoFoldable :: (MonoFoldable mono, Element mono ~ a) => Int32 -> mono -> WriteVector a
- fromMonoFoldable' :: (WriteVectorElement a, MonoFoldable mono, Element mono ~ a) => mono -> WriteVector a
- fromFoldable :: (WriteVectorElement a, Foldable f) => Int32 -> f a -> WriteVector a
- fromFoldable' :: (WriteVectorElement a, Foldable f) => f a -> WriteVector a
- fromList :: WriteVectorElement a => Int32 -> [a] -> WriteVector a
- fromList' :: WriteVectorElement a => [a] -> WriteVector a
- singleton :: WriteVectorElement a => a -> WriteVector a
- empty :: WriteVectorElement a => WriteVector a
- fromByteString :: ByteString -> WriteVector Word8
- fromLazyByteString :: ByteString -> WriteVector Word8
- class VectorElement a where
- index :: VectorElement a => Vector a -> Int32 -> Either ReadError a
- toByteString :: Vector Word8 -> ByteString
Creating a vector
class WriteVectorElement a where Source #
data WriteVector a Source #
A vector to be written to a flatbuffer.
:: (MonoFoldable mono, Element mono ~ a) | |
=> Int32 |
|
-> mono |
|
-> 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:
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.- Calling
olength
insidefromMonoFoldable
can inhibit some fusions which would otherwise be possible.
Since: 0.2.0.0
Instances
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
fromList' :: WriteVectorElement a => [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 ByteString
s 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 #
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
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