using System.Collections.Generic; namespace MLAgents { public class RawBytesChannel : SideChannel { private List m_MessagesReceived = new List(); private int m_ChannelId; /// /// RawBytesChannel provides a way to exchange raw byte arrays between Unity and Python. /// /// The identifier for the RawBytesChannel. Must be /// the same on Python and Unity. public RawBytesChannel(int channelId = 0) { m_ChannelId = channelId; } public override int ChannelType() { return (int)SideChannelType.RawBytesChannelStart + m_ChannelId; } public override void OnMessageReceived(byte[] data) { m_MessagesReceived.Add(data); } /// /// Sends the byte array message to the Python side channel. The message will be sent /// alongside the simulation step. /// /// The byte array of data to send to Python. public void SendRawBytes(byte[] data) { QueueMessageToSend(data); } /// /// Gets the messages that were sent by python since the last call to /// GetAndClearReceivedMessages. /// /// a list of byte array messages that Python has sent. public IList GetAndClearReceivedMessages() { var result = new List(); result.AddRange(m_MessagesReceived); m_MessagesReceived.Clear(); return result; } /// /// Gets the messages that were sent by python since the last call to /// GetAndClearReceivedMessages. Note that the messages received will not /// be cleared with a call to GetReceivedMessages. /// /// a list of byte array messages that Python has sent. public IList GetReceivedMessages() { var result = new List(); result.AddRange(m_MessagesReceived); return result; } } }