IBM Support

How can basic_string <wchar_t> be encoded and decoded?

Troubleshooting


Problem

How can basic_string be encoded and decoded?

Resolving The Problem

QUESTION:

How can basic_string <wchar_t> be encoded and decoded?


ANSWER:

Basic types have a "TypeDescriptor" which tells the Services Library information about the type so it can manipulate the objects in order to send them or use them in the UML debugger. If a class has attributes that are all basic types then a TypeDescriptor can be generated by Rose RealTime. The wchar_t does not have a predefined TypeDescriptor and it's attributes are not basic types, so the user is required to provide a way to encode and decode the type. This solution provides detailed information on how to do this, with examples, and some tips on dealing with wchar_t with distributed Connexis models.

Below is an example of encoding and decoding basic_string <wchar_t> with and without Connexis and the suggested procedure when encoding and decoding any class.

Goal - To encode and decode the type basic_string <wchar_t>. This is a string of wide (2 byte) characters, known as unicode.

Limitations -

1) The internal structure of the basic_string <wchar_t> class is not known. If the class members were known, and attributes were all types that are sendable by value and observable (encode), the toolset could generate a complete TypeDescriptor for this class. See the online help under C++ / C++ Reference / Classes and Data Types / C++ Data Type Examples / Integration Options. Since the internal structure is not known, a typedef will be used and the TypeDescriptor methods will be written.

2) Rose RealTime uses ASCII encoding to log data to an output window to watch an attribute in a watch window and to inject data from a probe. Therefore, when watching or logging, the result will not look like unicode characters. Rather each character will look like a short integer. Also, when injecting data, the ASCII format must be used.


Non-Connexis model -

Ideally we would like to create a small model that encodes and decodes the class. The problem is when data is sent between threads (i.e. intra-process) there is no need to encode and decode the data. The data could be logged to encode the data and injected from a probe to decode the it. However this is time consuming and requires user intervention.

We could begin with a Connexis model. However if a problem occurs it is much more difficult to determine where the problem is. For example, if the user sees invalid data at the receiver's end after decoding, is the problem that it was not encoded properly in the sender process or is the problem with the decoding in the receiver process?

A solution 24378 has been written which includes a simple model that allows the user to encode and decode an object within the same process. The non-Connexis model below was created using this solution as a starting point. This model has an element that is a typedef to basic_string <wchar_t>. In the C++ TargetRTS tab, all five TypeDescriptor methods have been specified, as is necessary for every typedef that needs to be encoded/decoded in Rose RealTime. The EncodeFunctionBody encodes the size of the WString and then encodes the WString contents. The DecodeFunctionBody retrieves the size of the WString, creates a WString of the correct size and populates it with the decoded information.

The model ASCII encodes the object, prints it to the console, then decodes the encoded information and logs the decoded information to the console which will again encode it. Since it is all in the same process, it is easier to debug and tools such as Purify can easily be utilized to check for memory leaks.


Connexis model -

Now that the ASCII encoding/decoding works in the simple model, the class can be tested in a Connexis model. By default Connexis uses CDR encoding. CDR is faster than ASCII. On the other hand, ASCII is easier to debug. If the ASCII encoding/decoding works in the non-Connexis model it should work in the Connexis model using CDR. If it does not work, try changing the Connexis model to use ASCII encoding/decoding. See the online help under Connexis User's Guide / Connexis Command Line Options / Miscellaneous Command Line Options and look for the option (-CNXtde=1). If it works under ASCII encoding/decoding but not under CDR, please contact customer support.





[{"Product":{"code":"SSSHKL","label":"Rational Rose RealTime"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"--","Platform":[{"code":"PF033","label":"Windows"}],"Version":"2002.05.20","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]

Historical Number

157129855

Document Information

Modified date:
16 June 2018

UID

swg21132407