public void TestMessageReadWrites()
        {
            var boolVal      = true;
            var intVal       = 1337;
            var floatVal     = 4.2f;
            var floatListVal = new float[] { 1001, 1002 };
            var stringVal    = "mlagents!";

            IncomingMessage incomingMsg;

            using (var outgoingMsg = new OutgoingMessage())
            {
                outgoingMsg.WriteBoolean(boolVal);
                outgoingMsg.WriteInt32(intVal);
                outgoingMsg.WriteFloat32(floatVal);
                outgoingMsg.WriteString(stringVal);
                outgoingMsg.WriteFloatList(floatListVal);

                incomingMsg = new IncomingMessage(outgoingMsg.ToByteArray());
            }

            Assert.AreEqual(boolVal, incomingMsg.ReadBoolean());
            Assert.AreEqual(intVal, incomingMsg.ReadInt32());
            Assert.AreEqual(floatVal, incomingMsg.ReadFloat32());
            Assert.AreEqual(stringVal, incomingMsg.ReadString());
            Assert.AreEqual(floatListVal, incomingMsg.ReadFloatList());
        }
 public void SendString(string message)
 {
     using (var msgOut = new OutgoingMessage())
     {
         msgOut.WriteString(message);
         QueueMessageToSend(msgOut);
     }
 }
 public void SendEnvInfoToPython(string info)
 {
     using (var msgOut = new OutgoingMessage())
     {
         msgOut.WriteString(info);
         QueueMessageToSend(msgOut);
     }
 }
Example #4
0
    public void SendPathsToPython(string modelPath, string inputPath)
    {
        var stringToSend = modelPath + "\n" + inputPath;

        using (var msgOut = new OutgoingMessage())
        {
            msgOut.WriteString(stringToSend);
            QueueMessageToSend(msgOut);
        }
    }
Example #5
0
 public void SendDebugStatementToPython(string logString, string stackTrace, LogType type)
 {
     if (type == LogType.Error)
     {
         var stringToSend = type.ToString() + ": " + logString + "\n" + stackTrace;
         using (var msgOut = new OutgoingMessage())
         {
             msgOut.WriteString(stringToSend);
             QueueMessageToSend(msgOut);
         }
     }
 }
        /// <summary>
        /// Sends a message to a remote connection. Default channel = 0
        /// </summary>
        public void RegisterHosting()
        {
            OutgoingMessage regMessage = MessagePool.CreateMessage();
            IPAddress       local      = NetUtilities.GetLocalAddress();

            regMessage.Write(NATMessageType.INITIATE_HOST);
            regMessage.WriteString("hello");

            fixed(byte *bytes = regMessage.Data)
            {
                ENet.MicroSend(Peer, 0, bytes, (IntPtr)regMessage.ByteCount, DeliveryMethod.Reliable);
            }

            MessagePool.Recycle(regMessage);
        }
Example #7
0
        public void GaussianSamplerTest()
        {
            float  mean      = 3.0f;
            float  stddev    = 0.2f;
            string parameter = "parameter2";

            using (var outgoingMsg = new OutgoingMessage())
            {
                outgoingMsg.WriteString(parameter);
                // 1 indicates this meessage is a Sampler
                outgoingMsg.WriteInt32(1);
                outgoingMsg.WriteInt32(k_Seed);
                outgoingMsg.WriteInt32((int)SamplerType.Gaussian);
                outgoingMsg.WriteFloat32(mean);
                outgoingMsg.WriteFloat32(stddev);
                byte[] message = GetByteMessage(m_Channel, outgoingMsg);
                SideChannelManager.ProcessSideChannelData(message);
            }
            Assert.AreEqual(2.936162f, m_Channel.GetWithDefault(parameter, 1.0f), k_Epsilon);
            Assert.AreEqual(2.951348f, m_Channel.GetWithDefault(parameter, 1.0f), k_Epsilon);
        }
Example #8
0
        public void UniformSamplerTest()
        {
            float  min_value = 1.0f;
            float  max_value = 2.0f;
            string parameter = "parameter1";

            using (var outgoingMsg = new OutgoingMessage())
            {
                outgoingMsg.WriteString(parameter);
                // 1 indicates this meessage is a Sampler
                outgoingMsg.WriteInt32(1);
                outgoingMsg.WriteInt32(k_Seed);
                outgoingMsg.WriteInt32((int)SamplerType.Uniform);
                outgoingMsg.WriteFloat32(min_value);
                outgoingMsg.WriteFloat32(max_value);
                byte[] message = GetByteMessage(m_Channel, outgoingMsg);
                SideChannelManager.ProcessSideChannelData(message);
            }
            Assert.AreEqual(1.208888f, m_Channel.GetWithDefault(parameter, 1.0f), k_Epsilon);
            Assert.AreEqual(1.118017f, m_Channel.GetWithDefault(parameter, 1.0f), k_Epsilon);
        }
Example #9
0
        public void MultiRangeUniformSamplerTest()
        {
            float[] intervals = new float[4];
            intervals[0] = 1.2f;
            intervals[1] = 2f;
            intervals[2] = 3.2f;
            intervals[3] = 4.1f;
            string parameter = "parameter3";

            using (var outgoingMsg = new OutgoingMessage())
            {
                outgoingMsg.WriteString(parameter);
                // 1 indicates this meessage is a Sampler
                outgoingMsg.WriteInt32(1);
                outgoingMsg.WriteInt32(k_Seed);
                outgoingMsg.WriteInt32((int)SamplerType.MultiRangeUniform);
                outgoingMsg.WriteFloatList(intervals);
                byte[] message = GetByteMessage(m_Channel, outgoingMsg);
                SideChannelManager.ProcessSideChannelData(message);
            }
            Assert.AreEqual(3.387999f, m_Channel.GetWithDefault(parameter, 1.0f), k_Epsilon);
            Assert.AreEqual(1.294413f, m_Channel.GetWithDefault(parameter, 1.0f), k_Epsilon);
        }