binrep-0.5.0: Encode precise binary representations directly in types
Safe HaskellSafe-Inferred
LanguageGHC2021

Binrep.Put.Mason

Synopsis

Documentation

class Put a where Source #

Methods

put :: a -> Builder Source #

Serialize to binary.

Instances

Instances details
Put Void Source #

Impossible to serialize Void.

Instance details

Defined in Binrep.Put.Mason

Methods

put :: Void -> Builder Source #

Put Int8 Source # 
Instance details

Defined in Binrep.Put.Mason

Methods

put :: Int8 -> Builder Source #

Put Word8 Source # 
Instance details

Defined in Binrep.Put.Mason

Methods

put :: Word8 -> Builder Source #

Put ByteString Source #

Serialize the bytestring as-is.

Careful -- the only way you're going to be able to parse this is to read until EOF.

Instance details

Defined in Binrep.Put.Mason

Put a => Put (Binreply a) Source # 
Instance details

Defined in Binrep.Via

Methods

put :: Binreply a -> Builder Source #

Put a => Put [a] Source #

Serialize each element in order. No length indicator, so parse until either error or EOF. Usually not what you want, but sometimes used at the "top" of binary formats.

Instance details

Defined in Binrep.Put.Mason

Methods

put :: [a] -> Builder Source #

Put (Endian end Int8) Source #

Endianness doesn't matter for single bytes.

Instance details

Defined in Binrep.Type.Int

Methods

put :: Endian end Int8 -> Builder Source #

Put (Endian end Word8) Source #

Endianness doesn't matter for single bytes.

Instance details

Defined in Binrep.Type.Int

Methods

put :: Endian end Word8 -> Builder Source #

(Put a, Put b) => Put (a, b) Source # 
Instance details

Defined in Binrep.Put.Mason

Methods

put :: (a, b) -> Builder Source #

runPut :: Put a => a -> ByteString Source #

Run the serializer.

putGenericNonSum :: forall {cd} {f} {asserts} a. (Generic a, Rep a ~ D1 cd f, GFoldMapNonSum Builder f, asserts ~ '['NoEmpty, 'NoSum], ApplyGCAsserts asserts f) => a -> Builder Source #

Serialize a term of the non-sum type a via its Generic instance.

putGenericSum :: forall {cd} {f} {asserts} a. (Generic a, Rep a ~ D1 cd f, GFoldMapSum 'SumOnly Builder f, asserts ~ '['NoEmpty, 'NeedSum], ApplyGCAsserts asserts f) => (String -> Builder) -> a -> Builder Source #

Serialize a term of the sum type a via its Generic instance.

You must provide a serializer for a's constructors. This is regrettably inefficient due to having to use Strings. Alas. Do write your own instance if you want better performance!

class PutWith r a where Source #

Put with inlined checks via an environment.

Minimal complete definition

Nothing

Methods

putWith :: r -> a -> Either String Builder Source #

Attempt to serialize to binary with the given environment.

default putWith :: Put a => r -> a -> Either String Builder Source #

Instances

Instances details
Put a => PutWith r [a] Source # 
Instance details

Defined in Binrep.Put.Mason

Methods

putWith :: r -> [a] -> Either String Builder Source #

putWithout :: Put a => a -> Either String Builder Source #

Helper for wrapping a BinRep into a BinRepWith (for encoding).

runPutWith :: PutWith r a => r -> a -> Either String ByteString Source #

Run the serializer with the given environment.

Orphan instances

GenericFoldMap Builder Source # 
Instance details

Associated Types

type GenericFoldMapC Builder a #