question

Upvote
Accepted
46 2 2 6

Decoding FieldList Contents with Field and Enumerated Types Dictionaries

It's not very clear from the docs HOW actually I can get decoded value from the dictionary.

For example the following request:

consumer.registerClient(EmaFactory.createReqMsg().domainType(6)
    .serviceName("ELEKTRON_EDGE").name("ADDYY.PQ"), appClient);

I receive

FieldEntry fid="15" name="CURRENCY" dataType="Enum" value="840"

How I can programmatically get corresponding value for 840 from enumtype.def dictionary? (840 "USD" US dollar)

elektronrefinitiv-realtimeelektron-sdkema-apirrtelektron-message-api
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hi dzmitry_shylovich. Thank you for your participation in the forum.

Is the reply below satisfactory in resolving your query?

If so please can you click the 'Accept' text next to the appropriate reply. This will guide all community members who have a similar question.

Thanks

AHS

Please be informed that a reply has been verified as correct in answering the question, and has been marked as such.
Thanks,
AHS

Upvote
Accepted
9.6k 10 7 7

EMA Java does not provide interface to get decoded enum value. EMA Java keeps the dictionaries (RDMFieldDictionary and enumtype.def) internally. However, EMA Java is open source so you can modify it to get decoded enum value according to the enum dictionary it has loaded as example shown below:

OmmEnum.java– add getEnum() method

public com.thomsonreuters.upa.codec.Enum getEnum();

OmmEnumImpl.java– implement getEnum() method

@Override
public com.thomsonreuters.upa.codec.Enum getEnum()
{
return _rsslEnum;
}

FieldEntry.java– add enumText() method

public String enumText();

FieldEntryImpl.java– implement enumText() to get decoded enum value according to enum dictionary

@Override
import com.thomsonreuters.upa.codec.EnumType;
…
public String enumText() {
OmmEnum aEnum= ((OmmEnum)_load);
EnumType enumType =_fieldList._rsslDictionary.entryEnumType(_rsslDictionaryEntry,aEnum.getEnum());
if(enumType==null) {
String errText = errorString().append("Attempt to enumText() while value(" )
.append(String.valueOf(aEnum.enumValue())).append(") is not found in enumtype.def").toString();
throw ommIUExcept().message(errText);
}
else
return enumType.display().toString();
}
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

This is a good way to convert the enum value to text. Wanted to state that the proposed solution goes against the EMA established decoding rules. Throwing exception when the enum text is not found in the dictionary on the decoding path is "frowned upon" due to the Java performance implications. The OmmError class should be used instead. Handling of this situation is tricky since it is unclear what caused the error: network glitch, wrong dictionary, or anything else. Blindly converting the OmmEnum into the OmmError may bring "wrong" consequences to apps that do not care about the enum text.

Upvotes
1.2k 23 31 44

It does not appear EMA supports enumerated types properly, it is possible with ETA.

EnumType enumType = dictionary.entryEnumType(dictionaryEntry, fidEnumValue);
System.out.println (enumType.display().toString());

You have the enum value in EMA but the dictionary is completely hidden.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

the ETA and RFA do provide means for enum value to text conversion. The EMA is planning to add a similar capability too.

Upvote
9.6k 10 7 7

The example to use enumText() which source code is above:

System.out.print("Fid: " + fieldEntry.fieldId() + " Name = " + fieldEntry.name() + " DataType: " + DataType.asString(fieldEntry.load().dataType()) + " Value: ");
...
case DataTypes.ENUM :
System.out.println(fieldEntry.enumValue() + "(" + fieldEntry.enumText()+")");
break;

The example output:

Fid: 15 Name = CURRENCY DataType: Enum Value: 840(USD)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
942 8 9 13

Hi @dzmitry_shylovich,

The Elektron SDK team just released a new version ("Elektron SDK - Java - 1.1.0" available for download here) that implements the features you need. The FieldEntry::getEnumDisplay() method gives you access to String representations of Enum values. This new SDK also allows you to get access to the internal EMA dictionary. I did not test these features yet but they seem promising.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.