binrep-0.1.0: Encode binary representations via types.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Binrep.ByteLen

Synopsis

Documentation

class ByteLen a where Source #

The size in bytes of the type can be known, preferably on the cheap e.g. reading a length field.

Aim to make this O(1). Except for where you can't like lists lol.

Importantly goes hand in hand with BinaryCodec! Maybe we should make it a function there lol!

This is useful for padding types generically, without having to track the read/write cursor. Yes, that feature *is* common and cheap for parsers (and to lesser extent, serializers), but you should really only be padding types that have a "static-ish" (= cheaply calculated) size. At least, I think so? I'm not quite sure.

Some instances ignore the argument. It would be possible to pull those out into a statically-known bytelength typeclass, but it wouldn't improve clarity or performance, just get rid of a couple undefineds.

Methods

blen :: a -> Natural Source #

Instances

Instances details
ByteLen (Str 'C) Source # 
Instance details

Defined in Binrep.Types.Strings

Methods

blen :: Str 'C -> Natural Source #

ByteLen (I 'U size e) => ByteLen (Str ('Pascal size e)) Source # 
Instance details

Defined in Binrep.Types.Strings

Methods

blen :: Str ('Pascal size e) -> Natural Source #

ByteLen a => ByteLen [a] Source # 
Instance details

Defined in Binrep.ByteLen

Methods

blen :: [a] -> Natural Source #

ByteLen (I s 'I1 e) Source # 
Instance details

Defined in Binrep.Types.Ints

Methods

blen :: I s 'I1 e -> Natural Source #

ByteLen (I s 'I2 e) Source # 
Instance details

Defined in Binrep.Types.Ints

Methods

blen :: I s 'I2 e -> Natural Source #

ByteLen (I s 'I4 e) Source # 
Instance details

Defined in Binrep.Types.Ints

Methods

blen :: I s 'I4 e -> Natural Source #

ByteLen (I s 'I8 e) Source # 
Instance details

Defined in Binrep.Types.Ints

Methods

blen :: I s 'I8 e -> Natural Source #

(ByteLen a, itype ~ I 'U size e, ByteLen itype) => ByteLen (WithRefine 'Enforced (LenPfx size e) a) Source #

TODO why safe

Instance details

Defined in Binrep.Types.Strings

Methods

blen :: WithRefine 'Enforced (LenPfx size e) a -> Natural Source #

KnownNat n => ByteLen (WithRefine 'Enforced (NullPadTo n) a) Source # 
Instance details

Defined in Binrep.Predicates.NullPadTo