HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulenetwork-byte-order-0.1.7Haskell2010

Network.ByteOrder

Peek and poke functions for network byte order.

  • 11 types
  • 1 class
  • 45 values

Types

4 declarations
typetype Offset = Int
#

Offset from the current pointer.

Poking

5 declarations
valuepoke8 :: Word8 -> Buffer -> Offset -> IO ()
#
Example3 expressions
let buf = pack [1,2,3,4]unsafeWithByteString buf (poke8 0)unpack buf[0,2,3,4]
valuepoke16 :: Word16 -> Buffer -> Offset -> IO ()
#
Example3 expressions
let buf = pack [1,2,3,4]unsafeWithByteString buf (poke16 (7*256 + 8))unpack buf[7,8,3,4]
valuepoke24 :: Word32 -> Buffer -> Offset -> IO ()
#
Example3 expressions
let buf = pack [1,2,3,4]unsafeWithByteString buf (poke24 (6*65536 + 7*256 + 8))unpack buf[6,7,8,4]
valuepoke32 :: Word32 -> Buffer -> Offset -> IO ()
#
Example3 expressions
let buf = pack [1,2,3,4]unsafeWithByteString buf (poke32 (6*65536 + 7*256 + 8))unpack buf[0,6,7,8]
valuepoke64 :: Word64 -> Buffer -> Offset -> IO ()
#
Example3 expressions
let buf = pack [1,2,3,4,5,6,7,8]unsafeWithByteString buf (poke64 (6*65536 + 7*256 + 8))unpack buf[0,0,0,0,0,6,7,8]

Peeking

6 declarations
valuepeek8 :: Buffer -> Offset -> IO Word8
#
Example2 expressions
let buf = pack [1,2,3,4]unsafeWithByteString buf peek81
valuepeek16 :: Buffer -> Offset -> IO Word16
#
Example2 expressions
let buf = pack [1,2,3,4]unsafeWithByteString buf peek16258
valuepeek24 :: Buffer -> Offset -> IO Word32
#
Example2 expressions
let buf = pack [1,2,3,4]unsafeWithByteString buf peek2466051
valuepeek32 :: Buffer -> Offset -> IO Word32
#
Example2 expressions
let buf = pack [1,2,3,4]unsafeWithByteString buf peek3216909060
valuepeek64 :: Buffer -> Offset -> IO Word64
#
Example2 expressions
let buf = pack [1,2,3,4,5,6,7,8]unsafeWithByteString buf peek6472623859790382856

From Word to ByteString

4 declarations
Example2 expressions
let w = foldl' (\x y -> x * 256 + y) 0 [5,6] :: Word16unpack $ bytestring16 w[5,6]
Example2 expressions
let w = foldl' (\x y -> x * 256 + y) 0 [5,6,7,8] :: Word32unpack $ bytestring32 w[5,6,7,8]
Example2 expressions
let w = foldl' (\x y -> x * 256 + y) 0 [1,2,3,4,5,6,7,8] :: Word64unpack $ bytestring64 w[1,2,3,4,5,6,7,8]

From ByteString to Word

4 declarations
valueword8 :: ByteString -> Word8
#
Example2 expressions
let buf = pack [1,2,3,4,5,6,7,8]word8 buf1
valueword32 :: ByteString -> Word32
#
Example2 expressions
let buf = pack [1,2,3,4,5,6,7,8]word32 buf16909060
valueword64 :: ByteString -> Word64
#
Example2 expressions
let buf = pack [1,2,3,4,5,6,7,8]word64 buf72623859790382856

Utilities

3 declarations
valuecopy :: Buffer -> ByteString -> IO Buffer
#

Copying the bytestring to the buffer. This function returns the point where the next copy should start.

Example2 expressions
let buf = "abc" :: ByteStringunsafeWithByteString buf $ \ptr _ -> Network.ByteOrder.copy ptr "ABC" >> return buf"ABC"
valuebufferIO :: Buffer -> Int -> (ByteString -> IO a) -> IO a
#

Converting the part of buffer to ByteString and executing the action with it.

Example2 expressions
let buf = "abcdef" :: ByteStringunsafeWithByteString buf $ \ptr _-> bufferIO ptr 2 return"ab"

