Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Titan » Multiple encodings in Titan
Multiple encodings in Titan [message #1764545] Wed, 31 May 2017 07:38 Go to next message
Naum Spaseski is currently offline Naum SpaseskiFriend
Messages: 81
Registered: February 2016
Location: Sophia Antipolis
Member

Hello everyone,

In the latest commits I saw that there is support for JSON codec. Is there a possibility to use multiple codecs (JSON and XML) in the same adapter to test different formats support? For example, in oneM2M there are two basic data formats, XML and JSON, but in the end of the types declaration file, there is only one encoding variant, XML. Is it possible in this case, instead of using XML, to use JSON codec?

Thank you in advance.

Best regards,
Naum
Re: Multiple encodings in Titan [message #1764551 is a reply to message #1764545] Wed, 31 May 2017 07:57 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 807
Registered: January 2015
Senior Member
Hi Naum,
we have briefly touch this issue in:

The unfinished business of multiple encodings
https://www.eclipse.org/forums/index.php/t/1079607/

Since then, based on the change request we have submitted , the possibility of multiple encodings was made part of the language , see
version 4.9.1 of TTCN-3 published in May this year.

But to answer your question: it is possible now in Titan to encode the same structure with multiple codecs, but not in a consistent and uniform manner. We are working on making it
more transparent and easy to understand by aligning it to the standard.

If you double-tag a structure that has 'with {encode "XML" }'
so as to be encoded with JSON, the codecs will be generated , but encvalue/decvalue will face an ambiguous situation as it will not know which encoding is to be referred to.
To clarify this , encvalue/decvalue and the like will have to be extended , and as I said we are working on that.

If you don't use encvalue but an external function declaration that unambiguously points to the needed coded,
it should behave.

But as I said, it's a work in progress.


Best regards
Elemer






[Updated on: Wed, 31 May 2017 07:58]

Report message to a moderator

Re: Multiple encodings in Titan [message #1766408 is a reply to message #1764551] Wed, 21 June 2017 08:02 Go to previous messageGo to next message
Naum Spaseski is currently offline Naum SpaseskiFriend
Messages: 81
Registered: February 2016
Location: Sophia Antipolis
Member

Hello Elemer,

I'm sorry that I respond to this thread long after your response, but I was shifting between multiple projects.

I tried declaring both at the end: 'with {encode "XML"; encode "JSON"; }' and it generates only the codecs for the latest encoding instruction (in this case only for JSON).
If I delete one of the lines and the corresponding enc/dec functions (i'm not using encvalue/decvalue), it compiles and executes as it should, even with JSON (note that I'm using the latest titan with the commit from yesterday (commit).

Best regards,
Naum
Re: Multiple encodings in Titan [message #1766417 is a reply to message #1766408] Wed, 21 June 2017 09:55 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 807
Registered: January 2015
Senior Member
Hi Naum,

I'm not sure I understand exactly what you are saying: so you can use both encodings , right?

As far as I remember this is how it should work: both encodings should be usable, although only one is apparently declared.
Don't forget that standards before 4.9.1 did not allow for multiple encodings.
The next release due November will contain full support for that.

Best regards
Elemer




Re: Multiple encodings in Titan [message #1766419 is a reply to message #1766417] Wed, 21 June 2017 10:04 Go to previous messageGo to next message
Naum Spaseski is currently offline Naum SpaseskiFriend
Messages: 81
Registered: February 2016
Location: Sophia Antipolis
Member

Hi Elemer,

No, I can't use both of the encodings in the same time, only one - either JSON or XML. If I declare both of them, the only one I can use is the last one. For example, if I declare:

 'with {
    encode "XML";
    encode "JSON";
}'

I can use only JSON, because it will override the XML codec, and afterwards, in the functions declarations, I will have an error like this (this is tested on oneM2M ATS, latest version from git):
OneM2M_Ports.ttcn: In TTCN-3 module `OneM2M_Ports':
 OneM2M_Ports.ttcn:53.2-86: In external function definition `enc_PrimitiveContentXML':
  OneM2M_Ports.ttcn:53.47-62: error: Input type `@OneM2M_Types.PrimitiveContent' does not support XER encoding. The following fields do not support XER encoding: aEAnnc_optional, aE_optional, accessControlPolicy_optional, accessControlPolicyAnnc_optional, contentInstance_optional, contentInstanceAnnc_optional, container_optional, containerAnnc_optional, flexContainer_optional, cSEBase_optional, group_optional, groupAnnc_optional, locationPolicy_optional, locationPolicyAnnc_optional, mgmtResource_optional, announcedMgmtResource_optional, node_optional, nodeAnnc_optional, pollingChannel_optional, schedule_optional, scheduleAnnc_optional, serviceSubscribedAppRule_optional, subscription_optional, semanticDescriptor_optional, genericInterworkingOperationInstance_optional, securityInfo, notification, aggregatedNotification, attributeList, responsePrimitive, resource, uRIList, resourceRefList, aggregatedResponse, aE_update_invalid, aCP_update_invalid, container_update_invalid, group_update_invalid, pollingChannel_update_invalid, schedule_update_invalid, subscription_update_invalid, locationPolicy_update_invalid
 OneM2M_Ports.ttcn:56.2-86: In external function definition `dec_PrimitiveContentXML':
  OneM2M_Ports.ttcn:56.71-86: error: Output type `@OneM2M_Types.PrimitiveContent' does not support XER encoding


Best regards,
Naum
Re: Multiple encodings in Titan [message #1766427 is a reply to message #1766419] Wed, 21 June 2017 10:50 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 807
Registered: January 2015
Senior Member
Hi Naum,

please try the following:

-leave only with { encode "JSON" }
-but add encoding variants for both encodings
-and declare external functions for both

adding variants should trigger the generation of both codecs

Please let me know of the results

BR

Elemer


Re: Multiple encodings in Titan [message #1766429 is a reply to message #1766427] Wed, 21 June 2017 11:11 Go to previous messageGo to next message
Naum Spaseski is currently offline Naum SpaseskiFriend
Messages: 81
Registered: February 2016
Location: Sophia Antipolis
Member

I added JSON variants only for AE (for now), and the result is the same, the XER codec isn't generated. Should I put for all of the types?

Best regards,
Naum
Re: Multiple encodings in Titan [message #1766430 is a reply to message #1766429] Wed, 21 June 2017 11:43 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 807
Registered: January 2015
Senior Member
Hi Naum,

can you please attach the code?

BR

Elemer
Re: Multiple encodings in Titan [message #1766432 is a reply to message #1766430] Wed, 21 June 2017 12:32 Go to previous messageGo to next message
Naum Spaseski is currently offline Naum SpaseskiFriend
Messages: 81
Registered: February 2016
Location: Sophia Antipolis
Member

Hi Elemer,

The code is in the attachments. I've reused the same code from the other XML example, only this time the oneM2M ATS is the latest version.

Best regards,
Naum
Re: Multiple encodings in Titan [message #1766435 is a reply to message #1766432] Wed, 21 June 2017 13:38 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 807
Registered: January 2015
Senior Member
Hi Naum,

OK, so I have done the following :

-removed the encode JSON:

with {
  encode "XML";
  //encode "JSON";
:
:
}



Now XML encoding is in effect; we have somehow to convince Titan that it needs to generate JSON codec for PrimitiveContent.
With a bit of trial and error I have added a dummy JSON variant to PrimitiveContent as below:

type union PrimitiveContent {
:
}with{
	variant(aEAnnc_optional) "JSON:name as aEAnnc_optional";
	
};
 



Now Titan will generate both XML and JSON codecs:

module test_codec{

	import from OneM2M_TestSystem all;
	import from OneM2M_Templates all;
	import from OneM2M_Types all;
	import from OneM2M_TypesAndValues all;
	import from OneM2M_Pixits all;
	import from OneM2M_Pics all;
	import from OneM2M_Functions all;
	import from LibCommon_Time all;
	import from XSD all;
	
	external function enc_PrimitiveContentXML(in PrimitiveContent pdu) return octetstring
	with { extension "prototype (convert) encode(XER:XER_EXTENDED)" }

	external function dec_PrimitiveContentXML(in octetstring pdu) return PrimitiveContent
	with { extension "prototype (convert) decode(XER:XER_EXTENDED)" }

	external function enc_PrimitiveContentJSON(in PrimitiveContent pdu) return octetstring
	with { extension "prototype (convert) encode(JSON)" }

	external function dec_PrimitiveContentJSON(in octetstring pdu) return PrimitiveContent
	with { extension "prototype (convert) decode(JSON)" }

	
testcase tc_codecTest() runs on CseTester system CseSystem {
		var RequestPrimitive v_primitive := valueof(m_createServiceSubscribedAppRule({"None"}, {PX_APP_ID}, {"C-AE-ID-STEM"}));
		log(v_primitive);
		var octetstring v_result :=enc_PrimitiveContentJSON(v_primitive.primitiveContent);
		log(v_result);
		v_result :=enc_PrimitiveContentXML(v_primitive.primitiveContent);
		log(v_result);


	}

control {

execute(tc_codecTest())

}


}



Which , when executed results in :

15:27:23.244584 Component type OneM2M_TestSystem.CseTester was initialized.
15:27:23.244856 Function rnd() returned 0.912226.
15:27:23.247558 { operation := int1 (1), to_ := "NotInitialized", from_ := "NotInitialized", requestIdentifier := "tc_codecTest-m_createServiceSubscribedAppRule912227", resourceType := int19 (19), primitiveContent := { serviceSubscribedAppRule_optional := { resourceName := omit, resourceType := omit, resourceID := omit, parentID := omit, creationTime := omit, lastModifiedTime := omit, labels := omit, accessControlPolicyIDs := omit, expirationTime := omit, dynamicAuthorizationConsultationIDs := omit, applicableCredIDs := { "None" }, allowedApp_IDs := { "myAppId" }, allowedAEs := { "C-AE-ID-STEM" }, allowedRole_IDs := omit, choice := omit } }, roleIDs := omit, originatingTimestamp := omit, requestExpirationTimestamp := omit, resultExpirationTimestamp := omit, operationExecutionTime := omit, responseType := omit, resultPersistence := omit, resultContent := omit, eventCategory := omit, deliveryAggregation := omit, groupRequestIdentifier := omit, filterCriteria := omit, discoveryResultType := omit, tokens := omit, tokenIDs := omit, localTokenIDs := omit, tokenRequestIndicator := omit }
15:27:23.256308 '7B22736572766963655375627363726962656441707052756C655F6F7074696F6E616C223A7B226170706C696361626C6543726564494473223A5B224E6F6E65225D2C22616C6C6F7765644170705F494473223A5B226D794170704964225D2C22616C6C6F776564414573223A5B22432D41452D49442D5354454D225D7D7D'O ("{\"serviceSubscribedAppRule_optional\":{\"applicableCredIDs\":[\"None\"],\"allowedApp_IDs\":[\"myAppId\"],\"allowedAEs\":[\"C-AE-ID-STEM\"]}}")
15:27:23.259801 '3C5072696D6974697665436F6E74656E7420786D6C6E733A6D326D3D27687474703A2F2F7777772E6F6E656D326D2E6F72672F786D6C2F70726F746F636F6C73273E0A093C6D326D3A736572766963655375627363726962656441707052756C655F6F7074696F6E616C3E0A09093C6170706C696361626C65437265644944733E4E6F6E653C2F6170706C696361626C65437265644944733E0A09093C616C6C6F7765644170702D4944733E6D7941707049643C2F616C6C6F7765644170702D4944733E0A09093C616C6C6F7765644145733E432D41452D49442D5354454D3C2F616C6C6F7765644145733E0A093C2F6D326D3A736572766963655375627363726962656441707052756C655F6F7074696F6E616C3E0A3C2F5072696D6974697665436F6E74656E743E0A0A'O ("<PrimitiveContent xmlns:m2m='http://www.onem2m.org/xml/protocols'>\n\t<m2m:serviceSubscribedAppRule_optional>\n\t\t<applicableCredIDs>None</applicableCredIDs>\n\t\t<allowedApp-IDs>myAppId</allowedApp-IDs>\n\t\t<allowedAEs>C-AE-ID-STEM</allowedAEs>\n\t</m2m:serviceSubscribedAppRule_optional>\n</PrimitiveContent>\n\n")
15:27:23.260746 Terminating component type OneM2M_TestSystem.CseTester.



Both codecs seem to work; Once the codecs are generated , they will probably work in a consistent manner.

Of course, the pertinent JSON variants will have to be added wherever necessary.


Best regards
Elemer



Re: Multiple encodings in Titan [message #1766450 is a reply to message #1766435] Wed, 21 June 2017 14:35 Go to previous message
Naum Spaseski is currently offline Naum SpaseskiFriend
Messages: 81
Registered: February 2016
Location: Sophia Antipolis
Member

Thank you Elemer, for the help. I added these variants, and it compiles and executes well with both codecs.

with{
	variant "untagged";
	variant(aEAnnc_optional) "JSON:name as aEAnnc_optional";
	variant(aE_optional) "JSON:name as aE_optional";
	variant(accessControlPolicy_optional) "JSON:name as accessControlPolicy_optional";
	variant(accessControlPolicyAnnc_optional) "JSON:name as accessControlPolicyAnnc_optional";
	variant(contentInstance_optional) "JSON:name as contentInstance_optional";
	variant(contentInstanceAnnc_optional) "JSON:name as contentInstanceAnnc_optional";
	variant(container_optional) "JSON:name as container_optional";
	variant(flexContainer_optional) "JSON:name as flexContainer_optional";
	variant(cSEBase_optional) "JSON:name as cSEBase_optional";
	variant(group_optional) "JSON:name as group_optional";
	variant(groupAnnc_optional) "JSON:name as groupAnnc_optional";
	variant(locationPolicy_optional) "JSON:name as locationPolicy_optional";
	variant(locationPolicyAnnc_optional) "JSON:name as locationPolicyAnnc_optional";
	variant(mgmtResource_optional) "JSON:name as mgmtResource_optional";
	variant(announcedMgmtResource_optional) "JSON:name as announcedMgmtResource_optional";
	variant(node_optional) "JSON:name as node_optional";
	variant(nodeAnnc_optional) "JSON:name as nodeAnnc_optional";
	variant(pollingChannel_optional) "JSON:name as pollingChannel_optional";
	variant(schedule_optional) "JSON:name as schedule_optional";
	variant(serviceSubscribedAppRule_optional) "JSON:name as serviceSubscribedAppRule_optional";
	variant(subscription_optional) "JSON:name as subscription_optional";
	variant(semanticDescriptor_optional) "JSON:name as semanticDescriptor_optional";
	variant(genericInterworkingOperationInstance_optional) "JSON:name as genericInterworkingOperationInstance_optional";
	variant(securityInfo) "JSON:name as securityInfo";
	variant(notification) "JSON:name as notification";
	variant(aggregatedNotification) "JSON:name as aggregatedNotification";
	variant(attributeList) "JSON:name as attributeList";
	variant(responsePrimitive) "JSON:name as responsePrimitive";
	variant(resource) "JSON:name as resource";
	variant(uRIList) "JSON:name as uRIList";
	variant(resourceRefList) "JSON:name as resourceRefList";
	variant(aggregatedResponse) "JSON:name as aggregatedResponse";
	variant(uRI) "JSON:name as uRI";
	variant(debugInfo) "JSON:name as debugInfo";
	variant(aE_update_invalid) "JSON:name as aE_update_invalid";
	variant(aCP_update_invalid) "JSON:name as aCP_update_invalid";
	variant(container_update_invalid) "JSON:name as container_update_invalid";
	variant(group_update_invalid) "JSON:name as group_update_invalid";
	variant(pollingChannel_update_invalid) "JSON:name as pollingChannel_update_invalid";
	variant(schedule_update_invalid) "JSON:name as schedule_update_invalid";
	variant(subscription_update_invalid) "JSON:name as subscription_update_invalid";
	variant(locationPolicy_update_invalid) "JSON:name as locationPolicy_update_invalid";
};


Best regards,
Naum
Previous Topic:Eclipse Titan 6.2.0 release announcement
Next Topic:Eclipse Titan available in Debian 9 and Ubuntu 17.04
Goto Forum:
  


Current Time: Thu Sep 20 14:10:54 GMT 2018

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

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

Back to the top