Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
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 undefined
s.
Instances
ByteLen (Str 'C) Source # | |
ByteLen (I 'U size e) => ByteLen (Str ('Pascal size e)) Source # | |
ByteLen a => ByteLen [a] Source # | |
Defined in Binrep.ByteLen | |
ByteLen (I s 'I1 e) Source # | |
ByteLen (I s 'I2 e) Source # | |
ByteLen (I s 'I4 e) Source # | |
ByteLen (I s 'I8 e) Source # | |
(ByteLen a, itype ~ I 'U size e, ByteLen itype) => ByteLen (WithRefine 'Enforced (LenPfx size e) a) Source # | TODO why safe |
Defined in Binrep.Types.Strings | |
KnownNat n => ByteLen (WithRefine 'Enforced (NullPadTo n) a) Source # | |
Defined in Binrep.Predicates.NullPadTo |