mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-03-14 18:10:30 +01:00
lang/c/msgpack: removed string type
git-svn-id: file:///Users/frsyuki/project/msgpack-git/svn/x@54 5a5092ae-2292-43ba-b2d5-dcab9c1a2731
This commit is contained in:
parent
f41c20a250
commit
249d3e9c90
@ -55,8 +55,7 @@ static void* unpack_array_start(void* data, unsigned int n) { return NULL; }
|
||||
static void unpack_array_item(void* data, void* c, void* o) { }
|
||||
static void* unpack_map_start(void* data, unsigned int n) { return NULL; }
|
||||
static void unpack_map_item(void* data, void* c, void* k, void* v) { }
|
||||
static void* unpack_string(void* data, const void* b, size_t l) { return NULL; }
|
||||
static void* unpack_raw(void* data, const void* b, size_t l) { /*printf("unpack raw %p %lu\n",b,l);*/ return NULL; }
|
||||
static void* unpack_raw(void* data, const void* b, const void* p, size_t l) { /*printf("unpack raw %p %lu\n",p,l);*/ return NULL; }
|
||||
|
||||
typedef struct {
|
||||
size_t allocated;
|
||||
@ -119,7 +118,7 @@ void bench_json(void)
|
||||
NULL,
|
||||
NULL,
|
||||
reformat_number,
|
||||
reformat_string,
|
||||
reformat_string,
|
||||
reformat_start_map,
|
||||
reformat_map_key,
|
||||
reformat_end_map,
|
||||
@ -236,7 +235,6 @@ void bench_msgpack(void)
|
||||
unpack_array_item,
|
||||
unpack_map_start,
|
||||
unpack_map_item,
|
||||
unpack_string,
|
||||
unpack_raw,
|
||||
};
|
||||
msgpack_unpack_t* mupk = msgpack_unpack_new(NULL, &cb);
|
||||
|
@ -65,8 +65,7 @@ static inline void* msgpack_unpack_array_start(msgpack_unpack_context* x, unsign
|
||||
static inline void msgpack_unpack_array_item(msgpack_unpack_context* x, void* c, void* o) { }
|
||||
static inline void* msgpack_unpack_map_start(msgpack_unpack_context* x, unsigned int n) { return NULL; }
|
||||
static inline void msgpack_unpack_map_item(msgpack_unpack_context* x, void* c, void* k, void* v) { }
|
||||
static inline void* msgpack_unpack_string(msgpack_unpack_context* x, const void* b, size_t l) { return NULL; }
|
||||
static inline void* msgpack_unpack_raw(msgpack_unpack_context* x, const void* b, size_t l) { return NULL; }
|
||||
static inline void* msgpack_unpack_raw(msgpack_unpack_context* x, const void* b, const void* p, size_t l) { return NULL; }
|
||||
|
||||
#include "msgpack/unpack/inline_impl.h"
|
||||
|
||||
@ -131,7 +130,6 @@ void bench_json(void)
|
||||
NULL,
|
||||
NULL,
|
||||
reformat_number,
|
||||
reformat_string,
|
||||
reformat_start_map,
|
||||
reformat_map_key,
|
||||
reformat_end_map,
|
||||
|
@ -39,8 +39,7 @@ typedef struct {
|
||||
void (*unpack_array_item)(void* data, void* c, void* o);
|
||||
void* (*unpack_map_start)(void* data, unsigned int n);
|
||||
void (*unpack_map_item)(void* data, void* c, void* k, void* v);
|
||||
void* (*unpack_string)(void* data, const void* b, size_t l);
|
||||
void* (*unpack_raw)(void* data, const void* b, size_t l);
|
||||
void* (*unpack_raw)(void* data, const void* b, const void* p, size_t l);
|
||||
} msgpack_unpack_callback;
|
||||
|
||||
typedef struct {
|
||||
|
@ -71,11 +71,8 @@ static inline void* msgpack_unpack_map_start(msgpack_unpack_t* x, unsigned int n
|
||||
static inline void msgpack_unpack_map_item(msgpack_unpack_t* x, void* c, void* k, void* v)
|
||||
{ x->callback.unpack_map_item(x->data, c, k, v); }
|
||||
|
||||
static inline void* msgpack_unpack_string(msgpack_unpack_t* x, const void* b, size_t l)
|
||||
{ return x->callback.unpack_string(x->data, b, l); }
|
||||
|
||||
static inline void* msgpack_unpack_raw(msgpack_unpack_t* x, const void* b, size_t l)
|
||||
{ return x->callback.unpack_raw(x->data, b, l); }
|
||||
static inline void* msgpack_unpack_raw(msgpack_unpack_t* x, const void* b, const void* p, size_t l)
|
||||
{ return x->callback.unpack_raw(x->data, b, p, l); }
|
||||
|
||||
|
||||
#include "msgpack/unpack/inline_impl.h"
|
||||
|
@ -20,5 +20,5 @@ msgpack_object msgpack_unpack_array_start(msgpack_unpack_context* x, unsigned in
|
||||
msgpack_object msgpack_unpack_map_start(msgpack_unpack_context* x, unsigned int n);
|
||||
void msgpack_unpack_map_item(msgpack_unpack_context* x, msgpack_object c, msgpack_object k, msgpack_object v);
|
||||
msgpack_object msgpack_unpack_string(msgpack_unpack_context* x, const void* b, size_t l);
|
||||
msgpack_object msgpack_unpack_raw(msgpack_unpack_context* x, const void* b, size_t l);
|
||||
msgpack_object msgpack_unpack_raw(msgpack_unpack_context* x, const void* b, const void* p, size_t l);
|
||||
|
||||
|
@ -34,7 +34,7 @@ typedef struct {
|
||||
size_t count;
|
||||
unsigned int ct;
|
||||
union {
|
||||
const unsigned char* terminal_trail_start;
|
||||
/*const unsigned char* terminal_trail_start;*/
|
||||
msgpack_object map_key;
|
||||
} tmp;
|
||||
} msgpack_unpacker_stack;
|
||||
|
@ -103,7 +103,7 @@ static inline uint64_t betoh64(uint64_t x) {
|
||||
typedef enum {
|
||||
CS_HEADER = 0x00, // nil
|
||||
|
||||
CS_STRING = 0x01,
|
||||
//CS_STRING = 0x01,
|
||||
//CS_ = 0x02, // false
|
||||
//CS_ = 0x03, // true
|
||||
|
||||
@ -186,15 +186,17 @@ int msgpack_unpacker_execute(msgpack_unpacker* ctx, const char* data, size_t len
|
||||
obj = func(user, arg); \
|
||||
/*printf("obj %d\n",obj);*/ \
|
||||
goto _push
|
||||
#define push_variable_value(func, arg, arglen) \
|
||||
obj = func(user, arg, arglen); \
|
||||
#define push_variable_value(func, base, pos, len) \
|
||||
obj = func(user, (const void*)base, (const void*)pos, len); \
|
||||
/*printf("obj %d\n",obj);*/ \
|
||||
goto _push
|
||||
|
||||
/*
|
||||
#define again_terminal_trail(_cs, from) \
|
||||
cs = _cs; \
|
||||
stack[top].tmp.terminal_trail_start = from; \
|
||||
goto _terminal_trail_again
|
||||
*/
|
||||
#define again_fixed_trail(_cs, trail_len) \
|
||||
trail = trail_len; \
|
||||
cs = _cs; \
|
||||
@ -237,8 +239,8 @@ int msgpack_unpacker_execute(msgpack_unpacker* ctx, const char* data, size_t len
|
||||
switch(*p) {
|
||||
case 0xc0: // nil
|
||||
push_simple_value(msgpack_unpack_nil);
|
||||
case 0xc1: // string
|
||||
again_terminal_trail(NEXT_CS(p), p+1);
|
||||
//case 0xc1: // string
|
||||
// again_terminal_trail(NEXT_CS(p), p+1);
|
||||
case 0xc2: // false
|
||||
push_simple_value(msgpack_unpack_false);
|
||||
case 0xc3: // true
|
||||
@ -289,16 +291,16 @@ int msgpack_unpacker_execute(msgpack_unpacker* ctx, const char* data, size_t len
|
||||
// end CS_HEADER
|
||||
|
||||
|
||||
_terminal_trail_again:
|
||||
++p;
|
||||
//_terminal_trail_again:
|
||||
// ++p;
|
||||
|
||||
case CS_STRING:
|
||||
if(*p == 0) {
|
||||
const unsigned char* start = stack[top].tmp.terminal_trail_start;
|
||||
obj = msgpack_unpack_string(user, start, p-start);
|
||||
goto _push;
|
||||
}
|
||||
goto _terminal_trail_again;
|
||||
//case CS_STRING:
|
||||
// if(*p == 0) {
|
||||
// const unsigned char* start = stack[top].tmp.terminal_trail_start;
|
||||
// obj = msgpack_unpack_string(user, start, p-start);
|
||||
// goto _push;
|
||||
// }
|
||||
// goto _terminal_trail_again;
|
||||
|
||||
|
||||
_fixed_trail_again:
|
||||
@ -343,7 +345,7 @@ int msgpack_unpacker_execute(msgpack_unpacker* ctx, const char* data, size_t len
|
||||
//case ACS_BIG_INT_VALUE:
|
||||
//_big_int_zero:
|
||||
// // FIXME
|
||||
// push_variable_value(msgpack_unpack_big_int, n, trail);
|
||||
// push_variable_value(msgpack_unpack_big_int, data, n, trail);
|
||||
|
||||
//case CS_BIG_FLOAT_16:
|
||||
// again_fixed_trail_if_zero(ACS_BIG_FLOAT_VALUE, (uint16_t)PTR_CAST_16(n), _big_float_zero);
|
||||
@ -352,7 +354,7 @@ int msgpack_unpacker_execute(msgpack_unpacker* ctx, const char* data, size_t len
|
||||
//case ACS_BIG_FLOAT_VALUE:
|
||||
//_big_float_zero:
|
||||
// // FIXME
|
||||
// push_variable_value(msgpack_unpack_big_float, n, trail);
|
||||
// push_variable_value(msgpack_unpack_big_float, data, n, trail);
|
||||
|
||||
case CS_RAW_16:
|
||||
again_fixed_trail_if_zero(ACS_RAW_VALUE, (uint16_t)PTR_CAST_16(n), _raw_zero);
|
||||
@ -360,7 +362,7 @@ int msgpack_unpacker_execute(msgpack_unpacker* ctx, const char* data, size_t len
|
||||
again_fixed_trail_if_zero(ACS_RAW_VALUE, (uint32_t)PTR_CAST_32(n), _raw_zero);
|
||||
case ACS_RAW_VALUE:
|
||||
_raw_zero:
|
||||
push_variable_value(msgpack_unpack_raw, n, trail);
|
||||
push_variable_value(msgpack_unpack_raw, data, n, trail);
|
||||
|
||||
case CS_ARRAY_16:
|
||||
start_container(msgpack_unpack_array_start, (uint16_t)PTR_CAST_16(n), CT_ARRAY_ITEM);
|
||||
|
@ -119,10 +119,4 @@ check([
|
||||
0xdf, 0x00, 0x00, 0x00, 0x02, 0xc0, 0xc2, 0xc3, 0xc2,
|
||||
], [{}, {nil=>false}, {true=>false, nil=>false}, {}, {nil=>false}, {true=>false, nil=>false}])
|
||||
|
||||
# string
|
||||
check([
|
||||
0x92,
|
||||
0xc1, 0x00,
|
||||
0xc1, ?a, ?b, ?c, 0x00,
|
||||
], ["", "abc"])
|
||||
|
||||
|
@ -71,11 +71,8 @@ static inline VALUE msgpack_unpack_map_start(msgpack_unpack_context* x, unsigned
|
||||
static inline void msgpack_unpack_map_item(msgpack_unpack_context* x, VALUE c, VALUE k, VALUE v)
|
||||
{ rb_hash_aset(c, k, v); }
|
||||
|
||||
static inline VALUE msgpack_unpack_string(msgpack_unpack_context* x, const void* b, size_t l)
|
||||
{ return rb_str_new(b, l); }
|
||||
|
||||
static inline VALUE msgpack_unpack_raw(msgpack_unpack_context* x, const void* b, size_t l)
|
||||
{ return rb_str_new(b, l); }
|
||||
static inline VALUE msgpack_unpack_raw(msgpack_unpack_context* x, const void* b, const void* p, size_t l)
|
||||
{ return rb_str_new(p, l); }
|
||||
|
||||
#include "msgpack/unpack/inline_impl.h"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user