package com.rosetta.messenger.network

class PacketGroupInfo : Packet() {
    var groupId: String = ""
    var members: List<String> = emptyList()

    override fun getPacketId(): Int = 0x12

    override fun receive(stream: Stream) {
        groupId = stream.readString()
        val count = stream.readInt16().coerceAtLeast(0)
        val parsed = ArrayList<String>(count)
        repeat(count) {
            parsed.add(stream.readString())
        }
        members = parsed
    }

    override fun send(): Stream {
        val stream = Stream()
        stream.writeInt16(getPacketId())
        stream.writeString(groupId)
        stream.writeInt16(members.size)
        members.forEach { member -> stream.writeString(member) }
        return stream
    }
}
