Sending struct-like data via Autobahn

#1

Hi,

I am currently investigating how Autobahn works (in conjunction with crossbar.io). My use case is sending some complex data from JS to C++. Take for example a C structure like this:

typedef struct {
int a;
int b;
} S1;

typedef struct {
S1 x;
S1 y;
} S2;

``

This is probably represented in JS best as object literal { x: { a : 0, b : 1 }, y: { a : 3, b : 4 } }.

Now, how can I send this from JS and retrieve it in C++ simply by

auto a = invocation->argument(0);

``

Can this be supported by the Autobahn API on both sides directly? Or do I have to write (or generate) code which transforms data like this into an array of plain data types?

Sorry, if this is a dump question…

Thanks in advance, regards,

Klaus

0 Likes

#2

Dump => Dumb

No question is dump.

I think write now you need to transpose data.

For me I produce message asynchronously(json format) via golang to be processed via python with twisted.

Format currently used(b/c were using JWT):

message example:

{

“event”: “PostToGoogleForum”,

“body”: {

“happened_to_uuid”: “1234-5678-9234-5678”,

“when”: “2017-04-25 11:37:53”, # but world surely use epoch

“what”: “Added post about blah” # we do event based so insert only

}

The above message is raw from frontend; at a api gateway before sent to crossbar to be processed via backend service, authorization and authentication is done and certain properties are added to the json object prior to being sent to crossbar and then to subscribed services.

At which point since we standardized on json we know how to convert to whichever object type we need, python => dict, node => object, perl => hash, c => struct, golang => struct. etc.

···

On Tuesday, April 25, 2017 at 11:37:53 AM UTC-5, Klaus Birken wrote:

Hi,

I am currently investigating how Autobahn works (in conjunction with crossbar.io). My use case is sending some complex data from JS to C++. Take for example a C structure like this:

typedef struct {
int a;
int b;
} S1;

typedef struct {
S1 x;
S1 y;
} S2;

``

This is probably represented in JS best as object literal { x: { a : 0, b : 1 }, y: { a : 3, b : 4 } }.

Now, how can I send this from JS and retrieve it in C++ simply by

auto a = invocation->argument(0);

``

Can this be supported by the Autobahn API on both sides directly? Or do I have to write (or generate) code which transforms data like this into an array of plain data types?

Sorry, if this is a dump question…

Thanks in advance, regards,

Klaus

0 Likes

#3

As karma would have it I would have two typos myself… fail.

second dump should be dumb # No question is dumb

write should be write # As an american I’m ashamed…

···

On Thursday, April 27, 2017 at 9:38:43 PM UTC-5, ma...@x-qa.com wrote:

Dump => Dumb

No question is dump.

I think write now you need to transpose data.

For me I produce message asynchronously(json format) via golang to be processed via python with twisted.

Format currently used(b/c were using JWT):

message example:

{

“event”: “PostToGoogleForum”,

“body”: {

“happened_to_uuid”: “1234-5678-9234-5678”,

“when”: “2017-04-25 11:37:53”, # but world surely use epoch

“what”: “Added post about blah” # we do event based so insert only

}

The above message is raw from frontend; at a api gateway before sent to crossbar to be processed via backend service, authorization and authentication is done and certain properties are added to the json object prior to being sent to crossbar and then to subscribed services.

At which point since we standardized on json we know how to convert to whichever object type we need, python => dict, node => object, perl => hash, c => struct, golang => struct. etc.

On Tuesday, April 25, 2017 at 11:37:53 AM UTC-5, Klaus Birken wrote:

Hi,

I am currently investigating how Autobahn works (in conjunction with crossbar.io). My use case is sending some complex data from JS to C++. Take for example a C structure like this:

typedef struct {
int a;
int b;
} S1;

typedef struct {
S1 x;
S1 y;
} S2;

``

This is probably represented in JS best as object literal { x: { a : 0, b : 1 }, y: { a : 3, b : 4 } }.

Now, how can I send this from JS and retrieve it in C++ simply by

auto a = invocation->argument(0);

``

Can this be supported by the Autobahn API on both sides directly? Or do I have to write (or generate) code which transforms data like this into an array of plain data types?

Sorry, if this is a dump question…

Thanks in advance, regards,

Klaus

0 Likes

#4

And in retro event should be named in past tense

···

On Thursday, April 27, 2017 at 9:38:43 PM UTC-5, ma...@x-qa.com wrote:

Dump => Dumb

No question is dump.

I think write now you need to transpose data.

For me I produce message asynchronously(json format) via golang to be processed via python with twisted.

Format currently used(b/c were using JWT):

message example:

{

“event”: “PostToGoogleForum”,

“body”: {

“happened_to_uuid”: “1234-5678-9234-5678”,

“when”: “2017-04-25 11:37:53”, # but world surely use epoch

“what”: “Added post about blah” # we do event based so insert only

}

The above message is raw from frontend; at a api gateway before sent to crossbar to be processed via backend service, authorization and authentication is done and certain properties are added to the json object prior to being sent to crossbar and then to subscribed services.

At which point since we standardized on json we know how to convert to whichever object type we need, python => dict, node => object, perl => hash, c => struct, golang => struct. etc.

On Tuesday, April 25, 2017 at 11:37:53 AM UTC-5, Klaus Birken wrote:

Hi,

I am currently investigating how Autobahn works (in conjunction with crossbar.io). My use case is sending some complex data from JS to C++. Take for example a C structure like this:

typedef struct {
int a;
int b;
} S1;

typedef struct {
S1 x;
S1 y;
} S2;

``

This is probably represented in JS best as object literal { x: { a : 0, b : 1 }, y: { a : 3, b : 4 } }.

Now, how can I send this from JS and retrieve it in C++ simply by

auto a = invocation->argument(0);

``

Can this be supported by the Autobahn API on both sides directly? Or do I have to write (or generate) code which transforms data like this into an array of plain data types?

Sorry, if this is a dump question…

Thanks in advance, regards,

Klaus

0 Likes

#5

Hi,

typos occur, never mind. Seems like I use “dump” more often than “dumb”, which is good :slight_smile:

Regarding your reply, I guess I don’t get it. Sure can I think of a generic mapping from JSON to C-structs, but how can it be done in the specific case I mentioned? AFAIK, in Autobahn there is no JSON, but msgpack instead. So still I am looking for a solution to the above question.

Regards,

Klaus

0 Likes