... | ... | @@ -85,4 +85,27 @@ Status: needs -fcpr-depth=4 or higher. |
|
|
val <-(,,,)<$> peekByteOff ptr 0<*> peekByteOff ptr 8<*> peekByteOff ptr 16<*> peekByteOff ptr 24let!ptr' = ptr `plusPtr`32
|
|
|
return (ptr', end, val)| otherwise =do(ptr', end')<- req ptr
|
|
|
peek4 ptr' end' req
|
|
|
```
|
|
|
|
|
|
## beam-word-poke.hs
|
|
|
|
|
|
|
|
|
This is a real-world example taken from [ https://github.com/tsurucapital/beamable/blob/master/src/Data/Beamable/Internal.hs\#L159](https://github.com/tsurucapital/beamable/blob/master/src/Data/Beamable/Internal.hs#L159).
|
|
|
It serializes a `Word` using a variable-length encoding.
|
|
|
|
|
|
|
|
|
Status: ok
|
|
|
|
|
|
```
|
|
|
moduleFoo(beamWordPoke)whereimportData.BitsimportData.MonoidimportData.WordimportForeign.PtrimportForeign.StorablenewtypePoke=Poke(PtrWord8->IO(PtrWord8))instanceMonoidPokewhere
|
|
|
mempty =Poke return
|
|
|
mappend (Poke a)(Poke b)=Poke$\ptr -> a ptr >>= b
|
|
|
|
|
|
beamWordPoke::Word->PokebeamWordPoke n
|
|
|
| next ==0= pokeWord8 firstSeptet
|
|
|
| otherwise = pokeWord8 (firstSeptet .|.0x80)<> beamWordPoke next
|
|
|
where
|
|
|
firstSeptet ::Word8
|
|
|
firstSeptet = fromIntegral $ n .&.0x7F
|
|
|
next = n `shiftR`7pokeWord8::Word8->PokepokeWord8 w =Poke$\p ->do poke p w; return $! p `plusPtr`1
|
|
|
``` |
|
|
\ No newline at end of file |