msgpack-c
msgpack-c copied to clipboard
how to get msgpack type dynamically ? (say, stringified or via typeid)
(originally asked here: https://github.com/rpclib/rpclib/issues/113)
As @sztomi mentioned at the original question, type
member variable is the way to get type.
See https://github.com/msgpack/msgpack-c/wiki/v2_0_cpp_object
It might be helpful: https://github.com/msgpack/msgpack-c/issues/462#issuecomment-216420435
could we have a toString(msgpack::type)
method/function added? that would help with debugging
@redboltz
Actually, could you please provide an example of how to get type
?
I'm using rpclib.
rpc::client c(...);
auto temp = c.call("function", "bar");
auto t=temp.type;
class clmdep_msgpack::v1::object_handle' has no member named 'type'
It seems that t is an msgpack::object handle not msgpack::object.
Try this:
auto t=temp.get().type
ah ya sorry just saw that at the same time...
to summarize remaining point:a msgpack::type::toString()
method/function would help.
BTW, @timotheecour I gave that same example on the other issue you opened and an additional one for composite types.
@sztomi thanks; however now I'm running into an issue wtih msgpack::type
caused by having to include msgpack.hpp
(it worked so long i only had to access rpclib but not when i need type)
foo.cpp:
#include <msgpack.hpp>
rpc::client c(...);
auto temp = c.call("function", "bar");
auto temp1=temp.get().type;
switch (temp1) {
case msgpack::type::NIL:
...
}
In file included from
include/msgpack/adaptor/carray.hpp:13:0,
from include/msgpack/type.hpp:4,
from include/msgpack.hpp:18,
from foo.cpp:12:
include/msgpack/v1/adaptor/carray.hpp:27:8: error: 'convert' is not a class template
struct convert<T[N]> {
^
include/msgpack/v1/adaptor/carray.hpp:28:14: error: 'object' in namespace 'msgpack' does not name a type
msgpack::object const& operator()(msgpack::object const& o, T* v) const {
I installed rpclib via:
cmake_minimum_required(VERSION 2.8.3)
project(rpclib)
find_package(catkin REQUIRED)
find_package(catkin_simple REQUIRED)
catkin_simple()
include(ExternalProject)
file(MAKE_DIRECTORY ${CATKIN_DEVEL_PREFIX}/include)
ExternalProject_Add(${PROJECT_NAME}-upstream
PREFIX upstream
GIT_REPOSITORY https://github.com/rpclib/rpclib.git
GIT_TAG v1.0.0
INSTALL_DIR ${CATKIN_DEVEL_PREFIX}
BUILD_IN_SOURCE 1
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CATKIN_DEVEL_PREFIX} -DCMAKE_CXX_FLAGS=-fPIC
UPDATE_COMMAND "" # avoid unnecessary recompiles
)
catkin_package(
CFG_EXTRAS ${PROJECT_NAME}-extras.cmake.em
LIBRARIES rpc
)
${PROJECT_NAME}-extras.cmake.em:
add_definitions(-DRPCLIB_MSGPACK=clmdep_msgpack)
Addding set(MSGPACK_CXX11 ON CACHE BOOL "Turn on C++11 for msgpack")
didn't help
@timotheecour This sounds like a different issue and probably not msgpack-related. Could you open a new ticket on the rpclib repo? I can see already that you are not using the latest release, so first of all please test with the v2.0.1 tag.