mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-03-18 20:38:00 +01:00
update pack/unpack routines
git-svn-id: file:///Users/frsyuki/project/msgpack-git/svn/x@100 5a5092ae-2292-43ba-b2d5-dcab9c1a2731
This commit is contained in:
parent
81a771094d
commit
a114f4a5a5
@ -1,4 +1,4 @@
|
|||||||
Copyright (C) 2008 FURUHASHI Sadayuki
|
Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -1,13 +1,18 @@
|
|||||||
lib_LTLIBRARIES = libmsgpackc.la
|
lib_LTLIBRARIES = libmsgpackc.la
|
||||||
|
|
||||||
libmsgpackc_la_SOURCES = \
|
libmsgpackc_la_SOURCES = \
|
||||||
pack.c \
|
unpack.c \
|
||||||
unpack.c
|
object.c \
|
||||||
|
zone.c
|
||||||
|
|
||||||
nobase_include_HEADERS = \
|
nobase_include_HEADERS = \
|
||||||
msgpack.h \
|
msgpack.h \
|
||||||
|
msgpack/sbuffer.h \
|
||||||
msgpack/pack.h \
|
msgpack/pack.h \
|
||||||
msgpack/unpack.h
|
msgpack/unpack.h \
|
||||||
|
msgpack/object.h \
|
||||||
|
msgpack/zone.h
|
||||||
|
|
||||||
libmsgpackc_la_LDFLAGS = -version-info 0:0:0
|
# -version-info CURRENT:REVISION:AGE
|
||||||
|
libmsgpackc_la_LDFLAGS = -version-info 1:0:0
|
||||||
|
|
||||||
|
2
c/README
2
c/README
@ -4,7 +4,7 @@ MessagePack is a binary-based efficient data interchange format.
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Copyright (C) 2008 FURUHASHI Sadayuki
|
Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* MessagePack for C
|
* MessagePack for C
|
||||||
*
|
*
|
||||||
* Copyright (C) 2008 FURUHASHI Sadayuki
|
* Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -15,5 +15,8 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
#include "msgpack/object.h"
|
||||||
|
#include "msgpack/zone.h"
|
||||||
#include "msgpack/pack.h"
|
#include "msgpack/pack.h"
|
||||||
#include "msgpack/unpack.h"
|
#include "msgpack/unpack.h"
|
||||||
|
#include "msgpack/sbuffer.h"
|
||||||
|
49
c/pack.c
49
c/pack.c
@ -1,49 +0,0 @@
|
|||||||
/*
|
|
||||||
* MessagePack packing routine for C
|
|
||||||
*
|
|
||||||
* Copyright (C) 2008 FURUHASHI Sadayuki
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
#include "msgpack/pack.h"
|
|
||||||
#include "msgpack/pack_define.h"
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
|
|
||||||
#define msgpack_pack_inline_func(name) \
|
|
||||||
void msgpack_pack_##name
|
|
||||||
|
|
||||||
#define msgpack_pack_inline_func_cint(name) \
|
|
||||||
void msgpack_pack_##name
|
|
||||||
|
|
||||||
#define msgpack_pack_user msgpack_pack_t*
|
|
||||||
|
|
||||||
#define msgpack_pack_append_buffer(user, buf, len) \
|
|
||||||
(*(user)->callback)((user)->data, (const char*)buf, len)
|
|
||||||
|
|
||||||
#include "msgpack/pack_template.h"
|
|
||||||
|
|
||||||
msgpack_pack_t* msgpack_pack_new(void* data, msgpack_pack_append_buffer_t callback)
|
|
||||||
{
|
|
||||||
msgpack_pack_t* ctx = calloc(1, sizeof(msgpack_pack_t));
|
|
||||||
if(!ctx) { return NULL; }
|
|
||||||
ctx->data = data;
|
|
||||||
ctx->callback = callback;
|
|
||||||
return ctx;
|
|
||||||
}
|
|
||||||
|
|
||||||
void msgpack_pack_free(msgpack_pack_t* ctx)
|
|
||||||
{
|
|
||||||
free(ctx);
|
|
||||||
}
|
|
||||||
|
|
92
c/pack.h
92
c/pack.h
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* MessagePack packing routine for C
|
* MessagePack for C packing routine
|
||||||
*
|
*
|
||||||
* Copyright (C) 2008 FURUHASHI Sadayuki
|
* Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -20,50 +20,90 @@
|
|||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
typedef void (*msgpack_pack_append_buffer_t)(void* data, const char* b, unsigned int i);
|
typedef int (*msgpack_pack_write_t)(void* data, const char* buf, unsigned int len);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void* data;
|
void* data;
|
||||||
msgpack_pack_append_buffer_t callback;
|
msgpack_pack_write_t callback;
|
||||||
} msgpack_pack_t;
|
} msgpack_pack_t;
|
||||||
|
|
||||||
msgpack_pack_t* msgpack_pack_new(void* data, msgpack_pack_append_buffer_t callback);
|
void msgpack_pack_init(msgpack_pack_t* ctx, void* data, msgpack_pack_write_t callback);
|
||||||
|
|
||||||
|
msgpack_pack_t* msgpack_pack_new(void* data, msgpack_pack_write_t callback);
|
||||||
void msgpack_pack_free(msgpack_pack_t* ctx);
|
void msgpack_pack_free(msgpack_pack_t* ctx);
|
||||||
|
|
||||||
void msgpack_pack_int(msgpack_pack_t* ctx, int d);
|
int msgpack_pack_short(msgpack_pack_t* ctx, short d);
|
||||||
void msgpack_pack_unsigned_int(msgpack_pack_t* ctx, unsigned int d);
|
int msgpack_pack_int(msgpack_pack_t* ctx, int d);
|
||||||
void msgpack_pack_long(msgpack_pack_t* ctx, long d);
|
int msgpack_pack_long(msgpack_pack_t* ctx, long d);
|
||||||
void msgpack_pack_unsigned_long(msgpack_pack_t* ctx, unsigned long d);
|
int msgpack_pack_long_long(msgpack_pack_t* ctx, long long d);
|
||||||
|
int msgpack_pack_unsigned_short(msgpack_pack_t* ctx, unsigned short d);
|
||||||
|
int msgpack_pack_unsigned_int(msgpack_pack_t* ctx, unsigned int d);
|
||||||
|
int msgpack_pack_unsigned_long(msgpack_pack_t* ctx, unsigned long d);
|
||||||
|
int msgpack_pack_unsigned_long_long(msgpack_pack_t* ctx, unsigned long long d);
|
||||||
|
|
||||||
void msgpack_pack_uint8(msgpack_pack_t* ctx, uint8_t d);
|
int msgpack_pack_uint8(msgpack_pack_t* ctx, uint8_t d);
|
||||||
void msgpack_pack_uint16(msgpack_pack_t* ctx, uint16_t d);
|
int msgpack_pack_uint16(msgpack_pack_t* ctx, uint16_t d);
|
||||||
void msgpack_pack_uint32(msgpack_pack_t* ctx, uint32_t d);
|
int msgpack_pack_uint32(msgpack_pack_t* ctx, uint32_t d);
|
||||||
void msgpack_pack_uint64(msgpack_pack_t* ctx, uint64_t d);
|
int msgpack_pack_uint64(msgpack_pack_t* ctx, uint64_t d);
|
||||||
void msgpack_pack_int8(msgpack_pack_t* ctx, int8_t d);
|
int msgpack_pack_int8(msgpack_pack_t* ctx, int8_t d);
|
||||||
void msgpack_pack_int16(msgpack_pack_t* ctx, int16_t d);
|
int msgpack_pack_int16(msgpack_pack_t* ctx, int16_t d);
|
||||||
void msgpack_pack_int32(msgpack_pack_t* ctx, int32_t d);
|
int msgpack_pack_int32(msgpack_pack_t* ctx, int32_t d);
|
||||||
void msgpack_pack_int64(msgpack_pack_t* ctx, int64_t d);
|
int msgpack_pack_int64(msgpack_pack_t* ctx, int64_t d);
|
||||||
|
|
||||||
void msgpack_pack_float(msgpack_pack_t* ctx, float d);
|
int msgpack_pack_float(msgpack_pack_t* ctx, float d);
|
||||||
void msgpack_pack_double(msgpack_pack_t* ctx, double d);
|
int msgpack_pack_double(msgpack_pack_t* ctx, double d);
|
||||||
|
|
||||||
void msgpack_pack_nil(msgpack_pack_t* ctx);
|
int msgpack_pack_nil(msgpack_pack_t* ctx);
|
||||||
void msgpack_pack_true(msgpack_pack_t* ctx);
|
int msgpack_pack_true(msgpack_pack_t* ctx);
|
||||||
void msgpack_pack_false(msgpack_pack_t* ctx);
|
int msgpack_pack_false(msgpack_pack_t* ctx);
|
||||||
|
|
||||||
void msgpack_pack_array(msgpack_pack_t* ctx, unsigned int n);
|
int msgpack_pack_array(msgpack_pack_t* ctx, unsigned int n);
|
||||||
|
|
||||||
void msgpack_pack_map(msgpack_pack_t* ctx, unsigned int n);
|
int msgpack_pack_map(msgpack_pack_t* ctx, unsigned int n);
|
||||||
|
|
||||||
void msgpack_pack_raw(msgpack_pack_t* ctx, size_t l);
|
int 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);
|
int msgpack_pack_raw_body(msgpack_pack_t* ctx, const void* b, size_t l);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define msgpack_pack_inline_func(name) \
|
||||||
|
inline int msgpack_pack ## name
|
||||||
|
|
||||||
|
#define msgpack_pack_inline_func_cint(name) \
|
||||||
|
inline int msgpack_pack ## name
|
||||||
|
|
||||||
|
#define msgpack_pack_user msgpack_pack_t*
|
||||||
|
|
||||||
|
#define msgpack_pack_append_buffer(user, buf, len) \
|
||||||
|
return (*(user)->callback)((user)->data, (const char*)buf, len)
|
||||||
|
|
||||||
|
#include "msgpack/pack_template.h"
|
||||||
|
|
||||||
|
inline void msgpack_pack_init(msgpack_pack_t* ctx, void* data, msgpack_pack_write_t callback)
|
||||||
|
{
|
||||||
|
ctx->data = data;
|
||||||
|
ctx->callback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline msgpack_pack_t* msgpack_pack_new(void* data, msgpack_pack_write_t callback)
|
||||||
|
{
|
||||||
|
msgpack_pack_t* ctx = (msgpack_pack_t*)calloc(1, sizeof(msgpack_pack_t));
|
||||||
|
if(!ctx) { return NULL; }
|
||||||
|
msgpack_pack_init(ctx, data, callback);
|
||||||
|
return ctx;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void msgpack_pack_free(msgpack_pack_t* ctx)
|
||||||
|
{
|
||||||
|
free(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
10
c/unpack.c
10
c/unpack.c
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* MessagePack unpacking routine for C
|
* MessagePack for C unpacking routine
|
||||||
*
|
*
|
||||||
* Copyright (C) 2008 FURUHASHI Sadayuki
|
* Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -21,13 +21,13 @@
|
|||||||
|
|
||||||
|
|
||||||
#define msgpack_unpack_struct(name) \
|
#define msgpack_unpack_struct(name) \
|
||||||
struct template_##name
|
struct template ## name
|
||||||
|
|
||||||
#define msgpack_unpack_func(ret, name) \
|
#define msgpack_unpack_func(ret, name) \
|
||||||
ret template_func_##name
|
ret template_func ## name
|
||||||
|
|
||||||
#define msgpack_unpack_callback(name) \
|
#define msgpack_unpack_callback(name) \
|
||||||
template_callback_##name
|
template_callback ## name
|
||||||
|
|
||||||
#define msgpack_unpack_object void*
|
#define msgpack_unpack_object void*
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* MessagePack unpacking routine for C
|
* MessagePack for C unpacking routine
|
||||||
*
|
*
|
||||||
* Copyright (C) 2008 FURUHASHI Sadayuki
|
* Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -54,11 +54,11 @@ typedef struct {
|
|||||||
|
|
||||||
msgpack_unpack_t* msgpack_unpack_new(void* data, msgpack_unpack_callback* callback);
|
msgpack_unpack_t* msgpack_unpack_new(void* data, msgpack_unpack_callback* callback);
|
||||||
void msgpack_unpack_free(msgpack_unpack_t* ctx);
|
void msgpack_unpack_free(msgpack_unpack_t* ctx);
|
||||||
void msgpack_unpack_reset(msgpack_unpack_t* ctx);
|
|
||||||
|
|
||||||
int msgpack_unpack_execute(msgpack_unpack_t* ctx,
|
int msgpack_unpack_execute(msgpack_unpack_t* ctx,
|
||||||
const char* data, size_t len, size_t* off);
|
const char* data, size_t len, size_t* off);
|
||||||
void* msgpack_unpack_data(msgpack_unpack_t* ctx);
|
void* msgpack_unpack_data(msgpack_unpack_t* ctx);
|
||||||
|
void msgpack_unpack_reset(msgpack_unpack_t* ctx);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
Copyright (C) 2008 FURUHASHI Sadayuki
|
Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -7,6 +7,7 @@ libmsgpack_la_SOURCES = \
|
|||||||
|
|
||||||
nobase_include_HEADERS = \
|
nobase_include_HEADERS = \
|
||||||
msgpack.hpp \
|
msgpack.hpp \
|
||||||
|
msgpack/sbuffer.hpp \
|
||||||
msgpack/pack.hpp \
|
msgpack/pack.hpp \
|
||||||
msgpack/unpack.hpp \
|
msgpack/unpack.hpp \
|
||||||
msgpack/object.hpp \
|
msgpack/object.hpp \
|
||||||
@ -41,6 +42,6 @@ MOSTLYCLEANFILES = \
|
|||||||
msgpack/type/tuple.hpp \
|
msgpack/type/tuple.hpp \
|
||||||
msgpack/zone.hpp
|
msgpack/zone.hpp
|
||||||
|
|
||||||
# FIXME
|
# -version-info CURRENT:REVISION:AGE
|
||||||
libmsgpack_la_LDFLAGS = -version-info 0:0:0
|
libmsgpack_la_LDFLAGS = -version-info 1:0:0
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ MessagePack is a binary-based efficient data interchange format.
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Copyright (C) 2008 FURUHASHI Sadayuki
|
Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// MessagePack for C++
|
// MessagePack for C++
|
||||||
//
|
//
|
||||||
// Copyright (C) 2008 FURUHASHI Sadayuki
|
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
@ -19,3 +19,4 @@
|
|||||||
#include "msgpack/zone.hpp"
|
#include "msgpack/zone.hpp"
|
||||||
#include "msgpack/pack.hpp"
|
#include "msgpack/pack.hpp"
|
||||||
#include "msgpack/unpack.hpp"
|
#include "msgpack/unpack.hpp"
|
||||||
|
#include "msgpack/sbuffer.hpp"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// MessagePack for C++ dynamic typed objects
|
// MessagePack for C++ dynamic typed objects
|
||||||
//
|
//
|
||||||
// Copyright (C) 2008 FURUHASHI Sadayuki
|
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
|
136
cpp/object.hpp
136
cpp/object.hpp
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// MessagePack for C++ static resolution routine
|
// MessagePack for C++ static resolution routine
|
||||||
//
|
//
|
||||||
// Copyright (C) 2008 FURUHASHI Sadayuki
|
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
@ -32,14 +32,16 @@ class type_error : public std::bad_cast { };
|
|||||||
|
|
||||||
|
|
||||||
namespace type {
|
namespace type {
|
||||||
static const unsigned char NIL = 0x01;
|
enum object_type {
|
||||||
static const unsigned char BOOLEAN = 0x02;
|
NIL = 0x01,
|
||||||
static const unsigned char POSITIVE_INTEGER = 0x03;
|
BOOLEAN = 0x02,
|
||||||
static const unsigned char NEGATIVE_INTEGER = 0x04;
|
POSITIVE_INTEGER = 0x03,
|
||||||
static const unsigned char DOUBLE = 0x05;
|
NEGATIVE_INTEGER = 0x04,
|
||||||
static const unsigned char RAW = 0x06;
|
DOUBLE = 0x05,
|
||||||
static const unsigned char ARRAY = 0x07;
|
RAW = 0x06,
|
||||||
static const unsigned char MAP = 0x08;
|
ARRAY = 0x07,
|
||||||
|
MAP = 0x08,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -59,7 +61,7 @@ struct object {
|
|||||||
} ref;
|
} ref;
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char type;
|
type::object_type type;
|
||||||
union_type via;
|
union_type via;
|
||||||
|
|
||||||
bool is_nil() { return type == type::NIL; }
|
bool is_nil() { return type == type::NIL; }
|
||||||
@ -68,7 +70,7 @@ struct object {
|
|||||||
T as();
|
T as();
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void convert(T& v);
|
void convert(T* v);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct implicit_type;
|
struct implicit_type;
|
||||||
@ -77,6 +79,21 @@ public:
|
|||||||
implicit_type convert();
|
implicit_type convert();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool operator==(const object x, const object y);
|
||||||
|
bool operator!=(const object x, const object y);
|
||||||
|
|
||||||
|
std::ostream& operator<< (std::ostream& s, const object o);
|
||||||
|
|
||||||
|
|
||||||
|
template <typename Stream, typename T>
|
||||||
|
inline void pack(Stream& s, const T& v);
|
||||||
|
|
||||||
|
template <typename Stream, typename T>
|
||||||
|
packer<Stream>& operator<< (packer<Stream>& o, const T& v);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T& operator>> (object o, T& v);
|
||||||
|
|
||||||
|
|
||||||
struct object::implicit_type {
|
struct object::implicit_type {
|
||||||
implicit_type(object o) : obj(o) { }
|
implicit_type(object o) : obj(o) { }
|
||||||
@ -89,39 +106,41 @@ private:
|
|||||||
object obj;
|
object obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::ostream& operator<< (std::ostream& s, const object o);
|
|
||||||
|
|
||||||
bool operator==(const object x, const object y);
|
template <typename Type>
|
||||||
inline bool operator!=(const object x, const object y) { return !(x == y); }
|
class define : public Type {
|
||||||
|
public:
|
||||||
|
typedef Type msgpack_type;
|
||||||
|
typedef define<Type> define_type;
|
||||||
|
|
||||||
|
define() {}
|
||||||
|
define(const msgpack_type& v) : msgpack_type(v) {}
|
||||||
|
|
||||||
|
template <typename Packer>
|
||||||
|
void msgpack_pack(Packer& o) const
|
||||||
|
{
|
||||||
|
o << static_cast<const msgpack_type&>(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void msgpack_unpack(object o)
|
||||||
|
{
|
||||||
|
o >> static_cast<msgpack_type&>(*this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
inline object& operator>> (object o, object& v)
|
|
||||||
{
|
|
||||||
v = o;
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
packer<Stream>& operator<< (packer<Stream>& o, const object& v);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline void convert(T& v, object o)
|
inline packer<Stream>& packer<Stream>::pack(const T& v)
|
||||||
{
|
{
|
||||||
o >> v;
|
*this << v;
|
||||||
}
|
return *this;
|
||||||
|
|
||||||
template <typename Stream, typename T>
|
|
||||||
inline void pack(packer<Stream>& o, const T& v)
|
|
||||||
{
|
|
||||||
o << v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Stream, typename T>
|
template <typename Stream, typename T>
|
||||||
inline void pack(Stream& s, const T& v)
|
inline void pack(Stream& s, const T& v)
|
||||||
{
|
{
|
||||||
packer<Stream> pk(s);
|
packer<Stream>(s).pack(v);
|
||||||
pack(pk, v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Stream, typename T>
|
template <typename Stream, typename T>
|
||||||
@ -130,7 +149,11 @@ inline void pack_copy(packer<Stream>& o, T v)
|
|||||||
pack(o, v);
|
pack(o, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline object& operator>> (object o, object& v)
|
||||||
|
{
|
||||||
|
v = o;
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline T& operator>> (object o, T& v)
|
inline T& operator>> (object o, T& v)
|
||||||
@ -147,27 +170,8 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const T& v)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename Type>
|
inline bool operator!=(const object x, const object y)
|
||||||
class define : public Type {
|
{ return !(x == y); }
|
||||||
public:
|
|
||||||
typedef Type msgpack_type;
|
|
||||||
typedef define<Type> define_type;
|
|
||||||
|
|
||||||
define() {}
|
|
||||||
define(msgpack_type v) : msgpack_type(v) {}
|
|
||||||
|
|
||||||
template <typename Packer>
|
|
||||||
void msgpack_pack(Packer& o) const
|
|
||||||
{
|
|
||||||
o << static_cast<const msgpack_type&>(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void msgpack_unpack(object o)
|
|
||||||
{
|
|
||||||
o >> static_cast<msgpack_type&>(*this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline object::implicit_type object::convert()
|
inline object::implicit_type object::convert()
|
||||||
@ -179,16 +183,32 @@ template <typename T>
|
|||||||
inline T object::as()
|
inline T object::as()
|
||||||
{
|
{
|
||||||
T v;
|
T v;
|
||||||
msgpack::convert(v, *this);
|
convert(&v);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void object::convert(T& v)
|
inline void object::convert(T* v)
|
||||||
{
|
{
|
||||||
msgpack::convert(v, *this);
|
*this >> *v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// obsolete
|
||||||
|
template <typename T>
|
||||||
|
inline void convert(T& v, object o)
|
||||||
|
{
|
||||||
|
o.convert(&v);
|
||||||
|
}
|
||||||
|
|
||||||
|
// obsolete
|
||||||
|
template <typename Stream, typename T>
|
||||||
|
inline void pack(packer<Stream>& o, const T& v)
|
||||||
|
{
|
||||||
|
o.pack(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
packer<Stream>& operator<< (packer<Stream>& o, const object& v)
|
packer<Stream>& operator<< (packer<Stream>& o, const object& v)
|
||||||
{
|
{
|
||||||
|
216
cpp/pack.hpp
216
cpp/pack.hpp
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// MessagePack for C++ serializing routine
|
// MessagePack for C++ serializing routine
|
||||||
//
|
//
|
||||||
// Copyright (C) 2008 FURUHASHI Sadayuki
|
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
@ -32,70 +32,73 @@ public:
|
|||||||
packer(Stream& s);
|
packer(Stream& s);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void pack_uint8(uint8_t d) { pack_uint8_impl(m_stream, d); }
|
template <typename T>
|
||||||
void pack_uint16(uint16_t d) { pack_uint16_impl(m_stream, d); }
|
packer<Stream>& pack(const T& v);
|
||||||
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_short(int d) { pack_short_impl(m_stream, d); }
|
packer<Stream>& pack_uint8(uint8_t d);
|
||||||
void pack_int(int d) { pack_int_impl(m_stream, d); }
|
packer<Stream>& pack_uint16(uint16_t d);
|
||||||
void pack_long(long d) { pack_long_impl(m_stream, d); }
|
packer<Stream>& pack_uint32(uint32_t d);
|
||||||
void pack_long_long(long long d) { pack_long_long_impl(m_stream, d); }
|
packer<Stream>& pack_uint64(uint64_t d);
|
||||||
void pack_unsigned_short(unsigned short d) { pack_unsigned_short_impl(m_stream, d); }
|
packer<Stream>& pack_int8(uint8_t d);
|
||||||
void pack_unsigned_int(unsigned int d) { pack_unsigned_int_impl(m_stream, d); }
|
packer<Stream>& pack_int16(uint16_t d);
|
||||||
void pack_unsigned_long(unsigned long d) { pack_unsigned_long_impl(m_stream, d); }
|
packer<Stream>& pack_int32(uint32_t d);
|
||||||
void pack_unsigned_long_long(unsigned long long d) { pack_unsigned_long_long_impl(m_stream, d); }
|
packer<Stream>& pack_int64(uint64_t d);
|
||||||
|
|
||||||
void pack_float(float d) { pack_float_impl(m_stream, d); }
|
packer<Stream>& pack_short(int d);
|
||||||
void pack_double(double d) { pack_double_impl(m_stream, d); }
|
packer<Stream>& pack_int(int d);
|
||||||
|
packer<Stream>& pack_long(long d);
|
||||||
|
packer<Stream>& pack_long_long(long long d);
|
||||||
|
packer<Stream>& pack_unsigned_short(unsigned short d);
|
||||||
|
packer<Stream>& pack_unsigned_int(unsigned int d);
|
||||||
|
packer<Stream>& pack_unsigned_long(unsigned long d);
|
||||||
|
packer<Stream>& pack_unsigned_long_long(unsigned long long d);
|
||||||
|
|
||||||
void pack_nil() { pack_nil_impl(m_stream); }
|
packer<Stream>& pack_float(float d);
|
||||||
void pack_true() { pack_true_impl(m_stream); }
|
packer<Stream>& pack_double(double d);
|
||||||
void pack_false() { pack_false_impl(m_stream); }
|
|
||||||
|
|
||||||
void pack_array(unsigned int n) { pack_array_impl(m_stream, n); }
|
packer<Stream>& pack_nil();
|
||||||
|
packer<Stream>& pack_true();
|
||||||
|
packer<Stream>& pack_false();
|
||||||
|
|
||||||
void pack_map(unsigned int n) { pack_map_impl(m_stream, n); }
|
packer<Stream>& pack_array(unsigned int n);
|
||||||
|
|
||||||
void pack_raw(size_t l) { pack_raw_impl(m_stream, l); }
|
packer<Stream>& pack_map(unsigned int n);
|
||||||
void pack_raw_body(const char* b, size_t l) { pack_raw_body_impl(m_stream, b, l); }
|
|
||||||
|
packer<Stream>& pack_raw(size_t l);
|
||||||
|
packer<Stream>& pack_raw_body(const char* b, size_t l);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void pack_uint8_impl(Stream& x, uint8_t d);
|
static void _pack_uint8(Stream& x, uint8_t d);
|
||||||
static void pack_uint16_impl(Stream& x, uint16_t d);
|
static void _pack_uint16(Stream& x, uint16_t d);
|
||||||
static void pack_uint32_impl(Stream& x, uint32_t d);
|
static void _pack_uint32(Stream& x, uint32_t d);
|
||||||
static void pack_uint64_impl(Stream& x, uint64_t d);
|
static void _pack_uint64(Stream& x, uint64_t d);
|
||||||
static void pack_int8_impl(Stream& x, int8_t d);
|
static void _pack_int8(Stream& x, int8_t d);
|
||||||
static void pack_int16_impl(Stream& x, int16_t d);
|
static void _pack_int16(Stream& x, int16_t d);
|
||||||
static void pack_int32_impl(Stream& x, int32_t d);
|
static void _pack_int32(Stream& x, int32_t d);
|
||||||
static void pack_int64_impl(Stream& x, int64_t d);
|
static void _pack_int64(Stream& x, int64_t d);
|
||||||
|
|
||||||
static void pack_short_impl(Stream& x, short d);
|
static void _pack_short(Stream& x, short d);
|
||||||
static void pack_int_impl(Stream& x, int d);
|
static void _pack_int(Stream& x, int d);
|
||||||
static void pack_long_impl(Stream& x, long d);
|
static void _pack_long(Stream& x, long d);
|
||||||
static void pack_long_long_impl(Stream& x, long long d);
|
static void _pack_long_long(Stream& x, long long d);
|
||||||
static void pack_unsigned_short_impl(Stream& x, unsigned short d);
|
static void _pack_unsigned_short(Stream& x, unsigned short d);
|
||||||
static void pack_unsigned_int_impl(Stream& x, unsigned int d);
|
static void _pack_unsigned_int(Stream& x, unsigned int d);
|
||||||
static void pack_unsigned_long_impl(Stream& x, unsigned long d);
|
static void _pack_unsigned_long(Stream& x, unsigned long d);
|
||||||
static void pack_unsigned_long_long_impl(Stream& x, unsigned long long d);
|
static void _pack_unsigned_long_long(Stream& x, unsigned long long d);
|
||||||
|
|
||||||
static void pack_float_impl(Stream& x, float d);
|
static void _pack_float(Stream& x, float d);
|
||||||
static void pack_double_impl(Stream& x, double d);
|
static void _pack_double(Stream& x, double d);
|
||||||
|
|
||||||
static void pack_nil_impl(Stream& x);
|
static void _pack_nil(Stream& x);
|
||||||
static void pack_true_impl(Stream& x);
|
static void _pack_true(Stream& x);
|
||||||
static void pack_false_impl(Stream& x);
|
static void _pack_false(Stream& x);
|
||||||
|
|
||||||
static void pack_array_impl(Stream& x, unsigned int n);
|
static void _pack_array(Stream& x, unsigned int n);
|
||||||
|
|
||||||
static void pack_map_impl(Stream& x, unsigned int n);
|
static void _pack_map(Stream& x, unsigned int n);
|
||||||
|
|
||||||
static void pack_raw_impl(Stream& x, size_t l);
|
static void _pack_raw(Stream& x, size_t l);
|
||||||
static void pack_raw_body_impl(Stream& x, const void* b, size_t l);
|
static void _pack_raw_body(Stream& x, const void* b, size_t l);
|
||||||
|
|
||||||
static void append_buffer(Stream& x, const unsigned char* buf, unsigned int len)
|
static void append_buffer(Stream& x, const unsigned char* buf, unsigned int len)
|
||||||
{ x.write((const char*)buf, len); }
|
{ x.write((const char*)buf, len); }
|
||||||
@ -107,13 +110,14 @@ private:
|
|||||||
packer();
|
packer();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#define msgpack_pack_inline_func(name) \
|
#define msgpack_pack_inline_func(name) \
|
||||||
template <typename Stream> \
|
template <typename Stream> \
|
||||||
inline void packer<Stream>::pack_ ## name ## _impl
|
inline void packer<Stream>::_pack ## name
|
||||||
|
|
||||||
#define msgpack_pack_inline_func_cint(name) \
|
#define msgpack_pack_inline_func_cint(name) \
|
||||||
template <typename Stream> \
|
template <typename Stream> \
|
||||||
inline void packer<Stream>::pack_ ## name ## _impl
|
inline void packer<Stream>::_pack ## name
|
||||||
|
|
||||||
#define msgpack_pack_user Stream&
|
#define msgpack_pack_user Stream&
|
||||||
|
|
||||||
@ -125,6 +129,112 @@ private:
|
|||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
packer<Stream>::packer(Stream& s) : m_stream(s) { }
|
packer<Stream>::packer(Stream& s) : m_stream(s) { }
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
inline packer<Stream>& packer<Stream>::pack_uint8(uint8_t d)
|
||||||
|
{ _pack_uint8(m_stream, d); return *this; }
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
inline packer<Stream>& packer<Stream>::pack_uint16(uint16_t d)
|
||||||
|
{ _pack_uint16(m_stream, d); return *this; }
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
inline packer<Stream>& packer<Stream>::pack_uint32(uint32_t d)
|
||||||
|
{ _pack_uint32(m_stream, d); return *this; }
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
inline packer<Stream>& packer<Stream>::pack_uint64(uint64_t d)
|
||||||
|
{ _pack_uint64(m_stream, d); return *this; }
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
inline packer<Stream>& packer<Stream>::pack_int8(uint8_t d)
|
||||||
|
{ _pack_int8(m_stream, d); return *this; }
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
inline packer<Stream>& packer<Stream>::pack_int16(uint16_t d)
|
||||||
|
{ _pack_int16(m_stream, d); return *this; }
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
inline packer<Stream>& packer<Stream>::pack_int32(uint32_t d)
|
||||||
|
{ _pack_int32(m_stream, d); return *this; }
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
inline packer<Stream>& packer<Stream>::pack_int64(uint64_t d)
|
||||||
|
{ _pack_int64(m_stream, d); return *this;}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
inline packer<Stream>& packer<Stream>::pack_short(int d)
|
||||||
|
{ _pack_short(m_stream, d); return *this; }
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
inline packer<Stream>& packer<Stream>::pack_int(int d)
|
||||||
|
{ _pack_int(m_stream, d); return *this; }
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
inline packer<Stream>& packer<Stream>::pack_long(long d)
|
||||||
|
{ _pack_long(m_stream, d); return *this; }
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
inline packer<Stream>& packer<Stream>::pack_long_long(long long d)
|
||||||
|
{ _pack_long_long(m_stream, d); return *this; }
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
inline packer<Stream>& packer<Stream>::pack_unsigned_short(unsigned short d)
|
||||||
|
{ _pack_unsigned_short(m_stream, d); return *this; }
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
inline packer<Stream>& packer<Stream>::pack_unsigned_int(unsigned int d)
|
||||||
|
{ _pack_unsigned_int(m_stream, d); return *this; }
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
inline packer<Stream>& packer<Stream>::pack_unsigned_long(unsigned long d)
|
||||||
|
{ _pack_unsigned_long(m_stream, d); return *this; }
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
inline packer<Stream>& packer<Stream>::pack_unsigned_long_long(unsigned long long d)
|
||||||
|
{ _pack_unsigned_long_long(m_stream, d); return *this; }
|
||||||
|
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
inline packer<Stream>& packer<Stream>::pack_float(float d)
|
||||||
|
{ _pack_float(m_stream, d); return *this; }
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
inline packer<Stream>& packer<Stream>::pack_double(double d)
|
||||||
|
{ _pack_double(m_stream, d); return *this; }
|
||||||
|
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
inline packer<Stream>& packer<Stream>::pack_nil()
|
||||||
|
{ _pack_nil(m_stream); return *this; }
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
inline packer<Stream>& packer<Stream>::pack_true()
|
||||||
|
{ _pack_true(m_stream); return *this; }
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
inline packer<Stream>& packer<Stream>::pack_false()
|
||||||
|
{ _pack_false(m_stream); return *this; }
|
||||||
|
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
inline packer<Stream>& packer<Stream>::pack_array(unsigned int n)
|
||||||
|
{ _pack_array(m_stream, n); return *this; }
|
||||||
|
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
inline packer<Stream>& packer<Stream>::pack_map(unsigned int n)
|
||||||
|
{ _pack_map(m_stream, n); return *this; }
|
||||||
|
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
inline packer<Stream>& packer<Stream>::pack_raw(size_t l)
|
||||||
|
{ _pack_raw(m_stream, l); return *this; }
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
inline packer<Stream>& packer<Stream>::pack_raw_body(const char* b, size_t l)
|
||||||
|
{ _pack_raw_body(m_stream, b, l); return *this; }
|
||||||
|
|
||||||
|
|
||||||
} // namespace msgpack
|
} // namespace msgpack
|
||||||
|
|
||||||
|
@ -29,11 +29,11 @@ inline std::vector<T> operator>> (object o, std::vector<T>& v)
|
|||||||
{
|
{
|
||||||
if(o.type != type::ARRAY) { throw type_error(); }
|
if(o.type != type::ARRAY) { throw type_error(); }
|
||||||
v.resize(o.via.container.size);
|
v.resize(o.via.container.size);
|
||||||
object* p(o.via.container.ptr);
|
object* p = o.via.container.ptr;
|
||||||
object* const pend(o.via.container.ptr + o.via.container.size);
|
object* const pend = o.via.container.ptr + o.via.container.size;
|
||||||
T* it(&v.front());
|
T* it = &v.front();
|
||||||
for(; p < pend; ++p, ++it) {
|
for(; p < pend; ++p, ++it) {
|
||||||
convert(*it, *p);
|
p->convert(it);
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
@ -45,7 +45,7 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const std::vector<T>& v)
|
|||||||
o.pack_array(v.size());
|
o.pack_array(v.size());
|
||||||
for(typename std::vector<T>::const_iterator it(v.begin()), it_end(v.end());
|
for(typename std::vector<T>::const_iterator it(v.begin()), it_end(v.end());
|
||||||
it != it_end; ++it) {
|
it != it_end; ++it) {
|
||||||
pack(o, *it);
|
o.pack(*it);
|
||||||
}
|
}
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
@ -47,12 +47,12 @@ inline type::assoc_vector<K,V>& operator>> (object o, type::assoc_vector<K,V>& v
|
|||||||
{
|
{
|
||||||
if(o.type != type::MAP) { throw type_error(); }
|
if(o.type != type::MAP) { throw type_error(); }
|
||||||
v.resize(o.via.container.size);
|
v.resize(o.via.container.size);
|
||||||
object* p(o.via.container.ptr);
|
object* p = o.via.container.ptr;
|
||||||
object* const pend(o.via.container.ptr + o.via.container.size);
|
object* const pend = o.via.container.ptr + o.via.container.size;
|
||||||
std::pair<K, V>* it(&v.front());
|
std::pair<K, V>* it(&v.front());
|
||||||
for(; p < pend; ++it) {
|
for(; p < pend; ++it) {
|
||||||
convert(it->first, *p); ++p;
|
p->convert(&it->first); ++p;
|
||||||
convert(it->second, *p); ++p;
|
p->convert(&it->second); ++p;
|
||||||
}
|
}
|
||||||
std::sort(v.begin(), v.end(), type::detail::pair_first_less<K,V>());
|
std::sort(v.begin(), v.end(), type::detail::pair_first_less<K,V>());
|
||||||
return v;
|
return v;
|
||||||
@ -64,8 +64,8 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const type::assoc_vector<K
|
|||||||
o.pack_map(v.size());
|
o.pack_map(v.size());
|
||||||
for(typename type::assoc_vector<K,V>::const_iterator it(v.begin()), it_end(v.end());
|
for(typename type::assoc_vector<K,V>::const_iterator it(v.begin()), it_end(v.end());
|
||||||
it != it_end; ++it) {
|
it != it_end; ++it) {
|
||||||
pack(o, it->first);
|
o.pack(it->first);
|
||||||
pack(o, it->second);
|
o.pack(it->second);
|
||||||
}
|
}
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
@ -79,14 +79,14 @@ inline std::map<K, V> operator>> (object o, std::map<K, V>& v)
|
|||||||
object* const pend(o.via.container.ptr + o.via.container.size*2);
|
object* const pend(o.via.container.ptr + o.via.container.size*2);
|
||||||
while(p < pend) {
|
while(p < pend) {
|
||||||
K key;
|
K key;
|
||||||
convert(key, *p); ++p;
|
p->convert(&key); ++p;
|
||||||
typename std::map<K,V>::iterator it(v.find(key));
|
typename std::map<K,V>::iterator it(v.find(key));
|
||||||
if(it != v.end()) {
|
if(it != v.end()) {
|
||||||
V val;
|
V val;
|
||||||
convert(val, *p); ++p;
|
p->convert(&val); ++p;
|
||||||
it->insert( std::pair<K,V>(key, val) );
|
it->insert( std::pair<K,V>(key, val) );
|
||||||
} else {
|
} else {
|
||||||
convert(it->second, *p); ++p;
|
p->convert(&it->second); ++p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
@ -98,8 +98,8 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const std::map<K,V>& v)
|
|||||||
o.pack_map(v.size());
|
o.pack_map(v.size());
|
||||||
for(typename std::map<K,V>::const_iterator it(v.begin()), it_end(v.end());
|
for(typename std::map<K,V>::const_iterator it(v.begin()), it_end(v.end());
|
||||||
it != it_end; ++it) {
|
it != it_end; ++it) {
|
||||||
pack(o, it->first);
|
o.pack(it->first);
|
||||||
pack(o, it->second);
|
o.pack(it->second);
|
||||||
}
|
}
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
@ -109,12 +109,12 @@ template <typename K, typename V>
|
|||||||
inline std::multimap<K, V> operator>> (object o, std::multimap<K, V>& v)
|
inline std::multimap<K, V> operator>> (object o, std::multimap<K, V>& v)
|
||||||
{
|
{
|
||||||
if(o.type != type::MAP) { throw type_error(); }
|
if(o.type != type::MAP) { throw type_error(); }
|
||||||
object* p(o.via.container.ptr);
|
object* p = o.via.container.ptr;
|
||||||
object* const pend(o.via.container.ptr + o.via.container.size*2);
|
object* const pend = o.via.container.ptr + o.via.container.size*2;
|
||||||
while(p < pend) {
|
while(p < pend) {
|
||||||
std::pair<K, V> value;
|
std::pair<K, V> value;
|
||||||
convert(value.first, *p); ++p;
|
p->convert(&value.first); ++p;
|
||||||
convert(value.second, *p); ++p;
|
p->convert(&value.second); ++p;
|
||||||
v.insert(value);
|
v.insert(value);
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
@ -126,8 +126,8 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const std::multimap<K,V>&
|
|||||||
o.pack_multimap(v.size());
|
o.pack_multimap(v.size());
|
||||||
for(typename std::multimap<K,V>::const_iterator it(v.begin()), it_end(v.end());
|
for(typename std::multimap<K,V>::const_iterator it(v.begin()), it_end(v.end());
|
||||||
it != it_end; ++it) {
|
it != it_end; ++it) {
|
||||||
pack(o, it->first);
|
o.pack(it->first);
|
||||||
pack(o, it->second);
|
o.pack(it->second);
|
||||||
}
|
}
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ struct tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> {
|
|||||||
tuple() {}
|
tuple() {}
|
||||||
tuple(typename tuple_type<A0>::transparent_reference _a0<%1.upto(i) {|j|%>, typename tuple_type<A<%=j%>>::transparent_reference _a<%=j%><%}%>) :
|
tuple(typename tuple_type<A0>::transparent_reference _a0<%1.upto(i) {|j|%>, typename tuple_type<A<%=j%>>::transparent_reference _a<%=j%><%}%>) :
|
||||||
a0(_a0)<%1.upto(i) {|j|%>, a<%=j%>(_a<%=j%>)<%}%> {}
|
a0(_a0)<%1.upto(i) {|j|%>, a<%=j%>(_a<%=j%>)<%}%> {}
|
||||||
tuple(object o) { convert(*this, o); }
|
tuple(object o) { o.convert(this); }
|
||||||
template <int N> typename tuple_element<value_type, N>::reference get()
|
template <int N> typename tuple_element<value_type, N>::reference get()
|
||||||
{ return tuple_element<value_type, N>(*this).get(); }
|
{ return tuple_element<value_type, N>(*this).get(); }
|
||||||
template <int N> typename const_tuple_element<value_type, N>::const_reference get() const
|
template <int N> typename const_tuple_element<value_type, N>::const_reference get() const
|
||||||
@ -138,7 +138,7 @@ type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& operator>> (
|
|||||||
if(o.type != type::ARRAY) { throw type_error(); }
|
if(o.type != type::ARRAY) { throw type_error(); }
|
||||||
if(o.via.container.size < <%=i+1%>) { throw type_error(); }
|
if(o.via.container.size < <%=i+1%>) { throw type_error(); }
|
||||||
<%0.upto(i) {|j|%>
|
<%0.upto(i) {|j|%>
|
||||||
convert<A<%=j%>>(v.template get<<%=j%>>(), o.via.container.ptr[<%=j%>]);<%}%>
|
o.via.container.ptr[<%=j%>].convert<A<%=j%>>(&v.template get<<%=j%>>());<%}%>
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
<%}%>
|
<%}%>
|
||||||
@ -158,7 +158,7 @@ const packer<Stream>& operator<< (
|
|||||||
const type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& v) {
|
const type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& v) {
|
||||||
o.pack_array(<%=i+1%>);
|
o.pack_array(<%=i+1%>);
|
||||||
<%0.upto(i) {|j|%>
|
<%0.upto(i) {|j|%>
|
||||||
pack(o, v.template get<<%=j%>>());<%}%>
|
o.pack(v.template get<<%=j%>>());<%}%>
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
<%}%>
|
<%}%>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// MessagePack for C++ deserializing routine
|
// MessagePack for C++ deserializing routine
|
||||||
//
|
//
|
||||||
// Copyright (C) 2008 FURUHASHI Sadayuki
|
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
@ -23,30 +23,25 @@ namespace msgpack {
|
|||||||
|
|
||||||
|
|
||||||
//namespace {
|
//namespace {
|
||||||
struct allocator {
|
struct unpack_user {
|
||||||
zone* z;
|
zone* z;
|
||||||
bool referenced;
|
bool referenced;
|
||||||
|
|
||||||
inline object* malloc_object(size_t n)
|
|
||||||
{
|
|
||||||
return (object*)z->malloc(sizeof(object)*n);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
//} // noname namespace
|
//} // noname namespace
|
||||||
|
|
||||||
|
|
||||||
#define msgpack_unpack_struct(name) \
|
#define msgpack_unpack_struct(name) \
|
||||||
struct msgpack_unpacker_##name
|
struct msgpack_unpacker ## name
|
||||||
|
|
||||||
#define msgpack_unpack_func(ret, name) \
|
#define msgpack_unpack_func(ret, name) \
|
||||||
ret msgpack_unpacker_##name
|
ret msgpack_unpacker ## name
|
||||||
|
|
||||||
#define msgpack_unpack_callback(name) \
|
#define msgpack_unpack_callback(name) \
|
||||||
msgpack_unpack_##name
|
msgpack_unpack ## name
|
||||||
|
|
||||||
#define msgpack_unpack_object object
|
#define msgpack_unpack_object object
|
||||||
|
|
||||||
#define msgpack_unpack_user allocator
|
#define msgpack_unpack_user unpack_user
|
||||||
|
|
||||||
|
|
||||||
struct msgpack_unpacker_context;
|
struct msgpack_unpacker_context;
|
||||||
@ -59,87 +54,87 @@ static int msgpack_unpacker_execute(struct msgpack_unpacker_context* ctx,
|
|||||||
const char* data, size_t len, size_t* off);
|
const char* data, size_t len, size_t* off);
|
||||||
|
|
||||||
|
|
||||||
static inline object msgpack_unpack_init(allocator* a)
|
static inline object msgpack_unpack_init(unpack_user* u)
|
||||||
{ return object(); }
|
{ return object(); }
|
||||||
|
|
||||||
static inline object msgpack_unpack_uint8(allocator* a, uint8_t d)
|
static inline object msgpack_unpack_uint8(unpack_user* u, uint8_t d)
|
||||||
{ object o; o.type = type::POSITIVE_INTEGER; o.via.u64 = d; return o; }
|
{ object o; o.type = type::POSITIVE_INTEGER; o.via.u64 = d; return o; }
|
||||||
|
|
||||||
static inline object msgpack_unpack_uint16(allocator* a, uint16_t d)
|
static inline object msgpack_unpack_uint16(unpack_user* u, uint16_t d)
|
||||||
{ object o; o.type = type::POSITIVE_INTEGER; o.via.u64 = d; return o; }
|
{ object o; o.type = type::POSITIVE_INTEGER; o.via.u64 = d; return o; }
|
||||||
|
|
||||||
static inline object msgpack_unpack_uint32(allocator* a, uint32_t d)
|
static inline object msgpack_unpack_uint32(unpack_user* u, uint32_t d)
|
||||||
{ object o; o.type = type::POSITIVE_INTEGER; o.via.u64 = d; return o; }
|
{ object o; o.type = type::POSITIVE_INTEGER; o.via.u64 = d; return o; }
|
||||||
|
|
||||||
static inline object msgpack_unpack_uint64(allocator* a, uint64_t d)
|
static inline object msgpack_unpack_uint64(unpack_user* u, uint64_t d)
|
||||||
{ object o; o.type = type::POSITIVE_INTEGER; o.via.u64 = d; return o; }
|
{ object o; o.type = type::POSITIVE_INTEGER; o.via.u64 = d; return o; }
|
||||||
|
|
||||||
static inline object msgpack_unpack_int8(allocator* a, int8_t d)
|
static inline object msgpack_unpack_int8(unpack_user* u, int8_t d)
|
||||||
{ if(d >= 0) { object o; o.type = type::POSITIVE_INTEGER; o.via.u64 = d; return o; }
|
{ if(d >= 0) { object o; o.type = type::POSITIVE_INTEGER; o.via.u64 = d; return o; }
|
||||||
else { object o; o.type = type::NEGATIVE_INTEGER; o.via.i64 = d; return o; } }
|
else { object o; o.type = type::NEGATIVE_INTEGER; o.via.i64 = d; return o; } }
|
||||||
|
|
||||||
static inline object msgpack_unpack_int16(allocator* a, int16_t d)
|
static inline object msgpack_unpack_int16(unpack_user* u, int16_t d)
|
||||||
{ if(d >= 0) { object o; o.type = type::POSITIVE_INTEGER; o.via.u64 = d; return o; }
|
{ if(d >= 0) { object o; o.type = type::POSITIVE_INTEGER; o.via.u64 = d; return o; }
|
||||||
else { object o; o.type = type::NEGATIVE_INTEGER; o.via.i64 = d; return o; } }
|
else { object o; o.type = type::NEGATIVE_INTEGER; o.via.i64 = d; return o; } }
|
||||||
|
|
||||||
static inline object msgpack_unpack_int32(allocator* a, int32_t d)
|
static inline object msgpack_unpack_int32(unpack_user* u, int32_t d)
|
||||||
{ if(d >= 0) { object o; o.type = type::POSITIVE_INTEGER; o.via.u64 = d; return o; }
|
{ if(d >= 0) { object o; o.type = type::POSITIVE_INTEGER; o.via.u64 = d; return o; }
|
||||||
else { object o; o.type = type::NEGATIVE_INTEGER; o.via.i64 = d; return o; } }
|
else { object o; o.type = type::NEGATIVE_INTEGER; o.via.i64 = d; return o; } }
|
||||||
|
|
||||||
static inline object msgpack_unpack_int64(allocator* a, int64_t d)
|
static inline object msgpack_unpack_int64(unpack_user* u, int64_t d)
|
||||||
{ if(d >= 0) { object o; o.type = type::POSITIVE_INTEGER; o.via.u64 = d; return o; }
|
{ if(d >= 0) { object o; o.type = type::POSITIVE_INTEGER; o.via.u64 = d; return o; }
|
||||||
else { object o; o.type = type::NEGATIVE_INTEGER; o.via.i64 = d; return o; } }
|
else { object o; o.type = type::NEGATIVE_INTEGER; o.via.i64 = d; return o; } }
|
||||||
|
|
||||||
static inline object msgpack_unpack_float(allocator* a, float d)
|
static inline object msgpack_unpack_float(unpack_user* u, float d)
|
||||||
{ object o; o.type = type::DOUBLE; o.via.dec = d; return o; }
|
{ object o; o.type = type::DOUBLE; o.via.dec = d; return o; }
|
||||||
|
|
||||||
static inline object msgpack_unpack_double(allocator* a, double d)
|
static inline object msgpack_unpack_double(unpack_user* u, double d)
|
||||||
{ object o; o.type = type::DOUBLE; o.via.dec = d; return o; }
|
{ object o; o.type = type::DOUBLE; o.via.dec = d; return o; }
|
||||||
|
|
||||||
static inline object msgpack_unpack_nil(allocator* a)
|
static inline object msgpack_unpack_nil(unpack_user* u)
|
||||||
{ object o; o.type = type::NIL; return o; }
|
{ object o; o.type = type::NIL; return o; }
|
||||||
|
|
||||||
static inline object msgpack_unpack_true(allocator* a)
|
static inline object msgpack_unpack_true(unpack_user* u)
|
||||||
{ object o; o.type = type::BOOLEAN; o.via.boolean = true; return o; }
|
{ object o; o.type = type::BOOLEAN; o.via.boolean = true; return o; }
|
||||||
|
|
||||||
static inline object msgpack_unpack_false(allocator* a)
|
static inline object msgpack_unpack_false(unpack_user* u)
|
||||||
{ object o; o.type = type::BOOLEAN; o.via.boolean = false; return o; }
|
{ object o; o.type = type::BOOLEAN; o.via.boolean = false; return o; }
|
||||||
|
|
||||||
static inline object msgpack_unpack_array(allocator* a, unsigned int n)
|
static inline object msgpack_unpack_array(unpack_user* u, unsigned int n)
|
||||||
{
|
{
|
||||||
object o;
|
object o;
|
||||||
o.type = type::ARRAY;
|
o.type = type::ARRAY;
|
||||||
o.via.container.size = 0;
|
o.via.container.size = 0;
|
||||||
o.via.container.ptr = a->malloc_object(n);
|
o.via.container.ptr = (object*)u->z->malloc(n*sizeof(object));
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void msgpack_unpack_array_item(allocator* a, object* c, object o)
|
static inline void msgpack_unpack_array_item(unpack_user* u, object* c, object o)
|
||||||
{ c->via.container.ptr[ c->via.container.size++ ] = o; }
|
{ c->via.container.ptr[ c->via.container.size++ ] = o; }
|
||||||
|
|
||||||
static inline object msgpack_unpack_map(allocator* a, unsigned int n)
|
static inline object msgpack_unpack_map(unpack_user* u, unsigned int n)
|
||||||
{
|
{
|
||||||
object o;
|
object o;
|
||||||
o.type = type::MAP;
|
o.type = type::MAP;
|
||||||
o.via.container.size = 0;
|
o.via.container.size = 0;
|
||||||
o.via.container.ptr = a->malloc_object(n*2);
|
o.via.container.ptr = (object*)u->z->malloc(n*2*sizeof(object));
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void msgpack_unpack_map_item(allocator* a, object* c, object k, object v)
|
static inline void msgpack_unpack_map_item(unpack_user* u, object* c, object k, object v)
|
||||||
{
|
{
|
||||||
c->via.container.ptr[ c->via.container.size ] = k;
|
c->via.container.ptr[ c->via.container.size ] = k;
|
||||||
c->via.container.ptr[ c->via.container.size+1 ] = v;
|
c->via.container.ptr[ c->via.container.size+1 ] = v;
|
||||||
++c->via.container.size;
|
++c->via.container.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline object msgpack_unpack_raw(allocator* a, const char* b, const char* p, unsigned int l)
|
static inline object msgpack_unpack_raw(unpack_user* u, const char* b, const char* p, unsigned int l)
|
||||||
{
|
{
|
||||||
object o;
|
object o;
|
||||||
o.type = type::RAW;
|
o.type = type::RAW;
|
||||||
o.via.ref.ptr = p;
|
o.via.ref.ptr = p;
|
||||||
o.via.ref.size = l;
|
o.via.ref.size = l;
|
||||||
a->referenced = true;
|
u->referenced = true;
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,8 +146,8 @@ struct context {
|
|||||||
context()
|
context()
|
||||||
{
|
{
|
||||||
msgpack_unpacker_init(&m_ctx);
|
msgpack_unpacker_init(&m_ctx);
|
||||||
allocator a = {NULL, false};
|
unpack_user u = {NULL, false};
|
||||||
m_ctx.user = a;
|
m_ctx.user = u;
|
||||||
}
|
}
|
||||||
|
|
||||||
~context() { }
|
~context() { }
|
||||||
@ -171,8 +166,8 @@ struct context {
|
|||||||
{
|
{
|
||||||
zone* z = m_ctx.user.z;
|
zone* z = m_ctx.user.z;
|
||||||
msgpack_unpacker_init(&m_ctx);
|
msgpack_unpacker_init(&m_ctx);
|
||||||
allocator a = {z, false};
|
unpack_user u = {z, false};
|
||||||
m_ctx.user = a;
|
m_ctx.user = u;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_zone(zone* z)
|
void set_zone(zone* z)
|
||||||
@ -193,7 +188,7 @@ private:
|
|||||||
context(const context&);
|
context(const context&);
|
||||||
};
|
};
|
||||||
|
|
||||||
context* as_ctx(void* m)
|
static inline context* as_ctx(void* m)
|
||||||
{
|
{
|
||||||
return reinterpret_cast<context*>(m);
|
return reinterpret_cast<context*>(m);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// MessagePack for C++ deserializing routine
|
// MessagePack for C++ deserializing routine
|
||||||
//
|
//
|
||||||
// Copyright (C) 2008 FURUHASHI Sadayuki
|
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// MessagePack for C++ memory pool
|
// MessagePack for C++ memory pool
|
||||||
//
|
//
|
||||||
// Copyright (C) 2008 FURUHASHI Sadayuki
|
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// MessagePack for C++ memory pool
|
// MessagePack for C++ memory pool
|
||||||
//
|
//
|
||||||
// Copyright (C) 2008 FURUHASHI Sadayuki
|
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* MessagePack unpacking routine template
|
* MessagePack unpacking routine template
|
||||||
*
|
*
|
||||||
* Copyright (C) 2008 FURUHASHI Sadayuki
|
* Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* MessagePack packing routine template
|
* MessagePack packing routine template
|
||||||
*
|
*
|
||||||
* Copyright (C) 2008 FURUHASHI Sadayuki
|
* Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -278,49 +278,49 @@ do { \
|
|||||||
|
|
||||||
#ifdef msgpack_pack_inline_func_fastint
|
#ifdef msgpack_pack_inline_func_fastint
|
||||||
|
|
||||||
msgpack_pack_inline_func_fastint(uint8)(msgpack_pack_user x, uint8_t d)
|
msgpack_pack_inline_func_fastint(_uint8)(msgpack_pack_user x, uint8_t d)
|
||||||
{
|
{
|
||||||
const unsigned char buf[2] = {0xcc, d};
|
const unsigned char buf[2] = {0xcc, d};
|
||||||
msgpack_pack_append_buffer(x, buf, 2);
|
msgpack_pack_append_buffer(x, buf, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
msgpack_pack_inline_func_fastint(uint16)(msgpack_pack_user x, uint16_t d)
|
msgpack_pack_inline_func_fastint(_uint16)(msgpack_pack_user x, uint16_t d)
|
||||||
{
|
{
|
||||||
const unsigned char buf[3] = {0xcd, STORE_BE16(d)};
|
const unsigned char buf[3] = {0xcd, STORE_BE16(d)};
|
||||||
msgpack_pack_append_buffer(x, buf, 3);
|
msgpack_pack_append_buffer(x, buf, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
msgpack_pack_inline_func_fastint(uint32)(msgpack_pack_user x, uint32_t d)
|
msgpack_pack_inline_func_fastint(_uint32)(msgpack_pack_user x, uint32_t d)
|
||||||
{
|
{
|
||||||
const unsigned char buf[5] = {0xce, STORE_BE32(d)};
|
const unsigned char buf[5] = {0xce, STORE_BE32(d)};
|
||||||
msgpack_pack_append_buffer(x, buf, 5);
|
msgpack_pack_append_buffer(x, buf, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
msgpack_pack_inline_func_fastint(uint64)(msgpack_pack_user x, uint64_t d)
|
msgpack_pack_inline_func_fastint(_uint64)(msgpack_pack_user x, uint64_t d)
|
||||||
{
|
{
|
||||||
const unsigned char buf[9] = {0xcf, STORE_BE64(d)};
|
const unsigned char buf[9] = {0xcf, STORE_BE64(d)};
|
||||||
msgpack_pack_append_buffer(x, buf, 9);
|
msgpack_pack_append_buffer(x, buf, 9);
|
||||||
}
|
}
|
||||||
|
|
||||||
msgpack_pack_inline_func_fastint(int8)(msgpack_pack_user x, int8_t d)
|
msgpack_pack_inline_func_fastint(_int8)(msgpack_pack_user x, int8_t d)
|
||||||
{
|
{
|
||||||
const unsigned char buf[2] = {0xd0, d};
|
const unsigned char buf[2] = {0xd0, d};
|
||||||
msgpack_pack_append_buffer(x, buf, 2);
|
msgpack_pack_append_buffer(x, buf, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
msgpack_pack_inline_func_fastint(int16)(msgpack_pack_user x, int16_t d)
|
msgpack_pack_inline_func_fastint(_int16)(msgpack_pack_user x, int16_t d)
|
||||||
{
|
{
|
||||||
const unsigned char buf[3] = {0xd1, STORE_BE16(d)};
|
const unsigned char buf[3] = {0xd1, STORE_BE16(d)};
|
||||||
msgpack_pack_append_buffer(x, buf, 3);
|
msgpack_pack_append_buffer(x, buf, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
msgpack_pack_inline_func_fastint(int32)(msgpack_pack_user x, int32_t d)
|
msgpack_pack_inline_func_fastint(_int32)(msgpack_pack_user x, int32_t d)
|
||||||
{
|
{
|
||||||
const unsigned char buf[5] = {0xd2, STORE_BE32(d)};
|
const unsigned char buf[5] = {0xd2, STORE_BE32(d)};
|
||||||
msgpack_pack_append_buffer(x, buf, 5);
|
msgpack_pack_append_buffer(x, buf, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
msgpack_pack_inline_func_fastint(int64)(msgpack_pack_user x, int64_t d)
|
msgpack_pack_inline_func_fastint(_int64)(msgpack_pack_user x, int64_t d)
|
||||||
{
|
{
|
||||||
const unsigned char buf[9] = {0xd3, STORE_BE64(d)};
|
const unsigned char buf[9] = {0xd3, STORE_BE64(d)};
|
||||||
msgpack_pack_append_buffer(x, buf, 9);
|
msgpack_pack_append_buffer(x, buf, 9);
|
||||||
@ -330,42 +330,42 @@ msgpack_pack_inline_func_fastint(int64)(msgpack_pack_user x, int64_t d)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
msgpack_pack_inline_func(uint8)(msgpack_pack_user x, uint8_t d)
|
msgpack_pack_inline_func(_uint8)(msgpack_pack_user x, uint8_t d)
|
||||||
{
|
{
|
||||||
msgpack_pack_real_uint8(x, d);
|
msgpack_pack_real_uint8(x, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
msgpack_pack_inline_func(uint16)(msgpack_pack_user x, uint16_t d)
|
msgpack_pack_inline_func(_uint16)(msgpack_pack_user x, uint16_t d)
|
||||||
{
|
{
|
||||||
msgpack_pack_real_uint16(x, d);
|
msgpack_pack_real_uint16(x, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
msgpack_pack_inline_func(uint32)(msgpack_pack_user x, uint32_t d)
|
msgpack_pack_inline_func(_uint32)(msgpack_pack_user x, uint32_t d)
|
||||||
{
|
{
|
||||||
msgpack_pack_real_uint32(x, d);
|
msgpack_pack_real_uint32(x, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
msgpack_pack_inline_func(uint64)(msgpack_pack_user x, uint64_t d)
|
msgpack_pack_inline_func(_uint64)(msgpack_pack_user x, uint64_t d)
|
||||||
{
|
{
|
||||||
msgpack_pack_real_uint64(x, d);
|
msgpack_pack_real_uint64(x, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
msgpack_pack_inline_func(int8)(msgpack_pack_user x, int8_t d)
|
msgpack_pack_inline_func(_int8)(msgpack_pack_user x, int8_t d)
|
||||||
{
|
{
|
||||||
msgpack_pack_real_int8(x, d);
|
msgpack_pack_real_int8(x, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
msgpack_pack_inline_func(int16)(msgpack_pack_user x, int16_t d)
|
msgpack_pack_inline_func(_int16)(msgpack_pack_user x, int16_t d)
|
||||||
{
|
{
|
||||||
msgpack_pack_real_int16(x, d);
|
msgpack_pack_real_int16(x, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
msgpack_pack_inline_func(int32)(msgpack_pack_user x, int32_t d)
|
msgpack_pack_inline_func(_int32)(msgpack_pack_user x, int32_t d)
|
||||||
{
|
{
|
||||||
msgpack_pack_real_int32(x, d);
|
msgpack_pack_real_int32(x, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
msgpack_pack_inline_func(int64)(msgpack_pack_user x, int64_t d)
|
msgpack_pack_inline_func(_int64)(msgpack_pack_user x, int64_t d)
|
||||||
{
|
{
|
||||||
msgpack_pack_real_int64(x, d);
|
msgpack_pack_real_int64(x, d);
|
||||||
}
|
}
|
||||||
@ -373,7 +373,7 @@ msgpack_pack_inline_func(int64)(msgpack_pack_user x, int64_t d)
|
|||||||
|
|
||||||
#ifdef msgpack_pack_inline_func_cint
|
#ifdef msgpack_pack_inline_func_cint
|
||||||
|
|
||||||
msgpack_pack_inline_func_cint(short)(msgpack_pack_user x, short d)
|
msgpack_pack_inline_func_cint(_short)(msgpack_pack_user x, short d)
|
||||||
{
|
{
|
||||||
#if defined(SIZEOF_SHORT) || defined(SHRT_MAX)
|
#if defined(SIZEOF_SHORT) || defined(SHRT_MAX)
|
||||||
#if SIZEOF_SHORT == 2 || SHRT_MAX == 0x7fff
|
#if SIZEOF_SHORT == 2 || SHRT_MAX == 0x7fff
|
||||||
@ -394,7 +394,7 @@ if(sizeof(short) == 2) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
msgpack_pack_inline_func_cint(int)(msgpack_pack_user x, int d)
|
msgpack_pack_inline_func_cint(_int)(msgpack_pack_user x, int d)
|
||||||
{
|
{
|
||||||
#if defined(SIZEOF_INT) || defined(INT_MAX)
|
#if defined(SIZEOF_INT) || defined(INT_MAX)
|
||||||
#if SIZEOF_INT == 2 || INT_MAX == 0x7fff
|
#if SIZEOF_INT == 2 || INT_MAX == 0x7fff
|
||||||
@ -415,7 +415,7 @@ if(sizeof(int) == 2) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
msgpack_pack_inline_func_cint(long)(msgpack_pack_user x, long d)
|
msgpack_pack_inline_func_cint(_long)(msgpack_pack_user x, long d)
|
||||||
{
|
{
|
||||||
#if defined(SIZEOF_LONG) || defined(LONG_MAX)
|
#if defined(SIZEOF_LONG) || defined(LONG_MAX)
|
||||||
#if SIZEOF_LONG == 2 || LONG_MAX == 0x7fffL
|
#if SIZEOF_LONG == 2 || LONG_MAX == 0x7fffL
|
||||||
@ -436,7 +436,7 @@ if(sizeof(long) == 2) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
msgpack_pack_inline_func_cint(long_long)(msgpack_pack_user x, long long d)
|
msgpack_pack_inline_func_cint(_long_long)(msgpack_pack_user x, long long d)
|
||||||
{
|
{
|
||||||
#if defined(SIZEOF_LONG_LONG) || defined(LLONG_MAX)
|
#if defined(SIZEOF_LONG_LONG) || defined(LLONG_MAX)
|
||||||
#if SIZEOF_LONG_LONG == 2 || LLONG_MAX == 0x7fffL
|
#if SIZEOF_LONG_LONG == 2 || LLONG_MAX == 0x7fffL
|
||||||
@ -457,7 +457,7 @@ if(sizeof(long long) == 2) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
msgpack_pack_inline_func_cint(unsigned_short)(msgpack_pack_user x, unsigned short d)
|
msgpack_pack_inline_func_cint(_unsigned_short)(msgpack_pack_user x, unsigned short d)
|
||||||
{
|
{
|
||||||
#if defined(SIZEOF_SHORT) || defined(USHRT_MAX)
|
#if defined(SIZEOF_SHORT) || defined(USHRT_MAX)
|
||||||
#if SIZEOF_SHORT == 2 || USHRT_MAX == 0xffffU
|
#if SIZEOF_SHORT == 2 || USHRT_MAX == 0xffffU
|
||||||
@ -478,7 +478,7 @@ if(sizeof(unsigned short) == 2) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
msgpack_pack_inline_func_cint(unsigned_int)(msgpack_pack_user x, unsigned int d)
|
msgpack_pack_inline_func_cint(_unsigned_int)(msgpack_pack_user x, unsigned int d)
|
||||||
{
|
{
|
||||||
#if defined(SIZEOF_INT) || defined(UINT_MAX)
|
#if defined(SIZEOF_INT) || defined(UINT_MAX)
|
||||||
#if SIZEOF_INT == 2 || UINT_MAX == 0xffffU
|
#if SIZEOF_INT == 2 || UINT_MAX == 0xffffU
|
||||||
@ -499,7 +499,7 @@ if(sizeof(unsigned int) == 2) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
msgpack_pack_inline_func_cint(unsigned_long)(msgpack_pack_user x, unsigned long d)
|
msgpack_pack_inline_func_cint(_unsigned_long)(msgpack_pack_user x, unsigned long d)
|
||||||
{
|
{
|
||||||
#if defined(SIZEOF_LONG) || defined(ULONG_MAX)
|
#if defined(SIZEOF_LONG) || defined(ULONG_MAX)
|
||||||
#if SIZEOF_LONG == 2 || ULONG_MAX == 0xffffUL
|
#if SIZEOF_LONG == 2 || ULONG_MAX == 0xffffUL
|
||||||
@ -520,7 +520,7 @@ if(sizeof(unsigned int) == 2) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
msgpack_pack_inline_func_cint(unsigned_long_long)(msgpack_pack_user x, unsigned long long d)
|
msgpack_pack_inline_func_cint(_unsigned_long_long)(msgpack_pack_user x, unsigned long long d)
|
||||||
{
|
{
|
||||||
#if defined(SIZEOF_LONG_LONG) || defined(ULLONG_MAX)
|
#if defined(SIZEOF_LONG_LONG) || defined(ULLONG_MAX)
|
||||||
#if SIZEOF_LONG_LONG == 2 || ULLONG_MAX == 0xffffUL
|
#if SIZEOF_LONG_LONG == 2 || ULLONG_MAX == 0xffffUL
|
||||||
@ -550,17 +550,19 @@ if(sizeof(unsigned long long) == 2) {
|
|||||||
* Float
|
* Float
|
||||||
*/
|
*/
|
||||||
|
|
||||||
msgpack_pack_inline_func(float)(msgpack_pack_user x, float d)
|
msgpack_pack_inline_func(_float)(msgpack_pack_user x, float d)
|
||||||
{
|
{
|
||||||
uint32_t n = *((uint32_t*)&d); // FIXME
|
union { char buf[4]; uint32_t num; } f;
|
||||||
const unsigned char buf[5] = {0xca, STORE_BE32(n)};
|
*((float*)&f.buf) = d; // FIXME
|
||||||
|
const unsigned char buf[5] = {0xca, STORE_BE32(f.num)};
|
||||||
msgpack_pack_append_buffer(x, buf, 5);
|
msgpack_pack_append_buffer(x, buf, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
msgpack_pack_inline_func(double)(msgpack_pack_user x, double d)
|
msgpack_pack_inline_func(_double)(msgpack_pack_user x, double d)
|
||||||
{
|
{
|
||||||
uint64_t n = *((uint64_t*)&d); // FIXME
|
union { char buf[8]; uint64_t num; } f;
|
||||||
const unsigned char buf[9] = {0xcb, STORE_BE64(n)};
|
*((double*)&f.buf) = d; // FIXME
|
||||||
|
const unsigned char buf[9] = {0xcb, STORE_BE64(f.num)};
|
||||||
msgpack_pack_append_buffer(x, buf, 9);
|
msgpack_pack_append_buffer(x, buf, 9);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -569,7 +571,7 @@ msgpack_pack_inline_func(double)(msgpack_pack_user x, double d)
|
|||||||
* Nil
|
* Nil
|
||||||
*/
|
*/
|
||||||
|
|
||||||
msgpack_pack_inline_func(nil)(msgpack_pack_user x)
|
msgpack_pack_inline_func(_nil)(msgpack_pack_user x)
|
||||||
{
|
{
|
||||||
static const unsigned char d = 0xc0;
|
static const unsigned char d = 0xc0;
|
||||||
msgpack_pack_append_buffer(x, &d, 1);
|
msgpack_pack_append_buffer(x, &d, 1);
|
||||||
@ -580,13 +582,13 @@ msgpack_pack_inline_func(nil)(msgpack_pack_user x)
|
|||||||
* Boolean
|
* Boolean
|
||||||
*/
|
*/
|
||||||
|
|
||||||
msgpack_pack_inline_func(true)(msgpack_pack_user x)
|
msgpack_pack_inline_func(_true)(msgpack_pack_user x)
|
||||||
{
|
{
|
||||||
static const unsigned char d = 0xc3;
|
static const unsigned char d = 0xc3;
|
||||||
msgpack_pack_append_buffer(x, &d, 1);
|
msgpack_pack_append_buffer(x, &d, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
msgpack_pack_inline_func(false)(msgpack_pack_user x)
|
msgpack_pack_inline_func(_false)(msgpack_pack_user x)
|
||||||
{
|
{
|
||||||
static const unsigned char d = 0xc2;
|
static const unsigned char d = 0xc2;
|
||||||
msgpack_pack_append_buffer(x, &d, 1);
|
msgpack_pack_append_buffer(x, &d, 1);
|
||||||
@ -597,7 +599,7 @@ msgpack_pack_inline_func(false)(msgpack_pack_user x)
|
|||||||
* Array
|
* Array
|
||||||
*/
|
*/
|
||||||
|
|
||||||
msgpack_pack_inline_func(array)(msgpack_pack_user x, unsigned int n)
|
msgpack_pack_inline_func(_array)(msgpack_pack_user x, unsigned int n)
|
||||||
{
|
{
|
||||||
if(n < 16) {
|
if(n < 16) {
|
||||||
unsigned char d = 0x90 | n;
|
unsigned char d = 0x90 | n;
|
||||||
@ -618,7 +620,7 @@ msgpack_pack_inline_func(array)(msgpack_pack_user x, unsigned int n)
|
|||||||
* Map
|
* Map
|
||||||
*/
|
*/
|
||||||
|
|
||||||
msgpack_pack_inline_func(map)(msgpack_pack_user x, unsigned int n)
|
msgpack_pack_inline_func(_map)(msgpack_pack_user x, unsigned int n)
|
||||||
{
|
{
|
||||||
if(n < 16) {
|
if(n < 16) {
|
||||||
unsigned char d = 0x80 | n;
|
unsigned char d = 0x80 | n;
|
||||||
@ -639,7 +641,7 @@ msgpack_pack_inline_func(map)(msgpack_pack_user x, unsigned int n)
|
|||||||
* Raw
|
* Raw
|
||||||
*/
|
*/
|
||||||
|
|
||||||
msgpack_pack_inline_func(raw)(msgpack_pack_user x, size_t l)
|
msgpack_pack_inline_func(_raw)(msgpack_pack_user x, size_t l)
|
||||||
{
|
{
|
||||||
if(l < 32) {
|
if(l < 32) {
|
||||||
unsigned char d = 0xa0 | l;
|
unsigned char d = 0xa0 | l;
|
||||||
@ -655,7 +657,7 @@ msgpack_pack_inline_func(raw)(msgpack_pack_user x, size_t l)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
msgpack_pack_inline_func(raw_body)(msgpack_pack_user x, const void* b, size_t 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);
|
msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* MessagePack unpacking routine template
|
* MessagePack unpacking routine template
|
||||||
*
|
*
|
||||||
* Copyright (C) 2008 FURUHASHI Sadayuki
|
* Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* MessagePack unpacking routine template
|
* MessagePack unpacking routine template
|
||||||
*
|
*
|
||||||
* Copyright (C) 2008 FURUHASHI Sadayuki
|
* Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -41,38 +41,38 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
msgpack_unpack_struct_decl(stack) {
|
msgpack_unpack_struct_decl(_stack) {
|
||||||
msgpack_unpack_object obj;
|
msgpack_unpack_object obj;
|
||||||
size_t count;
|
size_t count;
|
||||||
unsigned int ct;
|
unsigned int ct;
|
||||||
msgpack_unpack_object map_key;
|
msgpack_unpack_object map_key;
|
||||||
};
|
};
|
||||||
|
|
||||||
msgpack_unpack_struct_decl(context) {
|
msgpack_unpack_struct_decl(_context) {
|
||||||
msgpack_unpack_user user; // must be first
|
msgpack_unpack_user user; // must be first
|
||||||
unsigned int cs;
|
unsigned int cs;
|
||||||
unsigned int trail;
|
unsigned int trail;
|
||||||
unsigned int top;
|
unsigned int top;
|
||||||
msgpack_unpack_struct(stack) stack[MSGPACK_MAX_STACK_SIZE];
|
msgpack_unpack_struct(_stack) stack[MSGPACK_MAX_STACK_SIZE];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
msgpack_unpack_func(void, init)(msgpack_unpack_struct(context)* ctx)
|
msgpack_unpack_func(void, _init)(msgpack_unpack_struct(_context)* ctx)
|
||||||
{
|
{
|
||||||
/*memset(ctx, 0, sizeof( msgpack_unpack_struct(context) )); FIXME needed? */
|
/*memset(ctx, 0, sizeof( msgpack_unpack_struct(_context) )); FIXME needed? */
|
||||||
ctx->cs = CS_HEADER;
|
ctx->cs = CS_HEADER;
|
||||||
ctx->trail = 0;
|
ctx->trail = 0;
|
||||||
ctx->top = 0;
|
ctx->top = 0;
|
||||||
ctx->stack[0].obj = msgpack_unpack_callback(init)(&ctx->user);
|
ctx->stack[0].obj = msgpack_unpack_callback(_init)(&ctx->user);
|
||||||
}
|
}
|
||||||
|
|
||||||
msgpack_unpack_func(msgpack_unpack_object, data)(msgpack_unpack_struct(context)* unpacker)
|
msgpack_unpack_func(msgpack_unpack_object, _data)(msgpack_unpack_struct(_context)* unpacker)
|
||||||
{
|
{
|
||||||
return (unpacker)->stack[0].obj;
|
return (unpacker)->stack[0].obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
msgpack_unpack_func(int, execute)(msgpack_unpack_struct(context)* ctx, const char* data, size_t len, size_t* off)
|
msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const char* data, size_t len, size_t* off)
|
||||||
{
|
{
|
||||||
assert(len >= *off);
|
assert(len >= *off);
|
||||||
|
|
||||||
@ -83,11 +83,11 @@ msgpack_unpack_func(int, execute)(msgpack_unpack_struct(context)* ctx, const cha
|
|||||||
unsigned int trail = ctx->trail;
|
unsigned int trail = ctx->trail;
|
||||||
unsigned int cs = ctx->cs;
|
unsigned int cs = ctx->cs;
|
||||||
unsigned int top = ctx->top;
|
unsigned int top = ctx->top;
|
||||||
msgpack_unpack_struct(stack)* stack = ctx->stack;
|
msgpack_unpack_struct(_stack)* stack = ctx->stack;
|
||||||
msgpack_unpack_user* user = &ctx->user;
|
msgpack_unpack_user* user = &ctx->user;
|
||||||
|
|
||||||
msgpack_unpack_object obj;
|
msgpack_unpack_object obj;
|
||||||
msgpack_unpack_struct(stack)* c = NULL;
|
msgpack_unpack_struct(_stack)* c = NULL;
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -139,19 +139,19 @@ msgpack_unpack_func(int, execute)(msgpack_unpack_struct(context)* ctx, const cha
|
|||||||
case CS_HEADER:
|
case CS_HEADER:
|
||||||
switch(*p) {
|
switch(*p) {
|
||||||
case 0x00 ... 0x7f: // Positive Fixnum
|
case 0x00 ... 0x7f: // Positive Fixnum
|
||||||
push_fixed_value(uint8, *(uint8_t*)p);
|
push_fixed_value(_uint8, *(uint8_t*)p);
|
||||||
case 0xe0 ... 0xff: // Negative Fixnum
|
case 0xe0 ... 0xff: // Negative Fixnum
|
||||||
push_fixed_value(int8, *(int8_t*)p);
|
push_fixed_value(_int8, *(int8_t*)p);
|
||||||
case 0xc0 ... 0xdf: // Variable
|
case 0xc0 ... 0xdf: // Variable
|
||||||
switch(*p) {
|
switch(*p) {
|
||||||
case 0xc0: // nil
|
case 0xc0: // nil
|
||||||
push_simple_value(nil);
|
push_simple_value(_nil);
|
||||||
//case 0xc1: // string
|
//case 0xc1: // string
|
||||||
// again_terminal_trail(NEXT_CS(p), p+1);
|
// again_terminal_trail(NEXT_CS(p), p+1);
|
||||||
case 0xc2: // false
|
case 0xc2: // false
|
||||||
push_simple_value(false);
|
push_simple_value(_false);
|
||||||
case 0xc3: // true
|
case 0xc3: // true
|
||||||
push_simple_value(true);
|
push_simple_value(_true);
|
||||||
//case 0xc4:
|
//case 0xc4:
|
||||||
//case 0xc5:
|
//case 0xc5:
|
||||||
//case 0xc6:
|
//case 0xc6:
|
||||||
@ -188,9 +188,9 @@ msgpack_unpack_func(int, execute)(msgpack_unpack_struct(context)* ctx, const cha
|
|||||||
case 0xa0 ... 0xbf: // FixRaw
|
case 0xa0 ... 0xbf: // FixRaw
|
||||||
again_fixed_trail_if_zero(ACS_RAW_VALUE, ((unsigned int)*p & 0x1f), _raw_zero);
|
again_fixed_trail_if_zero(ACS_RAW_VALUE, ((unsigned int)*p & 0x1f), _raw_zero);
|
||||||
case 0x90 ... 0x9f: // FixArray
|
case 0x90 ... 0x9f: // FixArray
|
||||||
start_container(array, ((unsigned int)*p) & 0x0f, CT_ARRAY_ITEM);
|
start_container(_array, ((unsigned int)*p) & 0x0f, CT_ARRAY_ITEM);
|
||||||
case 0x80 ... 0x8f: // FixMap
|
case 0x80 ... 0x8f: // FixMap
|
||||||
start_container(map, ((unsigned int)*p) & 0x0f, CT_MAP_KEY);
|
start_container(_map, ((unsigned int)*p) & 0x0f, CT_MAP_KEY);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
goto _failed;
|
goto _failed;
|
||||||
@ -208,28 +208,30 @@ msgpack_unpack_func(int, execute)(msgpack_unpack_struct(context)* ctx, const cha
|
|||||||
//case CS_
|
//case CS_
|
||||||
//case CS_
|
//case CS_
|
||||||
case CS_FLOAT: {
|
case CS_FLOAT: {
|
||||||
uint32_t x = PTR_CAST_32(n); // FIXME
|
union { uint32_t num; char buf[4]; } f;
|
||||||
push_fixed_value(float, *((float*)&x)); }
|
f.num = PTR_CAST_32(n); // FIXME
|
||||||
|
push_fixed_value(_float, *((float*)f.buf)); }
|
||||||
case CS_DOUBLE: {
|
case CS_DOUBLE: {
|
||||||
uint64_t x = PTR_CAST_64(n); // FIXME
|
union { uint64_t num; char buf[8]; } f;
|
||||||
push_fixed_value(double, *((double*)&x)); }
|
f.num = PTR_CAST_64(n); // FIXME
|
||||||
|
push_fixed_value(_double, *((double*)f.buf)); }
|
||||||
case CS_UINT_8:
|
case CS_UINT_8:
|
||||||
push_fixed_value(uint8, (uint8_t)PTR_CAST_8(n));
|
push_fixed_value(_uint8, (uint8_t)PTR_CAST_8(n));
|
||||||
case CS_UINT_16:
|
case CS_UINT_16:
|
||||||
push_fixed_value(uint16, (uint16_t)PTR_CAST_16(n));
|
push_fixed_value(_uint16, (uint16_t)PTR_CAST_16(n));
|
||||||
case CS_UINT_32:
|
case CS_UINT_32:
|
||||||
push_fixed_value(uint32, (uint32_t)PTR_CAST_32(n));
|
push_fixed_value(_uint32, (uint32_t)PTR_CAST_32(n));
|
||||||
case CS_UINT_64:
|
case CS_UINT_64:
|
||||||
push_fixed_value(uint64, (uint64_t)PTR_CAST_64(n));
|
push_fixed_value(_uint64, (uint64_t)PTR_CAST_64(n));
|
||||||
|
|
||||||
case CS_INT_8:
|
case CS_INT_8:
|
||||||
push_fixed_value(int8, (int8_t)PTR_CAST_8(n));
|
push_fixed_value(_int8, (int8_t)PTR_CAST_8(n));
|
||||||
case CS_INT_16:
|
case CS_INT_16:
|
||||||
push_fixed_value(int16, (int16_t)PTR_CAST_16(n));
|
push_fixed_value(_int16, (int16_t)PTR_CAST_16(n));
|
||||||
case CS_INT_32:
|
case CS_INT_32:
|
||||||
push_fixed_value(int32, (int32_t)PTR_CAST_32(n));
|
push_fixed_value(_int32, (int32_t)PTR_CAST_32(n));
|
||||||
case CS_INT_64:
|
case CS_INT_64:
|
||||||
push_fixed_value(int64, (int64_t)PTR_CAST_64(n));
|
push_fixed_value(_int64, (int64_t)PTR_CAST_64(n));
|
||||||
|
|
||||||
//case CS_
|
//case CS_
|
||||||
//case CS_
|
//case CS_
|
||||||
@ -240,7 +242,7 @@ msgpack_unpack_func(int, execute)(msgpack_unpack_struct(context)* ctx, const cha
|
|||||||
//case ACS_BIG_INT_VALUE:
|
//case ACS_BIG_INT_VALUE:
|
||||||
//_big_int_zero:
|
//_big_int_zero:
|
||||||
// // FIXME
|
// // FIXME
|
||||||
// push_variable_value(big_int, data, n, trail);
|
// push_variable_value(_big_int, data, n, trail);
|
||||||
|
|
||||||
//case CS_BIG_FLOAT_16:
|
//case CS_BIG_FLOAT_16:
|
||||||
// again_fixed_trail_if_zero(ACS_BIG_FLOAT_VALUE, (uint16_t)PTR_CAST_16(n), _big_float_zero);
|
// again_fixed_trail_if_zero(ACS_BIG_FLOAT_VALUE, (uint16_t)PTR_CAST_16(n), _big_float_zero);
|
||||||
@ -249,7 +251,7 @@ msgpack_unpack_func(int, execute)(msgpack_unpack_struct(context)* ctx, const cha
|
|||||||
//case ACS_BIG_FLOAT_VALUE:
|
//case ACS_BIG_FLOAT_VALUE:
|
||||||
//_big_float_zero:
|
//_big_float_zero:
|
||||||
// // FIXME
|
// // FIXME
|
||||||
// push_variable_value(big_float, data, n, trail);
|
// push_variable_value(_big_float, data, n, trail);
|
||||||
|
|
||||||
case CS_RAW_16:
|
case CS_RAW_16:
|
||||||
again_fixed_trail_if_zero(ACS_RAW_VALUE, (uint16_t)PTR_CAST_16(n), _raw_zero);
|
again_fixed_trail_if_zero(ACS_RAW_VALUE, (uint16_t)PTR_CAST_16(n), _raw_zero);
|
||||||
@ -257,17 +259,17 @@ msgpack_unpack_func(int, execute)(msgpack_unpack_struct(context)* ctx, const cha
|
|||||||
again_fixed_trail_if_zero(ACS_RAW_VALUE, (uint32_t)PTR_CAST_32(n), _raw_zero);
|
again_fixed_trail_if_zero(ACS_RAW_VALUE, (uint32_t)PTR_CAST_32(n), _raw_zero);
|
||||||
case ACS_RAW_VALUE:
|
case ACS_RAW_VALUE:
|
||||||
_raw_zero:
|
_raw_zero:
|
||||||
push_variable_value(raw, data, n, trail);
|
push_variable_value(_raw, data, n, trail);
|
||||||
|
|
||||||
case CS_ARRAY_16:
|
case CS_ARRAY_16:
|
||||||
start_container(array, (uint16_t)PTR_CAST_16(n), CT_ARRAY_ITEM);
|
start_container(_array, (uint16_t)PTR_CAST_16(n), CT_ARRAY_ITEM);
|
||||||
case CS_ARRAY_32:
|
case CS_ARRAY_32:
|
||||||
start_container(array, (uint32_t)PTR_CAST_32(n), CT_ARRAY_ITEM);
|
start_container(_array, (uint32_t)PTR_CAST_32(n), CT_ARRAY_ITEM);
|
||||||
|
|
||||||
case CS_MAP_16:
|
case CS_MAP_16:
|
||||||
start_container(map, (uint16_t)PTR_CAST_16(n), CT_MAP_KEY);
|
start_container(_map, (uint16_t)PTR_CAST_16(n), CT_MAP_KEY);
|
||||||
case CS_MAP_32:
|
case CS_MAP_32:
|
||||||
start_container(map, (uint32_t)PTR_CAST_32(n), CT_MAP_KEY);
|
start_container(_map, (uint32_t)PTR_CAST_32(n), CT_MAP_KEY);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
goto _failed;
|
goto _failed;
|
||||||
@ -279,7 +281,7 @@ _push:
|
|||||||
c = &stack[top-1];
|
c = &stack[top-1];
|
||||||
switch(c->ct) {
|
switch(c->ct) {
|
||||||
case CT_ARRAY_ITEM:
|
case CT_ARRAY_ITEM:
|
||||||
msgpack_unpack_callback(array_item)(user, &c->obj, obj);
|
msgpack_unpack_callback(_array_item)(user, &c->obj, obj);
|
||||||
if(--c->count == 0) {
|
if(--c->count == 0) {
|
||||||
obj = c->obj;
|
obj = c->obj;
|
||||||
--top;
|
--top;
|
||||||
@ -292,7 +294,7 @@ _push:
|
|||||||
c->ct = CT_MAP_VALUE;
|
c->ct = CT_MAP_VALUE;
|
||||||
goto _header_again;
|
goto _header_again;
|
||||||
case CT_MAP_VALUE:
|
case CT_MAP_VALUE:
|
||||||
msgpack_unpack_callback(map_item)(user, &c->obj, c->map_key, obj);
|
msgpack_unpack_callback(_map_item)(user, &c->obj, c->map_key, obj);
|
||||||
if(--c->count == 0) {
|
if(--c->count == 0) {
|
||||||
obj = c->obj;
|
obj = c->obj;
|
||||||
--top;
|
--top;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* MessagePack packing routine for Ruby
|
* MessagePack for Ruby packing routine
|
||||||
*
|
*
|
||||||
* Copyright (C) 2008 FURUHASHI Sadayuki
|
* Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -19,10 +19,10 @@
|
|||||||
#include "msgpack/pack_define.h"
|
#include "msgpack/pack_define.h"
|
||||||
|
|
||||||
#define msgpack_pack_inline_func(name) \
|
#define msgpack_pack_inline_func(name) \
|
||||||
static inline void msgpack_pack_##name
|
static inline void msgpack_pack ## name
|
||||||
|
|
||||||
#define msgpack_pack_inline_func_cint(name) \
|
#define msgpack_pack_inline_func_cint(name) \
|
||||||
static inline void msgpack_pack_##name
|
static inline void msgpack_pack ## name
|
||||||
|
|
||||||
#define msgpack_pack_user VALUE
|
#define msgpack_pack_user VALUE
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* MessagePack packing routine for Ruby
|
* MessagePack for Ruby packing routine
|
||||||
*
|
*
|
||||||
* Copyright (C) 2008 FURUHASHI Sadayuki
|
* Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* MessagePack for Ruby
|
* MessagePack for Ruby
|
||||||
*
|
*
|
||||||
* Copyright (C) 2008 FURUHASHI Sadayuki
|
* Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -75,6 +75,13 @@ class MessagePackTestFormat < Test::Unit::TestCase
|
|||||||
check 9, -(1<<63)
|
check 9, -(1<<63)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "double" do
|
||||||
|
check 9, 1.0
|
||||||
|
check 9, 0.1
|
||||||
|
check 9, -0.1
|
||||||
|
check 9, -1.0
|
||||||
|
end
|
||||||
|
|
||||||
it "fixraw" do
|
it "fixraw" do
|
||||||
check_raw 1, 0
|
check_raw 1, 0
|
||||||
check_raw 1, (1<<5)-1
|
check_raw 1, (1<<5)-1
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* MessagePack unpacking routine for Ruby
|
* MessagePack for Ruby unpacking routine
|
||||||
*
|
*
|
||||||
* Copyright (C) 2008 FURUHASHI Sadayuki
|
* Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -26,13 +26,13 @@ typedef struct {
|
|||||||
|
|
||||||
|
|
||||||
#define msgpack_unpack_struct(name) \
|
#define msgpack_unpack_struct(name) \
|
||||||
struct msgpack_unpacker_##name
|
struct msgpack_unpacker ## name
|
||||||
|
|
||||||
#define msgpack_unpack_func(ret, name) \
|
#define msgpack_unpack_func(ret, name) \
|
||||||
ret msgpack_unpacker_##name
|
ret msgpack_unpacker ## name
|
||||||
|
|
||||||
#define msgpack_unpack_callback(name) \
|
#define msgpack_unpack_callback(name) \
|
||||||
template_callback_##name
|
template_callback ## name
|
||||||
|
|
||||||
#define msgpack_unpack_object VALUE
|
#define msgpack_unpack_object VALUE
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* MessagePack unpacking routine for Ruby
|
* MessagePack for Ruby unpacking routine
|
||||||
*
|
*
|
||||||
* Copyright (C) 2008 FURUHASHI Sadayuki
|
* Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user