Eldar Nezametdinov Eldar Nezametdinov - 1 year ago 127
Scala Question

How to add nested message into already created message ? (in Scala)

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

Answer Source

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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download