Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Titan » RAW Encoder and Decoder(decode the record type with optional field)
RAW Encoder and Decoder [message #1804603] Fri, 29 March 2019 09:30 Go to next message
le tian is currently offline le tianFriend
Messages: 16
Registered: October 2018
Junior Member
When I receive a piece of data, I want to use RAW mode to decode it as record type, but my record type has optional field, and the optional field in the data I receive is not filled in. How can I not operate on this optional field when decoding?
Re: RAW Encoder and Decoder [message #1804604 is a reply to message #1804603] Fri, 29 March 2019 09:44 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 1063
Registered: January 2015
Senior Member
Hi le tian,

If everything is in place (meaning that both sides are using exactly the same structures and exactly the same rules for encoding-decoding) the RAW decoder should correctly interpret the missing optional field as omit.




Best regards
Elemer

[Updated on: Fri, 29 March 2019 09:44]

Report message to a moderator

Re: RAW Encoder and Decoder [message #1804707 is a reply to message #1804604] Sat, 30 March 2019 01:02 Go to previous messageGo to next message
le tian is currently offline le tianFriend
Messages: 16
Registered: October 2018
Junior Member
for example:
I define the following data:
type record test_data
{
octetstring S1 length(2),
octetstring S2 lengtg(2) optional,
octetstring S3 length(2)
};
and define the following decode function and encode function:

external function enc_data(in test_data message) return octetstring
with {extension "prototype(convert) encode(RAW)"};
external function dec_data(in octetstring stream) return test_data
with {extension "prototype(convert) encode(RAW)"};

When I receive octetstring of length 4, and write the following statements:
test_data = dec_data (stream);
Does S2 automatically fill in omit at this point? If not, in this case, how to automatically fill S2 with omit
Re: RAW Encoder and Decoder [message #1804783 is a reply to message #1804707] Mon, 01 April 2019 08:30 Go to previous message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 1063
Registered: January 2015
Senior Member
Hi le tian,

I see the misunderstanding;

A few clarifications first:

-the decoder will read the stream byte by byte; at each byte it will have to be able to take a decision on how to continue; that is , it will not read the whole message and then parse and evaluate it;
-this means that your structure is not decodable: let's assume that the second field is omitted ; when reading the first byte of the third field ,no decoder can decide whether this is indeed the first byte of the third field or the first byte of the un-omitted second field; another piece of auxiliary information is necessary to do that
-protocols are designed specifically to help the decoder; not every protocol is decodable (although every protocol can be encoded)

So what you are missing in your simple protocol is an additional piece of information that would signal the absence or presence of your second optional field.
For that , the RAW attribute PRESENCE can be used.

One more remark here:
the ...length(2) expression is addressed to the compiler and it is disregarded by the codec; it is being used during compilation to check type restrictions;

to communicate this information to the codec, one will need a

with { variant "FIELDLENGTH(2)" };

encoding variant; this is being used during runtime. while encoding/decoding.

A complete example would look as below:


module RAWTest2
{

external function enc_data(in Test_data pdu) return octetstring
with { extension "prototype(convert)"
         extension "encode(RAW)"
       };


external function dec_data(in octetstring stream) return Test_data
  with { extension "prototype(convert)"
         extension "decode(RAW)"
         extension "errorbehavior(ALL:WARNING)"
       };


  type octetstring OCT1 length(1) with { variant "FIELDLENGTH(1)" };
  type octetstring OCT2 length(2) with { variant "FIELDLENGTH(2)" };

type record Test_data
{
OCT2  field1,
OCT1  presence_field, 
OCT2  field2 optional,
OCT2  field3
}  with {variant (field2) "PRESENCE(presence_field = 'FF'O)" };

template  Test_data t1:=
{
field1:='AABB'O,
presence_field:='FF'O,
field2:='CCDD'O,
field3:='EEFF'O

}



template  Test_data t2:=
{
field1:='AABB'O,
presence_field:='00'O,
field2:= omit,
field3:='EEFF'O

}

control {


log("Encode ", enc_data(valueof(t1)))

log("Decode",  dec_data(enc_data(valueof(t1))))

log("----------------------------------------------------------------------------------")


log("Encode ", enc_data(valueof(t2)))

log("Decode",  dec_data(enc_data(valueof(t2))))

log("----------------------------------------------------------------------------------")

}




}with { encode "RAW" };


and the execution log :

09:07:37.772726 - TTCN-3 Test Executor started in single mode. Version: CRL 113 200/6 R5B.
09:07:37.772820 - Maximum number of open file descriptors: 8192,   FD_SETSIZE = 1024
09:07:37.776253 - TTCN Logger v2.2 options: TimeStampFormat:=Time; LogEntityName:=No; LogEventTypes:=No; SourceInfoFormat:=Single; *.FileMask:=LOG_ALL; *.ConsoleMask:=ACTION | ERROR | TESTCASE | STATISTICS_VERDICT | STATISTICS_UNQUALIFIED | WARNING; LogFileSize:=0; LogFileNumber:=1; DiskFullAction:=Error
09:07:37.776291 - Initializing module PreGenRecordOf.
09:07:37.776310 - Initialization of module PreGenRecordOf finished.
09:07:37.776327 - Initializing module RAWTest2.
09:07:37.776362 - Initialization of module RAWTest2 finished.
09:07:37.776379 - Initializing module TitanLoggerApi.
09:07:37.776396 - Initialization of module TitanLoggerApi finished.
09:07:37.776419 RAWTest2.ttcn:48 Execution of control part in module RAWTest2 started.
09:07:37.776501 RAWTest2.ttcn:51 Encode 'AABBFFCCDDEEFF'O
09:07:37.777876 RAWTest2.ttcn:53 Decode{ field1 := 'AABB'O, presence_field := 'FF'O, field2 := 'CCDD'O, field3 := 'EEFF'O }
09:07:37.777913 RAWTest2.ttcn:55 ----------------------------------------------------------------------------------
09:07:37.777931 RAWTest2.ttcn:58 Encode 'AABB00EEFF'O
09:07:37.777955 RAWTest2.ttcn:60 Decode{ field1 := 'AABB'O, presence_field := '00'O, field2 := omit, field3 := 'EEFF'O }
09:07:37.777983 RAWTest2.ttcn:62 ----------------------------------------------------------------------------------
09:07:37.778002 RAWTest2.ttcn:62 Execution of control part in module RAWTest2 finished.
09:07:37.778117 - Verdict statistics: 0 none, 0 pass, 0 inconc, 0 fail, 0 error.
09:07:37.778176 - Test execution summary: 0 test case was executed. Overall verdict: none
09:07:37.778216 - TTCN-3 Test Executor finished in single mode.


for details on RAW, please see also:


The binary RAW encoder of Titan : part I(Basic principles)
https://www.eclipse.org/forums/index.php/t/1070954/


The binary RAW encoder of Titan : part II(Examples of attributes )
https://www.eclipse.org/forums/index.php/t/1071180/


The binary RAW encoder of Titan : part III(Automatic generation of codec functions - Function prototypes)
https://www.eclipse.org/forums/index.php/t/1071394/


I hope this helps


BR

Elemer










  • Attachment: RAWTest2.ttcn
    (Size: 1.25KB, Downloaded 37 times)
  • Attachment: Makefile
    (Size: 4.97KB, Downloaded 48 times)

[Updated on: Mon, 01 April 2019 13:22]

Report message to a moderator

Previous Topic:Using a unbound optional field
Next Topic:Products using Titan
Goto Forum:
  


Current Time: Fri Jul 10 17:29:14 GMT 2020

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

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

Back to the top