//..............................................................................
//
// UDP log representer
//

import "io_base.jncx"
import "io_SocketAddress.jnc"
import "log_Representation.jnc"

//..............................................................................

bool representUdpLog(
	log.Representation* representation,
	uint64_t recordCode,
	void const* p,
	size_t size,
	uint_t foldFlags
) {
	switch (recordCode) {
	case UdpLogRecordCode.TxPacket:
		io.SocketAddress const* address = (io.SocketAddress const*)p;

		representation.m_lineAttr.m_iconIdx = log.StdLogIcon.TxPacket;
		representation.m_lineAttr.m_backColor = ui.StdColor.PastelGray;
		representation.addHyperText($"To \e[34m%1"(address.getString()));
		break;

	case UdpLogRecordCode.RxPacket:
		io.SocketAddress const* address = (io.SocketAddress const*)p;

		representation.m_lineAttr.m_iconIdx = log.StdLogIcon.RxPacket;
		representation.m_lineAttr.m_backColor = ui.StdColor.PastelGray;
		representation.addHyperText($"From \e[34m%1"(address.getString()));
		break;

	case UdpLogRecordCode.TxPacketEx:
		uint32_t packetSize = *(uint32_t const*)p;
		io.SocketAddress const* address = (io.SocketAddress const*)(p + sizeof(uint32_t));

		representation.m_lineAttr.m_iconIdx = log.StdLogIcon.TxPacket;
		representation.m_lineAttr.m_backColor = ui.StdColor.PastelGray;
		representation.addHyperText($"To \e[34m%1\e[m (%2 bytes)"(
			address.getString(),
			packetSize
		));
		break;

	case UdpLogRecordCode.RxPacketEx:
		uint32_t packetSize = *(uint32_t const*)p;
		io.SocketAddress const* address = (io.SocketAddress const*)(p + sizeof(uint32_t));

		representation.m_lineAttr.m_iconIdx = log.StdLogIcon.RxPacket;
		representation.m_lineAttr.m_backColor = ui.StdColor.PastelGray;
		representation.addHyperText($"From \e[34m%1\e[m (%2 bytes)"(
			address.getString(),
			packetSize
		));
		break;

	default:
		return false;
	}

	return true;
}

//..............................................................................
