Skip to content

How to get map with C++ API #227

Open
@atimin

Description

@atimin

Hey again, I'm going deeper with WAMP and faced another problem.

I have a callee in python providing a procedure that should return a map:

from autobahn.asyncio.component import Component, run

from config_service.config import Config

config = Config()

component = Component(transports=[{'type': 'rawsocket', 'url': config.wamp_router}], realm=config.wamp_realm)


@component.on_join
def joined(session, details):
    def get_settings():
        return {"param1": 1, "param2": True, "param3": 2.0, "param4": "string"}

    session.register(get_settings, config.wamp_prefix + '.get')


if __name__ == "__main__":
    run([component])

I'm trying to call the procedure and get data in C++:

 session->call("adt.settings.get")
                .then([&](boost::future<autobahn::wamp_call_result> result) {
                  try {
                    auto ret = result.get();
                    LOG_INFO() << ret.kw_argument<int>("param1");
                  } catch (const std::exception& e) {
                    LOG_ERROR() << e.what();
                    io.stop();
                    return;
                  }
...

This code doesn't work and I have an exception : param1 keyword argument doesn't exist

In the logs and debug mode I see that the map is wrapped into an array:

RawSocket handshake reply received
connect successful: valid handshake
RX preparing to receive message ..
TX message (122 octets) ...
TX message: hello ["adt", {"authid":"","authmethods":[],"roles":{"subscriber":{},"publisher":{},"callee":{"features":{"call_timeout":true}},"caller":{"features":{"call_timeout":true}}}}]
RX message (844 octets) ...
RX message received.
RX message: welcome [4951396766928797, {"x_cb_node":"043ac2c80af9-1","x_cb_worker":"worker001","x_cb_peer":"tcp4:172.22.0.1:35404","x_cb_pid":21,"realm":"adt","authid":"NN6M-VRGE-JSN9-3F64-E5TM-W35Y","authrole":"anonymous","authmethod":"anonymous","authprovider":"static","authextra":{"x_cb_node":"043ac2c80af9-1","x_cb_worker":"worker001","x_cb_peer":"tcp4:172.22.0.1:35404","x_cb_pid":21},"roles":{"broker":{"features":{"publisher_identification":true,"pattern_based_subscription":true,"session_meta_api":true,"subscription_meta_api":true,"subscriber_blackwhite_listing":true,"publisher_exclusion":true,"subscription_revocation":true,"payload_transparency":true,"payload_encryption_cryptobox":true,"event_retention":true}},"dealer":{"features":{"caller_identification":true,"pattern_based_registration":true,"session_meta_api":true,"registration_meta_api":true,"shared_registration":true,"call_canceling":true,"progressive_call_results":true,"registration_revocation":true,"payload_transparency":true,"testament_meta_api":true,"payload_encryption_cryptobox":true}}}}]
RX preparing to receive message ..
TX message (21 octets) ...
TX message: call [1, {}, "adt.settings.get"]
RX message (138 octets) ...
RX message received.
RX message: result [1, {"callee":7189193259188515,"callee_authid":"NR3E-VAHH-M4V3-4YXC-7AS9-3QRK","callee_authrole":"anonymous"}, [{"param1":1,"param2":true,"param3":2,"param4":"string"}]]
RX preparing to receive message ..

However I can't figure out the way to extract it properly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions