| Copyright | (c) Dong Han 2017-2018 |
|---|---|
| License | BSD |
| Maintainer | winterland1989@gmail.com |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Z.Data.Vector.Hex
Description
This module provides hex encoding & decoding tools, as well as HexBytes newtype with hex textual instances.
Synopsis
- newtype HexBytes = HexBytes {
- unHexBytes :: Bytes
- hexEncode :: Bool -> Bytes -> Bytes
- hexEncodeText :: Bool -> Bytes -> Text
- hexEncodeBuilder :: Bool -> Bytes -> Builder ()
- hexDecode :: Bytes -> Maybe Bytes
- hexDecode' :: HasCallStack => Bytes -> Bytes
- hexDecodeWS :: Bytes -> Maybe Bytes
- hexDecodeWS' :: HasCallStack => Bytes -> Bytes
- data HexDecodeException
- hs_hex_encode :: MBA# Word8 -> Int -> BA# Word8 -> Int -> Int -> IO ()
- hs_hex_encode_upper :: MBA# Word8 -> Int -> BA# Word8 -> Int -> Int -> IO ()
- hs_hex_decode :: MBA# Word8 -> BA# Word8 -> Int -> Int -> IO Int
The HexBytes type
New type wrapper for Bytes with hex encoding(uppercase) Show/JSON instances.
Constructors
| HexBytes | |
Fields
| |
Encoding & Decoding functions
Encode Bytes using hex(base16) encoding.
hexDecode :: Bytes -> Maybe Bytes Source #
Decode a hex encoding string, return Nothing on illegal bytes or incomplete input.
hexDecode' :: HasCallStack => Bytes -> Bytes Source #
Decode a hex encoding string, throw HexDecodeException on error.
hexDecodeWS :: Bytes -> Maybe Bytes Source #
Decode a hex encoding string, ignore ASCII whitespace(space, tab, newline, vertical tab, form feed, carriage return).
This is useful when you get some hex nibbles by pasting from web, note only whitesapces between bytes(two nibbles) are allowed:
>>>hexDecodeWS "6f7481 da0e53"Just [111,116,129,218,14,83]>>>hexDecodeWS "6f7481d a0e53"Nothing
hexDecodeWS' :: HasCallStack => Bytes -> Bytes Source #
Decode a hex encoding string, ignore ASCII whitespace(space, tab, newline, vertical tab, form feed, carriage return), throw HexDecodeException on error.
data HexDecodeException Source #
Exception during hex decoding.
Constructors
| IllegalHexBytes Bytes CallStack | |
| IncompleteHexBytes Bytes CallStack |
Instances
| Exception HexDecodeException Source # | |
Defined in Z.Data.Vector.Hex Methods toException :: HexDecodeException -> SomeException # fromException :: SomeException -> Maybe HexDecodeException # | |
| Show HexDecodeException Source # | |
Defined in Z.Data.Vector.Hex Methods showsPrec :: Int -> HexDecodeException -> ShowS # show :: HexDecodeException -> String # showList :: [HexDecodeException] -> ShowS # | |