So, I have a Value Interface with these array field getter and setter methods, which works
interface Instrument: Marshallable {
...
fun setBidAt(index: Int, entry: OrderBookEntry)
@Array(length = 10)
fun getBidAt(index: Int): OrderBookEntry
}
interface OrderBookEntry: Marshallable{
var level: Int
var quantity: Long
var price: Double
var orders: Long
var side: OrderBookSide
}
However, I want a getter and setter that interact with the whole Array, something like:
interface Instrument: Marshallable {
...
fun setBids(entries: kotlin.Array<OrderBookEntry>)
@Array(length = 20)
fun getBids(): kotlin.Array<OrderBookEntry>
}
but as expected encountered some exceptions:
java.lang.IllegalStateException: bids field type class [Lme.oms.instrument.OrderBookEntry; is not supported: not a primitive, enum, CharSequence or another value interface
Now, does this mean that I can't leverage Chronicle Value Interface and have to create a custom class to achieve this? I have tried to look in both ChronicleValues and ChronicleMap test cases, seems like there is no test for this scenario?
EDIT: I managed to find a workaround by leveraging kotlin's extension function:
fun Instrument.getAsks(): kotlin.Array<OrderBookEntry>{
val array = arrayOf<OrderBookEntry>()
for (i in (0 until OrderBookMaxSize)) {
array[i] = getAskAt(i)
}
return array
}
If you use an interface via the
valuesmodule, the elements of the array also need to bevaluesso they can be flyweights as well. Without this information, it can't determine how large the elements of the array will be.