Request-Reply

6 posts / 0 new
Last post
Offline
Last seen: 8 years 10 months ago
Joined: 09/18/2015
Posts: 5
Request-Reply

Does anyone have some suggestions on how to handle determining on the Reply side what variables have actually been set in the message?  I know I could possibly have defaults to expect, but that is not optimal because I will not always know the appropriate defaults.  Just to clarify, I would like the Reply side to be aware of what variables in the received message were actually filled out by the requester.  Any help is greatly appreciated.

Gerardo Pardo's picture
Offline
Last seen: 4 months 1 week ago
Joined: 06/02/2010
Posts: 602

Hi,

What does your "request" type look like? What programming language(s) are you using on the Requester side and the Replier side?

One way to do this is to define a data-type for yoru request that has optional members. For example:

struct NestedType {
	long x;
	long y;
};

struct MyRequestType  {
    long id; //@key
    long long_data; //@Optional
    NestedType nt; //@Optional
};

When you do that the mapping to the programming language (e.g. C++) will be such that you will be able to set or not set the member. For example in C/C++ optional members will become pointers as in:

class NestedType {
  public:
    DDS_Long   x ;
    DDS_Long   y ;
};

class MyRequestType {
  public:
    DDS_Long   id ;
    DDS_Long   * long_data ;
    NestedType   * nested;
};

Note how the MyRequestType members long_data and nested are declared as pointers. If the requester does not want to set something. It should just set the member to NULL (this is for C or the traditional C++ language, other languages may do it differently by a similar mechanism is there). Then the Reply side will see those members set to NULL and know they were not set.

Gerardo

Offline
Last seen: 8 years 10 months ago
Joined: 09/18/2015
Posts: 5

Gerardo,

That is exactly what I was looking for.  Thank you for taking the time to explain the solution.

Offline
Last seen: 8 years 12 months ago
Joined: 10/15/2015
Posts: 2

Hi.

How can struct IDL to make reques-reply in Java application where can the requester request byte[]  and the replier will reply same the size of the data byte[]?

I did like this, but i faced a problem to convert ByteSeq to byte[], If there is any good way to request byte[] and the replier will reply same data size and type byte[], please.

........

struct Request {

octet n[8];

};


struct Reply {

sequence<octet, 2000> rqrp;



};

........

 

Br

Bani.

Offline
Last seen: 8 years 12 months ago
Joined: 10/15/2015
Posts: 2

Hi

How can struct IDL to make reques-reply Java application where can the requester request byte[] and the replier will reply same the data size and type  byte[]?

I did like this, but i faced a problem, i can not convert ByteSeq to byte[], please, if there is good and easy way to struct IDL?

Thanks 

Gerardo Pardo's picture
Offline
Last seen: 4 months 1 week ago
Joined: 06/02/2010
Posts: 602

Hi,

If you know the length of the Reply byte array ahead of time (like you did for the request), then you could define the Reply type with an array as well (instead of a sequence as in:

struct Reply {
    octet rqrp[8];
};

However this assumes the reply is always the same fixed size which given you want to copy the request it also implies the requests must also be the same fixed size... If you do not want this then the reply should be a sequence which has a variable length and can be adjusted each reply to match the length of the request. In this case once you get the ByteSeq on the reply you can use the ByteSeq.toArrayByte() operation to convert it to a byte[].

Gerardo