module Network.LibP2P.Core.Binary
( word16BE
, word32BE
, readWord16BE
, readWord32BE
) where
import Data.Binary.Get (getWord16be, getWord32be, runGet)
import Data.ByteString (ByteString)
import qualified Data.ByteString.Builder as Builder
import qualified Data.ByteString.Lazy as LBS
import Data.Word (Word16, Word32)
word16BE :: Word16 -> ByteString
word16BE :: Word16 -> ByteString
word16BE = LazyByteString -> ByteString
LBS.toStrict (LazyByteString -> ByteString)
-> (Word16 -> LazyByteString) -> Word16 -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> LazyByteString
Builder.toLazyByteString (Builder -> LazyByteString)
-> (Word16 -> Builder) -> Word16 -> LazyByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word16 -> Builder
Builder.word16BE
word32BE :: Word32 -> ByteString
word32BE :: Word32 -> ByteString
word32BE = LazyByteString -> ByteString
LBS.toStrict (LazyByteString -> ByteString)
-> (Word32 -> LazyByteString) -> Word32 -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> LazyByteString
Builder.toLazyByteString (Builder -> LazyByteString)
-> (Word32 -> Builder) -> Word32 -> LazyByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> Builder
Builder.word32BE
readWord16BE :: ByteString -> Word16
readWord16BE :: ByteString -> Word16
readWord16BE = Get Word16 -> LazyByteString -> Word16
forall a. Get a -> LazyByteString -> a
runGet Get Word16
getWord16be (LazyByteString -> Word16)
-> (ByteString -> LazyByteString) -> ByteString -> Word16
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> LazyByteString
LBS.fromStrict
readWord32BE :: ByteString -> Word32
readWord32BE :: ByteString -> Word32
readWord32BE = Get Word32 -> LazyByteString -> Word32
forall a. Get a -> LazyByteString -> a
runGet Get Word32
getWord32be (LazyByteString -> Word32)
-> (ByteString -> LazyByteString) -> ByteString -> Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> LazyByteString
LBS.fromStrict