using System;
namespace Unity.MLAgents.SideChannels
{
///
/// A Side Channel for sending data.
///
internal class StatsSideChannel : SideChannel
{
const string k_StatsSideChannelDefaultId = "a1d8f7b7-cec8-50f9-b78b-d3e165a78520";
///
/// Initializes the side channel. The constructor is internal because only one instance is
/// supported at a time.
///
internal StatsSideChannel()
{
ChannelId = new Guid(k_StatsSideChannelDefaultId);
}
///
/// Add a stat value for reporting.
///
/// The stat name.
/// The stat value.
/// How multiple values should be treated.
public void AddStat(string key, float value, StatAggregationMethod aggregationMethod)
{
using (var msg = new OutgoingMessage())
{
msg.WriteString(key);
msg.WriteFloat32(value);
msg.WriteInt32((int)aggregationMethod);
QueueMessageToSend(msg);
}
}
///
protected override void OnMessageReceived(IncomingMessage msg)
{
throw new UnityAgentsException("StatsSideChannel should never receive messages.");
}
}
}