Copyright | (c) Hideyuki Tanaka, 2009 |
---|---|
License | BSD3 |
Maintainer | tanaka.hideyuki@gmail.com |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell98 |
Low Level Interface to MessagePack C API
- type SimpleBuffer = ForeignPtr ()
- newSimpleBuffer :: IO SimpleBuffer
- simpleBufferData :: SimpleBuffer -> IO ByteString
- type Packer = ForeignPtr ()
- newPacker :: SimpleBuffer -> IO Packer
- packU8 :: Packer -> Word8 -> IO Int
- packU16 :: Packer -> Word16 -> IO Int
- packU32 :: Packer -> Word32 -> IO Int
- packU64 :: Packer -> Word64 -> IO Int
- packS8 :: Packer -> Int8 -> IO Int
- packS16 :: Packer -> Int16 -> IO Int
- packS32 :: Packer -> Int32 -> IO Int
- packS64 :: Packer -> Int64 -> IO Int
- packTrue :: Packer -> IO Int
- packFalse :: Packer -> IO Int
- packInt :: Integral a => Packer -> a -> IO Int
- packDouble :: Packer -> Double -> IO Int
- packNil :: Packer -> IO Int
- packBool :: Packer -> Bool -> IO Int
- packArray :: Packer -> Int -> IO Int
- packMap :: Packer -> Int -> IO Int
- packRAW :: Packer -> Int -> IO Int
- packRAWBody :: Packer -> ByteString -> IO Int
- packRAW' :: Packer -> ByteString -> IO Int
- type Unpacker = ForeignPtr ()
- defaultInitialBufferSize :: Int
- newUnpacker :: Int -> IO Unpacker
- unpackerReserveBuffer :: Unpacker -> Int -> IO Bool
- unpackerBuffer :: Unpacker -> IO (Ptr CChar)
- unpackerBufferCapacity :: Unpacker -> IO Int
- unpackerBufferConsumed :: Unpacker -> Int -> IO ()
- unpackerFeed :: Unpacker -> ByteString -> IO ()
- unpackerExecute :: Unpacker -> IO Int
- unpackerData :: Unpacker -> IO Object
- unpackerReleaseZone :: Unpacker -> IO Zone
- unpackerResetZone :: Unpacker -> IO ()
- unpackerReset :: Unpacker -> IO ()
- unpackerMessageSize :: Unpacker -> IO Int
- data Object
- packObject :: Packer -> Object -> IO ()
- data UnpackReturn
- unpackObject :: Zone -> ByteString -> IO (Either UnpackReturn (Int, Object))
- type Zone = Ptr ()
- newZone :: IO Zone
- freeZone :: Zone -> IO ()
- withZone :: (Zone -> IO a) -> IO a
Simple Buffer
type SimpleBuffer = ForeignPtr () Source
newSimpleBuffer :: IO SimpleBuffer Source
Create a new Simple Buffer. It will be deleted automatically.
simpleBufferData :: SimpleBuffer -> IO ByteString Source
Get data of Simple Buffer.
Serializer
type Packer = ForeignPtr () Source
newPacker :: SimpleBuffer -> IO Packer Source
Create new Packer. It will be deleted automatically.
packArray :: Packer -> Int -> IO Int Source
packArray
p n
starts packing an array.
Next n
data will consist this array.
packMap :: Packer -> Int -> IO Int Source
packMap
p n
starts packing a map.
Next n
pairs of data (2*n data) will consist this map.
packRAW :: Packer -> Int -> IO Int Source
packRAW
p n
starts packing a byte sequence.
Next total n
bytes of packRAWBody
call will consist this sequence.
packRAWBody :: Packer -> ByteString -> IO Int Source
Pack a byte sequence.
packRAW' :: Packer -> ByteString -> IO Int Source
Pack a single byte stream. It calls packRAW
and packRAWBody
.
Stream Deserializer
type Unpacker = ForeignPtr () Source
newUnpacker :: Int -> IO Unpacker Source
newUnpacker
initialBufferSize
creates a new Unpacker. It will be deleted automatically.
unpackerReserveBuffer :: Unpacker -> Int -> IO Bool Source
unpackerReserveBuffer
up size
reserves at least size
bytes of buffer.
unpackerBufferCapacity :: Unpacker -> IO Int Source
Get size of allocated buffer.
unpackerBufferConsumed :: Unpacker -> Int -> IO () Source
unpackerBufferConsumed
up size
notices that writed size
bytes to buffer.
unpackerFeed :: Unpacker -> ByteString -> IO () Source
Write byte sequence to Unpacker. It is utility funciton, calls unpackerReserveBuffer
, unpackerBuffer
and unpackerBufferConsumed
.
unpackerExecute :: Unpacker -> IO Int Source
Execute deserializing. It returns 0 when buffer contains not enough bytes, returns 1 when succeeded, returns negative value when it failed.
unpackerData :: Unpacker -> IO Object Source
Returns a deserialized object when unpackerExecute
returned 1.
unpackerReleaseZone :: Unpacker -> IO Zone Source
Release memory zone. The returned zone must be freed by calling freeZone
.
unpackerResetZone :: Unpacker -> IO () Source
Free memory zone used by Unapcker.
unpackerReset :: Unpacker -> IO () Source
Reset Unpacker state except memory zone.
unpackerMessageSize :: Unpacker -> IO Int Source
Returns number of bytes of sequence of deserializing object.
MessagePack Object
Object Representation of MessagePack data.
packObject :: Packer -> Object -> IO () Source
Pack a Object.
data UnpackReturn Source
UnpackContinue | not enough bytes to unpack object |
UnpackParseError | got invalid bytes |
UnpackError | other error |
unpackObject :: Zone -> ByteString -> IO (Either UnpackReturn (Int, Object)) Source
Unpack a single MessagePack object from byte sequence.