0

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
}
David Teh
  • 61
  • 5

1 Answers1

0

If you use an interface via the values module, the elements of the array also need to be values so they can be flyweights as well. Without this information, it can't determine how large the elements of the array will be.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • From what I understood, I just have to declare an interface with the getter and setters to make it a Value Interface. Edited my question to include the array element interface. The code in the first block works. My question is that if it is possible to have methods that have Array as their return type/takes Array as their arg in a Value Interface like the snippet in the 2nd code block in my question – David Teh Jul 11 '22 at 11:30