Closed mikeb01 closed 7 years ago
@mikeb01 Have you considered using the fromIndex
to grab the BEGIN_COMPOSITE token from the list of tokens passed in the callback?
Okay, I see now. Will test on Monday. I'll look to push a change for the wiki to make ir clearer.
The field token is important for when you have multiple fields using the same composite type in a message.
BTW this behaviour is similar for the other types. You get the field token then the valid range of tokens to describe the type.
Yep, I get it now. All of the information is there. The small oddity is having to deal with difference between when you a composite used in a field of a message and when it is used inside of another composite type.
E.g. on the ExecutionReport.orderState field
fieldToken.name = orderState
tokens.get(fromIndex).name = EvOrderState
tokens.get(fromIndex).referencedName = null
Then when at EvOrderState.account
fieldToken.name = orderState
tokens.get(fromIndex).name = account
tokens.get(fromIndex).referencedName = AccountKey
I was hoping to use fieldToken.name all the way down, but it continues to hold the field from the message (should of read the ExampleTokenListener in more detail).
So if you wanted to build a string representation of a path to a particular value, you need to track the whether an encoding is nested inside of a message or another composite to look up either the field or ref as appropriate. And the name of the type moves from the tokens.get(fromIndex).name
to tokens.get(fromIndex).referencedName
.
I'm guessing this stems from the committee's decision to distinguish between messages and composite types rather than just having types that can be composed.
I'll look at updating the Wiki to describe this scenario.
Yes the main issue here is composites are not really types and kind of a hybrid macro/type. In my view everything should be a type including messages and thus would compose much better. A repeating group should just be another message for example. Setting that aside and we cannot change the past.
It is worth considering Token.applicableName()
that takes account for if the name is a reference or the name of the type itself.
That would be really useful. Would this be called on the BEGIN_COMPOSITE (tokens.get(fromIndex))
token or the fieldToken?
@mikeb01 I don't understand the question. Can you try in a different form?
The referencedName
is to cover for when the ref
type is used in a composite. This way two or more members with the same type can be included but with different names as given in the ref type. The applicableName
is the ref name if available otherwise it is the name of the type.
Ignore my question. I was misunderstanding what applicableName would be useful for.
When using the OftMessageDecoder, which the
TokenListener.onBeginComposite()
callback the fieldToken supplied is the BEGIN_FIELD token for the field of the message that the decoder is currently at. However it would be useful if the BEGIN_COMPOSITE token was also available. Otherwise it is difficult to figure out where within a nested composite the value that you have arrived at is contained. See below for an example:Given the following definition, with a nested composite.
If I print out the information about the location of the various encodings, using the code below the name of the field token supplied will always been the name of the field of the message, making it difficult to determine if the current encoding is from an AccountKey composite type.
Output