messagepack 0.1.0.0 → 0.1.1
raw patch · 5 files changed
+65/−36 lines, 5 files
Files
- CHANGELOG +5/−0
- Data/MessagePack.hs +26/−11
- README.md +7/−0
- messagepack.cabal +18/−16
- tests/Main.hs +9/−9
+ CHANGELOG view
@@ -0,0 +1,5 @@+2014-07-25 Rodrigo Setti <rodrigosetti@gmail.com>++ * Initial version: Serialize instances tested for consistency.+ * Missing: Extension types+
Data/MessagePack.hs view
@@ -1,3 +1,18 @@+{-|+Module : Data.MessagePack+Description : Object data type with Serialize instances for it+Copyright : (c) Rodrigo Setti, 2014+License : MIT+Maintainer : rodrigosetti@gmail.com+Stability : experimental+Portability : portable++@Object@ is a message pack object, and it have constructors for all message+pack types.++The @Serialize@ instances define how Object values may be serialized and+deserialized to message pack binary format, following the specification.+-} module Data.MessagePack where import Control.Applicative@@ -45,7 +60,7 @@ put (ObjectDouble d) = putWord8 float64 >> putFloat64be d put (ObjectString t) =- header >> mapM_ put (BS.unpack bytes)+ header >> putByteString bytes where bytes = encodeUtf8 t size = BS.length bytes@@ -55,10 +70,10 @@ | size < 0x10000 = putWord8 str16 >> putWord16be (fromIntegral size) | otherwise = putWord8 str32 >> putWord32be (fromIntegral size) - put (ObjectBinary b) =- header >> mapM_ put (BS.unpack b)+ put (ObjectBinary bytes) =+ header >> putByteString bytes where- size = BS.length b+ size = BS.length bytes header | size < 0x100 = putWord8 bin8 >> putWord8 (fromIntegral size) | size < 0x10000 = putWord8 bin16 >> putWord16be (fromIntegral size)@@ -91,11 +106,11 @@ | k == true = return $ ObjectBool True | k == bin8 = do n <- fromIntegral <$> getWord8- ObjectBinary <$> getBytes n+ ObjectBinary <$> getByteString n | k == bin16 = do n <- fromIntegral <$> getWord16be- ObjectBinary <$> getBytes n+ ObjectBinary <$> getByteString n | k == bin32 = do n <- fromIntegral <$> getWord32be- ObjectBinary <$> getBytes n+ ObjectBinary <$> getByteString n | k == float32 = ObjectFloat <$> getFloat32be | k == float64 = ObjectDouble <$> getFloat64be@@ -112,13 +127,13 @@ | k == int64 = ObjectInt <$> fromIntegral <$> (get :: Get Int64) | k .&. fixstrMask == fixstr = let n = fromIntegral $ k .&. complement fixstrMask- in ObjectString <$> decodeUtf8 <$> getBytes n+ in ObjectString <$> decodeUtf8 <$> getByteString n | k == str8 = do n <- fromIntegral <$> getWord8- ObjectString <$> decodeUtf8 <$> getBytes n+ ObjectString <$> decodeUtf8 <$> getByteString n | k == str16 = do n <- fromIntegral <$> getWord16be- ObjectString <$> decodeUtf8 <$> getBytes n+ ObjectString <$> decodeUtf8 <$> getByteString n | k == str32 = do n <- fromIntegral <$> getWord32be- ObjectString <$> decodeUtf8 <$> getBytes n+ ObjectString <$> decodeUtf8 <$> getByteString n | k .&. fixarrayMask == fixarray = let n = fromIntegral $ k .&. complement fixarrayMask in ObjectArray <$> replicateM n get
+ README.md view
@@ -0,0 +1,7 @@+# messagepack++[](https://travis-ci.org/rodrigosetti/messagepack)++[Serialize](http://hackage.haskell.org/package/cereal) instance for+[Message Pack](http://msgpack.org) Object.+
messagepack.cabal view
@@ -1,19 +1,21 @@-name : messagepack-version : 0.1.0.0-synopsis : Serialize instance for Message Pack Object-description : Serialize instance for Message Pack Object-homepage : https://github.com/rodrigosetti/messagepack-license : MIT-license-file : LICENSE-author : Rodrigo Setti-stability : experimental-bug-reports : https://github.com/rodrigosetti/messagepack/issues-package-url : https://github.com/rodrigosetti/messagepack/archive/master.zip-maintainer : rodrigosetti@gmail.com-copyright : (c) 2014 Rodrigo Setti-category : Data-build-type : Simple-cabal-version : >=1.10+name : messagepack+version : 0.1.1+synopsis : Serialize instance for Message Pack Object+description : Serialize instance for Message Pack Object+homepage : https://github.com/rodrigosetti/messagepack+license : MIT+license-file : LICENSE+author : Rodrigo Setti+stability : experimental+bug-reports : https://github.com/rodrigosetti/messagepack/issues+package-url : https://github.com/rodrigosetti/messagepack/archive/master.zip+maintainer : rodrigosetti@gmail.com+copyright : (c) 2014 Rodrigo Setti+category : Data+build-type : Simple+cabal-version : >=1.10+extra-source-files : CHANGELOG+ , README.md source-repository head type : git
tests/Main.hs view
@@ -15,15 +15,15 @@ main = $(defaultMainGenerator) instance Arbitrary Object where- arbitrary = resize 6 $ oneof [ return ObjectNil- , ObjectInt <$> arbitrary- , ObjectBool <$> arbitrary- , ObjectFloat <$> arbitrary- , ObjectDouble <$> arbitrary- , ObjectString <$> arbitrary- , ObjectBinary <$> arbitrary- , ObjectArray <$> arbitrary- , ObjectMap <$> arbitrary ]+ arbitrary = sized $ \n -> oneof [ return ObjectNil+ , ObjectInt <$> arbitrary+ , ObjectBool <$> arbitrary+ , ObjectFloat <$> arbitrary+ , ObjectDouble <$> arbitrary+ , ObjectString <$> arbitrary+ , ObjectBinary <$> arbitrary+ , ObjectArray <$> resize (3 * n `quot` 4) arbitrary+ , ObjectMap <$> resize (3 * n `quot` 4) arbitrary ] shrink (ObjectString s) = map ObjectString $ shrink s shrink (ObjectBinary b) = map ObjectBinary $ shrink b