0

After adding nested message i recieve nested messages from main message and got nothing.

You can see it in logs: 1 and 2. Size of List 0 !

Any ideas?

message PacketPlayers
{
    repeated PacketPlayer players = 1;
}

enter image description here

Eldar Nezametdinov
  • 1,917
  • 4
  • 21
  • 23
  • is your PacketPlayers.players a mutable or an immutable List? – Samar Sep 12 '16 at 17:41
  • @Samar it's immutable seq by default, can't change – Eldar Nezametdinov Sep 12 '16 at 17:41
  • Is PacketPlayers.players a val or a var, can you show the code for your PacketPlayers class? Also, its better if you paste your code instead of pasting png's. You will get more responses. – Samar Sep 12 '16 at 18:00
  • @Samar val or var doesn't matter because class cointains immutable collection. Code for PacketPlayer is autogenerated from Proto3. Nothing interesting there for humans. I found solution and it was very obvious :( Rearranged code, made a mutable collection with nested messages and sent it(collection) to constructor. Thanks for answering anyway! :) – Eldar Nezametdinov Sep 12 '16 at 18:05

1 Answers1

1

ScalaPB case classes are immutable. In your example, addPlayers would not modify the instance it's called on, but return a new instance of PacketPlayer that has the additional players.

It is possible to avoid mutable arrays and vars in constructing the new object. For example:

val players = onlinePlayers.keySet.map(makePacketPlayer)
val packetPlayers = PacketPlayers().withPlayers(players)
thesamet
  • 6,382
  • 2
  • 31
  • 42