-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Library for encoding/decoding TNET strings for PGI -- -- Provides an API to encode/decode Haskell datatypes into the TNET -- protocol. @package tnet @version 0.0.1 -- | TNET is a library that implements the TNET serialization -- protocol to be used for PGI -- (http://code.google.com/p/polyweb/source/browse/doc/PGI.txt) -- applications. The TNET protocol (http://tnetstrings.org) is -- designed to be simple to implement in any language, please look at the -- README for the changes to the original tnetstrings spec. module TNET tnetParser :: Parser TValue -- | The TNET typeclass represents types that can be encoded and -- decoded in the TNET format. An example instance: -- --
--   data Person = Person {
--                   name :: String
--                 , age  :: Integer
--                 }
--   instance TNET Person where
--     toTNET (Person n a) = dict [ "name" .= n
--                                , "age"  .= a
--                                ]
--     fromTNET tval = do
--       n <- tval .: "name"
--       a <- tval .: "age"
--       return $ Person n a
--   
class TNET a toTNET :: TNET a => a -> TValue fromTNET :: TNET a => TValue -> Maybe a -- | A TValue represents a raw TNET object. TNET values are one of -- the following types: -- -- data TValue -- | Decode a TNET format bytestring into a Haskell value. An explicit type -- annotation may be needed if the type of the decoded value can not be -- determined: -- --
--   >>> decode "0:~" :: Maybe ()
--   Just ()
--   
-- --
--   >>> decode "0:~" :: Maybe (Maybe String)
--   Just Nothing
--   
-- --
--   >>> decode "1:5#" :: Maybe Integer
--   Just 5
--   
-- --
--   let x = decode "4:true!" in
--   case x of
--     Just True  -> putStrLn "got true!"
--     Just False -> putStrLn "got false!"
--     Nothing    -> putStrLn "error decoding"
--   
decode :: TNET a => ByteString -> Maybe a -- | Encode a Haskell value into the TNET format. Some examples: -- --
--   >>> encode 5
--   "1:5#"
--   
-- --
--   >>> encode "Hello"
--   "5:Hello$"
--   
-- --
--   >>> encode (-12.3)
--   "5:-12.3^"
--   
-- --
--   >>> encode ()
--   "0:~"
--   
encode :: TNET a => a -> ByteString -- | Used to create a TNET dictionary from TNET values. Meant to be used -- with the .= operator as in the following example: -- --
--   myDict = dict [ "a" .= 5
--                 , "is_dict" .= True
--                 ]
--   
dict :: [(String, TValue)] -> TValue (.=) :: TNET a => String -> a -> (String, TValue) -- | Helper function to extract TNET values from a TNET dictionary. Meant -- to be used as in the following example: -- --
--   data Person = Person {
--                   name :: String
--                 , age  :: Integer
--                 }
--   personFromDict :: TValue -> Maybe Person
--   personFromDict tdict = do
--     name <- tdict .: "name"
--     age  <- tdict .: "age"
--     return $ Person name age
--   
(.:) :: TNET a => TValue -> String -> Maybe a instance [overlap ok] Eq TValue instance [overlap ok] Show TValue instance [overlap ok] TNET a => TNET [a] instance [overlap ok] TNET a => TNET (Maybe a) instance [overlap ok] TNET ByteString instance [overlap ok] TNET Char instance [overlap ok] TNET String instance [overlap ok] TNET a => TNET [(String, a)] instance [overlap ok] TNET Bool instance [overlap ok] TNET Double instance [overlap ok] TNET Integer instance [overlap ok] TNET TValue instance [overlap ok] TNET ()