Merge branch 'master' of github.com:msgpack/msgpack

This commit is contained in:
frsyuki 2010-05-19 16:31:16 +09:00
commit 6cde9f3a9d
15 changed files with 165 additions and 56 deletions

View file

@ -1,5 +1,5 @@
Name: msgpack
Version: 0.2.0
Version: 0.2.1
License: BSD3
License-File: LICENSE
Author: Hideyuki Tanaka

View file

@ -297,7 +297,7 @@ foreign import ccall "msgpack_pack_raw_body_wrap" msgpack_pack_raw_body ::
-- | Pack a single byte stream. It calls 'packRAW' and 'packRAWBody'.
packRAW' :: Packer -> ByteString -> IO Int
packRAW' pc bs = do
packRAW pc (BS.length bs)
_ <- packRAW pc (BS.length bs)
packRAWBody pc bs
type Unpacker = ForeignPtr ()
@ -475,7 +475,7 @@ peekObject ptr = do
(#const MSGPACK_OBJECT_MAP) ->
peekObjectMap ptr
_ ->
fail "peekObject: unknown object type"
fail $ "peekObject: unknown object type (" ++ show typ ++ ")"
peekObjectBool :: Ptr a -> IO Object
peekObjectBool ptr = do
@ -541,11 +541,11 @@ packObject pc (ObjectDouble d) = packDouble pc d >> return ()
packObject pc (ObjectRAW bs) = packRAW' pc bs >> return ()
packObject pc (ObjectArray ls) = do
packArray pc (length ls)
_ <- packArray pc (length ls)
mapM_ (packObject pc) ls
packObject pc (ObjectMap ls) = do
packMap pc (length ls)
_ <- packMap pc (length ls)
mapM_ (\(a, b) -> packObject pc a >> packObject pc b) ls
data UnpackReturn =

View file

@ -27,7 +27,6 @@ module Data.MessagePack.Class(
import Control.Monad.Error
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as C8
import Data.Either
import Data.MessagePack.Base
@ -46,6 +45,11 @@ instance OBJECT Object where
fromObjectError :: String
fromObjectError = "fromObject: cannot cast"
instance OBJECT () where
toObject = const ObjectNil
fromObject ObjectNil = Right ()
fromObject _ = Left fromObjectError
instance OBJECT Int where
toObject = ObjectInteger
fromObject (ObjectInteger n) = Right n

View file

@ -21,7 +21,6 @@ module Data.MessagePack.Feed(
feederFromString,
) where
import Control.Monad
import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import Data.IORef
@ -33,12 +32,16 @@ type Feeder = IO (Maybe ByteString)
-- | Feeder from Handle
feederFromHandle :: Handle -> IO Feeder
feederFromHandle h = return $ do
bs <- BS.hGet h bufSize
bs <- BS.hGetNonBlocking h bufSize
if BS.length bs > 0
then return $ Just bs
then do return $ Just bs
else do
hClose h
return Nothing
c <- BS.hGet h 1
if BS.length c > 0
then do return $ Just c
else do
hClose h
return Nothing
where
bufSize = 4096

View file

@ -79,7 +79,7 @@ packToString :: MonadIO m => PackerT m r -> m ByteString
packToString m = do
sb <- liftIO $ newSimpleBuffer
pc <- liftIO $ newPacker sb
runPackerT m pc
_ <- runPackerT m pc
liftIO $ simpleBufferData sb
-- | Execcute given serializer and write byte sequence to Handle.
@ -115,18 +115,21 @@ instance MonadIO m => MonadIO (UnpackerT m) where
instance MonadIO m => MonadUnpacker (UnpackerT m) where
get = UnpackerT $ \up feed -> liftIO $ do
resp <- unpackerExecute up
guard $ resp>=0
when (resp==0) $ do
Just bs <- feed
unpackerFeed up bs
resp2 <- unpackerExecute up
guard $ resp2==1
executeOne up feed
obj <- unpackerData up
freeZone =<< unpackerReleaseZone up
unpackerReset up
let Right r = fromObject obj
return r
where
executeOne up feed = do
resp <- unpackerExecute up
guard $ resp>=0
when (resp==0) $ do
Just bs <- feed
unpackerFeed up bs
executeOne up feed
-- | Execute deserializer using given feeder.
unpackFrom :: MonadIO m => Feeder -> UnpackerT m r -> m r

View file

@ -19,9 +19,7 @@ module Data.MessagePack.Stream(
unpackObjectsFromString,
) where
import Control.Monad
import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import System.IO
import System.IO.Unsafe

View file

@ -3,10 +3,12 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.msgpack</groupId>
<artifactId>msgpack</artifactId>
<name>MessagePack for Java</name>
<version>1.0-SNAPSHOT</version>
<version>0.2</version>
<description>MessagePack for Java</description>
<name>MessagePack for Java</name>
<url>http://msgpack.sourceforge.net/</url>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
@ -16,9 +18,19 @@
</licenses>
<scm>
<connection>scm:git://github.com/msgpack/msgpack.git</connection>
<connection>scm:git:git://github.com/msgpack/msgpack.git</connection>
<url>scm:git:git://github.com/msgpack/msgpack.git</url>
</scm>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
@ -83,27 +95,50 @@
</plugins>
</reporting>
<repositories>
<repository>
<id>msgpack.sourceforge.net</id>
<name>MessagePack Maven2 Repository</name>
<url>http://msgpack.sourceforge.net/maven2</url>
</repository>
<repository>
<id>msgpack.sourceforge.net</id>
<name>MessagePack Maven2 Snapshot Repository</name>
<url>http://msgpack.sourceforge.net/maven2-snapshot</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<uniqueVersion>false</uniqueVersion>
<id>shell.sourceforge.net</id>
<name>Repository at sourceforge.net</name>
<url>scp://shell.sourceforge.net/home/groups/m/ms/msgpack/htdocs/maven2/</url>
</repository>
<snapshotRepository>
<uniqueVersion>true</uniqueVersion>
<id>shell.sourceforge.net</id>
<name>Repository Name</name>
<url>scp://shell.sourceforge.net/home/groups/m/ms/msgpack/htdocs/maven2-snapshot/</url>
</snapshotRepository>
</distributionManagement>
<profiles>
<!-- for sending artifacts to sourceforge.net repository -->
<profile>
<id>sourceforge</id>
<distributionManagement>
<repository>
<id>sourceforge.net</id>
<name>Repository at sourceforge.net</name>
<url>scpexe://shell.sourceforge.net/home/groups/m/ms/msgpack/htdocs/maven2/</url>
</repository>
</distributionManagement>
<id>release</id>
<build>
<plugins>
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.4</version>
<configuration>
<updateReleaseInfo>true</updateReleaseInfo>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View file

@ -1,3 +1,17 @@
0.12
- PERL_NO_GET_CONTEXT makes horrible dTHXs. remove it.
0.11
- oops(no feature changes)
0.10
- added more test cases.
- fixed portability issue
- (reviewed by gfx++)
0.09_01
- fixed memory leak issue(reported by Maxime Soulé)

View file

@ -1,7 +1,7 @@
use inc::Module::Install;
name 'Data-MessagePack';
all_from 'lib/Data/MessagePack.pm';
readme_from 'lib/Data/MessagePack.pm';
readme_from('lib/Data/MessagePack.pm');
perl_version '5.008005';
license 'perl';
@ -32,11 +32,10 @@ if ($Module::Install::AUTHOR && -d File::Spec->catfile('..', 'msgpack')) {
}
}
requires 'Test::More' => 0.95; # done_testing
requires 'Test::More' => 0.94; # done_testing
test_requires('Test::Requires');
auto_set_repository;
build_requires 'Test::More';
use_test_base;
auto_set_repository();
auto_include;
WriteAll;

34
perl/README Normal file
View file

@ -0,0 +1,34 @@
NAME
Data::MessagePack - messagepack
SYNOPSIS
my $packed = Data::MessagePack->pack($dat);
my $unpacked = Data::MessagePack->unpack($dat);
DESCRIPTION
Data::MessagePack is a binary packer for perl.
METHODS
my $packed = Data::MessagePack->pack($data);
pack the $data to messagepack format string.
my $unpacked = Data::MessagePack->unpack($msgpackstr);
unpack the $msgpackstr to messagepack format string.
Configuration Variables
$Data::MessagePack::PreferInteger
Pack the string as int when the value looks like int(EXPERIMENTAL).
AUTHORS
Tokuhiro Matsuno
THANKS TO
Jun Kuriyama
LICENSE
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
SEE ALSO
<http://msgpack.sourceforge.jp/>

View file

@ -4,7 +4,7 @@ use warnings;
use XSLoader;
use 5.008001;
our $VERSION = '0.09_01';
our $VERSION = '0.12';
our $PreferInteger = 0;
our $true = do { bless \(my $dummy = 1), "Data::MessagePack::Boolean" };

View file

@ -1,7 +1,7 @@
use strict;
use warnings;
use Data::MessagePack;
use Test::More;
use Test::More tests => 6;
my $input = [(undef)x16];
my $packed = Data::MessagePack->pack($input);
@ -22,5 +22,4 @@ is_deeply(Data::MessagePack->unpack($packed), $input);
is_deeply $up->data, $input;
}
done_testing;

