dahdit-0.5.1: Binary parsing and serialization with integrated size
Safe HaskellSafe-Inferred
LanguageHaskell2010

Dahdit.Iface

Synopsis

Documentation

class PrimMonad m => BinaryGetTarget z m where Source #

Abstracts over the sources we can read from.

Methods

getTargetOffset :: ByteCount -> Get a -> z -> m (Either GetError a, ByteCount) Source #

Get a value from the source given a starting offset, returning a result and final offset. On error, the offset will indicate where in the source the error occurred.

getTargetInc :: Maybe ByteCount -> Get a -> GetIncCb z m -> m (Either GetError a, ByteCount, ByteCount) Source #

Get a value incrementally from sources yielded by the given callback, returning a result, final offset in the whole stream, and final offset in the current chunk. Takes an optional maximum capacity.

Instances

Instances details
BinaryGetTarget ByteString IO Source # 
Instance details

Defined in Dahdit.Iface

PrimMonad m => BinaryGetTarget ShortByteString m Source # 
Instance details

Defined in Dahdit.Iface

PrimMonad m => BinaryGetTarget ByteArray m Source # 
Instance details

Defined in Dahdit.Iface

BinaryGetTarget Text IO Source # 
Instance details

Defined in Dahdit.Iface

BinaryGetTarget String IO Source # 
Instance details

Defined in Dahdit.Iface

MonadPrim s m => BinaryGetTarget (MutableByteArray s) m Source # 
Instance details

Defined in Dahdit.Iface

BinaryGetTarget (Vector Word8) IO Source # 
Instance details

Defined in Dahdit.Iface

BinaryGetTarget (IOVector Word8) IO Source # 
Instance details

Defined in Dahdit.Iface

getTarget :: BinaryGetTarget z m => Get a -> z -> m (Either GetError a, ByteCount) Source #

Get a value from the source, returning a result and final offset.

class BinaryGetTarget z m => BinaryPutTarget z m where Source #

Abstracts over the immutable sinks we can render to.

Methods

putTargetUnsafe :: Put -> ByteCount -> m z Source #

Put an action to the sink with the given length. Prefer putTarget to safely count capacity, or use encode to use byte size.

Instances

Instances details
BinaryPutTarget ByteString IO Source # 
Instance details

Defined in Dahdit.Iface

PrimMonad m => BinaryPutTarget ShortByteString m Source # 
Instance details

Defined in Dahdit.Iface

PrimMonad m => BinaryPutTarget ByteArray m Source # 
Instance details

Defined in Dahdit.Iface

BinaryPutTarget Text IO Source # 
Instance details

Defined in Dahdit.Iface

BinaryPutTarget String IO Source # 
Instance details

Defined in Dahdit.Iface

BinaryPutTarget (Vector Word8) IO Source # 
Instance details

Defined in Dahdit.Iface

putTarget :: BinaryPutTarget z m => Put -> m z Source #

Put an action to the sink with calculated capacity.

getEnd :: Get a -> Get a Source #

Wrapper that asserts a get action has consumed to the end.

decode :: (Binary a, BinaryGetTarget z m) => z -> m (Either GetError a, ByteCount) Source #

Decode a value from a source returning a result and consumed byte count.

decodeInc :: (Binary a, BinaryGetTarget z m) => Maybe ByteCount -> GetIncCb z m -> m (Either GetError a, ByteCount, ByteCount) Source #

Decode a value incrementally from sources yielded by a callback.

decodeEnd :: (Binary a, BinaryGetTarget z m) => z -> m (Either GetError a, ByteCount) Source #

decode but expect the end of input.

decodeFile :: Binary a => FilePath -> IO (Either GetError a, ByteCount) Source #

Decode a value from a file.

decodeFileEnd :: Binary a => FilePath -> IO (Either GetError a, ByteCount) Source #

decodeFile but expect the end of file.

encode :: (Binary a, BinaryPutTarget z m) => a -> m z Source #

Encode a value to a sink.

encodeFile :: Binary a => a -> FilePath -> IO () Source #

Encode a value to a file.

mutEncode :: (Binary a, MutBinaryPutTarget z m) => a -> z -> m ByteCount Source #

Encode a value to a mutable buffer, returning number of bytes filled.