Plan 9 from Bell Labs’s /usr/web/sources/contrib/fernan/nhc98/src/prelude/Binary/NewCBinary.hs

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


module NHC.Prelude
  ( {-class-} Binary(..)
  ) where

import BinHandle ({-type-}BinHandle)
import BinPtr    ({-type-}BinPtr)
import SeekBin   (seekBin)
import TellBin   (tellBin)

class Binary a where
    put_rec    :: BinHandle -> a -> IO ()
    get_rec    :: BinHandle -> IO a
    getFAt_rec :: BinHandle -> BinPtr a -> (a, BinPtr b)
    sizeOf     :: a -> Int


put    :: Binary a => BinHandle -> a -> IO (BinPtr a)
get    :: Binary a => BinHandle -> IO a
putAt  :: Binary a => BinHandle -> BinPtr a -> a -> IO ()
getAt  :: Binary a => BinHandle -> BinPtr a -> IO a
getFAt :: Binary a => BinHandle -> BinPtr a -> a

put    bh x   = tellBin bh >>= \p-> put_rec bh x >> return p
get    bh     = get_rec bh
putAt  bh p x = seekBin bh p >> put_rec bh x >> return ()
getAt  bh p   = seekBin bh p >> get_rec bh
getFAt bh p   = fst (getFAt_rec bh p)


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].