Class to read a buffer

1 declaration
classclass Readable a where
#

Methods

Instances2Readable

Reading from buffer

9 declarations
newtypenewtype ReadBuffer
#

Read only buffer. To ensure that the internal is not modified, this is an abstract data type.

Instances1Readable
valueread16 :: Readable a => a -> IO Word16
#

Reading two bytes as Word16 and ff two bytes.

Example1 expression
withReadBuffer "\x0\x1\x2\x3" $ read161
valueread24 :: Readable a => a -> IO Word32
#

Reading three bytes as Word32 and ff three bytes.

Example1 expression
withReadBuffer "\x0\x1\x2\x3" $ read24258
valueread32 :: Readable a => a -> IO Word32
#

Reading four bytes as Word32 and ff four bytes.

Example1 expression
withReadBuffer "\x0\x1\x2\x3" $ read3266051
valueextractByteString :: Readable a => a -> Int -> IO ByteString
#

Extracting ByteString from the current offset. The contents is copied, not shared. Its length is specified by the 2nd argument. If the length is positive, the area after the current pointer is extracted and FF the length finally. If the length is negative, the area before the current pointer is extracted and does not FF.

Example1 expression
withReadBuffer "abcdefg" $ \rbuf -> ff rbuf 1 >> extractByteString rbuf 2"bc"

Extracting ShortByteString from the current offset. The contents is copied, not shared. Its length is specified by the 2nd argument. If the length is positive, the area after the current pointer is extracted and FF the length finally. If the length is negative, the area before the current pointer is extracted and does not FF.

Example1 expression
withReadBuffer "abcdefg" $ \rbuf -> ff rbuf 2 >> extractShortByteString rbuf 3"cde"

Writing to buffer

16 declarations
valuewrite8 :: WriteBuffer -> Word8 -> IO ()
#

Write one byte and ff one byte. If buffer overrun occurs, BufferOverrun is thrown.

Example1 expression
withWriteBuffer 1 $ \wbuf -> write8 wbuf 65"A"
valuewrite16 :: WriteBuffer -> Word16 -> IO ()
#

Write two bytes and ff one byte. If buffer overrun occurs, BufferOverrun is thrown.

Example1 expression
withWriteBuffer 2 $ \wbuf -> write16 wbuf (65 * 256 + 66)"AB"
valuewrite24 :: WriteBuffer -> Word32 -> IO ()
#

Write three bytes and ff one byte. If buffer overrun occurs, BufferOverrun is thrown.

Example1 expression
withWriteBuffer 3 $ \wbuf -> write24 wbuf (65 * 256^(2 :: Int) + 66 * 256 + 67)"ABC"
valuewrite32 :: WriteBuffer -> Word32 -> IO ()
#

Write four bytes and ff one byte. If buffer overrun occurs, BufferOverrun is thrown.

Example1 expression
withWriteBuffer 4 $ \wbuf -> write32 wbuf (65 * 256^(3 :: Int) + 66 * 256^(2 :: Int) + 67 * 256 + 68)"ABCD"
valueshiftLastN :: WriteBuffer -> Int -> Int -> IO ()
#

Shifting the N-bytes area just before the current pointer (the 3rd argument). If the second argument is positive, shift it to right. If it is negative, shift it to left. offset moves as if it is sticky to the area.

Example3 expressions
withWriteBuffer 16 $ \wbuf -> copyByteString wbuf "ABCD" >> shiftLastN wbuf 1 3"ABBCD"withWriteBuffer 16 $ \wbuf -> copyByteString wbuf "ABCD" >> shiftLastN wbuf 2 3"ABCBCD"withWriteBuffer 16 $ \wbuf -> copyByteString wbuf "ABCDE" >> shiftLastN wbuf (-2) 3 >> ff wbuf 2"CDEDE"

Re-exporting

5 declarations
datadata Word8
#

8-bit unsigned integer type

