-
Notifications
You must be signed in to change notification settings - Fork 883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to convert EXT(type:1,size=8) data in cpp #1072
Comments
When msgpack-c(C++) receives EXT format family MessagePack formatted byte stream, msgpack-c creates You can access msgpack-c/test/msgpack_basic.cpp Line 328 in ac062e2
Or you can use msgpack-c/test/msgpack_basic.cpp Lines 590 to 608 in ac062e2
|
When i deserilize message, i have map which contains either int/bool/string/EXT(type:1,size8).
to convert EXT(type:1,size8) which initially contains int from python.
I parse it as follows.
void on_incoming_message(const AMQP::Message &message, uint64_t deliveryTag, bool redelivered)
//void on_incoming_message()
{
std::string msg(message.body(), message.bodySize());
msgpack::object_handle oh =
msgpack::unpack(msg.data(), msg.size());
// deserialized object is valid during the msgpack::object_handle instance is alive.
msgpack::object deserialized = oh.get();
cout << deserialized.type << "------------ type >>>" << endl;
std::cout << deserialized << std::endl;
// convert msgpack::object instance into the original type.
// if the type is mismatched, it throws msgpack::type_error exception.
std::unordered_map<std::string,std::string> output;
if (deserialized.type == msgpack::type::MAP) {
msgpack::object_map& map = deserialized.via.map;
output = convertObjectMap(deserialized.via.map);
}
print_event(output);
// or create the new instance
//msgpack::type::tuple<int, bool, std::string> dst2 =
std::unordered_map<std::string, std::string> convertObjectMap(const msgpack::object_map& objectMap)
{
std::unordered_map<std::string, std::string> result;
for (const auto& pair : objectMap)
{
std::string key, value;
// Convert the key to std::string
pair.key.convert(key);
// Convert the value to std::string
value = convertToString(pair.val);
// Store the key-value pair in the result map
result[key] = value;
}
return result;
}
std::string convertToString(const msgpack::object& obj) {
{
if (obj.type == msgpack::type::EXT) {
std::string msg(obj.via.ext.data(), obj.via.ext.size);
auto abc =msgpack::unpack(msg.data(),msg.size());
uint64_t intValue;
abc.get().convert(intValue);
value = std::to_string(intValue);
}
}
it is unable to parse value.
Im new to msgpack and cpp that could a reason of such simple questions
…________________________________
From: Takatoshi Kondo ***@***.***>
Sent: 25 May 2023 07:39
To: msgpack/msgpack-c ***@***.***>
Cc: Avalanchecoder ***@***.***>; Author ***@***.***>
Subject: Re: [msgpack/msgpack-c] how to convert EXT(type:1,size=8) data in cpp (Issue #1072)
When msgpack-c(C++) receives EXT format family MessagePack formatted byte stream, msgpack-c creates msgpack::object and its type is msgpack::type::EXT.
See https://github.com/msgpack/msgpack-c/wiki/v2_0_cpp_object
You can access msgpack::object directly as follows:
https://github.com/msgpack/msgpack-c/blob/ac062e28cbf80db345800b6e113dea8ab0055499/test/msgpack_basic.cpp#L328
Or you can use msgpack::type::ext or msgpack::type::ext_ref helper classes as follows:
https://github.com/msgpack/msgpack-c/blob/ac062e28cbf80db345800b6e113dea8ab0055499/test/msgpack_basic.cpp#L590-L608
—
Reply to this email directly, view it on GitHub<#1072 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AKQHHHVFEJLZD6FWYSNCQQLXH25NTANCNFSM6AAAAAAYNNRP4M>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
I recommend that create a simple code (no MAP, no AMQP). |
{"signal_id":2801684810234,"type":"SIGNAL","signaltype":"NEW_ENTRY","exit_time":datetime.time(15,55),"remarks":26}
elif isinstance(obj, datetime.time):
# always encode in the 8-byte form
data = datetime.datetime.combine(
datetime.datetime.today(), obj)
data = int((obj.hour * 60 * 60 + obj.minute * 60 + obj.second) * 1e6
+ obj.microsecond)
this is my encoding logic
I am sending this from python. datetime format which in convert in "int" with type code 1
when i deserialise msgpack in cpp
{"signal_id":2801684810234,"type":"SIGNAL","signaltype":"NEW_ENTRY","exit_time":"EXT(type:1,size:8)","remarks":26}
could you help me to deserialising this field "exit_time":"EXT(type:1,size:8)" ?
The text was updated successfully, but these errors were encountered: