A pointer to Word8.
Modulenetwork-byte-order-0.1.7Haskell2010
Network.ByteOrder
Peek and poke functions for network byte order.
- 11 types
- 1 class
- 45 values
- Packagenetwork-byte-order-0.1.7
- Exports57
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceByteOrder.hs
Types
4 declarationsOffset from the current pointer.
Size of a buffer.
Buffer overrun exception.
Constructors
BufferOverrunThe buffer size is not enough
Instances3Eq, Show, Exception
Eq BufferOverrunDefined in network-byte-order-0.1.7 · Network.ByteOrderShow BufferOverrunDefined in network-byte-order-0.1.7 · Network.ByteOrderException BufferOverrunDefined in network-byte-order-0.1.7 · Network.ByteOrder
Poking
5 declarationslet buf = pack [1,2,3,4]unsafeWithByteString buf (poke8 0)unpack buf[0,2,3,4]
let buf = pack [1,2,3,4]unsafeWithByteString buf (poke16 (7*256 + 8))unpack buf[7,8,3,4]
let buf = pack [1,2,3,4]unsafeWithByteString buf (poke24 (6*65536 + 7*256 + 8))unpack buf[6,7,8,4]
let buf = pack [1,2,3,4]unsafeWithByteString buf (poke32 (6*65536 + 7*256 + 8))unpack buf[0,6,7,8]
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 declarationslet buf = pack [1,2,3,4]unsafeWithByteString buf peek81
let buf = pack [1,2,3,4]unsafeWithByteString buf peek16258
let buf = pack [1,2,3,4]unsafeWithByteString buf peek2466051
let buf = pack [1,2,3,4]unsafeWithByteString buf peek3216909060
let buf = pack [1,2,3,4,5,6,7,8]unsafeWithByteString buf peek6472623859790382856
From Word to ByteString
4 declarationslet w = 5 :: Word8unpack $ bytestring8 w[5]
let w = foldl' (\x y -> x * 256 + y) 0 [5,6] :: Word16unpack $ bytestring16 w[5,6]
let w = foldl' (\x y -> x * 256 + y) 0 [5,6,7,8] :: Word32unpack $ bytestring32 w[5,6,7,8]
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 declarationslet buf = pack [1,2,3,4,5,6,7,8]word8 buf1
let buf = pack [1,2,3,4,5,6,7,8]word16 buf258
let buf = pack [1,2,3,4,5,6,7,8]word32 buf16909060
let buf = pack [1,2,3,4,5,6,7,8]word64 buf72623859790382856
Utilities
3 declarationsUsing 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.
Copying the bytestring to the buffer. This function returns the point where the next copy should start.
let buf = "abc" :: ByteStringunsafeWithByteString buf $ \ptr _ -> Network.ByteOrder.copy ptr "ABC" >> return buf"ABC"
Converting the part of buffer to ByteString and executing the action with it.
let buf = "abcdef" :: ByteStringunsafeWithByteString buf $ \ptr _-> bufferIO ptr 2 return"ab"
Class to read a buffer
1 declarationMethods
read8 :: a -> IO Word8Reading one byte as Word8 and ff one byte.
readInt8 :: a -> IO IntReading one byte as Int and ff one byte. If buffer overrun occurs, -1 is returned.
ff :: a -> Offset -> IO ()Fast forward the offset pointer. The boundary is not checked.
remainingSize :: a -> IO IntReturning the length of the remaining
position :: a -> IO IntExecuting an action on the current offset pointer.
withCurrentOffSet :: a -> (Buffer -> IO b) -> IO bsave :: a -> IO ()Memorizing the current offset pointer.
savingSize :: a -> IO IntGetting how many bytes from the saved offset pinter.
goBack :: a -> IO ()Moving the offset point to the saved point.
Instances2Readable
Readable ReadBufferDefined in network-byte-order-0.1.7 · Network.ByteOrderReadable WriteBufferDefined in network-byte-order-0.1.7 · Network.ByteOrder
Reading from buffer
9 declarationsRead only buffer. To ensure that the internal is not modified, this is an abstract data type.
Instances1Readable
Readable ReadBufferDefined in network-byte-order-0.1.7 · Network.ByteOrder
Creating a read buffer with the given buffer.
Converting ByteString to ReadBuffer and run the action with it.
Reading two bytes as Word16 and ff two bytes.
withReadBuffer "\x0\x1\x2\x3" $ read161
Reading three bytes as Word32 and ff three bytes.
withReadBuffer "\x0\x1\x2\x3" $ read24258
Reading four bytes as Word32 and ff four bytes.
withReadBuffer "\x0\x1\x2\x3" $ read3266051
Reading four bytes as Word64 and ff four bytes.
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.
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.
withReadBuffer "abcdefg" $ \rbuf -> ff rbuf 2 >> extractShortByteString rbuf 3"cde"
Writing to buffer
16 declarationsRead and write buffer.
Instances1Readable
Readable WriteBufferDefined in network-byte-order-0.1.7 · Network.ByteOrder
Creating a write buffer with the given buffer.
Reseting a write buffer.
Allocate a temporary buffer and copy the result to ByteString.
Allocate a temporary buffer and copy the result to ByteString with an additional value.
withWriteBuffer' 1 $ \wbuf -> write8 wbuf 65 >> return 'a'("A",'a')
Write one byte and ff one byte. If buffer overrun occurs, BufferOverrun is thrown.
withWriteBuffer 1 $ \wbuf -> write8 wbuf 65"A"
Write two bytes and ff one byte. If buffer overrun occurs, BufferOverrun is thrown.
withWriteBuffer 2 $ \wbuf -> write16 wbuf (65 * 256 + 66)"AB"
Write three bytes and ff one byte. If buffer overrun occurs, BufferOverrun is thrown.
withWriteBuffer 3 $ \wbuf -> write24 wbuf (65 * 256^(2 :: Int) + 66 * 256 + 67)"ABC"
Write four bytes and ff one byte. If buffer overrun occurs, BufferOverrun is thrown.
withWriteBuffer 4 $ \wbuf -> write32 wbuf (65 * 256^(3 :: Int) + 66 * 256^(2 :: Int) + 67 * 256 + 68)"ABCD"
Write four bytes and ff one byte. If buffer overrun occurs, BufferOverrun is thrown.
Copy the content of ByteString and ff its length. If buffer overrun occurs, BufferOverrun is thrown.
withWriteBuffer 3 $ \wbuf -> copyByteString wbuf "ABC""ABC"
Copy the content of ShortByteString and ff its length. If buffer overrun occurs, BufferOverrun is thrown.
withWriteBuffer 5 $ \wbuf -> copyShortByteString wbuf "ABCEF""ABCEF"
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.
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"
Copy the area from start to the current pointer to ByteString.
Copy the area from start to the current pointer to ShortByteString.
Getting the offset pointer.
Re-exporting
5 declarations8-bit unsigned integer type
Instances20Bounded, Enum, Eq, Integral, Data, Num, …
Bounded Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.WordEnum Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.WordEq Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.WordIntegral Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.WordData Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.DataNum Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.WordOrd Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.WordRead Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.ReadReal Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.WordShow Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.WordIx Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.WordBits Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.WordFiniteBits Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.WordStorable Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorablePrintfArg Word8Defined in base-4.20.2.0 · Text.PrintfNFData Word8Defined in deepseq-1.5.0.0 · Control.DeepSeqLift Word8Defined in template-haskell-2.22.0.0 · Language.Haskell.TH.SyntaxIArray UArray Word8Defined in array-0.5.8.0 · Data.Array.BaseMArray IOUArray Word8 IODefined in array-0.5.8.0 · Data.Array.IO.InternalsMArray (STUArray s) Word8 (ST s)Defined in array-0.5.8.0 · Data.Array.Base
16-bit unsigned integer type
Instances20Bounded, Enum, Eq, Integral, Data, Num, …
Bounded Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.WordEnum Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.WordEq Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.WordIntegral Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.WordData Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.DataNum Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.WordOrd Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.WordRead Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.ReadReal Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.WordShow Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.WordIx Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.WordBits Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.WordFiniteBits Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.WordStorable Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorablePrintfArg Word16Defined in base-4.20.2.0 · Text.PrintfNFData Word16Defined in deepseq-1.5.0.0 · Control.DeepSeqLift Word16Defined in template-haskell-2.22.0.0 · Language.Haskell.TH.SyntaxIArray UArray Word16Defined in array-0.5.8.0 · Data.Array.BaseMArray IOUArray Word16 IODefined in array-0.5.8.0 · Data.Array.IO.InternalsMArray (STUArray s) Word16 (ST s)Defined in array-0.5.8.0 · Data.Array.Base
32-bit unsigned integer type
Instances21Bounded, Enum, Eq, Integral, Data, Num, …
Bounded Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.WordEnum Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.WordEq Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.WordIntegral Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.WordData Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.DataNum Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.WordOrd Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.WordRead Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.ReadReal Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.WordShow Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.WordIx Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.WordBits Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.WordFiniteBits Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.WordStorable Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorablePrintfArg Word32Defined in base-4.20.2.0 · Text.PrintfNFData Word32Defined in deepseq-1.5.0.0 · Control.DeepSeqMantissa Word32Defined in bytestring-0.12.2.0 · Data.ByteString.Builder.RealFloat.InternalLift Word32Defined in template-haskell-2.22.0.0 · Language.Haskell.TH.SyntaxIArray UArray Word32Defined in array-0.5.8.0 · Data.Array.BaseMArray IOUArray Word32 IODefined in array-0.5.8.0 · Data.Array.IO.InternalsMArray (STUArray s) Word32 (ST s)Defined in array-0.5.8.0 · Data.Array.Base
64-bit unsigned integer type
Instances21Bounded, Enum, Eq, Integral, Data, Num, …
Bounded Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.WordEnum Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.WordEq Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.WordIntegral Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.WordData Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.DataNum Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.WordOrd Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.WordRead Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.ReadReal Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.WordShow Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.WordIx Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.WordBits Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.WordFiniteBits Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.WordStorable Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorablePrintfArg Word64Defined in base-4.20.2.0 · Text.PrintfNFData Word64Defined in deepseq-1.5.0.0 · Control.DeepSeqMantissa Word64Defined in bytestring-0.12.2.0 · Data.ByteString.Builder.RealFloat.InternalLift Word64Defined in template-haskell-2.22.0.0 · Language.Haskell.TH.SyntaxIArray UArray Word64Defined in array-0.5.8.0 · Data.Array.BaseMArray IOUArray Word64 IODefined in array-0.5.8.0 · Data.Array.IO.InternalsMArray (STUArray s) Word64 (ST s)Defined in array-0.5.8.0 · Data.Array.Base
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.TypeEq ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.TypeData ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.TypeOrd ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.TypeRead ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.TypeShow ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.TypeIsString ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.TypeBeware: 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.TypeMonoid ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.TypeNFData ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.TypeLift ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Typetype Item ByteString = Word8Defined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type