-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Network byte order utilities -- -- Peek and poke functions for network byte order. @package network-byte-order @version 0.1.2.0 -- | Peek and poke functions for network byte order. module Network.ByteOrder -- | A pointer to Word8. type Buffer = Ptr Word8 -- | Offset from the current pointer. type Offset = Int -- | Size of a buffer. type BufferSize = Int -- | Buffer overrun exception. data BufferOverrun -- | The buffer size is not enough BufferOverrun :: BufferOverrun -- |
--   >>> let buf = pack [1,2,3,4]
--   
--   >>> unsafeWithByteString buf (poke8 0)
--   
--   >>> unpack buf
--   [0,2,3,4]
--   
poke8 :: Word8 -> Buffer -> Offset -> IO () -- |
--   >>> let buf = pack [1,2,3,4]
--   
--   >>> unsafeWithByteString buf (poke16 (7*256 + 8))
--   
--   >>> unpack buf
--   [7,8,3,4]
--   
poke16 :: Word16 -> Buffer -> Offset -> IO () -- |
--   >>> let buf = pack [1,2,3,4]
--   
--   >>> unsafeWithByteString buf (poke24 (6*65536 + 7*256 + 8))
--   
--   >>> unpack buf
--   [6,7,8,4]
--   
poke24 :: Word32 -> Buffer -> Offset -> IO () -- |
--   >>> let buf = pack [1,2,3,4]
--   
--   >>> unsafeWithByteString buf (poke32 (6*65536 + 7*256 + 8))
--   
--   >>> unpack buf
--   [0,6,7,8]
--   
poke32 :: Word32 -> Buffer -> Offset -> IO () -- |
--   >>> 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]
--   
poke64 :: Word64 -> Buffer -> Offset -> IO () -- |
--   >>> let buf = pack [1,2,3,4]
--   
--   >>> unsafeWithByteString buf peek8
--   1
--   
peek8 :: Buffer -> Offset -> IO Word8 -- |
--   >>> let buf = pack [1,2,3,4]
--   
--   >>> unsafeWithByteString buf peek16
--   258
--   
peek16 :: Buffer -> Offset -> IO Word16 -- |
--   >>> let buf = pack [1,2,3,4]
--   
--   >>> unsafeWithByteString buf peek24
--   66051
--   
peek24 :: Buffer -> Offset -> IO Word32 -- |
--   >>> let buf = pack [1,2,3,4]
--   
--   >>> unsafeWithByteString buf peek32
--   16909060
--   
peek32 :: Buffer -> Offset -> IO Word32 -- |
--   >>> let buf = pack [1,2,3,4,5,6,7,8]
--   
--   >>> unsafeWithByteString buf peek64
--   72623859790382856
--   
peek64 :: Buffer -> Offset -> IO Word64 peekByteString :: Buffer -> Int -> IO ByteString -- |
--   >>> let w = 5 :: Word8
--   
--   >>> unpack $ bytestring8 w
--   [5]
--   
bytestring8 :: Word8 -> ByteString -- |
--   >>> let w = foldl' (\x y -> x * 256 + y) 0 [5,6] :: Word16
--   
--   >>> unpack $ bytestring16 w
--   [5,6]
--   
bytestring16 :: Word16 -> ByteString -- |
--   >>> let w = foldl' (\x y -> x * 256 + y) 0 [5,6,7,8] :: Word32
--   
--   >>> unpack $ bytestring32 w
--   [5,6,7,8]
--   
bytestring32 :: Word32 -> ByteString -- |
--   >>> let w = foldl' (\x y -> x * 256 + y) 0 [1,2,3,4,5,6,7,8] :: Word64
--   
--   >>> unpack $ bytestring64 w
--   [1,2,3,4,5,6,7,8]
--   
bytestring64 :: Word64 -> ByteString -- |
--   >>> let buf = pack [1,2,3,4,5,6,7,8]
--   
--   >>> word8 buf
--   1
--   
word8 :: ByteString -> Word8 -- |
--   >>> let buf = pack [1,2,3,4,5,6,7,8]
--   
--   >>> word16 buf
--   258
--   
word16 :: ByteString -> Word16 -- |
--   >>> let buf = pack [1,2,3,4,5,6,7,8]
--   
--   >>> word32 buf
--   16909060
--   
word32 :: ByteString -> Word32 -- |
--   >>> let buf = pack [1,2,3,4,5,6,7,8]
--   
--   >>> word64 buf
--   72623859790382856
--   
word64 :: ByteString -> Word64 -- | Using ByteString as Buffer and call the IO action -- of the second argument by passing the start point and the offset of -- the ByteString. Note that if a ByteString is created -- newly, its offset is 0. unsafeWithByteString :: ByteString -> (Buffer -> Offset -> IO a) -> IO a -- | Copying the bytestring to the buffer. This function returns the point -- where the next copy should start. copy :: Buffer -> ByteString -> IO Buffer bufferIO :: Buffer -> Int -> (ByteString -> IO a) -> IO a class Readable a -- | Reading one byte as Word8 and ff one byte. read8 :: Readable a => a -> IO Word8 -- | Reading one byte as Int and ff one byte. If buffer overrun -- occurs, -1 is returned. readInt8 :: Readable a => a -> IO Int -- | Fast forward the offset pointer. The boundary is not checked. ff :: Readable a => a -> Offset -> IO () -- | Returning the length of the remaining remainingSize :: Readable a => a -> IO Int -- | Executing an action on the current offset pointer. withCurrentOffSet :: Readable a => a -> (Buffer -> IO b) -> IO b -- | Memorizing the current offset pointer. save :: Readable a => a -> IO () -- | Getting how many bytes from the saved offset pinter. savingSize :: Readable a => a -> IO Int -- | Read only buffer. To ensure that the internal is not modified, this is -- an abstract data type. data ReadBuffer -- | Converting ByteString to ReadBuffer and run the action -- with it. withReadBuffer :: ByteString -> (ReadBuffer -> IO a) -> IO a -- | Reading two bytes as Word16 and ff two bytes. read16 :: Readable a => a -> IO Word16 -- | Reading three bytes as Word32 and ff three bytes. read24 :: Readable a => a -> IO Word32 -- | Reading four bytes as Word32 and ff four bytes. read32 :: Readable a => a -> IO Word32 -- | 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. extractByteString :: Readable a => a -> Int -> IO ByteString -- | 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. extractShortByteString :: Readable a => a -> Int -> IO ShortByteString -- | Read and write buffer. data WriteBuffer WriteBuffer :: !Buffer -> !Buffer -> !IORef Buffer -> !IORef Buffer -> WriteBuffer [start] :: WriteBuffer -> !Buffer [limit] :: WriteBuffer -> !Buffer [offset] :: WriteBuffer -> !IORef Buffer [oldoffset] :: WriteBuffer -> !IORef Buffer -- | Creating a write buffer with the given buffer. newWriteBuffer :: Buffer -> BufferSize -> IO WriteBuffer -- | Allocate a temporary buffer and copy the result to ByteString. withWriteBuffer :: BufferSize -> (WriteBuffer -> IO ()) -> IO ByteString -- | Write one byte and ff one byte. If buffer overrun occurs, -- BufferOverrun is thrown. write8 :: WriteBuffer -> Word8 -> IO () -- | Write two bytes and ff one byte. If buffer overrun occurs, -- BufferOverrun is thrown. write16 :: WriteBuffer -> Word16 -> IO () -- | Write three bytes and ff one byte. If buffer overrun occurs, -- BufferOverrun is thrown. write24 :: WriteBuffer -> Word32 -> IO () -- | Write four bytes and ff one byte. If buffer overrun occurs, -- BufferOverrun is thrown. write32 :: WriteBuffer -> Word32 -> IO () -- | Copy the content of ByteString and ff its length. If buffer -- overrun occurs, BufferOverrun is thrown. copyByteString :: WriteBuffer -> ByteString -> IO () -- | Copy the content of ShortByteString and ff its length. If -- buffer overrun occurs, BufferOverrun is thrown. copyShortByteString :: WriteBuffer -> ShortByteString -> IO () -- | Shifting the N-bytes area just before the current pointer. -- Offset is the distance from the offset pointer. If -- Offset is positive, shift it to right. If Offset is -- negative, shift it to left. shiftLastN :: WriteBuffer -> Offset -> Int -> IO () -- | Copy the area from start to the current pointer to -- ByteString. toByteString :: WriteBuffer -> IO ByteString -- | Copy the area from start to the current pointer to -- ShortByteString. toShortByteString :: WriteBuffer -> IO ShortByteString -- | Getting the offset pointer. currentOffset :: WriteBuffer -> IO Buffer -- | 8-bit unsigned integer type data Word8 -- | 16-bit unsigned integer type data Word16 -- | 32-bit unsigned integer type data Word32 -- | 64-bit unsigned integer type data Word64 -- | 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. data ByteString instance GHC.Show.Show Network.ByteOrder.BufferOverrun instance GHC.Classes.Eq Network.ByteOrder.BufferOverrun instance GHC.Exception.Type.Exception Network.ByteOrder.BufferOverrun instance Network.ByteOrder.Readable Network.ByteOrder.ReadBuffer instance Network.ByteOrder.Readable Network.ByteOrder.WriteBuffer