packages feed

ip 0.2 → 0.3

raw patch · 2 files changed

+27/−1 lines, 2 files

Files

ip.cabal view
@@ -1,5 +1,5 @@ name:                ip-version:             0.2+version:             0.3 synopsis:            Library for IP and MAC addresses description:         Please see README.md homepage:            https://github.com/andrewthad/ip#readme
src/Net/Mac.hs view
@@ -12,6 +12,11 @@ import qualified Data.Attoparsec.ByteString.Char8 as AB import Data.Bits ((.&.),(.|.),shiftR,shiftL,complement) import Net.Internal (attoparsecParseJSON)+import qualified Data.Text.Lazy.Builder as TBuilder+import Data.Text.Lazy.Builder.Int (hexadecimal)+import Data.Monoid ((<>))+import qualified Data.Aeson as Aeson+import qualified Data.Text.Lazy as LText  data Mac = Mac   { macA :: {-# UNPACK #-} !Word16@@ -21,8 +26,29 @@  instance Hashable Mac +instance ToJSON Mac where+  toJSON = Aeson.String . toText+ instance FromJSON Mac where   parseJSON = attoparsecParseJSON (textParser <* AT.endOfInput)++toText :: Mac -> Text+toText = LText.toStrict . TBuilder.toLazyText . toTextBuilder++toTextBuilder :: Mac -> TBuilder.Builder+toTextBuilder (Mac a b) = +  hexadecimal (255 .&. shiftR a 8 )+  <> colon+  <> hexadecimal (255 .&. a )+  <> colon+  <> hexadecimal (255 .&. shiftR b 24 )+  <> colon+  <> hexadecimal (255 .&. shiftR b 16 )+  <> colon+  <> hexadecimal (255 .&. shiftR b 8 )+  <> colon+  <> hexadecimal (255 .&. b)+  where colon = TBuilder.singleton ':'  -- | This does not do an endOfInput check textParser :: AT.Parser Mac