Instances20Bounded, Enum, Eq, Integral, Data, Num, …
  • Bounded Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Enum Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Eq Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Integral Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Data Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Data
  • Num Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Ord Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Read Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Real Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Show Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Ix Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Bits Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • FiniteBits Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Storable Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.Storable
  • PrintfArg Word8Defined in base-4.20.2.0 · Text.Printf
  • NFData Word8Defined in deepseq-1.5.0.0 · Control.DeepSeq
  • Lift Word8Defined in template-haskell-2.22.0.0 · Language.Haskell.TH.Syntax
  • IArray UArray Word8Defined in array-0.5.8.0 · Data.Array.Base
  • MArray IOUArray Word8 IODefined in array-0.5.8.0 · Data.Array.IO.Internals
  • MArray (STUArray s) Word8 (ST s)Defined in array-0.5.8.0 · Data.Array.Base
datadata Word16
#

16-bit unsigned integer type

Instances20Bounded, Enum, Eq, Integral, Data, Num, …
  • Bounded Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Enum Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Eq Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Integral Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Data Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Data
  • Num Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Ord Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Read Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Real Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Show Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Ix Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Bits Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • FiniteBits Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Storable Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.Storable
  • PrintfArg Word16Defined in base-4.20.2.0 · Text.Printf
  • NFData Word16Defined in deepseq-1.5.0.0 · Control.DeepSeq
  • Lift Word16Defined in template-haskell-2.22.0.0 · Language.Haskell.TH.Syntax
  • IArray UArray Word16Defined in array-0.5.8.0 · Data.Array.Base
  • MArray IOUArray Word16 IODefined in array-0.5.8.0 · Data.Array.IO.Internals
  • MArray (STUArray s) Word16 (ST s)Defined in array-0.5.8.0 · Data.Array.Base
datadata Word32
#

32-bit unsigned integer type

Instances21Bounded, Enum, Eq, Integral, Data, Num, …
  • Bounded Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Enum Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Eq Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Integral Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Data Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Data
  • Num Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Ord Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Read Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Real Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Show Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Ix Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Bits Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • FiniteBits Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Storable Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.Storable
  • PrintfArg Word32Defined in base-4.20.2.0 · Text.Printf
  • NFData Word32Defined in deepseq-1.5.0.0 · Control.DeepSeq
  • Mantissa Word32Defined in bytestring-0.12.2.0 · Data.ByteString.Builder.RealFloat.Internal
  • Lift Word32Defined in template-haskell-2.22.0.0 · Language.Haskell.TH.Syntax
  • IArray UArray Word32Defined in array-0.5.8.0 · Data.Array.Base
  • MArray IOUArray Word32 IODefined in array-0.5.8.0 · Data.Array.IO.Internals
  • MArray (STUArray s) Word32 (ST s)Defined in array-0.5.8.0 · Data.Array.Base
datadata Word64
#

64-bit unsigned integer type

Instances21Bounded, Enum, Eq, Integral, Data, Num, …
  • Bounded Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Enum Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Eq Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Integral Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Data Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Data
  • Num Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Ord Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Read Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Real Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Show Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Ix Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Bits Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • FiniteBits Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Storable Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.Storable
  • PrintfArg Word64Defined in base-4.20.2.0 · Text.Printf
  • NFData Word64Defined in deepseq-1.5.0.0 · Control.DeepSeq
  • Mantissa Word64Defined in bytestring-0.12.2.0 · Data.ByteString.Builder.RealFloat.Internal
  • Lift Word64Defined in template-haskell-2.22.0.0 · Language.Haskell.TH.Syntax
  • IArray UArray Word64Defined in array-0.5.8.0 · Data.Array.Base
  • MArray IOUArray Word64 IODefined in array-0.5.8.0 · Data.Array.IO.Internals
  • MArray (STUArray s) Word64 (ST s)Defined in array-0.5.8.0 · Data.Array.Base
datadata ByteString
#

A space-efficient representation of a Word8 vector, supporting many efficient operations.

A ByteString contains 8-bit bytes, or by using the operations from Data.ByteString.Char8 it can be interpreted as containing 8-bit characters.

Instances12IsList, Eq, Data, Ord, Read, Show, …
  • IsList ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • Eq ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • Data ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • Ord ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • Read ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • Show ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • IsString ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type

    Beware: fromString truncates multi-byte characters to octets. e.g. "枯朶に烏のとまりけり秋の暮" becomes �6k�nh~�Q��n�

  • Semigroup ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • Monoid ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • NFData ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • Lift ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • type Item ByteString = Word8Defined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type