module StatsD_CodecPort {

import from StatsD_Types all;
import from IPL4asp_PortType all;
import from IPL4asp_Types all;

type record StatsD_RecvFrom {
	ConnectionId	connId,
	HostName		remName,
	PortNumber		remPort,
	HostName		locName,
	PortNumber		locPort,
	StatsDMessage	msg
}

template StatsD_RecvFrom tr_StatsD_RecvFrom(template ConnectionId cid, template StatsDMessage msg) := {
	connId := cid,
	remName := ?,
	remPort := ?,
	locName := ?,
	locPort := ?,
	msg := msg
}

type record StatsD_Send {
	ConnectionId	connId,
	StatsDMessage	msg
}

private function IPL4_to_StatsD_RecvFrom(in ASP_RecvFrom pin, out StatsD_RecvFrom pout) {
	pout.connId := pin.connId;
	pout.remName := pin.remName;
	pout.remPort := pin.remPort;
	pout.locName := pin.locName;
	pout.locPort := pin.locPort;
	pout.msg := dec_StatsDMessage(oct2char(pin.msg));
} with { extension "prototype(fast)" };

private function StatsD_to_IPL4_Send(in StatsD_Send pin, out ASP_Send pout) {
	pout.connId := pin.connId;
	pout.proto := { udp := {} };
	pout.msg := char2oct(enc_StatsDMessage(pin.msg));
} with { extension "prototype(fast)" };

type port STATSD_CODEC_PT message {
	out	StatsD_Send;
	in	StatsD_RecvFrom,
		ASP_ConnId_ReadyToRelease,
		ASP_Event;
} with { extension "user IPL4asp_PT
	out(StatsD_Send -> ASP_Send: function(StatsD_to_IPL4_Send))
	in(ASP_RecvFrom -> StatsD_RecvFrom: function(IPL4_to_StatsD_RecvFrom);
	   ASP_ConnId_ReadyToRelease -> ASP_ConnId_ReadyToRelease: simple;
	   ASP_Event -> ASP_Event: simple)"
}

}