12
perl/t/07_break.t Normal file
View file

@ -0,0 +1,12 @@
use Test::More;
use Data::MessagePack;
use t::Util;
no warnings 'uninitialized'; # i need this. i need this.
plan tests => 1;
my $d = Data::MessagePack->unpack(Data::MessagePack->pack([{x => undef}]));
$d->[0]->{x} = 1;
ok delete $d->[0]->{x};
$d->[0] = 4;

View file

@ -40,7 +40,7 @@ typedef struct {
static INLINE SV *
get_bool (const char *name) {
SV * sv = get_sv( name, 1 );
SV * sv = sv_mortalcopy(get_sv( name, 1 ));
SvREADONLY_on(sv);
SvREADONLY_on( SvRV(sv) );
@ -73,7 +73,14 @@ static INLINE int template_callback_uint32(unpack_user* u, uint32_t d, SV** o)
{ *o = sv_2mortal(newSVuv(d)); return 0; }
static INLINE int template_callback_uint64(unpack_user* u, uint64_t d, SV** o)
{ *o = sv_2mortal(newSVuv(d)); return 0; }
{
#if IVSIZE==4
*o = sv_2mortal(newSVnv(d));
#else
*o = sv_2mortal(newSVuv(d));
#endif
return 0;
}
static INLINE int template_callback_int8(unpack_user* u, int8_t d, SV** o)
{ *o = sv_2mortal(newSViv((long)d)); return 0; }
@ -93,8 +100,9 @@ static INLINE int template_callback_float(unpack_user* u, float d, SV** o)
static INLINE int template_callback_double(unpack_user* u, double d, SV** o)
{ *o = sv_2mortal(newSVnv(d)); return 0; }
/* &PL_sv_undef is not so good. see http://gist.github.com/387743 */
static INLINE int template_callback_nil(unpack_user* u, SV** o)
{ *o = &PL_sv_undef; return 0; }
{ *o = sv_newmortal(); return 0; }
static INLINE int template_callback_true(unpack_user* u, SV** o)
{ *o = get_bool("Data::MessagePack::true") ; return 0; }
@ -115,7 +123,8 @@ static INLINE int template_callback_map_item(unpack_user* u, SV** c, SV* k, SV*
{ hv_store_ent((HV*)SvRV(*c), k, v, 0); SvREFCNT_inc(v); return 0; }
static INLINE int template_callback_raw(unpack_user* u, const char* b, const char* p, unsigned int l, SV** o)
{ *o = sv_2mortal((l == 0) ? newSVpv("", 0) : newSVpv(p, l)); return 0; }
{ *o = sv_2mortal((l==0) ? newSVpv("", 0) : newSVpv(p, l)); return 0; }
/* { *o = newSVpvn_flags(p, l, SVs_TEMP); return 0; } <= this does not works. */
#define UNPACKER(from, name) \
msgpack_unpack_t *name; \

View file

@ -2,7 +2,6 @@ use strict;
use warnings;
use Test::More;
use Data::MessagePack;
use Test::Requires 'Test::LeakTrace';
use Devel::Peek;
plan skip_all => '$ENV{LEAK_TEST} is required' unless $ENV{LEAK_TEST};