c++ - Unpacking msgpack to an arbitrary object, without msgpack_define -


i'm working on body of code deals custom string implementation rather std::string (long story various reasons has used) refer "string" here on.

i able pack string without issue using "raw" type pack raw char bytes , size i'm having problems unpacking it.

i able manually unpack shown below.

// before i've unpacked point following object has string msgpack::object_kv& kv = obj.via.map.ptr[0]; // kv.key == string want string key = string(key.via.raw.ptr, key.via.raw.size); // works 

but want use built in >> operator or .as template function , haven't been able manage it. don't have access modify string class add msgpack_unpack function nor add msgpack_define

i tried creating struct , giving msgpack_unpack function, apparently calls msgpack::object::implicit_type compiler replies

error: 'struct msgpack::object::implicit_type' private 

and can't figure out way of getting msgpack::object out of "implicit_type" object.

any ideas?

so figured out! hetepeperfan idea

after taking crack @ using operator>> overloading, problem prevented working before strange way operator>> being overloaded called msgpack code.

namespace msgpack {     string& operator>>(msgpack::object o, string& v) {         v = string(o.via.raw.ptr, o.via.raw.size);         return v;     } } 

i needed both use msgpack namespace, , match signature returning string reference , take object in not reference. seems little ridiculous works , can use built in "as<>" , convert functionality. awesome!


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -