mirror of
https://github.com/pocketpy/pocketpy
synced 2026-08-12 00:57:13 +08:00
Compare commits
No commits in common. "f2b6d90a7214e56d61813dcc96de2cc8ce36c5f5" and "4816c4471b4489fa3dbe8eb68743f32fe8c5dfb2" have entirely different histories.
f2b6d90a72
...
4816c4471b
@ -251,7 +251,7 @@
|
|||||||
* types in @ref docs/protocol.md for more information.
|
* types in @ref docs/protocol.md for more information.
|
||||||
*/
|
*/
|
||||||
#ifndef MPACK_EXTENSIONS
|
#ifndef MPACK_EXTENSIONS
|
||||||
#define MPACK_EXTENSIONS 1
|
#define MPACK_EXTENSIONS 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,20 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "mpack.h"
|
|
||||||
#include "pocketpy.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef bool (*is_mpack_ext_t)(py_Type type);
|
|
||||||
typedef bool (*py_to_mpack_ext_t)(py_Ref object, mpack_writer_t* writer);
|
|
||||||
typedef bool (*mpack_to_py_ext_t)(py_StackRef tmp, mpack_node_t node);
|
|
||||||
|
|
||||||
void mpack_config_exttype_callbacks(is_mpack_ext_t is_ext,
|
|
||||||
py_to_mpack_ext_t to_mpack,
|
|
||||||
mpack_to_py_ext_t to_py);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@ -1,22 +1,8 @@
|
|||||||
#include "pocketpy.h"
|
#include "pocketpy.h"
|
||||||
|
|
||||||
#include "mpack1.h"
|
#include "mpack.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
_Static_assert(MPACK_EXTENSIONS == 1, "You should change MPACK_EXTENSIONS in mpack.h to 1");
|
|
||||||
|
|
||||||
static is_mpack_ext_t is_mpack_ext;
|
|
||||||
static py_to_mpack_ext_t py_to_mpack_ext;
|
|
||||||
static mpack_to_py_ext_t mpack_to_py_ext;
|
|
||||||
|
|
||||||
void mpack_config_exttype_callbacks(is_mpack_ext_t is_ext,
|
|
||||||
py_to_mpack_ext_t to_mpack,
|
|
||||||
mpack_to_py_ext_t to_py) {
|
|
||||||
is_mpack_ext = is_ext;
|
|
||||||
py_to_mpack_ext = to_mpack;
|
|
||||||
mpack_to_py_ext = to_py;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool mpack_to_py(mpack_node_t node) {
|
static bool mpack_to_py(mpack_node_t node) {
|
||||||
py_StackRef tmp = py_pushtmp();
|
py_StackRef tmp = py_pushtmp();
|
||||||
|
|
||||||
@ -83,14 +69,6 @@ static bool mpack_to_py(mpack_node_t node) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case mpack_type_ext: {
|
|
||||||
if(!mpack_to_py_ext) {
|
|
||||||
return RuntimeError("msgpack: mpack_to_py_ext is not set, cannot handle ext type");
|
|
||||||
}
|
|
||||||
if(!mpack_to_py_ext(tmp, node)) return false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: return ValueError("msgpack: invalid node type");
|
default: return ValueError("msgpack: invalid node type");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -175,11 +153,6 @@ static bool py_to_mpack(py_Ref object, mpack_writer_t* writer) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
if(is_mpack_ext && is_mpack_ext(object->type)) {
|
|
||||||
assert(py_to_mpack_ext != NULL);
|
|
||||||
return py_to_mpack_ext(object, writer);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
mpack_write_nil(writer);
|
mpack_write_nil(writer);
|
||||||
return TypeError("msgpack: unsupported type '%t'", object->type);
|
return TypeError("msgpack: unsupported type '%t'", object->type);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user