summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrsyuki <frsyuki@5a5092ae-2292-43ba-b2d5-dcab9c1a2731>2009-02-15 09:09:58 +0000
committerfrsyuki <frsyuki@5a5092ae-2292-43ba-b2d5-dcab9c1a2731>2009-02-15 09:09:58 +0000
commit1ad04b22d8d3e5267ceec7fc1527651ee0eb0ffe (patch)
tree32306ccc1f374c72440de881b928df9e945bd99f
parent921b0ff62ec99e9339d6cfaa6ba724ae7bb5f9ce (diff)
downloadmsgpack-python-1ad04b22d8d3e5267ceec7fc1527651ee0eb0ffe.tar.gz
lang/c/msgpack: divide pack_raw() into pack_raw() and pack_raw_body()
git-svn-id: file:///Users/frsyuki/project/msgpack-git/svn/x@74 5a5092ae-2292-43ba-b2d5-dcab9c1a2731
-rw-r--r--c/bench.c3
-rw-r--r--c/pack.h4
-rw-r--r--cpp/bench.cpp3
-rw-r--r--cpp/object.hpp3
-rw-r--r--cpp/pack.hpp131
-rw-r--r--cpp/type/raw.hpp6
-rw-r--r--cpp/unpack.cpp4
-rw-r--r--msgpack/pack_template.h7
-rw-r--r--ruby/pack.c6
9 files changed, 28 insertions, 139 deletions
diff --git a/c/bench.c b/c/bench.c
index fa717c0..d72a10d 100644
--- a/c/bench.c
+++ b/c/bench.c
@@ -279,7 +279,8 @@ void bench_msgpack(void)
unsigned int i;
msgpack_pack_array(mpk, TASK_STR_LEN);
for(i=0; i < TASK_STR_LEN; ++i) {
- msgpack_pack_raw(mpk, TASK_STR_PTR, i);
+ msgpack_pack_raw(mpk, i);
+ msgpack_pack_raw_body(mpk, TASK_STR_PTR, i);
}
}
show_timer(mpkbuf.length);
diff --git a/c/pack.h b/c/pack.h
index c6cadf4..ec0683e 100644
--- a/c/pack.h
+++ b/c/pack.h
@@ -54,8 +54,8 @@ void msgpack_pack_true(msgpack_pack_t* ctx);
void msgpack_pack_false(msgpack_pack_t* ctx);
void msgpack_pack_array(msgpack_pack_t* ctx, unsigned int n);
void msgpack_pack_map(msgpack_pack_t* ctx, unsigned int n);
-void msgpack_pack_string(msgpack_pack_t* ctx, const char* b);
-void msgpack_pack_raw(msgpack_pack_t* ctx, const void* b, size_t l);
+void msgpack_pack_raw(msgpack_pack_t* ctx, size_t l);
+void msgpack_pack_raw_body(msgpack_pack_t* ctx, const void* b, size_t l);
#ifdef __cplusplus
diff --git a/cpp/bench.cpp b/cpp/bench.cpp
index 1aad807..aa303fa 100644
--- a/cpp/bench.cpp
+++ b/cpp/bench.cpp
@@ -142,7 +142,8 @@ void bench_msgpack_str()
msgpack::packer<simple_buffer> pk(buf);
pk.pack_array(TASK_STR_LEN);
for(unsigned int i=0; i < TASK_STR_LEN; ++i) {
- pk.pack_raw(TASK_STR_PTR, i);
+ pk.pack_raw(i);
+ pk.pack_raw_body(TASK_STR_PTR, i);
}
}
timer.show_stat(buf.size());
diff --git a/cpp/object.hpp b/cpp/object.hpp
index 77d55bb..13402cc 100644
--- a/cpp/object.hpp
+++ b/cpp/object.hpp
@@ -173,7 +173,8 @@ packer<Stream>& operator<< (packer<Stream>& o, const object& v)
return o;
case type::RAW:
- o.pack_raw(v.via.ref.ptr, v.via.ref.size);
+ o.pack_raw(v.via.ref.size);
+ o.pack_raw_body(v.via.ref.ptr, v.via.ref.size);
return o;
case type::ARRAY:
diff --git a/cpp/pack.hpp b/cpp/pack.hpp
index fe470b6..4fda4ff 100644
--- a/cpp/pack.hpp
+++ b/cpp/pack.hpp
@@ -47,7 +47,8 @@ public:
void pack_false() { pack_false_impl(m_stream); }
void pack_array(unsigned int n) { pack_array_impl(m_stream, n); }
void pack_map(unsigned int n) { pack_map_impl(m_stream, n); }
- void pack_raw(const char* b, size_t l) { pack_raw_impl(m_stream, (const void*)b, l); }
+ void pack_raw(size_t l) { pack_raw_impl(m_stream, l); }
+ void pack_raw_body(const char* b, size_t l) { pack_raw_body_impl(m_stream, b, l); }
private:
static void pack_int_impl(Stream& x, int d);
@@ -67,7 +68,9 @@ private:
static void pack_false_impl(Stream& x);
static void pack_array_impl(Stream& x, unsigned int n);
static void pack_map_impl(Stream& x, unsigned int n);
- static void pack_raw_impl(Stream& x, const void* b, size_t l);
+ static void pack_raw_impl(Stream& x, size_t l);
+ static void pack_raw_body_impl(Stream& x, const void* b, size_t l);
+
static void append_buffer(Stream& x, const unsigned char* buf, unsigned int len)
{ x.write((const char*)buf, len); }
@@ -90,130 +93,6 @@ template <typename Stream>
packer<Stream>::packer(Stream& s) : m_stream(s) { }
-/*
-class dynamic_stream {
-public:
- template <typename Stream>
- dynamic_stream(Stream& s);
-public:
- void write(const char* buf, size_t len)
- { (*m_function)(m_object, buf, len); }
-private:
- void* m_object;
- void (*m_function)(void* object, const char* buf, size_t len);
-private:
- struct write_trampoline;
-};
-
-
-class dynamic_packer {
-public:
- template <typename Stream>
- dynamic_packer(Stream& s);
-
-public:
- void pack_int(int d) { pack_int_impl(m_stream, d); }
- void pack_unsigned_int(unsigned int d) { pack_unsigned_int_impl(m_stream, d); }
- void pack_uint8(uint8_t d) { pack_uint8_impl(m_stream, d); }
- void pack_uint16(uint16_t d) { pack_uint16_impl(m_stream, d); }
- void pack_uint32(uint32_t d) { pack_uint32_impl(m_stream, d); }
- void pack_uint64(uint64_t d) { pack_uint64_impl(m_stream, d); }
- void pack_int8(uint8_t d) { pack_int8_impl(m_stream, d); }
- void pack_int16(uint16_t d) { pack_int16_impl(m_stream, d); }
- void pack_int32(uint32_t d) { pack_int32_impl(m_stream, d); }
- void pack_int64(uint64_t d) { pack_int64_impl(m_stream, d); }
- void pack_float(float d) { pack_float_impl(m_stream, d); }
- void pack_double(double d) { pack_double_impl(m_stream, d); }
- void pack_nil() { pack_nil_impl(m_stream); }
- void pack_true() { pack_true_impl(m_stream); }
- void pack_false() { pack_false_impl(m_stream); }
- void pack_array(unsigned int n) { pack_array_impl(m_stream, n); }
- void pack_map(unsigned int n) { pack_map_impl(m_stream, n); }
- void pack_string(const char* b) { pack_string_impl(m_stream, b); }
- void pack_raw(const char* b, size_t l) { pack_raw_impl(m_stream, (const void*)b, l); }
-
-private:
- static void pack_int_impl(dynamic_stream& x, int d);
- static void pack_unsigned_int_impl(dynamic_stream& x, unsigned int d);
- static void pack_uint8_impl(dynamic_stream& x, uint8_t d);
- static void pack_uint16_impl(dynamic_stream& x, uint16_t d);
- static void pack_uint32_impl(dynamic_stream& x, uint32_t d);
- static void pack_uint64_impl(dynamic_stream& x, uint64_t d);
- static void pack_int8_impl(dynamic_stream& x, int8_t d);
- static void pack_int16_impl(dynamic_stream& x, int16_t d);
- static void pack_int32_impl(dynamic_stream& x, int32_t d);
- static void pack_int64_impl(dynamic_stream& x, int64_t d);
- static void pack_float_impl(dynamic_stream& x, float d);
- static void pack_double_impl(dynamic_stream& x, double d);
- static void pack_nil_impl(dynamic_stream& x);
- static void pack_true_impl(dynamic_stream& x);
- static void pack_false_impl(dynamic_stream& x);
- static void pack_array_impl(dynamic_stream& x, unsigned int n);
- static void pack_map_impl(dynamic_stream& x, unsigned int n);
- static void pack_string_impl(dynamic_stream& x, const char* b);
- static void pack_raw_impl(dynamic_stream& x, const void* b, size_t l);
- static void append_buffer(dynamic_stream& x, const unsigned char* buf, unsigned int len)
- { x.write((const char*)buf, len); }
-
-private:
- dynamic_stream m_stream;
-
-private:
- dynamic_packer();
-};
-
-#define msgpack_pack_inline_func(name) \
- inline void dynamic_packer::pack_ ## name ## _impl
-#define msgpack_pack_user dynamic_stream&
-#define msgpack_pack_append_buffer append_buffer
-#include "msgpack/pack_template.h"
-
-template <typename Stream>
-dynamic_packer::dynamic_packer(Stream& s) : m_stream(s) { }
-
-struct dynamic_stream::write_trampoline {
-private:
- template <typename R>
- struct ret_type {
- typedef R (*type)(void*, const char*, size_t);
- };
-
- template <typename Stream, typename R,
- typename Ptr, typename Sz, R (Stream::*MemFun)(Ptr*, Sz)>
- static R trampoline(void* obj, const char* buf, size_t len)
- {
- return (reinterpret_cast<Stream*>(obj)->*MemFun)(buf, len);
- }
-
-public:
- template <typename Stream, typename R, typename Ptr, typename Sz>
- static typename ret_type<R>::type get(R (Stream::*func)(Ptr*, Sz))
- {
- R (*f)(void*, const char*, size_t) =
- &trampoline<Stream, R, Ptr, Sz, &Stream::write>;
- return f;
- }
-};
-
-template <typename Stream>
-dynamic_stream::dynamic_stream(Stream& s)
-{
- m_object = reinterpret_cast<void*>(&s);
- m_function = reinterpret_cast<void (*)(void*, const char*, size_t)>(
- write_trampoline::get(&Stream::write)
- );
-}
-
-
-template <typename Stream>
-inline void pack(Stream& s, object o)
-{
- dynamic_packer pk(s);
- o.pack(pk);
-}
-*/
-
-
} // namespace msgpack
#endif /* msgpack/pack.hpp */
diff --git a/cpp/type/raw.hpp b/cpp/type/raw.hpp
index 14e52f4..e4f9dd3 100644
--- a/cpp/type/raw.hpp
+++ b/cpp/type/raw.hpp
@@ -82,7 +82,8 @@ inline std::string& operator>> (object o, std::string& v)
template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, const type::raw_ref& v)
{
- o.pack_raw(v.ptr, v.size);
+ o.pack_raw(v.size);
+ o.pack_raw_body(v.ptr, v.size);
return o;
}
@@ -90,7 +91,8 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const type::raw_ref& v)
template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::string& v)
{
- o.pack_raw(v.data(), v.size());
+ o.pack_raw(v.size());
+ o.pack_raw_body(v.data(), v.size());
return o;
}
diff --git a/cpp/unpack.cpp b/cpp/unpack.cpp
index ce39afd..cbf1356 100644
--- a/cpp/unpack.cpp
+++ b/cpp/unpack.cpp
@@ -257,7 +257,7 @@ zone* unpacker::release_zone()
throw;
}
}
- m_ctx->user(&*m_zone);
+ m_ctx->user(m_zone.get());
return old.release();
}
@@ -268,7 +268,7 @@ object unpacker::data()
void unpacker::reset()
{
- if(m_off != 0) { std::auto_ptr<zone> old(release_zone()); }
+ if(m_off != 0) { delete release_zone(); }
m_ctx->reset();
}
diff --git a/msgpack/pack_template.h b/msgpack/pack_template.h
index 69c7345..1dbf6fd 100644
--- a/msgpack/pack_template.h
+++ b/msgpack/pack_template.h
@@ -282,7 +282,7 @@ msgpack_pack_inline_func(map)(msgpack_pack_user x, unsigned int n)
* Raw
*/
-msgpack_pack_inline_func(raw)(msgpack_pack_user x, const void* b, size_t l)
+msgpack_pack_inline_func(raw)(msgpack_pack_user x, size_t l)
{
if(l < 32) {
unsigned char d = 0xa0 | l;
@@ -296,9 +296,12 @@ msgpack_pack_inline_func(raw)(msgpack_pack_user x, const void* b, size_t l)
unsigned char buf[5] = {0xdb, STORE_BE32(d)};
msgpack_pack_append_buffer(x, buf, 5);
}
- msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
}
+msgpack_pack_inline_func(raw_body)(msgpack_pack_user x, const void* b, size_t l)
+{
+ msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
+}
#undef msgpack_pack_inline_func
#undef msgpack_pack_user
diff --git a/ruby/pack.c b/ruby/pack.c
index 54f610c..e62419d 100644
--- a/ruby/pack.c
+++ b/ruby/pack.c
@@ -45,7 +45,8 @@ static void msgpack_pack_true(VALUE x);
static void msgpack_pack_false(VALUE x);
static void msgpack_pack_array(VALUE x, unsigned int n);
static void msgpack_pack_map(VALUE x, unsigned int n);
-static void msgpack_pack_raw(VALUE x, const void* b, size_t l);
+static void msgpack_pack_raw(VALUE x, size_t l);
+static void msgpack_pack_raw_body(VALUE x, const void* b, size_t l);
*/
#include "msgpack/pack_template.h"
@@ -123,7 +124,8 @@ static VALUE MessagePack_Float_to_msgpack(int argc, VALUE *argv, VALUE self)
static VALUE MessagePack_String_to_msgpack(int argc, VALUE *argv, VALUE self)
{
ARG_BUFFER(out, argc, argv);
- msgpack_pack_raw(out, RSTRING_PTR(self), RSTRING_LEN(self));
+ msgpack_pack_raw(out, RSTRING_LEN(self));
+ msgpack_pack_raw_body(out, RSTRING_PTR(self), RSTRING_LEN(self));
return out;
}