Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Titan » How to work with optional fields
How to work with optional fields [message #1731771] Tue, 10 May 2016 06:10 Go to next message
Johannes Bro is currently offline Johannes BroFriend
Messages: 56
Registered: June 2015
Member
Hi All,

I want to implement a test port which can handle a record with optional fields. I try to explain my question on a easy example.


type record AnyField{
       octetstring  FirstSubfield,
       octetstring  SecondSubfield
}   

type record AnyHeader {
        integer accessNumber,
        AnyField dummyField optional,
}   


If I now create the respective C++ classes with the titan compiler. The Class AnyField do not have methods to fill the fields (FirstSubfield, SecondSubfield) with values. There is only a constructor to give all values at once. But this is in my case not possible. Is there any other possibility to fill step by step ?

I thought maybe the *_template classes can help me. I tried to fill first a object of them and give finaly the template object to the object of AnyHeader. But it does't work...
What is the aim/task of all this *_template classes ?

Re: How to work with optional fields [message #1731773 is a reply to message #1731771] Tue, 10 May 2016 06:26 Go to previous messageGo to next message
Kristof Szabados is currently offline Kristof SzabadosFriend
Messages: 60
Registered: July 2015
Member
Hi Johannes,

If you have a function with such a statement in TTCN-3:
"var AnyField example;
example.FirstSubfield := ''O
"

It will be translated to C++ as:
"
AnyField example;
example.FirstSubfield() = os_0;
"

Where "os_0" is the OCTETSTRING to be assigned.
Re: How to work with optional fields [message #1731775 is a reply to message #1731773] Tue, 10 May 2016 06:47 Go to previous messageGo to next message
Johannes Bro is currently offline Johannes BroFriend
Messages: 56
Registered: June 2015
Member
Please take a look to my attached files and give me a concrete example.

c++:

AnyHeader myHeader;

/* Fill the field step by step*/
.....



Re: How to work with optional fields [message #1731784 is a reply to message #1731775] Tue, 10 May 2016 07:31 Go to previous messageGo to next message
Kristof Szabados is currently offline Kristof SzabadosFriend
Messages: 60
Registered: July 2015
Member
There are 2 ways to going about this in general.
1) You can replicate a structured form of assigning value (which is slightly faster in runtime).
For example this TTCN-3 code
"
var AnyHeader MyHeader;
MyHeader := {
accessNumber := 1,
dummyField := {
FirstSubfield := ''O,
SecondSubfield := ''O
}
}
"
can be replicated in C++ as:
"
AnyHeader MyHeader;
MyHeader.accessNumber() = 1;
{
AnyField& tmp_1 = MyHeader.dummyField();
tmp_1.FirstSubfield() = os_0;
tmp_1.SecondSubfield() = os_0;
}
"

2) You can fill in the structure field-by-field.
This can be done in TTCN-3 like this:
"
MyHeader.accessNumber := 1;
MyHeader.dummyField.FirstSubfield := ''O;
MyHeader.dummyField.SecondSubfield := ''O;
"

Which can be replicated in C++ as:
"
MyHeader.accessNumber() = 1;
MyHeader.dummyField()().FirstSubfield() = os_0;
MyHeader.dummyField()().SecondSubfield() = os_0;
"

Please see the extra "()" needed to resolve optional fields
Re: How to work with optional fields [message #1731791 is a reply to message #1731784] Tue, 10 May 2016 08:16 Go to previous messageGo to next message
Johannes Bro is currently offline Johannes BroFriend
Messages: 56
Registered: June 2015
Member
Quote:
Please see the extra "()" needed to resolve optional fields


Exactly this was my mistake, sorry... Embarrassed I found it now in the documentation.

Thank you very much !
Re: How to work with optional fields [message #1731803 is a reply to message #1731791] Tue, 10 May 2016 09:38 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 1120
Registered: January 2015
Senior Member
Hi Johannes,

something entirely different:
as far as remember, you have been working on a test port for serial protocol.
This might be interesting for others too, so in case you finalized it, would you consider to contribute it to the Titan project?

Let me know if the answer is positive

Best regards
Elemer




Re: How to work with optional fields [message #1731807 is a reply to message #1731791] Tue, 10 May 2016 09:45 Go to previous messageGo to next message
Johannes Bro is currently offline Johannes BroFriend
Messages: 56
Registered: June 2015
Member
Hi Elemer,

it's not finished yet but so far I can contribute something what can helpful for the community, you will hear from me.


One more question:
What happens with fields which have omit as value if you encode these with the build in *.encode(....) function in to RAW ? Will these fields be skipped or just have zeros ?

[Updated on: Tue, 10 May 2016 09:54]

Report message to a moderator

Re: How to work with optional fields [message #1731810 is a reply to message #1731807] Tue, 10 May 2016 10:08 Go to previous message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 1120
Registered: January 2015
Senior Member
Hi Johannes,

I'm pretty sure they are skipped.

Best regards
Elemer



Previous Topic:XML encoding in TTCN-3 and Titan part 1: basics
Next Topic:XML encoding in TTCN-3 and Titan part II: example
Goto Forum:
  


Current Time: Fri Apr 19 22:51:05 GMT 2024

Powered by FUDForum. Page generated in 0.03782 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top